libnl  1.1
Modules
FIB Lookup
Netlink Families

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

struct nl_cache* flnl_result_alloc_cache ( void  )
read

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.

References nl_cache_alloc().

{
return nl_cache_alloc(&fib_lookup_ops);
}
struct nl_msg* flnl_lookup_build_request ( struct flnl_request *  req,
int  flags 
)
read
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.

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

Referenced by flnl_lookup().

{
struct nl_msg *msg;
struct nl_addr *addr;
uint64_t fwmark;
int tos, scope, table;
struct fib_result_nl fr = {0};
fwmark = flnl_request_get_fwmark(req);
tos = flnl_request_get_tos(req);
scope = flnl_request_get_scope(req);
table = flnl_request_get_table(req);
fr.fl_fwmark = fwmark != UINT_LEAST64_MAX ? fwmark : 0;
fr.fl_tos = tos >= 0 ? tos : 0;
fr.fl_scope = scope >= 0 ? scope : RT_SCOPE_UNIVERSE;
fr.tb_id_in = table >= 0 ? table : RT_TABLE_UNSPEC;
addr = flnl_request_get_addr(req);
if (!addr) {
nl_error(EINVAL, "Request must specify the address");
return NULL;
}
fr.fl_addr = *(uint32_t *) nl_addr_get_binary_addr(addr);
msg = nlmsg_alloc_simple(0, flags);
if (!msg)
goto errout;
if (nlmsg_append(msg, &fr, sizeof(fr), NLMSG_ALIGNTO) < 0)
goto errout;
return msg;
errout:
nlmsg_free(msg);
return NULL;
}
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.

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

{
struct nl_msg *msg;
int err;
if (!msg)
return nl_errno(ENOMEM);
err = nl_send_auto_complete(handle, msg);
nlmsg_free(msg);
if (err < 0)
return err;
return nl_cache_pickup(handle, cache);
}