This implements some common helper functions for IPv6 over X implementations based on network device types.
More...
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.
|
file | l2util.h |
| Link-layer helper function definitions.
|
|
|
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...
|
|
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. More...
|
|
◆ 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_type | The 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] | addr | A hardware address. |
[in] | addr_len | Number of bytes in addr . |
[out] | eui64 | The 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_type | The network device type of the device l2_addr should be generated for. |
[in] | ipv6_group | An IPv6 multicast address. |
[out] | l2_group | A 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_type | The 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] | addr | A hardware address. |
[in] | addr_len | Number of bytes in addr . |
[out] | iid | The 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_type | The 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] | iid | An IID based on dev_type . |
[out] | addr | The 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_type | The network device type of the device the opt came over in an NDP message. |
[in] | opt | An 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
.