mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
gnrc_netif: make _get_iid() just wrapper around _iid_from_addr()
This way the IID generation gets much simplified and code duplication is avoided since it removes GNRC's requirement for NETOPT_IPV6_IID.
This commit is contained in:
parent
eead6066dd
commit
7ae90564d9
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user