libnl: Routing Rules

libnl 3.10.0

Routing Rules
Routing Library (libnl-route)

## Allocation/Freeing
struct rtnl_rule * | rtnl_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.

## 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.
int | rtnl_rule_add (struct nl_sock *sk, struct rtnl_rule *tmpl, int flags)
| Add a new rule.

## 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.
int | rtnl_rule_delete (struct nl_sock *sk, 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, uint32_t prio)
uint32_t | rtnl_rule_get_prio (struct rtnl_rule *rule)
void | rtnl_rule_set_mark (struct rtnl_rule *rule, uint32_t mark)
uint32_t | rtnl_rule_get_mark (struct rtnl_rule *rule)
void | rtnl_rule_set_mask (struct rtnl_rule *rule, uint32_t mask)
uint32_t | rtnl_rule_get_mask (struct rtnl_rule *rule)
void | rtnl_rule_set_table (struct rtnl_rule *rule, uint32_t table)
uint32_t | rtnl_rule_get_table (struct rtnl_rule *rule)
void | rtnl_rule_set_dsfield (struct rtnl_rule *rule, uint8_t dsfield)
uint8_t | rtnl_rule_get_dsfield (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)
int | rtnl_rule_set_oif (struct rtnl_rule *rule, const char *dev)
char * | rtnl_rule_get_oif (struct rtnl_rule *rule)
void | rtnl_rule_set_action (struct rtnl_rule *rule, uint8_t action)
uint8_t | rtnl_rule_get_action (struct rtnl_rule *rule)
void | rtnl_rule_set_l3mdev (struct rtnl_rule *rule, int value)
| Set l3mdev value of the rule (FRA_L3MDEV)
int | rtnl_rule_get_l3mdev (struct rtnl_rule *rule)
| Get l3mdev value of the rule (FRA_L3MDEV)
int | rtnl_rule_set_protocol (struct rtnl_rule *rule, uint8_t protocol)
int | rtnl_rule_get_protocol (struct rtnl_rule *rule, uint8_t *protocol)
int | rtnl_rule_set_ipproto (struct rtnl_rule *rule, uint8_t ip_proto)
int | rtnl_rule_get_ipproto (struct rtnl_rule *rule, uint8_t *ip_proto)
int | rtnl_rule_set_sport (struct rtnl_rule *rule, uint16_t sport)
int | rtnl_rule_set_sport_range (struct rtnl_rule *rule, uint16_t start, uint16_t end)
int | rtnl_rule_get_sport (struct rtnl_rule *rule, uint16_t *start, uint16_t *end)
int | rtnl_rule_set_dport (struct rtnl_rule *rule, uint16_t dport)
int | rtnl_rule_set_dport_range (struct rtnl_rule *rule, uint16_t start, uint16_t end)
int | rtnl_rule_get_dport (struct rtnl_rule *rule, uint16_t *start, uint16_t *end)
void | rtnl_rule_set_realms (struct rtnl_rule *rule, uint32_t realms)
uint32_t | rtnl_rule_get_realms (struct rtnl_rule *rule)
void | rtnl_rule_set_goto (struct rtnl_rule *rule, uint32_t ref)
uint32_t | rtnl_rule_get_goto (struct rtnl_rule *rule)

## Detailed Description

## Function Documentation

## ◆ rtnl_rule_alloc()

struct rtnl_rule * rtnl_rule_alloc | ( | void |  | ) |

Definition at line 398 of file rule.c.

## ◆ rtnl_rule_put()

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

Definition at line 403 of file rule.c.

## ◆ rtnl_rule_alloc_cache()

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.

Parameters

  sock | 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.

Definition at line 426 of file rule.c.

References nl_cache_alloc(), and nl_cache_refill().

Here is the call graph for this function:

## ◆ rtnl_rule_build_add_request()

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.

Parameters

  tmpl | template with data of new rule
  flags | additional netlink message flags
  result | Result pointer

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
  0 on success or a negative error code.

Definition at line 551 of file rule.c.

Referenced by rtnl_rule_add().

Here is the caller graph for this function:

## ◆ rtnl_rule_add()

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

Add a new rule.

Parameters

  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 success or a negative error if an error occured.

Definition at line 570 of file rule.c.

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

Here is the call graph for this function:

## ◆ rtnl_rule_build_delete_request()

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.

Parameters

  rule | rule to delete
  flags | additional netlink message flags
  result | Result pointer

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
  0 on success or a negative error code.

Definition at line 607 of file rule.c.

Referenced by rtnl_rule_delete().

Here is the caller graph for this function:

## ◆ rtnl_rule_delete()

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

Delete a rule.

Parameters

  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 success or a negative error if an error occured.

Definition at line 625 of file rule.c.

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

Here is the call graph for this function:

## ◆ rtnl_rule_set_family()

void rtnl_rule_set_family | ( | struct rtnl_rule * | rule,
|  | int | family )

Definition at line 648 of file rule.c.

## ◆ rtnl_rule_get_family()

int rtnl_rule_get_family | ( | struct rtnl_rule * | rule | ) |

Definition at line 654 of file rule.c.

## ◆ rtnl_rule_set_prio()

void rtnl_rule_set_prio | ( | struct rtnl_rule * | rule,
|  | uint32_t | prio )

Definition at line 662 of file rule.c.

## ◆ rtnl_rule_get_prio()

uint32_t rtnl_rule_get_prio | ( | struct rtnl_rule * | rule | ) |

Definition at line 668 of file rule.c.

## ◆ rtnl_rule_set_mark()

void rtnl_rule_set_mark | ( | struct rtnl_rule * | rule,
|  | uint32_t | mark )

Definition at line 673 of file rule.c.

## ◆ rtnl_rule_get_mark()

uint32_t rtnl_rule_get_mark | ( | struct rtnl_rule * | rule | ) |

Definition at line 679 of file rule.c.

## ◆ rtnl_rule_set_mask()

void rtnl_rule_set_mask | ( | struct rtnl_rule * | rule,
|  | uint32_t | mask )

Definition at line 684 of file rule.c.

## ◆ rtnl_rule_get_mask()

uint32_t rtnl_rule_get_mask | ( | struct rtnl_rule * | rule | ) |

Definition at line 690 of file rule.c.

## ◆ rtnl_rule_set_table()

void rtnl_rule_set_table | ( | struct rtnl_rule * | rule,
|  | uint32_t | table )

Definition at line 695 of file rule.c.

## ◆ rtnl_rule_get_table()

uint32_t rtnl_rule_get_table | ( | struct rtnl_rule * | rule | ) |

Definition at line 701 of file rule.c.

## ◆ rtnl_rule_set_dsfield()

void rtnl_rule_set_dsfield | ( | struct rtnl_rule * | rule,
|  | uint8_t | dsfield )

Definition at line 706 of file rule.c.

## ◆ rtnl_rule_get_dsfield()

uint8_t rtnl_rule_get_dsfield | ( | struct rtnl_rule * | rule | ) |

Definition at line 712 of file rule.c.

## ◆ rtnl_rule_set_src()

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

Definition at line 737 of file rule.c.

## ◆ rtnl_rule_get_src()

struct nl_addr * rtnl_rule_get_src | ( | struct rtnl_rule * | rule | ) |

Definition at line 742 of file rule.c.

## ◆ rtnl_rule_set_dst()

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

Definition at line 747 of file rule.c.

## ◆ rtnl_rule_get_dst()

struct nl_addr * rtnl_rule_get_dst | ( | struct rtnl_rule * | rule | ) |

Definition at line 752 of file rule.c.

## ◆ rtnl_rule_set_iif()

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

Definition at line 757 of file rule.c.

## ◆ rtnl_rule_get_iif()

char * rtnl_rule_get_iif | ( | struct rtnl_rule * | rule | ) |

Definition at line 767 of file rule.c.

## ◆ rtnl_rule_set_oif()

int rtnl_rule_set_oif | ( | struct rtnl_rule * | rule,
|  | const char * | dev )

Definition at line 775 of file rule.c.

## ◆ rtnl_rule_get_oif()

char * rtnl_rule_get_oif | ( | struct rtnl_rule * | rule | ) |

Definition at line 785 of file rule.c.

## ◆ rtnl_rule_set_action()

void rtnl_rule_set_action | ( | struct rtnl_rule * | rule,
|  | uint8_t | action )

Definition at line 793 of file rule.c.

## ◆ rtnl_rule_get_action()

uint8_t rtnl_rule_get_action | ( | struct rtnl_rule * | rule | ) |

Definition at line 799 of file rule.c.

## ◆ rtnl_rule_set_l3mdev()

void rtnl_rule_set_l3mdev | ( | struct rtnl_rule * | rule,
|  | int | value )

Set l3mdev value of the rule (FRA_L3MDEV)

Parameters

  rule | rule
  value | value to set

Set the l3mdev value to value. Currently supported values are only 1 (set it) and -1 (unset it). All other values are reserved.

Definition at line 813 of file rule.c.

## ◆ rtnl_rule_get_l3mdev()

int rtnl_rule_get_l3mdev | ( | struct rtnl_rule * | rule | ) |

Get l3mdev value of the rule (FRA_L3MDEV)

Parameters

  rule | rule

Returns
  a negative error code, including -NLE_MISSING_ATTR if the property is unset. Otherwise returns a non-negative value. As FRA_L3MDEV is a boolean, the only expected value at the moment is 1.

Definition at line 833 of file rule.c.

## ◆ rtnl_rule_set_protocol()

int rtnl_rule_set_protocol | ( | struct rtnl_rule * | rule,
|  | uint8_t | protocol )

Definition at line 842 of file rule.c.

## ◆ rtnl_rule_get_protocol()

int rtnl_rule_get_protocol | ( | struct rtnl_rule * | rule,
|  | uint8_t * | protocol )

Definition at line 854 of file rule.c.

## ◆ rtnl_rule_set_ipproto()

int rtnl_rule_set_ipproto | ( | struct rtnl_rule * | rule,
|  | uint8_t | ip_proto )

Definition at line 863 of file rule.c.

## ◆ rtnl_rule_get_ipproto()

int rtnl_rule_get_ipproto | ( | struct rtnl_rule * | rule,
|  | uint8_t * | ip_proto )

Definition at line 875 of file rule.c.

## ◆ rtnl_rule_set_sport()

int rtnl_rule_set_sport | ( | struct rtnl_rule * | rule,
|  | uint16_t | sport )

Definition at line 904 of file rule.c.

## ◆ rtnl_rule_set_sport_range()

int rtnl_rule_set_sport_range | ( | struct rtnl_rule * | rule,
|  | uint16_t | start,
|  | uint16_t | end )

Definition at line 910 of file rule.c.

## ◆ rtnl_rule_get_sport()

int rtnl_rule_get_sport | ( | struct rtnl_rule * | rule,
|  | uint16_t * | start,
|  | uint16_t * | end )

Definition at line 917 of file rule.c.

## ◆ rtnl_rule_set_dport()

int rtnl_rule_set_dport | ( | struct rtnl_rule * | rule,
|  | uint16_t | dport )

Definition at line 927 of file rule.c.

## ◆ rtnl_rule_set_dport_range()

int rtnl_rule_set_dport_range | ( | struct rtnl_rule * | rule,
|  | uint16_t | start,
|  | uint16_t | end )

Definition at line 933 of file rule.c.

## ◆ rtnl_rule_get_dport()

int rtnl_rule_get_dport | ( | struct rtnl_rule * | rule,
|  | uint16_t * | start,
|  | uint16_t * | end )

Definition at line 940 of file rule.c.

## ◆ rtnl_rule_set_realms()

void rtnl_rule_set_realms | ( | struct rtnl_rule * | rule,
|  | uint32_t | realms )

Definition at line 950 of file rule.c.

## ◆ rtnl_rule_get_realms()

uint32_t rtnl_rule_get_realms | ( | struct rtnl_rule * | rule | ) |

Definition at line 956 of file rule.c.

## ◆ rtnl_rule_set_goto()

void rtnl_rule_set_goto | ( | struct rtnl_rule * | rule,
|  | uint32_t | ref )

Definition at line 961 of file rule.c.

## ◆ rtnl_rule_get_goto()

uint32_t rtnl_rule_get_goto | ( | struct rtnl_rule * | rule | ) |

Definition at line 967 of file rule.c.