The get function is used to return the internal ID of a class, given its class ID. The get function increments the usage count of the class. As an example, let us take a look at the cbq_get function in net/sched/sch_cbq.c.
static unsigned long cbq_get(struct Qdisc *sch, u32 classid)
{
struct cbq_sched_data *q = (struct cbq_sched_data *)sch->data;
struct cbq_class *cl = cbq_class_lookup(q, classid);
if (cl) {
cl->refcnt++;
return (unsigned long)cl;
}
return 0;
}
static __inline__ struct cbq_class *
cbq_class_lookup(struct cbq_sched_data *q, u32 classid)
{
struct cbq_class *cl;
for (cl = q->classes[cbq_hash(classid)]; cl; cl = cl->next)
if (cl->classid == classid)
return cl;
return NULL;
}
As shown in this function, the get function calls the cbq_class_lookup function to map the class ID to the internal ID. The cbq_class_lookup function searches the list of classes to determine the class with the specified class ID and return a pointer to the corresponding cbq_class structure, which contains the internal ID of the class, in addition to other information. The get function is invoked in the tc_ctl_tclass function in net/sched/sch_api.c. The tc_ctl_tclass function is invoked whenever an attempt is made to create, delete or change a class.