Routing Rules
[Routing Netlink]


Routing Rule Object Allocation/Freeage

rtnl_rule * rtnl_rule_alloc (void)
 Allocate a new rule object.
void rtnl_rule_put (struct rtnl_rule *rule)
 Give back reference on routing rule object.
void rtnl_rule_free (struct rtnl_rule *rule)
 Free routing rule object.

Routing Rule Cache Management

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.
nl_cache * rtnl_rule_alloc_cache (struct nl_handle *handle)
 Build a rule cache including all rules currently configured in the kernel.

Rule Addition

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

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)
 Set the address family of a rule to the specified value.
int rtnl_rule_get_family (struct rtnl_rule *rule)
 Get the address family of a rule.
void rtnl_rule_set_prio (struct rtnl_rule *rule, int prio)
 Set the priority of a rule to the specified value.
int rtnl_rule_get_prio (struct rtnl_rule *rule)
 Get the priority of a rule.
void rtnl_rule_set_fwmark (struct rtnl_rule *rule, uint64_t fwmark)
 Set the firewall mark of a rule to the specified value.
uint64_t rtnl_rule_get_fwmark (struct rtnl_rule *rule)
 Get the firewall mark of a rule.
void rtnl_rule_set_table (struct rtnl_rule *rule, int table)
 Set the table index of a rule to the specified value.
int rtnl_rule_get_table (struct rtnl_rule *rule)
 Get the table index of a rule.
void rtnl_rule_set_dsfield (struct rtnl_rule *rule, int dsfield)
 Set the dsfield of a rule to the specified value.
int rtnl_rule_get_dsfield (struct rtnl_rule *rule)
 Get the dsfield of a rule.
void rtnl_rule_set_src_len (struct rtnl_rule *rule, int len)
 Set the source address prefix length of a rule to the specified value.
int rtnl_rule_get_src_len (struct rtnl_rule *rule)
 Get the source address prefix length of a rule.
void rtnl_rule_set_dst_len (struct rtnl_rule *rule, int len)
 Set the destination address prefix length of a rule to the specified value.
int rtnl_rule_get_dst_len (struct rtnl_rule *rule)
 Get the destination address prefix length of a rule.
int rtnl_rule_set_src (struct rtnl_rule *rule, struct nl_addr *src)
 Set the source address of a rule.
nl_addr * rtnl_rule_get_src (struct rtnl_rule *rule)
 Get the source address of a rule.
int rtnl_rule_set_dst (struct rtnl_rule *rule, struct nl_addr *dst)
 Set the destination address of a rule.
nl_addr * rtnl_rule_get_dst (struct rtnl_rule *rule)
 Get the destination address of a rule.
int rtnl_rule_set_iif (struct rtnl_rule *rule, const char *dev)
 Set incoming interface of routing rule object.
char * rtnl_rule_get_iif (struct rtnl_rule *rule)
 Get incoming interface of routing rule object.
void rtnl_rule_set_action (struct rtnl_rule *rule, int type)
 Set action of routing rule object.
int rtnl_rule_get_action (struct rtnl_rule *rule)
 Get action of routing rule object.
void rtnl_rule_set_realms (struct rtnl_rule *rule, realm_t realms)
 Set realms of routing rule object.
realm_t rtnl_rule_get_realms (struct rtnl_rule *rule)
 Get realms of routing rule object.


Function Documentation

struct rtnl_rule* rtnl_rule_alloc ( void   ) 

Allocate a new rule object.

Returns:
New rule object

Definition at line 387 of file rule.c.

References nl_object_alloc_from_ops().

void rtnl_rule_put ( struct rtnl_rule *  rule  ) 

Give back reference on routing rule object.

Parameters:
rule Routing rule object to be given back.
Decrements the reference counter and frees the object if the last reference has been released.

Definition at line 399 of file rule.c.

References nl_object_put().

void rtnl_rule_free ( struct rtnl_rule *  rule  ) 

Free routing rule object.

Parameters:
rule Routing rule object to be freed.
Note:
Always use rtnl_rule_put() unless you're absolutely sure that no other user may have a reference on this object.

Definition at line 410 of file rule.c.

References nl_object_free().

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.

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 435 of file rule.c.

References nl_cache_alloc_from_ops(), and nl_cache_update().

Referenced by rtnl_rule_alloc_cache().

struct nl_cache* rtnl_rule_alloc_cache ( struct nl_handle *  handle  ) 

Build a rule cache including all rules currently configured in the kernel.

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 464 of file rule.c.

References rtnl_rule_alloc_cache_by_family().

struct nl_msg* rtnl_rule_build_add_request ( struct rtnl_rule *  tmpl,
int  flags 
)

Build netlink request message to add a new rule.

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 549 of file rule.c.

References NLM_F_CREATE.

Referenced by rtnl_rule_add().

int rtnl_rule_add ( struct nl_handle *  handle,
struct rtnl_rule *  tmpl,
int  flags 
)

Add a new rule.

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 566 of file rule.c.

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

struct nl_msg* rtnl_rule_build_delete_request ( struct rtnl_rule *  rule,
int  flags 
)

Build a netlink request message to delete a rule.

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 603 of file rule.c.

Referenced by rtnl_rule_delete().

int rtnl_rule_delete ( struct nl_handle *  handle,
struct rtnl_rule *  rule,
int  flags 
)

Delete a rule.

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 620 of file rule.c.

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

void rtnl_rule_set_family ( struct rtnl_rule *  rule,
int  family 
)

Set the address family of a rule to the specified value.

Parameters:
rule rule to change
family new address family

Definition at line 650 of file rule.c.

int rtnl_rule_get_family ( struct rtnl_rule *  rule  ) 

Get the address family of a rule.

Parameters:
rule rule handle
Returns:
Address family or AF_UNSPEC if not set

Definition at line 661 of file rule.c.

void rtnl_rule_set_prio ( struct rtnl_rule *  rule,
int  prio 
)

Set the priority of a rule to the specified value.

Parameters:
rule rule to change
prio new priority

Definition at line 674 of file rule.c.

int rtnl_rule_get_prio ( struct rtnl_rule *  rule  ) 

Get the priority of a rule.

Parameters:
rule rule handle
Returns:
Priority or -1 if not set

Definition at line 685 of file rule.c.

void rtnl_rule_set_fwmark ( struct rtnl_rule *  rule,
uint64_t  fwmark 
)

Set the firewall mark of a rule to the specified value.

Parameters:
rule rule to change
fwmark new firewall mark

Definition at line 698 of file rule.c.

uint64_t rtnl_rule_get_fwmark ( struct rtnl_rule *  rule  ) 

Get the firewall mark of a rule.

Parameters:
rule rule handle
Returns:
Firewall mark or UINT_LEAST64_MAX if not set

Definition at line 709 of file rule.c.

void rtnl_rule_set_table ( struct rtnl_rule *  rule,
int  table 
)

Set the table index of a rule to the specified value.

Parameters:
rule rule to change
table new table

Definition at line 722 of file rule.c.

int rtnl_rule_get_table ( struct rtnl_rule *  rule  ) 

Get the table index of a rule.

Parameters:
rule rule handle
Returns:
Table index or -1 if not set

Definition at line 733 of file rule.c.

void rtnl_rule_set_dsfield ( struct rtnl_rule *  rule,
int  dsfield 
)

Set the dsfield of a rule to the specified value.

Parameters:
rule rule to change
dsfield new dsfield value

Definition at line 746 of file rule.c.

int rtnl_rule_get_dsfield ( struct rtnl_rule *  rule  ) 

Get the dsfield of a rule.

Parameters:
rule rule handle
Returns:
dsfield or -1 if not set

Definition at line 757 of file rule.c.

void rtnl_rule_set_src_len ( struct rtnl_rule *  rule,
int  len 
)

Set the source address prefix length of a rule to the specified value.

Parameters:
rule rule to change
len new source address length

Definition at line 770 of file rule.c.

References nl_addr_set_prefixlen().

int rtnl_rule_get_src_len ( struct rtnl_rule *  rule  ) 

Get the source address prefix length of a rule.

Parameters:
rule rule handle
Returns:
Prefix length of source address or -1 if not set

Definition at line 783 of file rule.c.

void rtnl_rule_set_dst_len ( struct rtnl_rule *  rule,
int  len 
)

Set the destination address prefix length of a rule to the specified value.

Parameters:
rule rule to change
len new destination address length

Definition at line 796 of file rule.c.

References nl_addr_set_prefixlen().

int rtnl_rule_get_dst_len ( struct rtnl_rule *  rule  ) 

Get the destination address prefix length of a rule.

Parameters:
rule rule handle
Returns:
Prefix length of destination address or -1 if not set

Definition at line 809 of file rule.c.

int rtnl_rule_set_src ( struct rtnl_rule *  rule,
struct nl_addr *  src 
)

Set the source address of a rule.

Parameters:
rule rule to change
src new source address
Assigns the new source address to the specified rule handle. The address is validated against the address family if set already via either rtnl_rule_set_family() or by setting one of the other addresses. The assignment fails if the address families mismatch. In case the address family has not been specified yet, the address family of this new address is elected to be the requirement.

Returns:
0 on success or a negative error code.

Definition at line 851 of file rule.c.

struct nl_addr* rtnl_rule_get_src ( struct rtnl_rule *  rule  ) 

Get the source address of a rule.

Parameters:
rule rule handle
Returns:
Source address or NULL if not set

Definition at line 862 of file rule.c.

int rtnl_rule_set_dst ( struct rtnl_rule *  rule,
struct nl_addr *  dst 
)

Set the destination address of a rule.

Parameters:
rule rule to change
dst new destination address
Assigns the new destination address to the specified rule handle. The address is validated against the address family if set already via either rtnl_rule_set_family() or by setting one of the other addresses. The assignment fails if the address families mismatch. In case the address family has not been specified yet, the address family of this new address is elected to be the requirement.

Returns:
0 on success or a negative error code.

Definition at line 884 of file rule.c.

struct nl_addr* rtnl_rule_get_dst ( struct rtnl_rule *  rule  ) 

Get the destination address of a rule.

Parameters:
rule rule handle
Returns:
Destination address or NULL if not set

Definition at line 895 of file rule.c.

int rtnl_rule_set_iif ( struct rtnl_rule *  rule,
const char *  dev 
)

Set incoming interface of routing rule object.

Parameters:
rule Routing rule object to be modified.
dev Name of incoming interface.
Returns:
0 on success or a negative error code.

Definition at line 910 of file rule.c.

char* rtnl_rule_get_iif ( struct rtnl_rule *  rule  ) 

Get incoming interface of routing rule object.

Parameters:
rule Routing rule object.
Returns:
Name of incoming interface or NULL if not available.

Definition at line 925 of file rule.c.

void rtnl_rule_set_action ( struct rtnl_rule *  rule,
int  type 
)

Set action of routing rule object.

Parameters:
rule Routing rule object to be modified.
type New routing type specifying an action.

Definition at line 938 of file rule.c.

int rtnl_rule_get_action ( struct rtnl_rule *  rule  ) 

Get action of routing rule object.

Parameters:
rule Routing rule object.
Returns:
Routing type or a negative error code.

Definition at line 949 of file rule.c.

void rtnl_rule_set_realms ( struct rtnl_rule *  rule,
realm_t  realms 
)

Set realms of routing rule object.

Parameters:
rule Routing rule object to be modified.
realms New realms value.

Definition at line 962 of file rule.c.

realm_t rtnl_rule_get_realms ( struct rtnl_rule *  rule  ) 

Get realms of routing rule object.

Parameters:
rule Routing rule object.
Returns:
Realms value or 0 if not set.

Definition at line 973 of file rule.c.


Generated on Fri Apr 27 14:14:08 2007 for libnl by  doxygen 1.5.1