next up previous
Next: Init Up: Filters Previous: Filters

Classify

The classify function on a filter is used to match a packet to a class based on certain properties of the packet. The result of any classification can be one of four return values from the policing function tcf_police in net/sched/police.c, namely TC_POLICE_UNSPEC, TC_POLICE_OK, TC_POLICE_RECLASSIFY or TC_POLICE_SHOT. The policer is discussed in more detail in the next section. At this point, it is enough to understand that the tc_classify function returns TC_POLICE_UNSPEC when no matching filter is found for the packet. If not, the classifier fills in the tcf_result structure (defined in include/net/pkt_cls.h) and returns it. The tcf_result structure contains the internal ID as well as the class ID of the class to which the packet belongs. As an example, let us look into the route_classify function in net/sched/cls_route.c.

static int route_classify(struct sk_buff *skb, struct tcf_proto *tp,
                          struct tcf_result *res)
{               
 struct dst_entry *dst = skb->dst;

 if (dst) { 
  u32 clid = dst->tclassid; 
                      
  if (clid && (TC_H_MAJ(clid) == 0 ||
    !(TC_H_MAJ(clid^tp->q->handle)))) {
        res->classid = clid;
        res->class = 0;
        return 0;
    }
  }
  return -1;
}

The route classifier classifies packets based on the destination IP address. In the route_classify function, the destination is associated with a dst_entry structure (in include/net/dst.h). The class ID of the class is stored in the tclassid field of the dst_entry structure. If the destination to which the packet needs to be sent is determined, the corresponding class ID is returned in the tcf_result structure. In general, the filters are also associated with policers, to determine if a flow is in profile. Having discussed the classify function, let us now discuss the init function of a filter.


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