libnl 1.1

Universal 32-bit Classifier

Classifier Modules

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)

Function Documentation

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.

References nl_data_append().

Referenced by rtnl_u32_add_key_uint16(), and rtnl_u32_add_key_uint32().

{
        struct tc_u32_sel *sel;
        struct rtnl_u32 *u;
        int err;

        u = u32_alloc(cls);
        if (!u)
                return nl_errno(ENOMEM);

        sel = u32_selector_alloc(u);
        if (!sel)
                return nl_errno(ENOMEM);

        err = nl_data_append(u->cu_selector, NULL, sizeof(struct tc_u32_key));
        if (err < 0)
                return err;

        /* the selector might have been moved by realloc */
        sel = u32_selector(u);

        sel->keys[sel->nkeys].mask = mask;
        sel->keys[sel->nkeys].val = val & mask;
        sel->keys[sel->nkeys].off = off;
        sel->keys[sel->nkeys].offmask = offmask;
        sel->nkeys++;
        u->cu_mask |= U32_ATTR_SELECTOR;

        return 0;
}
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.

References rtnl_u32_add_key().

{
        int shift = ((off & 3) == 0 ? 16 : 0);
        if (off % 2)
                return nl_error(EINVAL, "Invalid offset alignment");

        return rtnl_u32_add_key(cls, htonl((uint32_t)val << shift),
                                htonl((uint32_t)mask << shift),
                                off & ~3, offmask);
}
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.

References rtnl_u32_add_key().

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