cgroup classifier problem

Thomas Haller thaller at redhat.com
Thu May 12 10:07:41 PDT 2016


On Thu, 2016-05-05 at 08:03 +0000, Gilles Dejaegere wrote:
> 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.


Hi,

I don't know the answer to this (I never tried it).

But as you know how to do it with iproute2 (tc), I would look at
iproute2.

tc basically creates a netlink message, fills it according to the
command line options, and sends it. I would look which properties are
set, and set the same via libnl3.

sorry for not being of more help.


good luck,
Thomas


> 
> 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.
> 
> 
> _______________________________________________
> libnl mailing list
> libnl at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/libnl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/libnl/attachments/20160512/37ebb97e/attachment.sig>


More information about the libnl mailing list