libnl 3.7.0

Flags Translations

char * rtnl_addr_flags2str (int flags, char *buf, size_t size)
 
int rtnl_addr_str2flags (const char *name)
 

Allocation/Freeing

struct rtnl_addr * rtnl_addr_alloc (void)
 
void rtnl_addr_put (struct rtnl_addr *addr)
 

Cache Management

int rtnl_addr_alloc_cache (struct nl_sock *sk, struct nl_cache **result)
 
struct rtnl_addr * rtnl_addr_get (struct nl_cache *cache, int ifindex, struct nl_addr *addr)
 Search address in cache. More...
 

Addition

int rtnl_addr_build_add_request (struct rtnl_addr *addr, int flags, struct nl_msg **result)
 Build netlink request message to request addition of new address. More...
 
int rtnl_addr_add (struct nl_sock *sk, struct rtnl_addr *addr, int flags)
 Request addition of new address. More...
 

Deletion

int rtnl_addr_build_delete_request (struct rtnl_addr *addr, int flags, struct nl_msg **result)
 Build a netlink request message to request deletion of an address. More...
 
int rtnl_addr_delete (struct nl_sock *sk, struct rtnl_addr *addr, int flags)
 Request deletion of an address. More...
 

Attributes

int rtnl_addr_set_label (struct rtnl_addr *addr, const char *label)
 
char * rtnl_addr_get_label (struct rtnl_addr *addr)
 
void rtnl_addr_set_ifindex (struct rtnl_addr *addr, int ifindex)
 
int rtnl_addr_get_ifindex (struct rtnl_addr *addr)
 
void rtnl_addr_set_link (struct rtnl_addr *addr, struct rtnl_link *link)
 
struct rtnl_linkrtnl_addr_get_link (struct rtnl_addr *addr)
 
void rtnl_addr_set_family (struct rtnl_addr *addr, int family)
 
int rtnl_addr_get_family (struct rtnl_addr *addr)
 
void rtnl_addr_set_prefixlen (struct rtnl_addr *addr, int prefixlen)
 Set the prefix length / netmask. More...
 
int rtnl_addr_get_prefixlen (struct rtnl_addr *addr)
 
void rtnl_addr_set_scope (struct rtnl_addr *addr, int scope)
 
int rtnl_addr_get_scope (struct rtnl_addr *addr)
 
void rtnl_addr_set_flags (struct rtnl_addr *addr, unsigned int flags)
 
void rtnl_addr_unset_flags (struct rtnl_addr *addr, unsigned int flags)
 
unsigned int rtnl_addr_get_flags (struct rtnl_addr *addr)
 
int rtnl_addr_set_local (struct rtnl_addr *addr, struct nl_addr *local)
 
struct nl_addr * rtnl_addr_get_local (struct rtnl_addr *addr)
 
int rtnl_addr_set_peer (struct rtnl_addr *addr, struct nl_addr *peer)
 
struct nl_addr * rtnl_addr_get_peer (struct rtnl_addr *addr)
 
int rtnl_addr_set_broadcast (struct rtnl_addr *addr, struct nl_addr *bcast)
 
struct nl_addr * rtnl_addr_get_broadcast (struct rtnl_addr *addr)
 
int rtnl_addr_set_multicast (struct rtnl_addr *addr, struct nl_addr *multicast)
 
struct nl_addr * rtnl_addr_get_multicast (struct rtnl_addr *addr)
 
int rtnl_addr_set_anycast (struct rtnl_addr *addr, struct nl_addr *anycast)
 
struct nl_addr * rtnl_addr_get_anycast (struct rtnl_addr *addr)
 
uint32_t rtnl_addr_get_valid_lifetime (struct rtnl_addr *addr)
 
void rtnl_addr_set_valid_lifetime (struct rtnl_addr *addr, uint32_t lifetime)
 
uint32_t rtnl_addr_get_preferred_lifetime (struct rtnl_addr *addr)
 
void rtnl_addr_set_preferred_lifetime (struct rtnl_addr *addr, uint32_t lifetime)
 
uint32_t rtnl_addr_get_create_time (struct rtnl_addr *addr)
 
uint32_t rtnl_addr_get_last_update_time (struct rtnl_addr *addr)
 

Detailed Description

Note
The maximum size of an address label is IFNAMSIZ.
The address may not contain a prefix length if the peer address has been specified already.
1) Address Addition
// Allocate an empty address object to be filled out with the attributes
// of the new address.
struct rtnl_addr *addr = rtnl_addr_alloc();
// Fill out the mandatory attributes of the new address. Setting the
// local address will automatically set the address family and the
// prefix length to the correct values.
rtnl_addr_set_ifindex(addr, ifindex);
rtnl_addr_set_local(addr, local_addr);
// The label of the address can be specified, currently only supported
// by IPv4 and DECnet.
rtnl_addr_set_label(addr, "mylabel");
// The peer address can be specified if necessary, in either case a peer
// address will be sent to the kernel in order to fullfil the interface
// requirements. If none is set, it will equal the local address.
// Note: Real peer addresses are only supported by IPv4 for now.
rtnl_addr_set_peer(addr, peer_addr);
// In case you want to have the address have a scope other than global
// it may be overwritten using rtnl_addr_set_scope(). The scope currently
// cannot be set for IPv6 addresses.
rtnl_addr_set_scope(addr, rtnl_str2scope("site"));
// Broadcast address may be specified using the relevant
// functions, the address family will be verified if one of the other
// addresses has been set already. Currently only works for IPv4.
rtnl_addr_set_broadcast(addr, broadcast_addr);
// Build the netlink message and send it to the kernel, the operation will
// block until the operation has been completed. Alternatively the required
// netlink message can be built using rtnl_addr_build_add_request() to be
// sent out using nl_send_auto_complete().
rtnl_addr_add(sk, addr, 0);
// Free the memory
rtnl_addr_put(addr);
int rtnl_addr_add(struct nl_sock *sk, struct rtnl_addr *addr, int flags)
Request addition of new address.
Definition: addr.c:748
2) Address Deletion
// Allocate an empty address object to be filled out with the attributes
// matching the address to be deleted. Alternatively a fully equipped
// address object out of a cache can be used instead.
struct rtnl_addr *addr = rtnl_addr_alloc();
// The only mandatory parameter besides the address family is the interface
// index the address is on, i.e. leaving out all other parameters will
// result in all addresses of the specified address family interface tuple
// to be deleted.
rtnl_addr_set_ifindex(addr, ifindex);
// Specyfing the address family manually is only required if neither the
// local nor peer address have been specified.
rtnl_addr_set_family(addr, AF_INET);
// Specyfing the local address is optional but the best choice to delete
// specific addresses.
rtnl_addr_set_local(addr, local_addr);
// The label of the address can be specified, currently only supported
// by IPv4 and DECnet.
rtnl_addr_set_label(addr, "mylabel");
// The peer address can be specified if necessary, in either case a peer
// address will be sent to the kernel in order to fullfil the interface
// requirements. If none is set, it will equal the local address.
// Note: Real peer addresses are only supported by IPv4 for now.
rtnl_addr_set_peer(addr, peer_addr);
// Build the netlink message and send it to the kernel, the operation will
// block until the operation has been completed. Alternatively the required
// netlink message can be built using rtnl_addr_build_delete_request()
// to be sent out using nl_send_auto_complete().
rtnl_addr_delete(sk, addr, 0);
// Free the memory
rtnl_addr_put(addr);
int rtnl_addr_delete(struct nl_sock *sk, struct rtnl_addr *addr, int flags)
Request deletion of an address.
Definition: addr.c:820

Function Documentation

◆ rtnl_addr_alloc()

struct rtnl_addr * rtnl_addr_alloc ( void  )

Definition at line 560 of file addr.c.

◆ rtnl_addr_put()

void rtnl_addr_put ( struct rtnl_addr *  addr)

Definition at line 565 of file addr.c.

◆ rtnl_addr_alloc_cache()

int rtnl_addr_alloc_cache ( struct nl_sock *  sk,
struct nl_cache **  result 
)

Definition at line 577 of file addr.c.

◆ rtnl_addr_get()

struct rtnl_addr * rtnl_addr_get ( struct nl_cache *  cache,
int  ifindex,
struct nl_addr *  addr 
)

Search address in cache.

Parameters
cacheAddress cache
ifindexInterface index of address
addrLocal address part

Searches address cache previously allocated with rtnl_addr_alloc_cache() for an address with a matching local address.

The reference counter is incremented before returning the address, therefore the reference must be given back with rtnl_addr_put() after usage.

Returns
Address object or NULL if no match was found.

Definition at line 596 of file addr.c.

References nl_addr_cmp(), and nl_object_get().

+ Here is the call graph for this function:

◆ rtnl_addr_build_add_request()

int rtnl_addr_build_add_request ( struct rtnl_addr *  addr,
int  flags,
struct nl_msg **  result 
)

Build netlink request message to request addition of new address.

Parameters
addrAddress object representing the new address.
flagsAdditional netlink message flags.
resultPointer to store resulting message.

Builds a new netlink message requesting the addition of a new address. 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.

Minimal required attributes:

  • interface index (rtnl_addr_set_ifindex())
  • local address (rtnl_addr_set_local())

The scope will default to universe except for loopback addresses in which case a host scope is used if not specified otherwise.

Note
Free the memory after usage using nlmsg_free().
Returns
0 on success or a negative error code.

Definition at line 722 of file addr.c.

Referenced by rtnl_addr_add().

+ Here is the caller graph for this function:

◆ rtnl_addr_add()

int rtnl_addr_add ( struct nl_sock *  sk,
struct rtnl_addr *  addr,
int  flags 
)

Request addition of new address.

Parameters
skNetlink socket.
addrAddress object representing the new address.
flagsAdditional netlink message flags.

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

See also
rtnl_addr_build_add_request()
Returns
0 on success or a negative error if an error occured.

Definition at line 748 of file addr.c.

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

+ Here is the call graph for this function:

◆ rtnl_addr_build_delete_request()

int rtnl_addr_build_delete_request ( struct rtnl_addr *  addr,
int  flags,
struct nl_msg **  result 
)

Build a netlink request message to request deletion of an address.

Parameters
addrAddress object to be deleteted.
flagsAdditional netlink message flags.
resultPointer to store resulting message.

Builds a new netlink message requesting a deletion of an address. 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.

Minimal required attributes:

  • interface index (rtnl_addr_set_ifindex())
  • address family (rtnl_addr_set_family())

Optional attributes:

  • local address (rtnl_addr_set_local())
  • label (rtnl_addr_set_label(), IPv4/DECnet only)
  • peer address (rtnl_addr_set_peer(), IPv4 only)
Note
Free the memory after usage using nlmsg_free().
Returns
0 on success or a negative error code.

Definition at line 795 of file addr.c.

Referenced by rtnl_addr_delete().

+ Here is the caller graph for this function:

◆ rtnl_addr_delete()

int rtnl_addr_delete ( struct nl_sock *  sk,
struct rtnl_addr *  addr,
int  flags 
)

Request deletion of an address.

Parameters
skNetlink socket.
addrAddress object to be deleted.
flagsAdditional netlink message flags.

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

See also
rtnl_addr_build_delete_request();
Returns
0 on success or a negative error if an error occured.

Definition at line 820 of file addr.c.

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

+ Here is the call graph for this function:

◆ rtnl_addr_set_label()

int rtnl_addr_set_label ( struct rtnl_addr *  addr,
const char *  label 
)

Definition at line 843 of file addr.c.

◆ rtnl_addr_get_label()

char * rtnl_addr_get_label ( struct rtnl_addr *  addr)

Definition at line 854 of file addr.c.

◆ rtnl_addr_set_ifindex()

void rtnl_addr_set_ifindex ( struct rtnl_addr *  addr,
int  ifindex 
)

Definition at line 862 of file addr.c.

◆ rtnl_addr_get_ifindex()

int rtnl_addr_get_ifindex ( struct rtnl_addr *  addr)

Definition at line 868 of file addr.c.

◆ rtnl_addr_set_link()

void rtnl_addr_set_link ( struct rtnl_addr *  addr,
struct rtnl_link link 
)

Definition at line 873 of file addr.c.

◆ rtnl_addr_get_link()

struct rtnl_link * rtnl_addr_get_link ( struct rtnl_addr *  addr)

Definition at line 886 of file addr.c.

◆ rtnl_addr_set_family()

void rtnl_addr_set_family ( struct rtnl_addr *  addr,
int  family 
)

Definition at line 896 of file addr.c.

◆ rtnl_addr_get_family()

int rtnl_addr_get_family ( struct rtnl_addr *  addr)

Definition at line 902 of file addr.c.

◆ rtnl_addr_set_prefixlen()

void rtnl_addr_set_prefixlen ( struct rtnl_addr *  addr,
int  prefixlen 
)

Set the prefix length / netmask.

Parameters
addrAddress
prefixlenLength of prefix (netmask)

Modifies the length of the prefix. If the address object contains a peer address the prefix length will apply to it, otherwise the prefix length will apply to the local address of the address.

If the address object contains a peer or local address the corresponding struct nl_addr will be updated with the new prefix length.

Note
Specifying a length of 0 will remove the prefix length alltogether.
See also
rtnl_addr_get_prefixlen()

Definition at line 923 of file addr.c.

References nl_addr_set_prefixlen().

+ Here is the call graph for this function:

◆ rtnl_addr_get_prefixlen()

int rtnl_addr_get_prefixlen ( struct rtnl_addr *  addr)

Definition at line 942 of file addr.c.

◆ rtnl_addr_set_scope()

void rtnl_addr_set_scope ( struct rtnl_addr *  addr,
int  scope 
)

Definition at line 947 of file addr.c.

◆ rtnl_addr_get_scope()

int rtnl_addr_get_scope ( struct rtnl_addr *  addr)

Definition at line 953 of file addr.c.

◆ rtnl_addr_set_flags()

void rtnl_addr_set_flags ( struct rtnl_addr *  addr,
unsigned int  flags 
)

Definition at line 958 of file addr.c.

◆ rtnl_addr_unset_flags()

void rtnl_addr_unset_flags ( struct rtnl_addr *  addr,
unsigned int  flags 
)

Definition at line 965 of file addr.c.

◆ rtnl_addr_get_flags()

unsigned int rtnl_addr_get_flags ( struct rtnl_addr *  addr)

Definition at line 972 of file addr.c.

◆ rtnl_addr_set_local()

int rtnl_addr_set_local ( struct rtnl_addr *  addr,
struct nl_addr *  local 
)

Definition at line 1003 of file addr.c.

◆ rtnl_addr_get_local()

struct nl_addr * rtnl_addr_get_local ( struct rtnl_addr *  addr)

Definition at line 1023 of file addr.c.

◆ rtnl_addr_set_peer()

int rtnl_addr_set_peer ( struct rtnl_addr *  addr,
struct nl_addr *  peer 
)

Definition at line 1028 of file addr.c.

◆ rtnl_addr_get_peer()

struct nl_addr * rtnl_addr_get_peer ( struct rtnl_addr *  addr)

Definition at line 1044 of file addr.c.

◆ rtnl_addr_set_broadcast()

int rtnl_addr_set_broadcast ( struct rtnl_addr *  addr,
struct nl_addr *  bcast 
)

Definition at line 1049 of file addr.c.

◆ rtnl_addr_get_broadcast()

struct nl_addr * rtnl_addr_get_broadcast ( struct rtnl_addr *  addr)

Definition at line 1057 of file addr.c.

◆ rtnl_addr_set_multicast()

int rtnl_addr_set_multicast ( struct rtnl_addr *  addr,
struct nl_addr *  multicast 
)

Definition at line 1062 of file addr.c.

◆ rtnl_addr_get_multicast()

struct nl_addr * rtnl_addr_get_multicast ( struct rtnl_addr *  addr)

Definition at line 1071 of file addr.c.

◆ rtnl_addr_set_anycast()

int rtnl_addr_set_anycast ( struct rtnl_addr *  addr,
struct nl_addr *  anycast 
)

Definition at line 1076 of file addr.c.

◆ rtnl_addr_get_anycast()

struct nl_addr * rtnl_addr_get_anycast ( struct rtnl_addr *  addr)

Definition at line 1085 of file addr.c.

◆ rtnl_addr_get_valid_lifetime()

uint32_t rtnl_addr_get_valid_lifetime ( struct rtnl_addr *  addr)

Definition at line 1090 of file addr.c.

◆ rtnl_addr_set_valid_lifetime()

void rtnl_addr_set_valid_lifetime ( struct rtnl_addr *  addr,
uint32_t  lifetime 
)

Definition at line 1098 of file addr.c.

◆ rtnl_addr_get_preferred_lifetime()

uint32_t rtnl_addr_get_preferred_lifetime ( struct rtnl_addr *  addr)

Definition at line 1104 of file addr.c.

◆ rtnl_addr_set_preferred_lifetime()

void rtnl_addr_set_preferred_lifetime ( struct rtnl_addr *  addr,
uint32_t  lifetime 
)

Definition at line 1112 of file addr.c.

◆ rtnl_addr_get_create_time()

uint32_t rtnl_addr_get_create_time ( struct rtnl_addr *  addr)

Definition at line 1118 of file addr.c.

◆ rtnl_addr_get_last_update_time()

uint32_t rtnl_addr_get_last_update_time ( struct rtnl_addr *  addr)

Definition at line 1123 of file addr.c.

◆ rtnl_addr_flags2str()

char * rtnl_addr_flags2str ( int  flags,
char *  buf,
size_t  size 
)

Definition at line 1148 of file addr.c.

◆ rtnl_addr_str2flags()

int rtnl_addr_str2flags ( const char *  name)

Definition at line 1154 of file addr.c.