libnl: Traffic Classes

libnl 3.7.0

Modules
Traffic Classes
Routing Library (libnl-route) » Traffic Control

## Modules
| Class Based Queueing (CBQ)
| Differentiated Services Marker (DSMARK)
| Hierachical Token Bucket (HTB)
| Hierarchical Fair Service Curve (HFSC)

## Allocation/Freeing
struct rtnl_class * | rtnl_class_alloc (void)
void | rtnl_class_put (struct rtnl_class *class)

## Addition/Modification/Deletion
int | rtnl_class_build_add_request (struct rtnl_class *class, int flags, struct nl_msg **result)
| Build a netlink message requesting the addition of a traffic class. More...
int | rtnl_class_add (struct nl_sock *sk, struct rtnl_class *class, int flags)
| Add/Update traffic class. More...
int | rtnl_class_build_delete_request (struct rtnl_class *class, struct nl_msg **result)
| Build netlink message requesting the deletion of a traffic class. More...
int | rtnl_class_delete (struct nl_sock *sk, struct rtnl_class *class)
| Delete traffic class. More...

## Leaf Qdisc
struct rtnl_qdisc * | rtnl_class_leaf_qdisc (struct rtnl_class *class, struct nl_cache *cache)
| Lookup the leaf qdisc of a traffic class. More...

## Cache Related Functions
int | rtnl_class_alloc_cache (struct nl_sock *sk, int ifindex, struct nl_cache **result)
| Allocate a cache and fill it with all configured traffic classes. More...
struct rtnl_class * | rtnl_class_get (struct nl_cache *cache, int ifindex, uint32_t handle)
| Search traffic class by interface index and handle. More...
struct rtnl_class * | rtnl_class_get_by_parent (struct nl_cache *cache, int ifindex, uint32_t parent)
| Search class by interface index and parent. More...

## Deprecated Functions
void | rtnl_class_foreach_child (struct rtnl_class *class, struct nl_cache *cache, void(*cb)(struct nl_object *, void *), void *arg)
| Call a callback for each child of a class. More...
void | rtnl_class_foreach_cls (struct rtnl_class *class, struct nl_cache *cache, void(*cb)(struct nl_object *, void *), void *arg)
| Call a callback for each classifier attached to the class. More...

## Detailed Description

## Function Documentation

## ◆ rtnl_class_build_add_request()

int rtnl_class_build_add_request | ( | struct rtnl_class * | class,
|  | int | flags,
|  | struct nl_msg ** | result
| ) |  |

Build a netlink message requesting the addition of a traffic class.

Parameters

  class | Traffic class to add
  flags | Additional netlink message flags
  result | Pointer to store resulting netlink message

The behaviour of this function is identical to rtnl_class_add() with the exception that it will not send the message but return it int the provided return pointer instead.

See also
  rtnl_class_add()

Returns
  0 on success or a negative error code.

Definition at line 123 of file class.c.

Referenced by rtnl_class_add().

Here is the caller graph for this function:

## ◆ rtnl_class_add()

int rtnl_class_add | ( | struct nl_sock * | sk,
|  | struct rtnl_class * | class,
|  | int | flags
| ) |  |

Add/Update traffic class.

Parameters

  sk | Netlink socket
  class | Traffic class to add
  flags | Additional netlink message flags

Builds a `RTM_NEWTCLASS` netlink message requesting the addition of a new traffic class and sends the message to the kernel. The configuration of the traffic class is derived from the attributes of the specified traffic class.

The following flags may be specified:

- `NLM_F_CREATE:` Create traffic class if it does not exist, otherwise -NLE_OBJ_NOTFOUND is returned.
- `NLM_F_EXCL:` Return -NLE_EXISTS if a traffic class with matching handle exists already.

Existing traffic classes with matching handles will be updated, unless the flag `NLM_F_EXCL` is specified. If no matching traffic class exists, it will be created if the flag `NLM_F_CREATE` is set, otherwise the error -NLE_OBJ_NOTFOUND is returned.

If the parent qdisc does not support classes, the error `NLE_OPNOTSUPP` is returned.

After sending, the function will wait for the ACK or an eventual error message to be received and will therefore block until the operation has been completed.

Note
  Disabling auto-ack (nl_socket_disable_auto_ack()) will cause this function to return immediately after sending. In this case, it is the responsibility of the caller to handle any error messages returned.

Returns
  0 on success or a negative error code.

Definition at line 165 of file class.c.

References nl_send_sync(), and rtnl_class_build_add_request().

Here is the call graph for this function:

## ◆ rtnl_class_build_delete_request()

int rtnl_class_build_delete_request | ( | struct rtnl_class * | class,
|  | struct nl_msg ** | result
| ) |  |

Build netlink message requesting the deletion of a traffic class.

Parameters

  class | Traffic class to delete
  result | Pointer to store resulting netlink message

The behaviour of this function is identical to rtnl_class_delete() with the exception that it will not send the message but return it in the provided return pointer instead.

See also
  rtnl_class_delete()

Returns
  0 on success or a negative error code.

Definition at line 189 of file class.c.

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

Referenced by rtnl_class_delete().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ rtnl_class_delete()

int rtnl_class_delete | ( | struct nl_sock * | sk,
|  | struct rtnl_class * | class
| ) |  |

Delete traffic class.

Parameters

  sk | Netlink socket
  class | Traffic class to delete

Builds a `RTM_DELTCLASS` netlink message requesting the deletion of a traffic class and sends the message to the kernel.

The message is constructed out of the following attributes:

- `ifindex` and `handle` (required)
- `parent` (optional, must match if provided)

All other class attributes including all class type specific attributes are ignored.

After sending, the function will wait for the ACK or an eventual error message to be received and will therefore block until the operation has been completed.

Note
  Disabling auto-ack (nl_socket_disable_auto_ack()) will cause this function to return immediately after sending. In this case, it is the responsibility of the caller to handle any error messages returned.

Returns
  0 on success or a negative error code.

Definition at line 246 of file class.c.

References nl_send_sync(), and rtnl_class_build_delete_request().

Here is the call graph for this function:

## ◆ rtnl_class_leaf_qdisc()

struct rtnl_qdisc* rtnl_class_leaf_qdisc | ( | struct rtnl_class * | class,
|  | struct nl_cache * | cache
| ) |  |

Lookup the leaf qdisc of a traffic class.

Parameters

  class | the parent traffic class
  cache | a qdisc cache allocated using rtnl_qdisc_alloc_cache()

Returns
  Matching Qdisc or NULL if the traffic class has no leaf qdisc

Definition at line 271 of file class.c.

References rtnl_qdisc_get_by_parent().

Here is the call graph for this function:

## ◆ rtnl_class_alloc_cache()

int rtnl_class_alloc_cache | ( | struct nl_sock * | sk,
|  | int | ifindex,
|  | struct nl_cache ** | result
| ) |  |

Allocate a cache and fill it with all configured traffic classes.

Parameters

  sk | Netlink socket
  ifindex | Interface index of the network device
  result | Pointer to store the created cache

Allocates a new traffic class cache and fills it with a list of all configured traffic classes on a specific network device. Release the cache with nl_cache_free().

Returns
  0 on success or a negative error code.

Definition at line 306 of file class.c.

References nl_cache_alloc().

Here is the call graph for this function:

## ◆ rtnl_class_get()

struct rtnl_class* rtnl_class_get | ( | struct nl_cache * | cache,
|  | int | ifindex,
|  | uint32_t | handle
| ) |  |

Search traffic class by interface index and handle.

Parameters

  cache | Traffic class cache
  ifindex | Interface index
  handle | ID of traffic class

Searches a traffic class cache previously allocated with rtnl_class_alloc_cache() and searches for a traffi class matching the interface index and handle.

The reference counter is incremented before returning the traffic class, therefore the reference must be given back with rtnl_class_put() after usage.

Returns
  Traffic class or NULL if no match was found.

Definition at line 347 of file class.c.

## ◆ rtnl_class_get_by_parent()

struct rtnl_class* rtnl_class_get_by_parent | ( | struct nl_cache * | cache,
|  | int | ifindex,
|  | uint32_t | parent
| ) |  |

Search class by interface index and parent.

Parameters

  cache | Traffic class cache
  ifindex | Interface index
  parent | Handle of parent qdisc

Searches a class cache previously allocated with rtnl_class_alloc_cache() and searches for a class matching the interface index and parent qdisc.

The reference counter is incremented before returning the class, therefore the reference must be given back with rtnl_class_put() after usage.

Returns
  pointer to class inside the cache or NULL if no match was found.

Definition at line 378 of file class.c.

## ◆ rtnl_class_foreach_child()

void rtnl_class_foreach_child | ( | struct rtnl_class * | class,
|  | struct nl_cache * | cache,
|  | void(*)(struct nl_object *, void *) | cb,
|  | void * | arg
| ) |  |

Call a callback for each child of a class.

Deprecated:
  Use of this function is deprecated, it does not allow to handle the out of memory situation that can occur.

Definition at line 409 of file class.c.

## ◆ rtnl_class_foreach_cls()

void rtnl_class_foreach_cls | ( | struct rtnl_class * | class,
|  | struct nl_cache * | cache,
|  | void(*)(struct nl_object *, void *) | cb,
|  | void * | arg
| ) |  |

Call a callback for each classifier attached to the class.

Deprecated:
  Use of this function is deprecated, it does not allow to handle the out of memory situation that can occur.

Definition at line 432 of file class.c.