next up previous
Next: Dump Up: Filters Previous: Delete

Walk

The walk function on a filter is used to iterate over all the elements of a filter and invokes a callback function for each of the elements. This is usually used to obtain diagnostic data for all the elements of a filter. For example, let us take a look at the tcindex_walk function in net/sched/cls_tcindex.c.

static void tcindex_walk(struct tcf_proto *tp, struct tcf_walker *walker)
{
 struct tcindex_data *p = PRIV(tp);
 struct tcindex_filter *f;
 int i;

 for (i = 0; i < HASH_SIZE; i++)
  for (f = p->h[i]; f; f = f->next) {
   if (walker->count >= walker->skip)
    if (walker->fn(tp,(unsigned long) f,walker) < 0) {
      walker->stop = 1;
      return;
    }
    walker->count++;
  }
}

This portion of the code shows that the walk command iterates over all the filters of a specified filter and invokes a callback function. The walk function is called from the tc_dump_tfilter function in net/sched/cls_api.c, which is invoked when a dump request is made on all the filters. The portion of the code in tc_dump_tfilter that does this shown below:

static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
{
struct tcf_proto *tp, **chain;
.
for (tp=*chain, t=0; tp; tp = tp->next, t++) {
.
.
 if (tp->ops->walk == NULL) continue;
 tp->ops->walk(tp, &arg.w);
}
.
.

The callback function maps to the tcf_node_dump function in the same file. In tcf_node_dump, the tcf_fill_node function is invoked, which calls the dump function on all the filters. The dump function on a filter, which is discussed later is used to dump statistical information about the filter.



Saravanan Radhakrishnan
1999-09-30