libnl  1.1.4
Modules
Classifiers

Modules

 Classifier Modules
 
 Classifier Object
 

Classifier Addition/Modification/Deletion

struct nl_msg * rtnl_cls_build_add_request (struct rtnl_cls *cls, int flags)
 Build a netlink message to add a new classifier. More...
 
int rtnl_cls_add (struct nl_handle *handle, struct rtnl_cls *cls, int flags)
 Add a new classifier. More...
 
struct nl_msg * rtnl_cls_build_change_request (struct rtnl_cls *cls, int flags)
 Build a netlink message to change classifier attributes. More...
 
int rtnl_cls_change (struct nl_handle *handle, struct rtnl_cls *cls, int flags)
 Change a classifier. More...
 
struct nl_msg * rtnl_cls_build_delete_request (struct rtnl_cls *cls, int flags)
 Build a netlink request message to delete a classifier. More...
 
int rtnl_cls_delete (struct nl_handle *handle, struct rtnl_cls *cls, int flags)
 Delete a classifier. More...
 

Cache Management

struct nl_cache * rtnl_cls_alloc_cache (struct nl_handle *handle, int ifindex, uint32_t parent)
 Build a classifier cache including all classifiers attached to the specified class/qdisc on eht specified interface. More...
 

Detailed Description

Classifier Identification
  • protocol
  • priority
  • parent
  • interface
  • kind
  • handle

Function Documentation

struct nl_msg* rtnl_cls_build_add_request ( struct rtnl_cls *  cls,
int  flags 
)
Parameters
clsclassifier to add
flagsadditional netlink message flags

Builds a new netlink message requesting an addition of a classifier 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. classifier must contain the attributes of the new classifier set via rtnl_cls_set_* functions. opts may point to the clsasifier specific options.

Returns
New netlink message

Definition at line 145 of file classifier.c.

References NLM_F_CREATE.

Referenced by rtnl_cls_add().

146 {
147  return cls_build(cls, RTM_NEWTFILTER, NLM_F_CREATE | flags);
148 }
#define NLM_F_CREATE
Create config object if it doesn't already exist.
int rtnl_cls_add ( struct nl_handle *  handle,
struct rtnl_cls *  cls,
int  flags 
)
Parameters
handlenetlink handle
clsclassifier to add
flagsadditional netlink message flags

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

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

Definition at line 162 of file classifier.c.

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

163 {
164  int err;
165  struct nl_msg *msg;
166 
167  msg = rtnl_cls_build_add_request(cls, flags);
168  if (!msg)
169  return nl_errno(ENOMEM);
170 
171  err = nl_send_auto_complete(handle, msg);
172  nlmsg_free(msg);
173  if (err < 0)
174  return err;
175 
176  return nl_wait_for_ack(handle);
177 }
int nl_wait_for_ack(struct nl_handle *handle)
Wait for ACK.
Definition: nl.c:801
void nlmsg_free(struct nl_msg *n)
Free a netlink message.
Definition: msg.c:656
struct nl_msg * rtnl_cls_build_add_request(struct rtnl_cls *cls, int flags)
Build a netlink message to add a new classifier.
Definition: classifier.c:145
int nl_send_auto_complete(struct nl_handle *handle, struct nl_msg *msg)
Send netlink message and check & extend header values as needed.
Definition: nl.c:373
struct nl_msg* rtnl_cls_build_change_request ( struct rtnl_cls *  cls,
int  flags 
)
Parameters
clsclassifier to change
flagsadditional netlink message flags

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
The netlink message

Definition at line 191 of file classifier.c.

References NLM_F_REPLACE.

Referenced by rtnl_cls_change().

192 {
193  return cls_build(cls, RTM_NEWTFILTER, NLM_F_REPLACE | flags);
194 }
#define NLM_F_REPLACE
Replace existing matching config object with this request.
int rtnl_cls_change ( struct nl_handle *  handle,
struct rtnl_cls *  cls,
int  flags 
)
Parameters
handlenetlink handle
clsclassifier to change
flagsadditional 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 sucess or a negative error if an error occured.

Definition at line 208 of file classifier.c.

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

210 {
211  int err;
212  struct nl_msg *msg;
213 
214  msg = rtnl_cls_build_change_request(cls, flags);
215  if (!msg)
216  return nl_errno(ENOMEM);
217 
218  err = nl_send_auto_complete(handle, msg);
219  nlmsg_free(msg);
220  if (err < 0)
221  return err;
222 
223  return nl_wait_for_ack(handle);
224 }
int nl_wait_for_ack(struct nl_handle *handle)
Wait for ACK.
Definition: nl.c:801
void nlmsg_free(struct nl_msg *n)
Free a netlink message.
Definition: msg.c:656
struct nl_msg * rtnl_cls_build_change_request(struct rtnl_cls *cls, int flags)
Build a netlink message to change classifier attributes.
Definition: classifier.c:191
int nl_send_auto_complete(struct nl_handle *handle, struct nl_msg *msg)
Send netlink message and check & extend header values as needed.
Definition: nl.c:373
struct nl_msg* rtnl_cls_build_delete_request ( struct rtnl_cls *  cls,
int  flags 
)
Parameters
clsclassifier to delete
flagsadditional netlink message flags

Builds a new netlink message requesting a deletion of a classifier. 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
New netlink message

Definition at line 238 of file classifier.c.

Referenced by rtnl_cls_delete().

239 {
240  return cls_build(cls, RTM_DELTFILTER, flags);
241 }
int rtnl_cls_delete ( struct nl_handle *  handle,
struct rtnl_cls *  cls,
int  flags 
)
Parameters
handlenetlink handle
clsclassifier to delete
flagsadditional netlink message flags

Builds a netlink message by calling rtnl_cls_build_delete_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 sucess or a negative error if an error occured.

Definition at line 256 of file classifier.c.

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

257 {
258  int err;
259  struct nl_msg *msg;
260 
261  msg = rtnl_cls_build_delete_request(cls, flags);
262  if (!msg)
263  return nl_errno(ENOMEM);
264 
265  err = nl_send_auto_complete(handle, msg);
266  nlmsg_free(msg);
267  if (err < 0)
268  return err;
269 
270  return nl_wait_for_ack(handle);
271 }
int nl_wait_for_ack(struct nl_handle *handle)
Wait for ACK.
Definition: nl.c:801
void nlmsg_free(struct nl_msg *n)
Free a netlink message.
Definition: msg.c:656
int nl_send_auto_complete(struct nl_handle *handle, struct nl_msg *msg)
Send netlink message and check & extend header values as needed.
Definition: nl.c:373
struct nl_msg * rtnl_cls_build_delete_request(struct rtnl_cls *cls, int flags)
Build a netlink request message to delete a classifier.
Definition: classifier.c:238
struct nl_cache* rtnl_cls_alloc_cache ( struct nl_handle *  handle,
int  ifindex,
uint32_t  parent 
)
Parameters
handlenetlink handle
ifindexinterface index of the link the classes are attached to.
parentparent qdisc/class

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

Note
The caller is responsible for destroying and freeing the cache after using it.
Returns
The cache or NULL if an error has occured.

Definition at line 295 of file classifier.c.

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

297 {
298  struct nl_cache * cache;
299 
300  cache = nl_cache_alloc(&rtnl_cls_ops);
301  if (cache == NULL)
302  return NULL;
303 
304  cache->c_iarg1 = ifindex;
305  cache->c_iarg2 = parent;
306 
307  if (handle && nl_cache_refill(handle, cache) < 0) {
308  nl_cache_free(cache);
309  return NULL;
310  }
311 
312  return cache;
313 }
void nl_cache_free(struct nl_cache *cache)
Free a cache.
Definition: cache.c:277
int nl_cache_refill(struct nl_handle *handle, struct nl_cache *cache)
(Re)fill a cache with the contents in the kernel.
Definition: cache.c:680
Classifier operations.
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate an empty cache.
Definition: cache.c:170