next up previous
Next: Walk Up: Filters Previous: Change

Delete

The delete function on a filter is used to delete a particular element of the filter. As was discussed previously, to delete the entire filter, the destroy function on the filter is invoked. As in the case of the destroy function, the delete function results in an unbind_tcf function being called on the class to which the element is attached. The policer attached to the element is also removed. As an example, let us take a look at the tcindex_delete function in net/sched/cls_tcindex.c.

static int tcindex_delete(struct tcf_proto *tp, unsigned long arg)
{
.
.
 for (walk = p->h+HASH(f->key); *walk && *walk != f;
  walk = &(*walk)->next);
 if (!*walk) return -ENOENT;
 *walk = f->next;
 cl = xchg(&f->res.class,0);
 if (cl) tp->q->ops->cl_ops->unbind_tcf(tp->q,cl);
.
 tcf_police_release(f->police);
.
.
}

This function searches for the internal element in a filter by walking through the filter, and after determining this, makes the class 0 (the xchg function does this) and calls the unbind_tcf function to detach itself from the class. After this, it also releases the policer, if any, that is attached to the element. The distinction between the delete on an element and a destroy on a filter is made in the tc_ctl_tfilter function. The following portion of code from tc_ctl_tfilter will make this evident:

fh = tp->ops->get(tp, t->tcm_handle);

if (fh == 0) {
 if (n->nlmsg_type == RTM_DELTFILTER && t->tcm_handle == 0) {
  *back = tp->next;
  tp->ops->destroy(tp);
  kfree(tp);
  err = 0;
  goto errout;
}
.
.

switch (n->nlmsg_type) {
.
.

 case RTM_DELTFILTER:
     err = tp->ops->delete(tp, fh);
     goto errout;

}
.
.

The get function is used to obtain the internal ID for the filter. As mentioned earlier in this section, a filter has a handle of zero, while the internal elements are identified by the handles. If the internal ID returned by the get function is zero, and if the DELETE option is specified, then it can be concluded that a filter needs to be destroyed. If the handle returned is not zero, then it can be concluded that a particular element of the filter needs to be deleted.


next up previous
Next: Walk Up: Filters Previous: Change
Saravanan Radhakrishnan
1999-09-30