libnl: Classifiers

libnl 3.12.0

Classifiers
Routing Library (libnl-route) » Traffic Control

## Topics
| Basic Classifier
| Control Groups Classifier
| Extended Match
| Firewall Classifier
| Match-all Classifier
| Universal 32-bit Classifier

## Allocation/Freeing
struct rtnl_cls * | rtnl_cls_alloc (void)
void | rtnl_cls_put (struct rtnl_cls *cls)

## Attributes
void | rtnl_cls_set_prio (struct rtnl_cls *cls, uint16_t prio)
uint16_t | rtnl_cls_get_prio (struct rtnl_cls *cls)
void | rtnl_cls_set_protocol (struct rtnl_cls *cls, uint16_t protocol)
uint16_t | rtnl_cls_get_protocol (struct rtnl_cls *cls)

## Addition/Modification/Deletion
int | rtnl_cls_build_add_request (struct rtnl_cls *cls, int flags, struct nl_msg **result)
| Build a netlink message requesting the addition of a classifier.
int | rtnl_cls_add (struct nl_sock *sk, struct rtnl_cls *cls, int flags)
| Add/Update classifier.
int | rtnl_cls_build_change_request (struct rtnl_cls *cls, int flags, struct nl_msg **result)
| Build a netlink message to change classifier attributes.
int | rtnl_cls_change (struct nl_sock *sk, struct rtnl_cls *cls, int flags)
| Change a classifier.
int | rtnl_cls_build_delete_request (struct rtnl_cls *cls, int flags, struct nl_msg **result)
| Build netlink message requesting the deletion of a classifier.
int | rtnl_cls_delete (struct nl_sock *sk, struct rtnl_cls *cls, int flags)
| Delete classifier.

## Cache Related Functions
int | rtnl_cls_alloc_cache (struct nl_sock *sk, int ifindex, uint32_t parent, struct nl_cache **result)
| Allocate a cache and fill it with all configured classifiers.
void | rtnl_cls_cache_set_tc_params (struct nl_cache *cache, int ifindex, uint32_t parent)
| Set interface index and parent handle for classifier cache.
struct rtnl_cls * | rtnl_cls_find_by_handle (struct nl_cache *cache, int ifindex, uint32_t parent, uint32_t handle)
| Search classifier by interface index, parent and handle.
struct rtnl_cls * | rtnl_cls_find_by_prio (struct nl_cache *cache, int ifindex, uint32_t parent, uint16_t prio)
| Search classifier by interface index, parent and priority.

## Detailed Description

## Function Documentation

## ◆ rtnl_cls_alloc()

struct rtnl_cls * rtnl_cls_alloc | ( | void |  | ) |

Definition at line 68 of file cls.c.

## ◆ rtnl_cls_put()

void rtnl_cls_put | ( | struct rtnl_cls * | cls | ) |

Definition at line 79 of file cls.c.

## ◆ rtnl_cls_set_prio()

void rtnl_cls_set_prio | ( | struct rtnl_cls * | cls,
|  | uint16_t | prio )

Definition at line 91 of file cls.c.

## ◆ rtnl_cls_get_prio()

uint16_t rtnl_cls_get_prio | ( | struct rtnl_cls * | cls | ) |

Definition at line 97 of file cls.c.

## ◆ rtnl_cls_set_protocol()

void rtnl_cls_set_protocol | ( | struct rtnl_cls * | cls,
|  | uint16_t | protocol )

Definition at line 105 of file cls.c.

## ◆ rtnl_cls_get_protocol()

uint16_t rtnl_cls_get_protocol | ( | struct rtnl_cls * | cls | ) |

Definition at line 111 of file cls.c.

## ◆ rtnl_cls_build_add_request()

int rtnl_cls_build_add_request | ( | struct rtnl_cls * | cls,
|  | int | flags,
|  | struct nl_msg ** | result )

Build a netlink message requesting the addition of a classifier.

Parameters

  cls | Classifier to add
  flags | Additional netlink message flags
  result | Pointer to store resulting netlink message

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

See also
  rtnl_cls_add()

Returns
  0 on success or a negative error code.

Definition at line 141 of file cls.c.

Referenced by rtnl_cls_add().

Here is the caller graph for this function:

## ◆ rtnl_cls_add()

int rtnl_cls_add | ( | struct nl_sock * | sk,
|  | struct rtnl_cls * | cls,
|  | int | flags )

Add/Update classifier.

Parameters

  sk | Netlink socket
  cls | Classifier to add/update
  flags | Additional netlink message flags

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

The following flags may be specified:

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

Existing classifiers with matching handles will be updated, unless the flag `NLM_F_EXCL` is specified. If no matching classifier 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 188 of file cls.c.

References nl_send_sync(), and rtnl_cls_build_add_request().

Here is the call graph for this function:

## ◆ rtnl_cls_build_change_request()

int rtnl_cls_build_change_request | ( | struct rtnl_cls * | cls,
|  | int | flags,
|  | struct nl_msg ** | result )

Build a netlink message to change classifier attributes.

Parameters

  cls | classifier to change
  flags | additional netlink message flags
  result | Pointer to store resulting message.

Builds a new netlink message requesting a change of a neigh attributes. 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 212 of file cls.c.

Referenced by rtnl_cls_change().

Here is the caller graph for this function:

## ◆ rtnl_cls_change()

int rtnl_cls_change | ( | struct nl_sock * | sk,
|  | struct rtnl_cls * | cls,
|  | int | flags )

Change a classifier.

Parameters

  sk | Netlink socket.
  cls | classifier to change
  flags | additional netlink message flags

Builds a netlink message by calling rtnl_cls_build_change_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.

Returns
  0 on success or a negative error if an error occured.

Definition at line 230 of file cls.c.

References nl_send_sync(), and rtnl_cls_build_change_request().

Here is the call graph for this function:

## ◆ rtnl_cls_build_delete_request()

int rtnl_cls_build_delete_request | ( | struct rtnl_cls * | cls,
|  | int | flags,
|  | struct nl_msg ** | result )

Build netlink message requesting the deletion of a classifier.

Parameters

  cls | Classifier to delete
  flags | Additional netlink message flags
  result | Pointer to store resulting netlink message

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

See also
  rtnl_cls_delete()

Returns
  0 on success or a negative error code.

Definition at line 255 of file cls.c.

Referenced by rtnl_cls_delete().

Here is the caller graph for this function:

## ◆ rtnl_cls_delete()

int rtnl_cls_delete | ( | struct nl_sock * | sk,
|  | struct rtnl_cls * | cls,
|  | int | flags )

Delete classifier.

Parameters

  sk | Netlink socket
  cls | Classifier to delete
  flags | Additional netlink message flags

Builds a `RTM_DELTFILTER` netlink message requesting the deletion of a classifier and sends the message to the kernel.

The message is constructed out of the following attributes:

- `ifindex` (required)
- `prio` (required)
- `protocol` (required)
- `handle` (required)
- `parent` (optional, if not specified parent equals root-qdisc)
- `kind` (optional, must match if provided)

All other classifier 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 299 of file cls.c.

References nl_send_sync(), and rtnl_cls_build_delete_request().

Here is the call graph for this function:

## ◆ rtnl_cls_alloc_cache()

int rtnl_cls_alloc_cache | ( | struct nl_sock * | sk,
|  | int | ifindex,
|  | uint32_t | parent,
|  | struct nl_cache ** | result )

Allocate a cache and fill it with all configured classifiers.

Parameters

  sk | Netlink socket
  ifindex | Interface index of the network device
  parent | Parent qdisc/traffic class class
  result | Pointer to store the created cache

Allocates a new classifier cache and fills it with a list of all configured classifier attached to the specified parent qdisc/traffic class on the specified network device. Release the cache with nl_cache_free().

Returns
  0 on success or a negative error code.

Definition at line 331 of file cls.c.

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

Here is the call graph for this function:

## ◆ rtnl_cls_cache_set_tc_params()

void rtnl_cls_cache_set_tc_params | ( | struct nl_cache * | cache,
|  | int | ifindex,
|  | uint32_t | parent )

Set interface index and parent handle for classifier cache.

Parameters

  cache | Pointer to cache
  parent | Parent qdisc/traffic class class

Set the interface index and parent handle of a classifier cache. This is useful for reusing some existed classifier cache to reduce the overhead introduced by memory allocation.

Returns
  void.

Definition at line 363 of file cls.c.

## ◆ rtnl_cls_find_by_handle()

struct rtnl_cls * rtnl_cls_find_by_handle | ( | struct nl_cache * | cache,
|  | int | ifindex,
|  | uint32_t | parent,
|  | uint32_t | handle )

Search classifier by interface index, parent and handle.

Parameters

  cache | Classifier cache
  ifindex | Interface index
  parent | Parent
  handle | Handle

Searches a classifier cache previously allocated with rtnl_cls_alloc_cache() and searches for a classifier matching the interface index, parent and handle.

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

Returns
  Classifier or NULL if no match was found.

Definition at line 386 of file cls.c.

References nl_object_get().

Here is the call graph for this function:

## ◆ rtnl_cls_find_by_prio()

struct rtnl_cls * rtnl_cls_find_by_prio | ( | struct nl_cache * | cache,
|  | int | ifindex,
|  | uint32_t | parent,
|  | uint16_t | prio )

Search classifier by interface index, parent and priority.

Parameters

  cache | Classifier cache
  ifindex | Interface index
  parent | Parent
  prio | Priority

Searches a classifier cache previously allocated with rtnl_cls_alloc_cache() and searches for a classifier matching the interface index, parent and prio.

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

Returns
  Classifier or NULL if no match was found.

Definition at line 422 of file cls.c.

References nl_object_get().

Here is the call graph for this function: