netfilter
firewalling, NAT, and packet mangling for linux
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Routing Rules
Collaboration diagram for Routing Rules:

Allocation/Freeing

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

Cache Management

int rtnl_rule_alloc_cache (struct nl_sock *sock, int family, struct nl_cache **result)
 Build a rule cache including all rules currently configured in the kernel. More...
 

Rule Addition

int rtnl_rule_build_add_request (struct rtnl_rule *tmpl, int flags, struct nl_msg **result)
 Build netlink request message to add a new rule. More...
 
int rtnl_rule_add (struct nl_sock *sk, struct rtnl_rule *tmpl, int flags)
 Add a new rule. More...
 

Rule Deletion

int rtnl_rule_build_delete_request (struct rtnl_rule *rule, int flags, struct nl_msg **result)
 Build a netlink request message to delete a rule. More...
 
int rtnl_rule_delete (struct nl_sock *sk, struct rtnl_rule *rule, int flags)
 Delete a rule. More...
 

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_addrrtnl_rule_get_src (struct rtnl_rule *rule)
 
int rtnl_rule_set_dst (struct rtnl_rule *rule, struct nl_addr *dst)
 
struct nl_addrrtnl_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, uint32_t realms)
 
uint32_t rtnl_rule_get_realms (struct rtnl_rule *rule)
 

Detailed Description

Function Documentation

int rtnl_rule_add ( struct nl_sock sk,
struct rtnl_rule tmpl,
int  flags 
)

Add a new rule.

  • sk Netlink socket.
  • 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.

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

Here is the call graph for this function:

struct rtnl_rule* rtnl_rule_alloc ( void  )

References nl_object_alloc().

Referenced by nl_cli_rule_alloc().

Here is the call graph for this function:

Here is the caller graph for this function:

int rtnl_rule_alloc_cache ( struct nl_sock sock,
int  family,
struct nl_cache **  result 
)

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

  • sk Netlink socket.
  • family Address family or AF_UNSPEC.
  • result Pointer to store resulting cache.

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

Returns
0 on success or a negative error code.

References nl_cache::c_iarg1, nl_cache_alloc(), nl_cache_refill(), and NLE_NOMEM.

Referenced by nl_cli_rule_alloc_cache().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Build netlink request message to add a new rule.

  • 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

References NLM_F_CREATE, and RTM_NEWRULE.

Referenced by rtnl_rule_add().

Here is the caller graph for this function:

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

Build a netlink request message to delete a rule.

  • 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

References RTM_DELRULE.

Referenced by rtnl_rule_delete().

Here is the caller graph for this function:

int rtnl_rule_delete ( struct nl_sock sk,
struct rtnl_rule rule,
int  flags 
)

Delete a rule.

  • sk Netlink socket.
  • 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.

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

Here is the call graph for this function:

int rtnl_rule_get_action ( struct rtnl_rule rule)

References NLE_NOATTR, and rtnl_rule::r_type.

int rtnl_rule_get_dsfield ( struct rtnl_rule rule)

References rtnl_rule::r_dsfield.

struct nl_addr* rtnl_rule_get_dst ( struct rtnl_rule rule)

References NULL, and rtnl_rule::r_dst.

int rtnl_rule_get_dst_len ( struct rtnl_rule rule)

References rtnl_rule::r_dst_len.

int rtnl_rule_get_family ( struct rtnl_rule rule)

References rtnl_rule::r_family.

char* rtnl_rule_get_iif ( struct rtnl_rule rule)

References NULL, and rtnl_rule::r_iif.

uint64_t rtnl_rule_get_mark ( struct rtnl_rule rule)

References rtnl_rule::r_mark.

int rtnl_rule_get_prio ( struct rtnl_rule rule)

References rtnl_rule::r_prio.

uint32_t rtnl_rule_get_realms ( struct rtnl_rule rule)

References rtnl_rule::r_realms.

struct nl_addr* rtnl_rule_get_src ( struct rtnl_rule rule)

References NULL, and rtnl_rule::r_src.

int rtnl_rule_get_src_len ( struct rtnl_rule rule)

References rtnl_rule::r_src_len.

int rtnl_rule_get_table ( struct rtnl_rule rule)

References rtnl_rule::r_table.

void rtnl_rule_put ( struct rtnl_rule rule)

References nl_object_put().

Here is the call graph for this function:

void rtnl_rule_set_action ( struct rtnl_rule rule,
int  type 
)

References rtnl_rule::r_type, and type.

void rtnl_rule_set_dsfield ( struct rtnl_rule rule,
int  dsfield 
)

References rtnl_rule::r_dsfield.

int rtnl_rule_set_dst ( struct rtnl_rule rule,
struct nl_addr dst 
)
void rtnl_rule_set_dst_len ( struct rtnl_rule rule,
int  len 
)

References len, nl_addr_set_prefixlen(), rtnl_rule::r_dst, and rtnl_rule::r_dst_len.

Here is the call graph for this function:

void rtnl_rule_set_family ( struct rtnl_rule rule,
int  family 
)

References rtnl_rule::r_family.

Referenced by nl_cli_rule_parse_family().

Here is the caller graph for this function:

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

References IFNAMSIZ, NLE_RANGE, and rtnl_rule::r_iif.

void rtnl_rule_set_mark ( struct rtnl_rule rule,
uint64_t  mark 
)

References mark, and rtnl_rule::r_mark.

void rtnl_rule_set_prio ( struct rtnl_rule rule,
int  prio 
)

References rtnl_rule::r_prio.

void rtnl_rule_set_realms ( struct rtnl_rule rule,
uint32_t  realms 
)

References rtnl_rule::r_realms.

int rtnl_rule_set_src ( struct rtnl_rule rule,
struct nl_addr src 
)
void rtnl_rule_set_src_len ( struct rtnl_rule rule,
int  len 
)

References len, nl_addr_set_prefixlen(), rtnl_rule::r_src, and rtnl_rule::r_src_len.

Here is the call graph for this function:

void rtnl_rule_set_table ( struct rtnl_rule rule,
int  table 
)

References rtnl_rule::r_table.