黎明748 发表于 2014-08-14 15:02

tc class的 parent 和classid参数疑问

// 以下是tc class的parent参数取值的说明
    parent == TC_H_UNSPEC - unspecified parent.
    parent == TC_H_ROOT   - class is root, which has no parent.
    parent == X:0- parent is root class.
    parent == X:Y- parent is a node in hierarchy.
    parent == 0:Y- parent is X:Y, where X:0 is qdisc.
// 以下是tc class的classid参数取值的说明
    handle == 0:0- generate handle from kernel pool.
    handle == 0:Y- class is X:Y, where X:0 is qdisc.
    handle == X:Y- clear.
    handle == X:0- root class.
*/


static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
{
        struct tcmsg *tcm = NLMSG_DATA(n);
        struct rtattr **tca = arg;
        struct net_device *dev;
        struct Qdisc *q = NULL;
        struct Qdisc_class_ops *cops;
        unsigned long cl = 0;
        unsigned long new_cl;
        u32 pid = tcm->tcm_parent;
        u32 clid = tcm->tcm_handle;
        u32 qid = TC_H_MAJ(clid);
        int err;

        if ((dev = __dev_get_by_index(tcm->tcm_ifindex)) == NULL)
                return -ENODEV;

        /*
           parent == TC_H_UNSPEC - unspecified parent.
           parent == TC_H_ROOT   - class is root, which has no parent.
           parent == X:0       - parent is root class.
           parent == X:Y       - parent is a node in hierarchy.
           parent == 0:Y       - parent is X:Y, where X:0 is qdisc.

           handle == 0:0       - generate handle from kernel pool.
           handle == 0:Y       - class is X:Y, where X:0 is qdisc.
           handle == X:Y       - clear.
           handle == X:0       - root class.
       */

        /* Step 1. Determine qdisc handle X:0 */

        if (pid != TC_H_ROOT) {
                u32 qid1 = TC_H_MAJ(pid);

                if (qid && qid1) {
                        /* If both majors are known, they must be identical. */
                        if (qid != qid1)
                                return -EINVAL;
                } else if (qid1) {
                        qid = qid1;
                } else if (qid == 0)
                        qid = dev->qdisc_sleeping->handle;

                /* Now qid is genuine qdisc handle consistent
                   both with parent and child.

                   TC_H_MAJ(pid) still may be unspecified, complete it now.
               */
                if (pid)
                        pid = TC_H_MAKE(qid, pid);
        } else {
                if (qid == 0)
                        qid = dev->qdisc_sleeping->handle;
        }

弄不明白啊。有谁知道的吗
页: [1]
查看完整版本: tc class的 parent 和classid参数疑问