libnl 1.1.4
Modules

Modules

 Route Object
 
 Utilities
 Routing Utility Functions.
 

Cache Management

struct nl_cache * rtnl_route_alloc_cache (struct nl_handle *handle)
 Build a route cache holding all routes currently configured in the kernel.
 

Route Addition

struct nl_msg * rtnl_route_build_add_request (struct rtnl_route *tmpl, int flags)
 
int rtnl_route_add (struct nl_handle *handle, struct rtnl_route *route, int flags)
 
struct nl_msg * rtnl_route_build_del_request (struct rtnl_route *tmpl, int flags)
 
int rtnl_route_del (struct nl_handle *handle, struct rtnl_route *route, int flags)
 

Detailed Description

Function Documentation

◆ rtnl_route_alloc_cache()

struct nl_cache * rtnl_route_alloc_cache ( struct nl_handle *  handle)
Parameters
handlenetlink handle

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

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 241 of file route.c.

242{
243 struct nl_cache *cache;
244
245 cache = nl_cache_alloc(&rtnl_route_ops);
246 if (!cache)
247 return NULL;
248
249 if (handle && nl_cache_refill(handle, cache) < 0) {
250 free(cache);
251 return NULL;
252 }
253
254 return cache;
255}
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate an empty cache.
Definition: cache.c:170
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

References nl_cache_alloc(), and nl_cache_refill().

◆ rtnl_route_build_add_request()

struct nl_msg * rtnl_route_build_add_request ( struct rtnl_route *  tmpl,
int  flags 
)

Definition at line 366 of file route.c.

367{
368 return build_route_msg(tmpl, RTM_NEWROUTE, NLM_F_CREATE | flags);
369}
#define NLM_F_CREATE
Create config object if it doesn't already exist.

◆ rtnl_route_add()

int rtnl_route_add ( struct nl_handle *  handle,
struct rtnl_route *  route,
int  flags 
)

Definition at line 371 of file route.c.

373{
374 struct nl_msg *msg;
375 int err;
376
377 msg = rtnl_route_build_add_request(route, flags);
378 if (!msg)
379 return nl_get_errno();
380
381 err = nl_send_auto_complete(handle, msg);
382 nlmsg_free(msg);
383 if (err < 0)
384 return err;
385
386 return nl_wait_for_ack(handle);
387}
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
int nl_wait_for_ack(struct nl_handle *handle)
Wait for ACK.
Definition: nl.c:801

◆ rtnl_route_build_del_request()

struct nl_msg * rtnl_route_build_del_request ( struct rtnl_route *  tmpl,
int  flags 
)

Definition at line 389 of file route.c.

390{
391 return build_route_msg(tmpl, RTM_DELROUTE, flags);
392}

◆ rtnl_route_del()

int rtnl_route_del ( struct nl_handle *  handle,
struct rtnl_route *  route,
int  flags 
)

Definition at line 394 of file route.c.

396{
397 struct nl_msg *msg;
398 int err;
399
400 msg = rtnl_route_build_del_request(route, flags);
401 if (!msg)
402 return nl_get_errno();
403
404 err = nl_send_auto_complete(handle, msg);
405 nlmsg_free(msg);
406 if (err < 0)
407 return err;
408
409 return nl_wait_for_ack(handle);
410}