libnl 1.1.4
Modules

Modules

 Request
 

Allocation/Freeing

struct flnl_result * flnl_result_alloc (void)
 
void flnl_result_put (struct flnl_result *res)
 

Cache Management

struct nl_cache * flnl_result_alloc_cache (void)
 Allocate lookup result cache.
 

Lookup

struct nl_msg * flnl_lookup_build_request (struct flnl_request *req, int flags)
 Builds a netlink request message to do a lookup.
 
int flnl_lookup (struct nl_handle *handle, struct flnl_request *req, struct nl_cache *cache)
 Perform FIB Lookup.
 

Attribute Access

int flnl_result_get_table_id (struct flnl_result *res)
 
int flnl_result_get_prefixlen (struct flnl_result *res)
 
int flnl_result_get_nexthop_sel (struct flnl_result *res)
 
int flnl_result_get_type (struct flnl_result *res)
 
int flnl_result_get_scope (struct flnl_result *res)
 
int flnl_result_get_error (struct flnl_result *res)
 

Detailed Description

Function Documentation

◆ flnl_result_alloc()

struct flnl_result * flnl_result_alloc ( void  )

Definition at line 158 of file lookup.c.

159{
160 return (struct flnl_result *) nl_object_alloc(&result_obj_ops);
161}
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
Definition: object.c:42

◆ flnl_result_put()

void flnl_result_put ( struct flnl_result *  res)

Definition at line 163 of file lookup.c.

164{
165 nl_object_put((struct nl_object *) res);
166}
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
Definition: object.c:178

◆ flnl_result_alloc_cache()

struct nl_cache * flnl_result_alloc_cache ( void  )

Allocates a new lookup result cache and initializes it properly.

Note
Free the memory after usage using nl_cache_destroy_and_free().
Returns
Newly allocated cache or NULL if an error occured.

Definition at line 183 of file lookup.c.

184{
185 return nl_cache_alloc(&fib_lookup_ops);
186}
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate an empty cache.
Definition: cache.c:170

References nl_cache_alloc().

◆ flnl_lookup_build_request()

struct nl_msg * flnl_lookup_build_request ( struct flnl_request *  req,
int  flags 
)
Parameters
reqRequested match.
flagsadditional netlink message flags

Builds a new netlink message requesting a change of link attributes. 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. old must point to a link currently configured in the kernel and tmpl must contain the attributes to be changed set via rtnl_link_set_* functions.

Returns
New netlink message
Note
Not all attributes can be changed, see Changeable Attributes for more details.

Definition at line 212 of file lookup.c.

213{
214 struct nl_msg *msg;
215 struct nl_addr *addr;
216 uint64_t fwmark;
217 int tos, scope, table;
218 struct fib_result_nl fr = {0};
219
220 fwmark = flnl_request_get_fwmark(req);
221 tos = flnl_request_get_tos(req);
222 scope = flnl_request_get_scope(req);
223 table = flnl_request_get_table(req);
224
225 fr.fl_fwmark = fwmark != UINT_LEAST64_MAX ? fwmark : 0;
226 fr.fl_tos = tos >= 0 ? tos : 0;
227 fr.fl_scope = scope >= 0 ? scope : RT_SCOPE_UNIVERSE;
228 fr.tb_id_in = table >= 0 ? table : RT_TABLE_UNSPEC;
229
230 addr = flnl_request_get_addr(req);
231 if (!addr) {
232 nl_error(EINVAL, "Request must specify the address");
233 return NULL;
234 }
235
236 fr.fl_addr = *(uint32_t *) nl_addr_get_binary_addr(addr);
237
238 msg = nlmsg_alloc_simple(0, flags);
239 if (!msg)
240 goto errout;
241
242 if (nlmsg_append(msg, &fr, sizeof(fr), NLMSG_ALIGNTO) < 0)
243 goto errout;
244
245 return msg;
246
247errout:
248 nlmsg_free(msg);
249 return NULL;
250}
void * nl_addr_get_binary_addr(struct nl_addr *addr)
Get binary address of abstract address object.
Definition: addr.c:756
struct nl_msg * nlmsg_alloc_simple(int nlmsgtype, int flags)
Allocate a new netlink message.
Definition: msg.c:448
void nlmsg_free(struct nl_msg *n)
Free a netlink message.
Definition: msg.c:656
int nlmsg_append(struct nl_msg *n, void *data, size_t len, int pad)
Append data to tail of a netlink message.
Definition: msg.c:549

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

Referenced by flnl_lookup().

◆ flnl_lookup()

int flnl_lookup ( struct nl_handle *  handle,
struct flnl_request *  req,
struct nl_cache *  cache 
)
Parameters
handleNetlink handle.
reqLookup request object.
cacheCache for result.

Builds a netlink message to request a FIB lookup, waits for the reply and adds the result to the specified cache.

Returns
0 on success or a negative error code.

Definition at line 263 of file lookup.c.

265{
266 struct nl_msg *msg;
267 int err;
268
269 msg = flnl_lookup_build_request(req, 0);
270 if (!msg)
271 return nl_errno(ENOMEM);
272
273 err = nl_send_auto_complete(handle, msg);
274 nlmsg_free(msg);
275 if (err < 0)
276 return err;
277
278 return nl_cache_pickup(handle, cache);
279}
int nl_cache_pickup(struct nl_handle *handle, struct nl_cache *cache)
Pickup a netlink dump response and put it into a cache.
Definition: cache.c:505
struct nl_msg * flnl_lookup_build_request(struct flnl_request *req, int flags)
Builds a netlink request message to do a lookup.
Definition: lookup.c:212
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

References flnl_lookup_build_request(), nl_cache_pickup(), nl_send_auto_complete(), and nlmsg_free().

◆ flnl_result_get_table_id()

int flnl_result_get_table_id ( struct flnl_result *  res)

Definition at line 288 of file lookup.c.

289{
290 return res->fr_table_id;
291}

◆ flnl_result_get_prefixlen()

int flnl_result_get_prefixlen ( struct flnl_result *  res)

Definition at line 293 of file lookup.c.

294{
295 return res->fr_prefixlen;
296}

◆ flnl_result_get_nexthop_sel()

int flnl_result_get_nexthop_sel ( struct flnl_result *  res)

Definition at line 298 of file lookup.c.

299{
300 return res->fr_nh_sel;
301}

◆ flnl_result_get_type()

int flnl_result_get_type ( struct flnl_result *  res)

Definition at line 303 of file lookup.c.

304{
305 return res->fr_type;
306}

◆ flnl_result_get_scope()

int flnl_result_get_scope ( struct flnl_result *  res)

Definition at line 308 of file lookup.c.

309{
310 return res->fr_scope;
311}

◆ flnl_result_get_error()

int flnl_result_get_error ( struct flnl_result *  res)

Definition at line 313 of file lookup.c.

314{
315 return res->fr_error;
316}