Stack-independent helpers for IPv6 over X

This implements some common helper functions for IPv6 over X implementations based on network device types. More...

Detailed Description

This implements some common helper functions for IPv6 over X implementations based on network device types.

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. More...
 
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. More...
 
int l2util_ipv6_iid_to_addr (int dev_type, const eui64_t *iid, uint8_t *addr)
 Converts an IPv6 IID to a hardware address. More...
 
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. More...
 

Function Documentation

◆ 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_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.