libnl  1.1.4
Modules

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. More...
 
int rtnl_class_add (struct nl_handle *handle, struct rtnl_class *class, int flags)
 Add a new class. More...
 

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. More...
 

Detailed Description

Function Documentation

◆ rtnl_class_build_add_request()

struct nl_msg* rtnl_class_build_add_request ( struct rtnl_class *  class,
int  flags 
)
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.

129 {
130  return class_build(class, RTM_NEWTCLASS, NLM_F_CREATE | flags);
131 }

Referenced by rtnl_class_add().

◆ rtnl_class_add()

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.

150 {
151  struct nl_msg *msg;
152  int err;
153 
154  msg = rtnl_class_build_add_request(class, flags);
155  if (!msg)
156  return nl_errno(ENOMEM);
157 
158  err = nl_send_auto_complete(handle, msg);
159  nlmsg_free(msg);
160  if (err < 0)
161  return err;
162 
163  return nl_wait_for_ack(handle);
164 }

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

◆ rtnl_class_alloc_cache()

struct nl_cache* rtnl_class_alloc_cache ( struct nl_handle *  handle,
int  ifindex 
)
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.

185 {
186  struct nl_cache * cache;
187 
188  cache = nl_cache_alloc(&rtnl_class_ops);
189  if (!cache)
190  return NULL;
191 
192  cache->c_iarg1 = ifindex;
193 
194  if (handle && nl_cache_refill(handle, cache) < 0) {
195  nl_cache_free(cache);
196  return NULL;
197  }
198 
199  return cache;
200 }

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

nl_wait_for_ack
int nl_wait_for_ack(struct nl_handle *handle)
Wait for ACK.
Definition: nl.c:801
rtnl_class_build_add_request
struct nl_msg * rtnl_class_build_add_request(struct rtnl_class *class, int flags)
Build a netlink message to add a new class.
Definition: class.c:128
NLM_F_CREATE
#define NLM_F_CREATE
Create config object if it doesn't already exist.
Definition: netlink-kernel.h:134
rtnl_class_ops
Class operations.
Definition: class-modules.h:26
nlmsg_free
void nlmsg_free(struct nl_msg *n)
Free a netlink message.
Definition: msg.c:656
nl_send_auto_complete
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
nl_cache_alloc
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate an empty cache.
Definition: cache.c:170
nl_cache_refill
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
nl_cache_free
void nl_cache_free(struct nl_cache *cache)
Free a cache.
Definition: cache.c:277