Routing Rules
[Routing Netlink]

Allocation/Freeing



struct rtnl_rule * rtnl_rule_alloc (void)
void rtnl_rule_put (struct rtnl_rule *rule)

Cache Management



struct nl_cache * rtnl_rule_alloc_cache_by_family (struct nl_handle *handle, int family)
 Build a rule cache including all rules of the specified family currently configured in the kernel.
struct nl_cache * rtnl_rule_alloc_cache (struct nl_handle *handle)
 Build a rule cache including all rules currently configured in the kernel.

Rule Addition



struct nl_msg * rtnl_rule_build_add_request (struct rtnl_rule *tmpl, int flags)
 Build netlink request message to add a new rule.
int rtnl_rule_add (struct nl_handle *handle, struct rtnl_rule *tmpl, int flags)
 Add a new rule.

Rule Deletion



struct nl_msg * rtnl_rule_build_delete_request (struct rtnl_rule *rule, int flags)
 Build a netlink request message to delete a rule.
int rtnl_rule_delete (struct nl_handle *handle, struct rtnl_rule *rule, int flags)
 Delete a rule.

Attribute Modification



void rtnl_rule_set_family (struct rtnl_rule *rule, int family)
int rtnl_rule_get_family (struct rtnl_rule *rule)
void rtnl_rule_set_prio (struct rtnl_rule *rule, int prio)
int rtnl_rule_get_prio (struct rtnl_rule *rule)
void rtnl_rule_set_mark (struct rtnl_rule *rule, uint64_t mark)
uint64_t rtnl_rule_get_mark (struct rtnl_rule *rule)
void rtnl_rule_set_table (struct rtnl_rule *rule, int table)
int rtnl_rule_get_table (struct rtnl_rule *rule)
void rtnl_rule_set_dsfield (struct rtnl_rule *rule, int dsfield)
int rtnl_rule_get_dsfield (struct rtnl_rule *rule)
void rtnl_rule_set_src_len (struct rtnl_rule *rule, int len)
int rtnl_rule_get_src_len (struct rtnl_rule *rule)
void rtnl_rule_set_dst_len (struct rtnl_rule *rule, int len)
int rtnl_rule_get_dst_len (struct rtnl_rule *rule)
int rtnl_rule_set_src (struct rtnl_rule *rule, struct nl_addr *src)
struct nl_addr * rtnl_rule_get_src (struct rtnl_rule *rule)
int rtnl_rule_set_dst (struct rtnl_rule *rule, struct nl_addr *dst)
struct nl_addr * rtnl_rule_get_dst (struct rtnl_rule *rule)
int rtnl_rule_set_iif (struct rtnl_rule *rule, const char *dev)
char * rtnl_rule_get_iif (struct rtnl_rule *rule)
void rtnl_rule_set_action (struct rtnl_rule *rule, int type)
int rtnl_rule_get_action (struct rtnl_rule *rule)
void rtnl_rule_set_realms (struct rtnl_rule *rule, realm_t realms)
realm_t rtnl_rule_get_realms (struct rtnl_rule *rule)

Function Documentation

struct nl_cache* rtnl_rule_alloc_cache_by_family ( struct nl_handle *  handle,
int  family 
) [read]
Parameters:
handle netlink handle
family address family

Allocates a new rule cache, initializes it properly and updates it to include all rules of the specified address family currently configured in the kernel.

Note:
The caller is responsible for destroying and freeing the cache after using it. (nl_cache_destroy_and_free())
Returns:
The new cache or NULL if an error occured.

Definition at line 449 of file rule.c.

References nl_cache_alloc(), and nl_cache_refill().

Referenced by rtnl_rule_alloc_cache().

00451 {
00452         struct nl_cache * cache;
00453 
00454         cache = nl_cache_alloc(&rtnl_rule_ops);
00455         if (cache == NULL)
00456                 return NULL;
00457 
00458         /* XXX RULE_CACHE_FAMILY(cache) = family; */
00459 
00460         if (handle && nl_cache_refill(handle, cache) < 0) {
00461                 free(cache);
00462                 return NULL;
00463         }
00464 
00465         return cache;
00466 }

struct nl_cache* rtnl_rule_alloc_cache ( struct nl_handle *  handle  )  [read]
Parameters:
handle netlink handle

Allocates a new rule cache, initializes it properly and updates it to include all rules currently configured in the kernel.

Note:
The caller is responsible for destroying and freeing the cache after using it. (nl_cache_destroy_and_free())
Returns:
The new cache or NULL if an error occured.

Definition at line 479 of file rule.c.

References rtnl_rule_alloc_cache_by_family().

00480 {
00481         return rtnl_rule_alloc_cache_by_family(handle, AF_UNSPEC);
00482 }

struct nl_msg* rtnl_rule_build_add_request ( struct rtnl_rule *  tmpl,
int  flags 
) [read]
Parameters:
tmpl template with data of new rule
flags additional netlink message flags

Builds a new netlink message requesting a addition of a new rule. 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. tmpl must contain the attributes of the new address set via rtnl_rule_set_* functions.

Returns:
The netlink message

Definition at line 564 of file rule.c.

References NLM_F_CREATE.

Referenced by rtnl_rule_add().

00565 {
00566         return build_rule_msg(tmpl, RTM_NEWRULE, NLM_F_CREATE | flags);
00567 }

int rtnl_rule_add ( struct nl_handle *  handle,
struct rtnl_rule *  tmpl,
int  flags 
)
Parameters:
handle netlink handle
tmpl template with requested changes
flags additional netlink message flags

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

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

Definition at line 581 of file rule.c.

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

00582 {
00583         int err;
00584         struct nl_msg *msg;
00585         
00586         msg = rtnl_rule_build_add_request(tmpl, flags);
00587         if (!msg)
00588                 return nl_errno(ENOMEM);
00589 
00590         err = nl_send_auto_complete(handle, msg);
00591         if (err < 0)
00592                 return err;
00593 
00594         nlmsg_free(msg);
00595         return nl_wait_for_ack(handle);
00596 }

struct nl_msg* rtnl_rule_build_delete_request ( struct rtnl_rule *  rule,
int  flags 
) [read]
Parameters:
rule rule to delete
flags additional netlink message flags

Builds a new netlink message requesting a deletion of a rule. 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. rule must point to an existing address.

Returns:
The netlink message

Definition at line 618 of file rule.c.

Referenced by rtnl_rule_delete().

00619 {
00620         return build_rule_msg(rule, RTM_DELRULE, flags);
00621 }

int rtnl_rule_delete ( struct nl_handle *  handle,
struct rtnl_rule *  rule,
int  flags 
)
Parameters:
handle netlink handle
rule rule to delete
flags additional netlink message flags

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

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

Definition at line 635 of file rule.c.

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

00637 {
00638         int err;
00639         struct nl_msg *msg;
00640         
00641         msg = rtnl_rule_build_delete_request(rule, flags);
00642         if (!msg)
00643                 return nl_errno(ENOMEM);
00644 
00645         err = nl_send_auto_complete(handle, msg);
00646         if (err < 0)
00647                 return err;
00648 
00649         nlmsg_free(msg);
00650         return nl_wait_for_ack(handle);
00651 }


Generated on 30 Oct 2009 for libnl by  doxygen 1.6.1