libnl 3.7.0

Abstract data type representing any kind of network address. More...

Address Family Transformations

char * nl_af2str (int family, char *buf, size_t size)
 
int nl_str2af (const char *name)
 

Creating Abstract Network Addresses

struct nl_addr * nl_addr_alloc (size_t maxsize)
 Allocate empty abstract address. More...
 
struct nl_addr * nl_addr_build (int family, const void *buf, size_t size)
 Allocate abstract address based on a binary address. More...
 
struct nl_addr * nl_addr_alloc_attr (const struct nlattr *nla, int family)
 Allocate abstract address based on Netlink attribute. More...
 
int nl_addr_parse (const char *addrstr, int hint, struct nl_addr **result)
 Allocate abstract address based on character string. More...
 
struct nl_addr * nl_addr_clone (const struct nl_addr *addr)
 Clone existing abstract address object. More...
 

Managing Usage References

struct nl_addr * nl_addr_get (struct nl_addr *addr)
 Increase the reference counter of an abstract address. More...
 
void nl_addr_put (struct nl_addr *addr)
 Decrease the reference counter of an abstract address. More...
 
int nl_addr_shared (const struct nl_addr *addr)
 Check whether an abstract address is shared. More...
 

Miscellaneous

int nl_addr_cmp (const struct nl_addr *a, const struct nl_addr *b)
 Compare abstract addresses. More...
 
int nl_addr_cmp_prefix (const struct nl_addr *a, const struct nl_addr *b)
 Compare the prefix of two abstract addresses. More...
 
int nl_addr_iszero (const struct nl_addr *addr)
 Returns true if the address consists of all zeros. More...
 
int nl_addr_valid (const char *addr, int family)
 Check if address string is parseable for a specific address family. More...
 
int nl_addr_guess_family (const struct nl_addr *addr)
 Guess address family of abstract address based on address size. More...
 
int nl_addr_fill_sockaddr (const struct nl_addr *addr, struct sockaddr *sa, socklen_t *salen)
 Fill out sockaddr structure with values from abstract address object. More...
 

Getting Information About Addresses

int nl_addr_info (const struct nl_addr *addr, struct addrinfo **result)
 Call getaddrinfo() for an abstract address object. More...
 
int nl_addr_resolve (const struct nl_addr *addr, char *host, size_t hostlen)
 Resolve abstract address object to a name using getnameinfo(). More...
 

Attributes

void nl_addr_set_family (struct nl_addr *addr, int family)
 Set address family. More...
 
int nl_addr_get_family (const struct nl_addr *addr)
 Return address family. More...
 
int nl_addr_set_binary_addr (struct nl_addr *addr, const void *buf, size_t len)
 Set binary address of abstract address object. More...
 
void * nl_addr_get_binary_addr (const struct nl_addr *addr)
 Get binary address of abstract address object. More...
 
unsigned int nl_addr_get_len (const struct nl_addr *addr)
 Get length of binary address of abstract address object. More...
 
void nl_addr_set_prefixlen (struct nl_addr *addr, int prefixlen)
 Set the prefix length of an abstract address. More...
 
unsigned int nl_addr_get_prefixlen (const struct nl_addr *addr)
 Return prefix length of abstract address object. More...
 

Translations to Strings

char * nl_addr2str (const struct nl_addr *addr, char *buf, size_t size)
 Convert abstract address object to character string. More...
 

Detailed Description

Abstract data type representing any kind of network address.

Related sections in the development guide:

Header

#include <netlink/addr.h>

Function Documentation

◆ nl_addr_alloc()

struct nl_addr * nl_addr_alloc ( size_t  maxsize)

Allocate empty abstract address.

Parameters
maxsizeUpper limit of the binary address to be stored

The new address object will be empty with a prefix length of 0 and will be capable of holding binary addresses up to the specified limit.

See also
nl_addr_build()
nl_addr_parse()
nl_addr_put()
Returns
Allocated address object or NULL upon failure.

Definition at line 180 of file addr.c.

Referenced by nl_addr_build(), and nl_addr_parse().

+ Here is the caller graph for this function:

◆ nl_addr_build()

struct nl_addr * nl_addr_build ( int  family,
const void *  buf,
size_t  size 
)

Allocate abstract address based on a binary address.

Parameters
familyAddress family
bufBinary address
sizeLength of binary address

This function will allocate an abstract address capable of holding the binary address specified. The prefix length will be set to the full length of the binary address provided.

See also
nl_addr_alloc()
nl_addr_alloc_attr()
nl_addr_parse()
nl_addr_put()
Returns
Allocated address object or NULL upon failure.

Definition at line 211 of file addr.c.

References nl_addr_alloc().

Referenced by nl_addr_alloc_attr(), nl_addr_clone(), rtnl_link_geneve_get_remote(), rtnl_link_vxlan_get_group(), and rtnl_link_vxlan_get_local().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nl_addr_alloc_attr()

struct nl_addr * nl_addr_alloc_attr ( const struct nlattr *  nla,
int  family 
)

Allocate abstract address based on Netlink attribute.

Parameters
nlaNetlink attribute
familyAddress family.

Allocates an abstract address based on the specified Netlink attribute by interpreting the payload of the Netlink attribute as the binary address.

This function is identical to:

nl_addr_build(family, nla_data(nla), nla_len(nla));
struct nl_addr * nl_addr_build(int family, const void *buf, size_t size)
Allocate abstract address based on a binary address.
Definition: addr.c:211
void * nla_data(const struct nlattr *nla)
Return pointer to the payload section.
Definition: attr.c:114
int nla_len(const struct nlattr *nla)
Return length of the payload .
Definition: attr.c:125
See also
nl_addr_alloc()
nl_addr_build()
nl_addr_parse()
nl_addr_put()
Returns
Allocated address object or NULL upon failure.

Definition at line 256 of file addr.c.

References nl_addr_build(), nla_data(), and nla_len().

+ Here is the call graph for this function:

◆ nl_addr_parse()

int nl_addr_parse ( const char *  addrstr,
int  hint,
struct nl_addr **  result 
)

Allocate abstract address based on character string.

Parameters
addrstrAddress represented as character string.
hintAddress family hint or AF_UNSPEC.
resultPointer to store resulting address.

Regognizes the following address formats:

Format Len Family
----------------------------------------------------------------
IPv6 address format 16 AF_INET6
ddd.ddd.ddd.ddd 4 AF_INET
HH:HH:HH:HH:HH:HH 6 AF_LLC
AA{.|,}NNNN 2 AF_DECnet
HH:HH:HH:... variable AF_UNSPEC

Special values:

  • none: All bits and length set to 0.
  • {default|all|any}: All bits set to 0, length based on hint or AF_INET if no hint is given.

The prefix length may be appened at the end prefixed with a slash, e.g. 10.0.0.0/8.

See also
nl_addr_alloc()
nl_addr_build()
nl_addr_put()
Returns
0 on success or a negative error code.

Definition at line 292 of file addr.c.

References nl_addr_alloc(), nl_addr_set_binary_addr(), nl_addr_set_family(), and nl_addr_set_prefixlen().

+ Here is the call graph for this function:

◆ nl_addr_clone()

struct nl_addr * nl_addr_clone ( const struct nl_addr *  addr)

Clone existing abstract address object.

Parameters
addrAbstract address object

Allocates new abstract address representing an identical clone of an existing address.

See also
nl_addr_alloc()
nl_addr_put()
Returns
Allocated abstract address or NULL upon failure.

Definition at line 492 of file addr.c.

References nl_addr_build().

Referenced by rtnl_link_macvlan_add_macaddr(), xfrmnl_sel_clone(), and xfrmnl_user_tmpl_clone().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nl_addr_get()

struct nl_addr * nl_addr_get ( struct nl_addr *  addr)

Increase the reference counter of an abstract address.

Parameters
addrAbstract address

Increases the reference counter of the address and thus prevents the release of the memory resources until the reference is given back using the function nl_addr_put().

See also
nl_addr_put()
Returns
Pointer to the existing abstract address

Definition at line 522 of file addr.c.

Referenced by rtnl_link_macvlan_del_macaddr(), and rtnl_link_vf_set_addr().

+ Here is the caller graph for this function:

◆ nl_addr_put()

void nl_addr_put ( struct nl_addr *  addr)

Decrease the reference counter of an abstract address.

Parameters
addrAbstract addr
Note
The resources of the abstract address will be freed after the last reference to the address has been returned.
See also
nl_addr_get()

Definition at line 538 of file addr.c.

Referenced by rtnl_link_macvlan_del_macaddr(), rtnl_link_macvlan_set_mode(), rtnl_link_vf_free(), and rtnl_link_vf_set_addr().

+ Here is the caller graph for this function:

◆ nl_addr_shared()

int nl_addr_shared ( const struct nl_addr *  addr)

Check whether an abstract address is shared.

Parameters
addrAbstract address object.
Returns
Non-zero if the abstract address is shared, otherwise 0.

Definition at line 555 of file addr.c.

◆ nl_addr_cmp()

int nl_addr_cmp ( const struct nl_addr *  a,
const struct nl_addr *  b 
)

Compare abstract addresses.

Parameters
aAn abstract address
bAnother abstract address

Verifies whether the address family, address length, prefix length, and binary addresses of two abstract addresses matches.

Note
This function will not respect the prefix length in the sense that only the actual prefix will be compared. Please refer to the nl_addr_cmp_prefix() function if you require this functionality.
See also
nl_addr_cmp_prefix()
Returns
Integer less than, equal to or greather than zero if the two addresses match.

Definition at line 584 of file addr.c.

Referenced by rtnl_addr_get(), rtnl_link_macvlan_del_macaddr(), rtnl_neigh_get(), and rtnl_neigh_get_by_vlan().

+ Here is the caller graph for this function:

◆ nl_addr_cmp_prefix()

int nl_addr_cmp_prefix ( const struct nl_addr *  a,
const struct nl_addr *  b 
)

Compare the prefix of two abstract addresses.

Parameters
aAn abstract address
bAnother abstract address

Verifies whether the address family and the binary address covered by the smaller prefix length of the two abstract addresses matches.

See also
nl_addr_cmp()
Returns
Integer less than, equal to or greather than zero if the two addresses match.

Definition at line 623 of file addr.c.

Referenced by xfrmnl_sel_cmp(), and xfrmnl_user_tmpl_cmp().

+ Here is the caller graph for this function:

◆ nl_addr_iszero()

int nl_addr_iszero ( const struct nl_addr *  addr)

Returns true if the address consists of all zeros.

Parameters
addrAbstract address
Returns
1 if the binary address consists of all zeros, 0 otherwise.

Definition at line 649 of file addr.c.

◆ nl_addr_valid()

int nl_addr_valid ( const char *  addr,
int  family 
)

Check if address string is parseable for a specific address family.

Parameters
addrAddress represented as character string.
familyDesired address family.
Returns
1 if the address is parseable assuming the specified address family, otherwise 0 is returned.

Definition at line 668 of file addr.c.

◆ nl_addr_guess_family()

int nl_addr_guess_family ( const struct nl_addr *  addr)

Guess address family of abstract address based on address size.

Parameters
addrAbstract address object.
Returns
Numeric address family or AF_UNSPEC

Definition at line 708 of file addr.c.

◆ nl_addr_fill_sockaddr()

int nl_addr_fill_sockaddr ( const struct nl_addr *  addr,
struct sockaddr *  sa,
socklen_t *  salen 
)

Fill out sockaddr structure with values from abstract address object.

Parameters
addrAbstract address object.
saDestination sockaddr structure buffer.
salenLength of sockaddr structure buffer.

Fills out the specified sockaddr structure with the data found in the specified abstract address. The salen argument needs to be set to the size of sa but will be modified to the actual size used during before the function exits.

Returns
0 on success or a negative error code

Definition at line 735 of file addr.c.

Referenced by nl_addr_resolve().

+ Here is the caller graph for this function:

◆ nl_addr_info()

int nl_addr_info ( const struct nl_addr *  addr,
struct addrinfo **  result 
)

Call getaddrinfo() for an abstract address object.

Parameters
addrAbstract address object.
resultPointer to store resulting address list.

Calls getaddrinfo() for the specified abstract address in AI_NUMERICHOST mode.

Note
The caller is responsible for freeing the linked list using the interface provided by getaddrinfo(3).
Returns
0 on success or a negative error code.

Definition at line 803 of file addr.c.

References nl_addr2str().

+ Here is the call graph for this function:

◆ nl_addr_resolve()

int nl_addr_resolve ( const struct nl_addr *  addr,
char *  host,
size_t  hostlen 
)

Resolve abstract address object to a name using getnameinfo().

Parameters
addrAbstract address object.
hostDestination buffer for host name.
hostlenLength of destination buffer.

Resolves the abstract address to a name and writes the looked up result into the host buffer. getnameinfo() is used to perform the lookup and is put into NI_NAMEREQD mode so the function will fail if the lookup couldn't be performed.

Returns
0 on success or a negative error code.

Definition at line 847 of file addr.c.

References nl_addr_fill_sockaddr().

+ Here is the call graph for this function:

◆ nl_addr_set_family()

void nl_addr_set_family ( struct nl_addr *  addr,
int  family 
)

Set address family.

Parameters
addrAbstract address object
familyAddress family
See also
nl_addr_get_family()

Definition at line 879 of file addr.c.

Referenced by nl_addr_parse().

+ Here is the caller graph for this function:

◆ nl_addr_get_family()

int nl_addr_get_family ( const struct nl_addr *  addr)

Return address family.

Parameters
addrAbstract address object
See also
nl_addr_set_family()
Returns
The numeric address family or AF_UNSPEC

Definition at line 892 of file addr.c.

Referenced by rtnl_link_geneve_set_remote(), rtnl_link_macvlan_add_macaddr(), rtnl_link_macvlan_del_macaddr(), rtnl_link_vxlan_set_group(), and rtnl_link_vxlan_set_local().

+ Here is the caller graph for this function:

◆ nl_addr_set_binary_addr()

int nl_addr_set_binary_addr ( struct nl_addr *  addr,
const void *  buf,
size_t  len 
)

Set binary address of abstract address object.

Parameters
addrAbstract address object.
bufBuffer containing binary address.
lenLength of buffer containing binary address.

Modifies the binary address portion of the abstract address. The abstract address must be capable of holding the required amount or this function will fail.

Note
This function will not modify the prefix length. It is within the responsibility of the caller to set the prefix length to the desirable length.
See also
nl_addr_alloc()
nl_addr_get_binary_addr()
nl_addr_get_len()
Returns
0 on success or a negative error code.

Definition at line 917 of file addr.c.

Referenced by nl_addr_parse().

+ Here is the caller graph for this function:

◆ nl_addr_get_binary_addr()

void * nl_addr_get_binary_addr ( const struct nl_addr *  addr)

Get binary address of abstract address object.

Parameters
addrAbstract address object.
See also
nl_addr_set_binary_addr()
nl_addr_get_len()
Returns
Pointer to binary address of length nl_addr_get_len()

Definition at line 940 of file addr.c.

Referenced by flnl_lookup_build_request(), nla_put_addr(), rtnl_link_geneve_set_remote(), rtnl_link_vxlan_set_group(), and rtnl_link_vxlan_set_local().

+ Here is the caller graph for this function:

◆ nl_addr_get_len()

unsigned int nl_addr_get_len ( const struct nl_addr *  addr)

Get length of binary address of abstract address object.

Parameters
addrAbstract address object.
See also
nl_addr_get_binary_addr()
nl_addr_set_binary_addr()

Definition at line 952 of file addr.c.

Referenced by nla_put_addr(), rtnl_link_geneve_set_remote(), rtnl_link_vxlan_set_group(), and rtnl_link_vxlan_set_local().

+ Here is the caller graph for this function:

◆ nl_addr_set_prefixlen()

void nl_addr_set_prefixlen ( struct nl_addr *  addr,
int  prefixlen 
)

Set the prefix length of an abstract address.

Parameters
addrAbstract address object
prefixlenNew prefix length
See also
nl_addr_get_prefixlen()

Definition at line 964 of file addr.c.

Referenced by nl_addr_parse(), and rtnl_addr_set_prefixlen().

+ Here is the caller graph for this function:

◆ nl_addr_get_prefixlen()

unsigned int nl_addr_get_prefixlen ( const struct nl_addr *  addr)

Return prefix length of abstract address object.

Parameters
addrAbstract address object
See also
nl_addr_set_prefixlen()

Definition at line 975 of file addr.c.

◆ nl_addr2str()

char * nl_addr2str ( const struct nl_addr *  addr,
char *  buf,
size_t  size 
)

Convert abstract address object to character string.

Parameters
addrAbstract address object.
bufDestination buffer.
sizeSize of destination buffer.

Converts an abstract address to a character string and stores the result in the specified destination buffer.

Returns
Address represented in ASCII stored in destination buffer.

Definition at line 998 of file addr.c.

Referenced by nl_addr_info().

+ Here is the caller graph for this function:

◆ nl_af2str()

char * nl_af2str ( int  family,
char *  buf,
size_t  size 
)

Definition at line 1124 of file addr.c.

◆ nl_str2af()

int nl_str2af ( const char *  name)

Definition at line 1129 of file addr.c.