libnl 1.1
Modules

Queueing Classes

Traffic Control

Modules

 Class Modules
 Class Object

Addition/Modification

struct nl_msg * rtnl_class_build_add_request (struct rtnl_class *class, int flags)
 Build a netlink message to add a new class.
int rtnl_class_add (struct nl_handle *handle, struct rtnl_class *class, int flags)
 Add a new class.

Cache Management

struct nl_cache * rtnl_class_alloc_cache (struct nl_handle *handle, int ifindex)
 Build a class cache including all classes attached to the specified interface.

Function Documentation

struct nl_msg* rtnl_class_build_add_request ( struct rtnl_class *  class,
int  flags 
) [read]
Parameters:
classclass to add
flagsadditional netlink message flags

Builds a new netlink message requesting an addition of a class. The netlink message header isn't fully equipped with all relevant fields and must be sent out via nl_send_auto_complete() or supplemented as needed.

Common message flags

  • NLM_F_REPLACE - replace possibly existing classes
Returns:
New netlink message

Definition at line 128 of file class.c.

References NLM_F_CREATE.

Referenced by rtnl_class_add().

{
        return class_build(class, RTM_NEWTCLASS, NLM_F_CREATE | flags);
}
int rtnl_class_add ( struct nl_handle *  handle,
struct rtnl_class *  class,
int  flags 
)
Parameters:
handlenetlink handle
classclass to delete
flagsadditional netlink message flags

Builds a netlink message by calling rtnl_qdisc_build_add_request(), sends the request to the kernel and waits for the next ACK to be received and thus blocks until the request has been processed.

Common message flags

  • NLM_F_REPLACE - replace possibly existing classes
Returns:
0 on success or a negative error code

Definition at line 148 of file class.c.

References nl_send_auto_complete(), nl_wait_for_ack(), nlmsg_free(), and rtnl_class_build_add_request().

{
        struct nl_msg *msg;
        int err;

        msg = rtnl_class_build_add_request(class, flags);
        if (!msg)
                return nl_errno(ENOMEM);

        err = nl_send_auto_complete(handle, msg);
        if (err < 0)
                return err;

        nlmsg_free(msg);
        return nl_wait_for_ack(handle);
}
struct nl_cache* rtnl_class_alloc_cache ( struct nl_handle *  handle,
int  ifindex 
) [read]
Parameters:
handlenetlink handle
ifindexinterface index of the link the classes are attached to.

Allocates a new cache, initializes it properly and updates it to include all classes attached to the specified interface.

Returns:
The cache or NULL if an error has occured.

Definition at line 184 of file class.c.

References nl_cache_alloc(), nl_cache_free(), and nl_cache_refill().

{
        struct nl_cache * cache;
        
        cache = nl_cache_alloc(&rtnl_class_ops);
        if (!cache)
                return NULL;

        cache->c_iarg1 = ifindex;
        
        if (handle && nl_cache_refill(handle, cache) < 0) {
                nl_cache_free(cache);
                return NULL;
        }

        return cache;
}