next up previous
Next: Destroy Up: Filters Previous: Classify


The init function on a filter is used to initialize the parameters for a filter. As an example, let us take a look at the tcindex_init function in net/sched/cls_tcindex.c, which is used to initialize the parameters for a tcindex classifier.

static int tcindex_init(struct tcf_proto *tp)
  struct tcindex_data *p;

  p = kmalloc(sizeof(struct tcindex_data),GFP_KERNEL);
  if (!p) {
    return -ENOMEM;
  tp->root = p;
  p->mask = 0xffff;
  p->shift = 0;
  p->fall_through = 1;
  return 0;
The tcindex_data structure, the definition of which is available in the same file, is initialized in the tcindex_init function. The mask and the shift, which are used in combination to determine a handle are set to 0xffff and 0 respectively. The details of the tcindex classifier are discussed in more detail later. The init function is invoked from the tc_ctl_tfilter function in net/sched/cls_api.c, which is called whenever a filter is added, deleted or changed.

Saravanan Radhakrishnan