gnrc_netif: centralize S/TLLAO length to address length function
The function to infer the link-layer address length from the length of a S/TLLAO is very dependent on the IPv6 over X specification and thus should be grouped with the other IP over X functions.
This commit is contained in:
parent
465631f83c
commit
8f763535ac
@ -495,9 +495,40 @@ static inline int gnrc_netif_ipv6_get_iid(gnrc_netif_t *netif, eui64_t *iid)
|
|||||||
(void)iid;
|
(void)iid;
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 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 [RFC 4861, section 4.6.1](https://tools.ietf.org/html/rfc4861#section-4.6.1)
|
||||||
|
*
|
||||||
|
* @pre `netif->flags & GNRC_NETIF_FLAGS_HAS_L2ADDR`
|
||||||
|
*
|
||||||
|
* @attention When `NDEBUG` is not defined, the node fails with an assertion
|
||||||
|
* instead of returning `-ENOTSUP`
|
||||||
|
*
|
||||||
|
* @param[in] netif The network interface @p opt was received on within an NDP
|
||||||
|
* message.
|
||||||
|
* @param[in] opt An NDP source/target link-layer address option.
|
||||||
|
*
|
||||||
|
* @return Length of the link-layer address in @p opt on success
|
||||||
|
* @return `-ENOTSUP`, when implementation does not know how to derive the
|
||||||
|
* length of the link-layer address from @p opt's length field based
|
||||||
|
* on gnrc_netif_t::device_type of @p netif.
|
||||||
|
* @return `-EINVAL` if `opt->len` was an invalid value for the given
|
||||||
|
* gnrc_netif_t::device_type of @p netif.
|
||||||
|
*/
|
||||||
|
int gnrc_netif_ndp_addr_len_from_l2ao(gnrc_netif_t *netif,
|
||||||
|
const ndp_opt_t *opt);
|
||||||
#else /* defined(MODULE_GNRC_IPV6) || defined(DOXYGEN) */
|
#else /* defined(MODULE_GNRC_IPV6) || defined(DOXYGEN) */
|
||||||
#define gnrc_netif_ipv6_iid_from_addr(netif, addr, addr_len, iid) (-ENOTSUP)
|
#define gnrc_netif_ipv6_iid_from_addr(netif, addr, addr_len, iid) (-ENOTSUP)
|
||||||
#define gnrc_netif_ipv6_iid_to_addr(netif, iid, addr) (-ENOTSUP)
|
#define gnrc_netif_ipv6_iid_to_addr(netif, iid, addr) (-ENOTSUP)
|
||||||
|
#define gnrc_netif_ndp_addr_len_from_l2ao(netif, opt) (-ENOTSUP)
|
||||||
#define gnrc_netif_ipv6_get_iid(netif, iid) (-ENOTSUP)
|
#define gnrc_netif_ipv6_get_iid(netif, iid) (-ENOTSUP)
|
||||||
#endif /* defined(MODULE_GNRC_IPV6) || defined(DOXYGEN) */
|
#endif /* defined(MODULE_GNRC_IPV6) || defined(DOXYGEN) */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|||||||
@ -148,6 +148,56 @@ int gnrc_netif_ipv6_iid_to_addr(const gnrc_netif_t *netif, const eui64_t *iid,
|
|||||||
}
|
}
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int gnrc_netif_ndp_addr_len_from_l2ao(gnrc_netif_t *netif,
|
||||||
|
const ndp_opt_t *opt)
|
||||||
|
{
|
||||||
|
assert(netif->flags & GNRC_NETIF_FLAGS_HAS_L2ADDR);
|
||||||
|
switch (netif->device_type) {
|
||||||
|
#ifdef MODULE_CC110X
|
||||||
|
case NETDEV_TYPE_CC110X:
|
||||||
|
(void)opt;
|
||||||
|
return sizeof(uint8_t);
|
||||||
|
#endif /* MODULE_CC110X */
|
||||||
|
#if defined(MODULE_NETDEV_ETH) || defined(MODULE_ESP_NOW)
|
||||||
|
case NETDEV_TYPE_ETHERNET:
|
||||||
|
case NETDEV_TYPE_ESP_NOW:
|
||||||
|
/* see https://tools.ietf.org/html/rfc2464#section-6*/
|
||||||
|
if (opt->len == 1U) {
|
||||||
|
return ETHERNET_ADDR_LEN;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
#endif /* defined(MODULE_NETDEV_ETH) || defined(MODULE_ESP_NOW) */
|
||||||
|
#ifdef MODULE_NRFMIN
|
||||||
|
case NETDEV_TYPE_NRFMIN:
|
||||||
|
(void)opt;
|
||||||
|
return sizeof(uint16_t);
|
||||||
|
#endif /* MODULE_NRFMIN */
|
||||||
|
#if defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_XBEE)
|
||||||
|
case NETDEV_TYPE_IEEE802154:
|
||||||
|
/* see https://tools.ietf.org/html/rfc4944#section-8 */
|
||||||
|
switch (opt->len) {
|
||||||
|
case 1U:
|
||||||
|
return IEEE802154_SHORT_ADDRESS_LEN;
|
||||||
|
case 2U:
|
||||||
|
return IEEE802154_LONG_ADDRESS_LEN;
|
||||||
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
#endif /* defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_XBEE) */
|
||||||
|
default:
|
||||||
|
(void)opt;
|
||||||
|
#ifdef DEVELHELP
|
||||||
|
LOG_ERROR("gnrc_netif: can't get address length from NDP link-layer "
|
||||||
|
"address option on interface %u\n", netif->pid);
|
||||||
|
#endif
|
||||||
|
assert(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
#endif /* MODULE_GNRC_IPV6 */
|
#endif /* MODULE_GNRC_IPV6 */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|||||||
@ -30,18 +30,6 @@
|
|||||||
|
|
||||||
static char addr_str[IPV6_ADDR_MAX_STR_LEN];
|
static char addr_str[IPV6_ADDR_MAX_STR_LEN];
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Determines supposed link-layer address from interface and option
|
|
||||||
* length
|
|
||||||
*
|
|
||||||
* @param[in] netif A network interface.
|
|
||||||
* @param[in] opt A SL2AO or TL2AO.
|
|
||||||
*
|
|
||||||
* @return The length of the L2 address carried in @p opt.
|
|
||||||
*/
|
|
||||||
static inline unsigned _get_l2addr_len(gnrc_netif_t *netif,
|
|
||||||
const ndp_opt_t *opt);
|
|
||||||
|
|
||||||
void _snd_ns(const ipv6_addr_t *tgt, gnrc_netif_t *netif,
|
void _snd_ns(const ipv6_addr_t *tgt, gnrc_netif_t *netif,
|
||||||
const ipv6_addr_t *src, const ipv6_addr_t *dst)
|
const ipv6_addr_t *src, const ipv6_addr_t *dst)
|
||||||
{
|
{
|
||||||
@ -104,10 +92,10 @@ void _handle_sl2ao(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6,
|
|||||||
{
|
{
|
||||||
assert(netif != NULL);
|
assert(netif != NULL);
|
||||||
_nib_onl_entry_t *nce = _nib_onl_get(&ipv6->src, netif->pid);
|
_nib_onl_entry_t *nce = _nib_onl_get(&ipv6->src, netif->pid);
|
||||||
unsigned l2addr_len;
|
int l2addr_len;
|
||||||
|
|
||||||
l2addr_len = _get_l2addr_len(netif, sl2ao);
|
l2addr_len = gnrc_netif_ndp_addr_len_from_l2ao(netif, sl2ao);
|
||||||
if (l2addr_len == 0U) {
|
if (l2addr_len < 0) {
|
||||||
DEBUG("nib: Unexpected SL2AO length. Ignoring SL2AO\n");
|
DEBUG("nib: Unexpected SL2AO length. Ignoring SL2AO\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -174,43 +162,6 @@ void _handle_sl2ao(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned _get_l2addr_len(gnrc_netif_t *netif,
|
|
||||||
const ndp_opt_t *opt)
|
|
||||||
{
|
|
||||||
switch (netif->device_type) {
|
|
||||||
#ifdef MODULE_CC110X
|
|
||||||
case NETDEV_TYPE_CC110X:
|
|
||||||
(void)opt;
|
|
||||||
return sizeof(uint8_t);
|
|
||||||
#endif /* MODULE_CC110X */
|
|
||||||
#if defined(MODULE_NETDEV_ETH) || defined(MODULE_ESP_NOW)
|
|
||||||
case NETDEV_TYPE_ETHERNET:
|
|
||||||
case NETDEV_TYPE_ESP_NOW:
|
|
||||||
(void)opt;
|
|
||||||
return ETHERNET_ADDR_LEN;
|
|
||||||
#endif /* defined(MODULE_NETDEV_ETH) || defined(MODULE_ESP_NOW) */
|
|
||||||
#ifdef MODULE_NRFMIN
|
|
||||||
case NETDEV_TYPE_NRFMIN:
|
|
||||||
(void)opt;
|
|
||||||
return sizeof(uint16_t);
|
|
||||||
#endif /* MODULE_NRFMIN */
|
|
||||||
#if defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_XBEE)
|
|
||||||
case NETDEV_TYPE_IEEE802154:
|
|
||||||
switch (opt->len) {
|
|
||||||
case 1U:
|
|
||||||
return IEEE802154_SHORT_ADDRESS_LEN;
|
|
||||||
case 2U:
|
|
||||||
return IEEE802154_LONG_ADDRESS_LEN;
|
|
||||||
default:
|
|
||||||
return 0U;
|
|
||||||
}
|
|
||||||
#endif /* defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_XBEE) */
|
|
||||||
default:
|
|
||||||
(void)opt;
|
|
||||||
return 0U;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if GNRC_IPV6_NIB_CONF_ARSM
|
#if GNRC_IPV6_NIB_CONF_ARSM
|
||||||
/**
|
/**
|
||||||
* @brief Calculates exponential back-off for retransmission timer for
|
* @brief Calculates exponential back-off for retransmission timer for
|
||||||
@ -379,13 +330,13 @@ void _probe_nbr(_nib_onl_entry_t *nbr, bool reset)
|
|||||||
void _handle_adv_l2(gnrc_netif_t *netif, _nib_onl_entry_t *nce,
|
void _handle_adv_l2(gnrc_netif_t *netif, _nib_onl_entry_t *nce,
|
||||||
const icmpv6_hdr_t *icmpv6, const ndp_opt_t *tl2ao)
|
const icmpv6_hdr_t *icmpv6, const ndp_opt_t *tl2ao)
|
||||||
{
|
{
|
||||||
unsigned l2addr_len = 0;
|
int l2addr_len = 0;
|
||||||
|
|
||||||
assert(nce != NULL);
|
assert(nce != NULL);
|
||||||
assert(netif != NULL);
|
assert(netif != NULL);
|
||||||
if (tl2ao != NULL) {
|
if (tl2ao != NULL) {
|
||||||
l2addr_len = _get_l2addr_len(netif, tl2ao);
|
l2addr_len = gnrc_netif_ndp_addr_len_from_l2ao(netif, tl2ao);
|
||||||
if (l2addr_len == 0U) {
|
if (l2addr_len < 0) {
|
||||||
DEBUG("nib: Unexpected TL2AO length. Ignoring TL2AO\n");
|
DEBUG("nib: Unexpected TL2AO length. Ignoring TL2AO\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user