Modules | Variables

Queueing Disciplines
[Traffic Control]

Modules

 Blackhole
 Class Based Queueing (CBQ)
 Differentiated Services Marker (DSMARK)
 Packet/Bytes FIFO (pfifo/bfifo)
 

The FIFO qdisc comes in two flavours:


 Hierachical Token Bucket (HTB)
 Network Emulator
 

For further documentation see http://linux-net.osdl.org/index.php/Netem.


 (Fast) Prio
 Random Early Detection (RED)
 Stochastic Fairness Queueing (SFQ)
 Token Bucket Filter (TBF)

Variables

struct nl_object_ops qdisc_obj_ops

QDisc Addition



int rtnl_qdisc_build_add_request (struct rtnl_qdisc *qdisc, int flags, struct nl_msg **result)
 Build a netlink message to add a new qdisc.
int rtnl_qdisc_add (struct nl_sock *sk, struct rtnl_qdisc *qdisc, int flags)
 Add a new qdisc.

QDisc Modification



int rtnl_qdisc_build_change_request (struct rtnl_qdisc *qdisc, struct rtnl_qdisc *new, struct nl_msg **result)
 Build a netlink message to change attributes of a existing qdisc.
int rtnl_qdisc_change (struct nl_sock *sk, struct rtnl_qdisc *qdisc, struct rtnl_qdisc *new)
 Change attributes of a qdisc.

QDisc Deletion



int rtnl_qdisc_build_delete_request (struct rtnl_qdisc *qdisc, struct nl_msg **result)
 Build a netlink request message to delete a qdisc.
int rtnl_qdisc_delete (struct nl_sock *sk, struct rtnl_qdisc *qdisc)
 Delete a qdisc.

Qdisc Cache Management



int rtnl_qdisc_alloc_cache (struct nl_sock *sk, struct nl_cache **result)
 Build a qdisc cache including all qdiscs currently configured in the kernel.
struct rtnl_qdisc * rtnl_qdisc_get_by_parent (struct nl_cache *cache, int ifindex, uint32_t parent)
 Look up qdisc by its parent in the provided cache.
struct rtnl_qdisc * rtnl_qdisc_get (struct nl_cache *cache, int ifindex, uint32_t handle)
 Look up qdisc by its handle in the provided cache.

Allocation/Freeing



struct rtnl_qdisc * rtnl_qdisc_alloc (void)
void rtnl_qdisc_put (struct rtnl_qdisc *qdisc)

Iterators



void rtnl_qdisc_foreach_child (struct rtnl_qdisc *qdisc, struct nl_cache *cache, void(*cb)(struct nl_object *, void *), void *arg)
 Call a callback for each child class of a qdisc.
void rtnl_qdisc_foreach_cls (struct rtnl_qdisc *qdisc, struct nl_cache *cache, void(*cb)(struct nl_object *, void *), void *arg)
 Call a callback for each filter attached to the qdisc.

Detailed Description

Qdisc Handles
In general, qdiscs are identified by the major part of a traffic control handle (the upper 16 bits). A few special values exist though:
  • TC_H_ROOT: root qdisc (directly attached to the device)
  • TC_H_INGRESS: ingress qdisc (directly attached to the device)
  • TC_H_UNSPEC: unspecified qdisc (no reference)
1) Adding a Qdisc
 // Allocate a new empty qdisc to be filled out
 struct rtnl_qdisc *qdisc = rtnl_qdisc_alloc();

 // ... specify the kind of the Qdisc
 rtnl_qdisc_set_kind(qdisc, "pfifo");

 // Specify the device the qdisc should be attached to
 rtnl_qdisc_set_ifindex(qdisc, ifindex);

 // ... specify the parent qdisc
 rtnl_qdisc_set_parent(qdisc, TC_H_ROOT);

 // Specifying the handle is not required but makes reidentifying easier
 // and may help to avoid adding a qdisc twice.
 rtnl_qdisc_set_handle(qdisc, 0x000A0000);

 // Now on to specify the qdisc specific options, see the relevant qdisc
 // modules for documentation, in this example we set the upper limit of
 // the packet fifo qdisc to 64
 rtnl_qdisc_fifo_set_limit(qdisc, 64);

 rtnl_qdisc_add(handle, qdisc, NLM_R_REPLACE);

 // Free up the memory
 rtnl_qdisc_put(qdisc);
2) Deleting a Qdisc
 // Allocate a new empty qdisc to be filled out with the parameters
 // specifying the qdisc to be deleted. Alternatively a fully equiped
 // Qdisc object from a cache can be used.
 struct rtnl_qdisc *qdisc = rtnl_qdisc_alloc();

 // The interface index of the device the qdisc is on and the parent handle
 // are the least required fields to be filled out.
 // Note: Specify TC_H_ROOT or TC_H_INGRESS as parent handle to delete the
 //       root respectively root ingress qdisc.
 rtnl_qdisc_set_ifindex(qdisc, ifindex);
 rtnl_qdisc_set_parent(qdisc, parent_handle);

 // If required for identification, the handle can be specified as well.
 rtnl_qdisc_set_handle(qdisc, qdisc_handle);

 // Not required but maybe helpful as sanity check, the kind of the qdisc
 // can be specified to avoid mistakes.
 rtnl_qdisc_set_kind(qdisc, "pfifo");

 // Finally delete the qdisc with rtnl_qdisc_delete(), alternatively
 // rtnl_qdisc_build_delete_request() can be invoked to generate an
 // appropritate netlink message to send out.
 rtnl_qdisc_delete(handle, qdisc);

 // Free up the memory
 rtnl_qdisc_put(qdisc);

Function Documentation

int rtnl_qdisc_build_add_request ( struct rtnl_qdisc *  qdisc,
int  flags,
struct nl_msg **  result 
)

Build a netlink message to add a new qdisc.

Parameters:
qdisc qdisc to add
flags additional netlink message flags
result Pointer to store resulting message.

Builds a new netlink message requesting an addition of a qdisc. 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 used:

  • NLM_F_REPLACE - replace a potential existing qdisc
Returns:
0 on success or a negative error code.

Definition at line 165 of file qdisc.c.

Referenced by rtnl_qdisc_add().

Here is the caller graph for this function:

int rtnl_qdisc_add ( struct nl_sock *  sk,
struct rtnl_qdisc *  qdisc,
int  flags 
)

Add a new qdisc.

Parameters:
sk Netlink socket.
qdisc qdisc to delete
flags additional netlink message flags

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

Common message flags used:

  • NLM_F_REPLACE - replace a potential existing qdisc
Returns:
0 on success or a negative error code

Definition at line 186 of file qdisc.c.

References nlmsg_free(), and rtnl_qdisc_build_add_request().

Here is the call graph for this function:

int rtnl_qdisc_build_change_request ( struct rtnl_qdisc *  qdisc,
struct rtnl_qdisc *  new,
struct nl_msg **  result 
)

Build a netlink message to change attributes of a existing qdisc.

Parameters:
qdisc qdisc to change
new new qdisc attributes
result Pointer to store resulting message.

Builds a new netlink message requesting an change of qdisc attributes. 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.

Returns:
0 on success or a negative error code.

Definition at line 223 of file qdisc.c.

Referenced by rtnl_qdisc_change().

Here is the caller graph for this function:

int rtnl_qdisc_change ( struct nl_sock *  sk,
struct rtnl_qdisc *  qdisc,
struct rtnl_qdisc *  new 
)

Change attributes of a qdisc.

Parameters:
sk Netlink socket.
qdisc qdisc to change
new new qdisc attributes

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

Returns:
0 on success or a negative error code

Definition at line 242 of file qdisc.c.

References nlmsg_free(), and rtnl_qdisc_build_change_request().

Here is the call graph for this function:

int rtnl_qdisc_build_delete_request ( struct rtnl_qdisc *  qdisc,
struct nl_msg **  result 
)

Build a netlink request message to delete a qdisc.

Parameters:
qdisc qdisc to delete
result Pointer to store resulting message.

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

Returns:
0 on success or a negative error code.

Definition at line 278 of file qdisc.c.

References nlmsg_alloc_simple(), nlmsg_append(), and nlmsg_free().

Referenced by rtnl_qdisc_delete().

Here is the call graph for this function:

Here is the caller graph for this function:

int rtnl_qdisc_delete ( struct nl_sock *  sk,
struct rtnl_qdisc *  qdisc 
)

Delete a qdisc.

Parameters:
sk Netlink socket.
qdisc qdisc to delete

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

Returns:
0 on success or a negative error code

Definition at line 316 of file qdisc.c.

References nlmsg_free(), and rtnl_qdisc_build_delete_request().

Here is the call graph for this function:

int rtnl_qdisc_alloc_cache ( struct nl_sock *  sk,
struct nl_cache **  result 
)

Build a qdisc cache including all qdiscs currently configured in the kernel.

Parameters:
sk Netlink socket.
result Pointer to store resulting message.

Allocates a new cache, initializes it properly and updates it to include all qdiscs currently configured in the kernel.

Returns:
0 on success or a negative error code.

Definition at line 350 of file qdisc.c.

struct rtnl_qdisc* rtnl_qdisc_get_by_parent ( struct nl_cache *  cache,
int  ifindex,
uint32_t  parent 
) [read]

Look up qdisc by its parent in the provided cache.

Parameters:
cache qdisc cache
ifindex interface the qdisc is attached to
parent parent handle
Returns:
pointer to qdisc inside the cache or NULL if no match was found.

Definition at line 362 of file qdisc.c.

References nl_object_get().

Referenced by rtnl_class_leaf_qdisc().

Here is the call graph for this function:

Here is the caller graph for this function:

struct rtnl_qdisc* rtnl_qdisc_get ( struct nl_cache *  cache,
int  ifindex,
uint32_t  handle 
) [read]

Look up qdisc by its handle in the provided cache.

Parameters:
cache qdisc cache
ifindex interface the qdisc is attached to
handle qdisc handle
Returns:
pointer to qdisc inside the cache or NULL if no match was found.

Definition at line 387 of file qdisc.c.

References nl_object_get().

Here is the call graph for this function:

void rtnl_qdisc_foreach_child ( struct rtnl_qdisc *  qdisc,
struct nl_cache *  cache,
void(*)(struct nl_object *, void *)  cb,
void *  arg 
)

Call a callback for each child class of a qdisc.

Parameters:
qdisc the parent qdisc
cache a class cache including all classes of the interface the specified qdisc is attached to
cb callback function
arg argument to be passed to callback function

Definition at line 443 of file qdisc.c.

References nl_cache_foreach_filter(), rtnl_tc_set_ifindex(), rtnl_tc_set_kind(), rtnl_tc_set_parent(), and TC_CAST.

Here is the call graph for this function:

void rtnl_qdisc_foreach_cls ( struct rtnl_qdisc *  qdisc,
struct nl_cache *  cache,
void(*)(struct nl_object *, void *)  cb,
void *  arg 
)

Call a callback for each filter attached to the qdisc.

Parameters:
qdisc the parent qdisc
cache a filter cache including at least all the filters attached to the specified qdisc
cb callback function
arg argument to be passed to callback function

Definition at line 469 of file qdisc.c.

References nl_cache_foreach_filter(), rtnl_tc_set_ifindex(), and rtnl_tc_set_parent().

Here is the call graph for this function:


Variable Documentation

struct nl_object_ops qdisc_obj_ops
Initial value:
 {
        .oo_name                = "route/qdisc",
        .oo_size                = sizeof(struct rtnl_qdisc),
        .oo_free_data           = rtnl_tc_free_data,
        .oo_clone               = rtnl_tc_clone,
        .oo_dump = {
            [NL_DUMP_LINE]      = rtnl_tc_dump_line,
            [NL_DUMP_DETAILS]   = rtnl_tc_dump_details,
            [NL_DUMP_STATS]     = rtnl_tc_dump_stats,
        },
        .oo_compare             = rtnl_tc_compare,
        .oo_id_attrs            = (TCA_ATTR_IFINDEX | TCA_ATTR_HANDLE),
}

Definition at line 517 of file qdisc.c.