Skip to content
Snippets Groups Projects
Unverified Commit 6a4c764c authored by Cenk Gündoğan's avatar Cenk Gündoğan Committed by GitHub
Browse files

Merge pull request #10569 from miri64/gnrc_netif/enh/rm-get-NETOPT_IPV6_IID

gnrc_netif: make _get_iid() just wrapper around _iid_from_addr()
parents 9767dd3d 7ae90564
No related branches found
No related tags found
No related merge requests found
...@@ -280,18 +280,6 @@ void gnrc_netif_ipv6_group_leave_internal(gnrc_netif_t *netif, ...@@ -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, int gnrc_netif_ipv6_group_idx(gnrc_netif_t *netif,
const ipv6_addr_t *addr); 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 */ #endif /* MODULE_GNRC_IPV6 */
/** /**
...@@ -466,9 +454,40 @@ int gnrc_netif_ipv6_iid_from_addr(const gnrc_netif_t *netif, ...@@ -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, int gnrc_netif_ipv6_iid_to_addr(const gnrc_netif_t *netif, const eui64_t *iid,
uint8_t *addr); 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) */ #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_ipv6_get_iid(netif, iid) (-ENOTSUP)
#endif /* defined(MODULE_GNRC_IPV6) || defined(DOXYGEN) */ #endif /* defined(MODULE_GNRC_IPV6) || defined(DOXYGEN) */
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -183,9 +183,7 @@ int gnrc_netif_get_from_netdev(gnrc_netif_t *netif, gnrc_netapi_opt_t *opt) ...@@ -183,9 +183,7 @@ int gnrc_netif_get_from_netdev(gnrc_netif_t *netif, gnrc_netapi_opt_t *opt)
break; break;
case NETOPT_IPV6_IID: case NETOPT_IPV6_IID:
assert(opt->data_len >= sizeof(eui64_t)); assert(opt->data_len >= sizeof(eui64_t));
if (gnrc_netif_ipv6_get_iid(netif, opt->data) == 0) { res = gnrc_netif_ipv6_get_iid(netif, opt->data);
res = sizeof(eui64_t);
}
break; break;
case NETOPT_MAX_PACKET_SIZE: case NETOPT_MAX_PACKET_SIZE:
if (opt->context == GNRC_NETTYPE_IPV6) { if (opt->context == GNRC_NETTYPE_IPV6) {
...@@ -813,28 +811,6 @@ int gnrc_netif_ipv6_group_idx(gnrc_netif_t *netif, const ipv6_addr_t *addr) ...@@ -813,28 +811,6 @@ int gnrc_netif_ipv6_group_idx(gnrc_netif_t *netif, const ipv6_addr_t *addr)
return idx; 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) static inline bool _addr_anycast(const gnrc_netif_t *netif, unsigned idx)
{ {
return (netif->ipv6.addrs_flags[idx] & GNRC_NETIF_IPV6_ADDRS_FLAGS_ANYCAST); return (netif->ipv6.addrs_flags[idx] & GNRC_NETIF_IPV6_ADDRS_FLAGS_ANYCAST);
......
...@@ -108,7 +108,7 @@ static bool _try_addr_reconfiguration(gnrc_netif_t *netif) ...@@ -108,7 +108,7 @@ static bool _try_addr_reconfiguration(gnrc_netif_t *netif)
eui64_t orig_iid; eui64_t orig_iid;
bool remove_old = false, hwaddr_reconf; 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; remove_old = true;
} }
/* seize netif to netif thread since _try_l2addr_reconfiguration uses /* seize netif to netif thread since _try_l2addr_reconfiguration uses
......
...@@ -651,10 +651,12 @@ static void test_ipv6_get_iid(void) ...@@ -651,10 +651,12 @@ static void test_ipv6_get_iid(void)
eui64_t res; eui64_t res;
uint16_t ieee802154_l2addr_len = 2U; 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, &ethernet_ipv6_ll.u64[1], TEST_ASSERT_EQUAL_INT(0, memcmp(&res, &ethernet_ipv6_ll.u64[1],
sizeof(res))); 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], TEST_ASSERT_EQUAL_INT(0, memcmp(&res, &ieee802154_ipv6_ll_long.u64[1],
sizeof(res))); sizeof(res)));
TEST_ASSERT_EQUAL_INT(sizeof(ieee802154_l2addr_len), TEST_ASSERT_EQUAL_INT(sizeof(ieee802154_l2addr_len),
...@@ -662,7 +664,8 @@ static void test_ipv6_get_iid(void) ...@@ -662,7 +664,8 @@ static void test_ipv6_get_iid(void)
NETOPT_SRC_LEN, 0, NETOPT_SRC_LEN, 0,
&ieee802154_l2addr_len, &ieee802154_l2addr_len,
sizeof(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))); TEST_ASSERT_EQUAL_INT(0, memcmp(&res, &ieee802154_eui64_short, sizeof(res)));
/* reset to source length 8 */ /* reset to source length 8 */
ieee802154_l2addr_len = 8U; ieee802154_l2addr_len = 8U;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment