Using libnl to create u32 hashkey

Adrian Ban adrian.ban at mantech.ro
Wed Nov 23 18:57:28 EST 2011


Hi,

I'm making progress with hash filters :) :

filter parent 1: protocol ip pref 1 u32
filter parent 1: protocol ip pref 1 u32 fh 1: ht divisor 256
filter parent 1: protocol ip pref 1 u32 fh 800: ht divisor 1
filter parent 1: protocol ip pref 2 u32
filter parent 1: protocol ip pref 2 u32 fh 801: ht divisor 1
filter parent 1: protocol ip pref 2 u32 fh 801::800 order 2048 key ht 
801 bkt 0 link 1:  (rule hit 0 success 0)
   match 00000000/00000000 at 12 (success 0 )
     hash mask ff000000 at 0

This is a major step for next step :).

This is exactly with this tc command:

$TC filter add dev $DEVin  parent 0x01:0x0000 prio 1 protocol ip u32
$TC filter add dev $DEVin  parent 0x01:0x0000 prio 1 protocol ip
handle 1: u32 divisor 256

$TC filter add dev $DEVin parent 0x01:0x0000 prio 2 protocol ip u32 \
       match ip dst 0.0.0.0/0 \
       hashkey mask 0xff000000 at 16 \
       link 1:


Until so far so good! I'm going to try to add more hash filter. If 
everything will be fine I'll make a patch with 3 new functions for user 
space and 4 functions that will be used by those 3 new functions.

The functions that are used by rtnl_u32_set_divisor, rtnl_u32_set_link, 
rtnl_u32_set_hashmask are copied from iproute -> tc -> f_u32.c. This 
file was an inspiration for building the 3 main functions.

Regards,
Adrian


On 11/22/2011 2:07 PM, Thomas Graf wrote:
> On Tue, Nov 22, 2011 at 01:46:30PM +0200, Adrian Ban wrote:
>> Hi,
>>
>> I saw that. For this reason I've made a function that set the divisor:
>>
>> #include<netlink/netlink.h>
>> #include<netlink/route/tc.h>
>> #include<netlink/route/classifier.h>
>> #include "include/rtnl_u32.h"
>>
>> int rtnl_u32_set_divisor(struct rtnl_cls *mycls, uint16_t divisor)
>> {
>>
>>          struct rtnl_u32 *u;
>>
>>          if (!(u = (struct rtnl_u32*)rtnl_tc_data(TC_CAST(mycls))))
>>                  return -NLE_NOMEM;
>>
>>          printf("Mask before set   : 0x%X\n", u->cu_mask);
>>          u->cu_divisor = divisor;
>>          u->cu_mask |= U32_ATTR_DIVISOR;
>>          printf("Divisor is set to : 0x%X\n", u->cu_divisor);
>>          printf("Mask is set to    : 0x%X\n", u->cu_mask);
>>          return 0;
>>
>> }
> Great, feel free to send patches.




More information about the libnl mailing list