diff --git a/sys/include/net/gnrc/netif/internal.h b/sys/include/net/gnrc/netif/internal.h index 8ce4c4ff6d8f..22e31ed08c5c 100644 --- a/sys/include/net/gnrc/netif/internal.h +++ b/sys/include/net/gnrc/netif/internal.h @@ -280,18 +280,6 @@ void gnrc_netif_ipv6_group_leave_internal(gnrc_netif_t *netif, */ int gnrc_netif_ipv6_group_idx(gnrc_netif_t *netif, const ipv6_addr_t *addr); - -/** - * @brief Gets interface identifier (IID) of an interface's link-layer address - * - * @param[in] netif the network interface - * @param[out] eui64 the IID - * - * @return 0, on success - * @return -ENOTSUP, if interface has no link-layer address or if - * gnrc_netif_t::device_type is not supported. - */ -int gnrc_netif_ipv6_get_iid(gnrc_netif_t *netif, eui64_t *eui64); #endif /* MODULE_GNRC_IPV6 */ /** @@ -466,9 +454,40 @@ int gnrc_netif_ipv6_iid_from_addr(const gnrc_netif_t *netif, */ int gnrc_netif_ipv6_iid_to_addr(const gnrc_netif_t *netif, const eui64_t *iid, uint8_t *addr); + +/** + * @brief Converts an interface IID of an interface's hardware address + * + * @param[in] netif The network interface @p iid came from + * @param[out] iid The IID based on gnrc_netif_t::device_type + * + * @note This wraps around @ref gnrc_netif_ipv6_iid_from_addr by using + * by using gnrc_netif_t::l2addr and gnrc_netif_t::l2addr_len of + * @p netif. + * + * @return `sizeof(eui64_t)` on success. + * @return `-ENOTSUP`, if interface has no link-layer address or if + * gnrc_netif_t::device_type is not supported. + * @return `-EINVAL`, when gnrc_netif_t::l2addr_len of @p netif is invalid for + * the gnrc_netif_t::device_type of @p netif. + */ +static inline int gnrc_netif_ipv6_get_iid(gnrc_netif_t *netif, eui64_t *iid) +{ +#if GNRC_NETIF_L2ADDR_MAXLEN > 0 + if (netif->flags & GNRC_NETIF_FLAGS_HAS_L2ADDR) { + return gnrc_netif_ipv6_iid_from_addr(netif, + netif->l2addr, netif->l2addr_len, + iid); + } +#endif /* GNRC_NETIF_L2ADDR_MAXLEN > 0 */ + (void)netif; + (void)iid; + return -ENOTSUP; +} #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_to_addr(netif, iid, addr) (-ENOTSUP) +#define gnrc_netif_ipv6_get_iid(netif, iid) (-ENOTSUP) #endif /* defined(MODULE_GNRC_IPV6) || defined(DOXYGEN) */ #ifdef __cplusplus diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index 5a27de43fba7..12879ebf028e 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -177,9 +177,7 @@ int gnrc_netif_get_from_netdev(gnrc_netif_t *netif, gnrc_netapi_opt_t *opt) break; case NETOPT_IPV6_IID: assert(opt->data_len >= sizeof(eui64_t)); - if (gnrc_netif_ipv6_get_iid(netif, opt->data) == 0) { - res = sizeof(eui64_t); - } + res = gnrc_netif_ipv6_get_iid(netif, opt->data); break; case NETOPT_MAX_PACKET_SIZE: if (opt->context == GNRC_NETTYPE_IPV6) { @@ -807,28 +805,6 @@ int gnrc_netif_ipv6_group_idx(gnrc_netif_t *netif, const ipv6_addr_t *addr) return idx; } -int gnrc_netif_ipv6_get_iid(gnrc_netif_t *netif, eui64_t *eui64) -{ -#if GNRC_NETIF_L2ADDR_MAXLEN > 0 - if (netif->flags & GNRC_NETIF_FLAGS_HAS_L2ADDR) { - /* the device driver abstraction should be able to provide us with the - * IPV6_IID, so we try this first */ - int res = netif->dev->driver->get(netif->dev, NETOPT_IPV6_IID, - eui64, sizeof(eui64_t)); - if (res == sizeof(eui64_t)) { - return 0; - } - res = gnrc_netif_ipv6_iid_from_addr(netif, - netif->l2addr, netif->l2addr_len, - eui64); - if (res > 0) { - return 0; - } - } -#endif /* GNRC_NETIF_L2ADDR_MAXLEN > 0 */ - return -ENOTSUP; -} - static inline bool _addr_anycast(const gnrc_netif_t *netif, unsigned idx) { return (netif->ipv6.addrs_flags[idx] & GNRC_NETIF_IPV6_ADDRS_FLAGS_ANYCAST); diff --git a/sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c b/sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c index e32896d119e9..65d8ffdba445 100644 --- a/sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c +++ b/sys/net/gnrc/network_layer/ipv6/nib/_nib-slaac.c @@ -108,7 +108,7 @@ static bool _try_addr_reconfiguration(gnrc_netif_t *netif) eui64_t orig_iid; bool remove_old = false, hwaddr_reconf; - if (gnrc_netif_ipv6_get_iid(netif, &orig_iid) == 0) { + if (gnrc_netif_ipv6_get_iid(netif, &orig_iid) > 0) { remove_old = true; } /* seize netif to netif thread since _try_l2addr_reconfiguration uses diff --git a/tests/gnrc_netif/main.c b/tests/gnrc_netif/main.c index 4a0d3b0d3fb4..216443ce07df 100644 --- a/tests/gnrc_netif/main.c +++ b/tests/gnrc_netif/main.c @@ -651,10 +651,12 @@ static void test_ipv6_get_iid(void) eui64_t res; uint16_t ieee802154_l2addr_len = 2U; - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_ipv6_get_iid(ethernet_netif, &res)); + TEST_ASSERT_EQUAL_INT(sizeof(eui64_t), + gnrc_netif_ipv6_get_iid(ethernet_netif, &res)); TEST_ASSERT_EQUAL_INT(0, memcmp(&res, ðernet_ipv6_ll.u64[1], sizeof(res))); - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_ipv6_get_iid(ieee802154_netif, &res)); + TEST_ASSERT_EQUAL_INT(sizeof(eui64_t), + gnrc_netif_ipv6_get_iid(ieee802154_netif, &res)); TEST_ASSERT_EQUAL_INT(0, memcmp(&res, &ieee802154_ipv6_ll_long.u64[1], sizeof(res))); TEST_ASSERT_EQUAL_INT(sizeof(ieee802154_l2addr_len), @@ -662,7 +664,8 @@ static void test_ipv6_get_iid(void) NETOPT_SRC_LEN, 0, &ieee802154_l2addr_len, sizeof(ieee802154_l2addr_len))); - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_ipv6_get_iid(ieee802154_netif, &res)); + TEST_ASSERT_EQUAL_INT(sizeof(eui64_t), + gnrc_netif_ipv6_get_iid(ieee802154_netif, &res)); TEST_ASSERT_EQUAL_INT(0, memcmp(&res, &ieee802154_eui64_short, sizeof(res))); /* reset to source length 8 */ ieee802154_l2addr_len = 8U;