libnl 1.1.4

Attribute Modifications

void rtnl_u32_set_handle (struct rtnl_cls *cls, int htid, int hash, int nodeid)
 
int rtnl_u32_set_classid (struct rtnl_cls *cls, uint32_t classid)
 

Selector Modifications

int rtnl_u32_set_flags (struct rtnl_cls *cls, int flags)
 
int rtnl_u32_add_key (struct rtnl_cls *cls, uint32_t val, uint32_t mask, int off, int offmask)
 Append new 32-bit key to the selector.
 
int rtnl_u32_add_key_uint8 (struct rtnl_cls *cls, uint8_t val, uint8_t mask, int off, int offmask)
 
int rtnl_u32_add_key_uint16 (struct rtnl_cls *cls, uint16_t val, uint16_t mask, int off, int offmask)
 Append new selector key to match a 16-bit number.
 
int rtnl_u32_add_key_uint32 (struct rtnl_cls *cls, uint32_t val, uint32_t mask, int off, int offmask)
 Append new selector key to match a 32-bit number.
 
int rtnl_u32_add_key_in_addr (struct rtnl_cls *cls, struct in_addr *addr, uint8_t bitmask, int off, int offmask)
 
int rtnl_u32_add_key_in6_addr (struct rtnl_cls *cls, struct in6_addr *addr, uint8_t bitmask, int off, int offmask)
 

Detailed Description

Function Documentation

◆ rtnl_u32_set_handle()

void rtnl_u32_set_handle ( struct rtnl_cls *  cls,
int  htid,
int  hash,
int  nodeid 
)

Definition at line 408 of file u32.c.

410{
411 uint32_t handle = (htid << 20) | (hash << 12) | nodeid;
412
413 tca_set_handle((struct rtnl_tca *) cls, handle );
414}

◆ rtnl_u32_set_classid()

int rtnl_u32_set_classid ( struct rtnl_cls *  cls,
uint32_t  classid 
)

Definition at line 416 of file u32.c.

417{
418 struct rtnl_u32 *u;
419
420 u = u32_alloc(cls);
421 if (!u)
422 return nl_errno(ENOMEM);
423
424 u->cu_classid = classid;
425 u->cu_mask |= U32_ATTR_CLASSID;
426
427 return 0;
428}

◆ rtnl_u32_set_flags()

int rtnl_u32_set_flags ( struct rtnl_cls *  cls,
int  flags 
)

Definition at line 437 of file u32.c.

438{
439 struct tc_u32_sel *sel;
440 struct rtnl_u32 *u;
441
442 u = u32_alloc(cls);
443 if (!u)
444 return nl_errno(ENOMEM);
445
446 sel = u32_selector_alloc(u);
447 if (!sel)
448 return nl_errno(ENOMEM);
449
450 sel->flags |= flags;
451 u->cu_mask |= U32_ATTR_SELECTOR;
452
453 return 0;
454}

◆ rtnl_u32_add_key()

int rtnl_u32_add_key ( struct rtnl_cls *  cls,
uint32_t  val,
uint32_t  mask,
int  off,
int  offmask 
)
Parameters
clsclassifier to be modifier
valvalue to be matched (network byte-order)
maskmask to be applied before matching (network byte-order)
offoffset, in bytes, to start matching
offmaskoffset mask

General selectors define the pattern, mask and offset the pattern will be matched to the packet contents. Using the general selectors you can match virtually any single bit in the IP (or upper layer) header.

Definition at line 470 of file u32.c.

472{
473 struct tc_u32_sel *sel;
474 struct rtnl_u32 *u;
475 int err;
476
477 u = u32_alloc(cls);
478 if (!u)
479 return nl_errno(ENOMEM);
480
481 sel = u32_selector_alloc(u);
482 if (!sel)
483 return nl_errno(ENOMEM);
484
485 err = nl_data_append(u->cu_selector, NULL, sizeof(struct tc_u32_key));
486 if (err < 0)
487 return err;
488
489 /* the selector might have been moved by realloc */
490 sel = u32_selector(u);
491
492 sel->keys[sel->nkeys].mask = mask;
493 sel->keys[sel->nkeys].val = val & mask;
494 sel->keys[sel->nkeys].off = off;
495 sel->keys[sel->nkeys].offmask = offmask;
496 sel->nkeys++;
497 u->cu_mask |= U32_ATTR_SELECTOR;
498
499 return 0;
500}
int nl_data_append(struct nl_data *data, void *buf, size_t size)
Append data to an abstract data object.
Definition: data.c:85

References nl_data_append().

Referenced by rtnl_u32_add_key_uint16(), and rtnl_u32_add_key_uint32().

◆ rtnl_u32_add_key_uint8()

int rtnl_u32_add_key_uint8 ( struct rtnl_cls *  cls,
uint8_t  val,
uint8_t  mask,
int  off,
int  offmask 
)

Definition at line 502 of file u32.c.

504{
505 int shift = 24 - 8 * (off & 3);
506
507 return rtnl_u32_add_key(cls, htonl((uint32_t)val << shift),
508 htonl((uint32_t)mask << shift),
509 off & ~3, offmask);
510}
int rtnl_u32_add_key(struct rtnl_cls *cls, uint32_t val, uint32_t mask, int off, int offmask)
Append new 32-bit key to the selector.
Definition: u32.c:470

◆ rtnl_u32_add_key_uint16()

int rtnl_u32_add_key_uint16 ( struct rtnl_cls *  cls,
uint16_t  val,
uint16_t  mask,
int  off,
int  offmask 
)
Parameters
clsclassifier to be modified
valvalue to be matched (host byte-order)
maskmask to be applied before matching (host byte-order)
offoffset, in bytes, to start matching
offmaskoffset mask

Definition at line 521 of file u32.c.

523{
524 int shift = ((off & 3) == 0 ? 16 : 0);
525 if (off % 2)
526 return nl_error(EINVAL, "Invalid offset alignment");
527
528 return rtnl_u32_add_key(cls, htonl((uint32_t)val << shift),
529 htonl((uint32_t)mask << shift),
530 off & ~3, offmask);
531}

References rtnl_u32_add_key().

◆ rtnl_u32_add_key_uint32()

int rtnl_u32_add_key_uint32 ( struct rtnl_cls *  cls,
uint32_t  val,
uint32_t  mask,
int  off,
int  offmask 
)
Parameters
clsclassifier to be modified
valvalue to be matched (host byte-order)
maskmask to be applied before matching (host byte-order)
offoffset, in bytes, to start matching
offmaskoffset mask

Definition at line 542 of file u32.c.

544{
545 return rtnl_u32_add_key(cls, htonl(val), htonl(mask),
546 off & ~3, offmask);
547}

References rtnl_u32_add_key().

◆ rtnl_u32_add_key_in_addr()

int rtnl_u32_add_key_in_addr ( struct rtnl_cls *  cls,
struct in_addr *  addr,
uint8_t  bitmask,
int  off,
int  offmask 
)

Definition at line 549 of file u32.c.

551{
552 uint32_t mask = 0xFFFFFFFF << (32 - bitmask);
553 return rtnl_u32_add_key(cls, addr->s_addr, htonl(mask), off, offmask);
554}

◆ rtnl_u32_add_key_in6_addr()

int rtnl_u32_add_key_in6_addr ( struct rtnl_cls *  cls,
struct in6_addr *  addr,
uint8_t  bitmask,
int  off,
int  offmask 
)

Definition at line 556 of file u32.c.

558{
559 int i, err;
560
561 for (i = 1; i <= 4; i++) {
562 if (32 * i - bitmask <= 0) {
563 if ((err = rtnl_u32_add_key(cls, addr->s6_addr32[i-1],
564 0xFFFFFFFF, off+4*(i-1), offmask)) < 0)
565 return err;
566 }
567 else if (32 * i - bitmask < 32) {
568 uint32_t mask = 0xFFFFFFFF << (32 * i - bitmask);
569 if ((err = rtnl_u32_add_key(cls, addr->s6_addr32[i-1],
570 htonl(mask), off+4*(i-1), offmask)) < 0)
571 return err;
572 }
573 /* otherwise, if (32*i - bitmask >= 32) no key is generated */
574 }
575
576 return 0;
577}