cgroup classifier problem

Gilles Dejaegere gilles.dejaegere at mail.polimi.it
Thu May 5 01:03:27 PDT 2016


Dear All,

I have some trouble making a "cgroup classifier". When trying to add  them, I always get an "Unable to add cls: Invalid input data or  parameter" answer. I am trying to do the same as these two commands :  "tc qdisc add dev eth10 root handle 10: htb default 1" and "tc filter add dev eth10 parent 10: protocol ip prio 10 handle 1  cgroup". I did not succeed to make my code work. I suspect that the  problem comes from the handle attribute for two reasons. First of all,  it is the only attribute that when removed changes the error in "Missing attribute". And secondly, when I try to make a  "u32" instead of "cgroup" classifier, I can simply remove this attribute  and everything will work fine. 
I have tried changing the values of both the classifier and the parent qdisc but nothing works.

Here is the code : 


#include <stdio.h>
#include <linux/if_ether.h>

#include <netlink/netlink.h>
#include <netlink/socket.h>
#include <netlink/cache.h>
#include <netlink/route/link.h>
#include <netlink/route/addr.h>
#include <netlink/route/qdisc.h>
#include <netlink/route/qdisc/htb.h>
#include <netlink/route/class.h>
#include <netlink/route/classifier.h>
#include <netlink/route/cls/cgroup.h>

int main () {
    struct nl_sock *sock;
    struct rtnl_link *link; 
    struct rtnl_qdisc *qdisc;
    struct rtnl_cls *cls;
    
    int if_index;
    int err;
    
    sock = nl_socket_alloc();
    nl_connect(sock, NETLINK_ROUTE);
    
    if( rtnl_link_get_kernel(sock, 0, "eth10", &link) >= 0) {   
        if_index = rtnl_link_get_ifindex(link);
    }

    //creating Qdisc
    if ((qdisc = rtnl_qdisc_alloc())) {
        printf("qdisc allocated \n");
    }
    
    rtnl_tc_set_link(TC_CAST(qdisc), link);
    rtnl_tc_set_parent(TC_CAST(qdisc), TC_H_ROOT);
    rtnl_tc_set_handle(TC_CAST(qdisc), TC_HANDLE(10,0));
    rtnl_tc_set_kind(TC_CAST(qdisc), "htb");
    rtnl_htb_set_defcls(qdisc, 0x1);           
    rtnl_htb_set_rate2quantum(qdisc, 10);
    err = rtnl_qdisc_add(sock, qdisc, NLM_F_CREATE);

    if (err < 0) {
            fprintf(stderr, "Unable to add qdisc: %s\n", nl_geterror(err));
    }    
    rtnl_qdisc_put(qdisc);

    //creating classifier    
    uint32_t protocol = ETH_P_IP;     
    uint32_t prio = 10;
    if ((cls = rtnl_cls_alloc())) {
        printf("cls allocated \n");
    }
    
    rtnl_tc_set_link(TC_CAST(cls), link);
    rtnl_tc_set_kind(TC_CAST(cls), "cgroup");
    rtnl_tc_set_parent(TC_CAST(cls), TC_HANDLE(10,0));
    rtnl_tc_set_handle(TC_CAST(cls), TC_HANDLE(10,1));
    rtnl_cls_set_prio(cls, prio);
    rtnl_cls_set_protocol(cls, protocol);
    
    err = rtnl_cls_add(sock, cls, NLM_F_CREATE);

    if (err < 0) {
            fprintf(stderr, "Unable to add cls: %s\n", nl_geterror(err));
            return err;
    }       
}

I am not used to mailing list so I hope it is the appropriate place to ask my question.

Thank you in advance for your help.

Gilles Dejaegere.




More information about the libnl mailing list