Loading...
Searching...
No Matches
Stack-independent helpers for IPv6 over X

This implements some common helper functions for IPv6 over X implementations based on [network device types] (net_netdev_type). More...

Detailed Description

This implements some common helper functions for IPv6 over X implementations based on [network device types] (net_netdev_type).

Attention
If you add a new network device type have at least a look at the implementation of these functions.

Files

file  l2util.h
 Link-layer helper function definitions.
 

Macros

#define L2UTIL_ADDR_MAX_LEN   (8U)
 maximum expected length for addresses
 

Functions

int l2util_eui64_from_addr (int dev_type, const uint8_t *addr, size_t addr_len, eui64_t *eui64)
 Converts a given hardware address to an EUI-64.
 
int l2util_ipv6_iid_from_addr (int dev_type, const uint8_t *addr, size_t addr_len, eui64_t *iid)
 Converts a given hardware address to an IPv6 IID.
 
int l2util_ipv6_iid_to_addr (int dev_type, const eui64_t *iid, uint8_t *addr)
 Converts an IPv6 IID to a hardware address.
 
int l2util_ndp_addr_len_from_l2ao (int dev_type, const ndp_opt_t *opt)
 Derives the length of the link-layer address in an NDP link-layer address option from that option's length field and the given device type.
 
int l2util_ipv6_group_to_l2_group (int dev_type, const ipv6_addr_t *ipv6_group, uint8_t *l2_group)
 Converts an IPv6 multicast address to a multicast address of the respective link layer.
 
char * l2util_addr_to_str (const uint8_t *addr, size_t addr_len, char *out)
 Converts a hardware address to a human readable string.
 
size_t l2util_addr_from_str (const char *str, uint8_t *out)
 Parses a string of colon-separated hexadecimals to a hardware address.
 
static bool l2util_addr_equal (const uint8_t *addr_a, uint8_t addr_a_len, const uint8_t *addr_b, uint8_t addr_b_len)
 Checks if two l2 addresses are equal.
 

Macro Definition Documentation

◆ L2UTIL_ADDR_MAX_LEN

#define L2UTIL_ADDR_MAX_LEN   (8U)

maximum expected length for addresses

Definition at line 37 of file l2util.h.

Function Documentation

◆ l2util_addr_equal()

static bool l2util_addr_equal ( const uint8_t *  addr_a,
uint8_t  addr_a_len,
const uint8_t *  addr_b,
uint8_t  addr_b_len 
)
inlinestatic

Checks if two l2 addresses are equal.

Parameters
[in]addr_aFirst hardware address.
[in]addr_a_lenLength of first hardware address.
[in]addr_bSecond hardware address.
[in]addr_b_lenLength of second hardware address.
Returns
true if the addresses match, false if not.

Definition at line 203 of file l2util.h.

◆ l2util_addr_from_str()

size_t l2util_addr_from_str ( const char *  str,
uint8_t *  out 
)

Parses a string of colon-separated hexadecimals to a hardware address.

The input format must be like xx:xx:xx:xx where xx will be the bytes of addr in hexadecimal representation.

Precondition
(out != NULL)
out MUST have allocated at least GNRC_NETIF_L2ADDR_MAXLEN bytes.
Parameters
[in]strA string of colon-separated hexadecimals.
[out]outThe resulting hardware address. Must at least have GNRC_NETIF_L2ADDR_MAXLEN bytes allocated.
Returns
Actual length of out on success.
0, on failure.

◆ l2util_addr_to_str()

char * l2util_addr_to_str ( const uint8_t *  addr,
size_t  addr_len,
char *  out 
)

Converts a hardware address to a human readable string.

The format will be like xx:xx:xx:xx where xx are the bytes of addr in hexadecimal representation.

Precondition
(out != NULL) && ((addr != NULL) || (addr_len == 0))
out MUST have allocated at least 3 * addr_len bytes.
Parameters
[in]addrA hardware address.
[in]addr_lenLength of addr.
[out]outA string to store the output in. Must at least have 3 * addr_len bytes allocated.
Returns
out.

◆ l2util_eui64_from_addr()

int l2util_eui64_from_addr ( int  dev_type,
const uint8_t *  addr,
size_t  addr_len,
eui64_t eui64 
)

Converts a given hardware address to an EUI-64.

Attention
When the link-layer of the interface has link-layer addresses, and NDEBUG is not defined, the node fails with an assertion instead returning -ENOTSUP.
Parameters
[in]dev_typeThe network device type of the device addr came from (either because it is the configured address of the device or from a packet that came over it).
[in]addrA hardware address.
[in]addr_lenNumber of bytes in addr.
[out]eui64The EUI-64 based on gnrc_netif_t::device_type
Returns
sizeof(eui64_t) on success.
-ENOTSUP, when dev_type does not support EUI-64 conversion.
-EINVAL, when addr_len is invalid for the dev_type.

◆ l2util_ipv6_group_to_l2_group()

int l2util_ipv6_group_to_l2_group ( int  dev_type,
const ipv6_addr_t ipv6_group,
uint8_t *  l2_group 
)

Converts an IPv6 multicast address to a multicast address of the respective link layer.

Precondition
There is enough allocated space in l2_group for an address for a device of type dev_type (e.g. 6 bytes for an ethernet address).
Parameters
[in]dev_typeThe network device type of the device l2_addr should be generated for.
[in]ipv6_groupAn IPv6 multicast address.
[out]l2_groupA link layer multicast address
Returns
Length of l2_group in bytes
-ENOTSUP if link layer does not support multicast.

◆ l2util_ipv6_iid_from_addr()

int l2util_ipv6_iid_from_addr ( int  dev_type,
const uint8_t *  addr,
size_t  addr_len,
eui64_t iid 
)

Converts a given hardware address to an IPv6 IID.

Attention
When the link-layer of the interface has link-layer addresses, and NDEBUG is not defined, the node fails with an assertion instead returning -ENOTSUP.
Parameters
[in]dev_typeThe network device type of the device addr came from (either because it is the configured address of the device or from a packet that came over it).
[in]addrA hardware address.
[in]addr_lenNumber of bytes in addr.
[out]iidThe IID based on gnrc_netif_t::device_type
Returns
sizeof(eui64_t) on success.
-ENOTSUP, when dev_type does not support IID conversion.
-EINVAL, when addr_len is invalid for the dev_type.

◆ l2util_ipv6_iid_to_addr()

int l2util_ipv6_iid_to_addr ( int  dev_type,
const eui64_t iid,
uint8_t *  addr 
)

Converts an IPv6 IID to a hardware address.

Precondition
iid was based on a hardware address
The number of bytes available at addr is less or equal to L2UTIL_ADDR_MAX_LEN.
Attention
When NDEBUG is not defined, the node fails with an assertion instead of returning -ENOTSUP
Parameters
[in]dev_typeThe network device type of the device the iid came from (either because it is based on the configured address of the device or from a packet that came over it).
[in]iidAn IID based on dev_type.
[out]addrThe hardware address. It is assumed that iid was based on a hardware address and that the available number of bytes in addr are greater or equal to L2UTIL_ADDR_MAX_LEN.
Returns
Length of resulting addr on success.
-ENOTSUP, when dev_type does not support reverse IID conversion.

◆ l2util_ndp_addr_len_from_l2ao()

int l2util_ndp_addr_len_from_l2ao ( int  dev_type,
const ndp_opt_t opt 
)

Derives the length of the link-layer address in an NDP link-layer address option from that option's length field and the given device type.

Note
If an RFC exists that specifies how IPv6 operates over a link-layer, this function usually implements the section "Unicast Address Mapping".
See also
RFC 4861, section 4.6.1
Attention
When NDEBUG is not defined, the node fails with an assertion instead of returning -ENOTSUP
Parameters
[in]dev_typeThe network device type of the device the opt came over in an NDP message.
[in]optAn NDP source/target link-layer address option.
Returns
Length of the link-layer address in opt on success
-ENOTSUP, when implementation does not know how to derive the length of the link-layer address from opt's length field based on dev_type.
-EINVAL if opt->len was an invalid value for the given dev_type.