Skip to content

Commit

Permalink
gnrc_netif: centralize function to init IPv6 MTU
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Nov 30, 2018
1 parent c9f6998 commit cc0bc9c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 47 deletions.
9 changes: 9 additions & 0 deletions sys/include/net/gnrc/netif.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,14 @@ int gnrc_netif_set_from_netdev(gnrc_netif_t *netif,
netopt_t gnrc_netif_get_l2addr_opt(gnrc_netif_t *netif);

#if defined(MODULE_GNRC_IPV6) || defined(DOXYGEN)
/**
* @brief Initialize IPv6 MTU and other packet length related members of
* @ref gnrc_netif_t based on gnrc_netif_t::device_type
*
* @param[in,out] netif The network interface to initialize the MTU for.
*/
void gnrc_netif_ipv6_init_mtu(gnrc_netif_t *netif);

/**
* @brief Converts a given hardware address to an IPv6 IID.
*
Expand Down Expand Up @@ -539,6 +547,7 @@ int gnrc_netif_ipv6_iid_to_addr(const gnrc_netif_t *netif, const eui64_t *iid,
int gnrc_netif_ndp_addr_len_from_l2ao(gnrc_netif_t *netif,
const ndp_opt_t *opt);
#else /* defined(MODULE_GNRC_IPV6) || defined(DOXYGEN) */
#define gnrc_netif_ipv6_init_mtu(netif) (void)netif
#define gnrc_netif_ipv6_iid_to_addr(netif, addr, addr_len, iid) (-ENOTSUP)
#define gnrc_netif_ipv6_iid_from_addr(netif, iid, addr) (-ENOTSUP)
#define gnrc_netif_ndp_addr_len_from_l2ao(netif, opt) (-ENOTSUP)
Expand Down
48 changes: 1 addition & 47 deletions sys/net/gnrc/netif/gnrc_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,53 +1150,7 @@ static void _init_from_device(gnrc_netif_t *netif)
(void)res;
assert(res == sizeof(tmp));
netif->device_type = (uint8_t)tmp;
switch (netif->device_type) {
#if defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_NRFMIN) || defined(MODULE_XBEE)
case NETDEV_TYPE_IEEE802154:
case NETDEV_TYPE_NRFMIN:
#ifdef MODULE_GNRC_SIXLOWPAN_IPHC
netif->flags |= GNRC_NETIF_FLAGS_6LO_HC;
#endif
#ifdef MODULE_GNRC_IPV6
res = dev->driver->get(dev, NETOPT_MAX_PACKET_SIZE, &tmp, sizeof(tmp));
assert(res == sizeof(tmp));
#ifdef MODULE_GNRC_SIXLOWPAN
netif->ipv6.mtu = IPV6_MIN_MTU;
netif->sixlo.max_frag_size = tmp;
#else
netif->ipv6.mtu = tmp;
#endif
#endif
break;
#endif /* MODULE_NETDEV_IEEE802154 */
#ifdef MODULE_NETDEV_ETH
case NETDEV_TYPE_ETHERNET:
#ifdef MODULE_GNRC_IPV6
netif->ipv6.mtu = ETHERNET_DATA_LEN;
#endif
break;
#endif
#ifdef MODULE_NORDIC_SOFTDEVICE_BLE
case NETDEV_TYPE_BLE:
netif->ipv6.mtu = IPV6_MIN_MTU;
#ifdef MODULE_GNRC_SIXLOWPAN_IPHC
netif->flags |= GNRC_NETIF_FLAGS_6LO_HC;
#endif
break;
#endif
default:
#ifdef MODULE_GNRC_IPV6
res = dev->driver->get(dev, NETOPT_MAX_PACKET_SIZE, &tmp, sizeof(tmp));
if (res < 0) {
/* assume maximum possible transition unit */
netif->ipv6.mtu = UINT16_MAX;
}
else {
netif->ipv6.mtu = tmp;
}
#endif
break;
}
gnrc_netif_ipv6_init_mtu(netif);
_update_l2addr_from_dev(netif);
}

Expand Down
60 changes: 60 additions & 0 deletions sys/net/gnrc/netif/gnrc_netif_device_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,66 @@ netopt_t gnrc_netif_get_l2addr_opt(gnrc_netif_t *netif)
}

#ifdef MODULE_GNRC_IPV6
void gnrc_netif_ipv6_init_mtu(gnrc_netif_t *netif)
{
#ifdef MODULE_GNRC_IPV6
netdev_t *dev = netif->dev;
int res;
uint16_t tmp;

switch (netif->device_type) {
#if defined(MODULE_NETDEV_IEEE802154) || defined(MODULE_NRFMIN) || \
defined(MODULE_XBEE)
case NETDEV_TYPE_IEEE802154:
case NETDEV_TYPE_NRFMIN:
#ifdef MODULE_GNRC_SIXLOWPAN_IPHC
netif->flags |= GNRC_NETIF_FLAGS_6LO_HC;
#endif
res = dev->driver->get(dev, NETOPT_MAX_PACKET_SIZE,
&tmp, sizeof(tmp));
assert(res == sizeof(tmp));
#ifdef MODULE_GNRC_SIXLOWPAN
netif->ipv6.mtu = IPV6_MIN_MTU;
netif->sixlo.max_frag_size = tmp;
#else
netif->ipv6.mtu = tmp;
#endif
break;
#endif /* MODULE_NETDEV_IEEE802154 */
#ifdef MODULE_NETDEV_ETH
case NETDEV_TYPE_ETHERNET:
#ifdef MODULE_GNRC_IPV6
netif->ipv6.mtu = ETHERNET_DATA_LEN;
#endif
break;
#endif
#ifdef MODULE_NORDIC_SOFTDEVICE_BLE
case NETDEV_TYPE_BLE:
netif->ipv6.mtu = IPV6_MIN_MTU;
#ifdef MODULE_GNRC_SIXLOWPAN_IPHC
netif->flags |= GNRC_NETIF_FLAGS_6LO_HC;
#endif
break;
#endif
default:
#ifdef DEVELHELP
LOG_DEBUG("gnrc_netif: getting MTU from device for interface %i\n",
netif->pid);
#endif
res = dev->driver->get(dev, NETOPT_MAX_PACKET_SIZE,
&tmp, sizeof(tmp));
if (res < 0) {
/* assume maximum possible transition unit */
netif->ipv6.mtu = UINT16_MAX;
}
else {
netif->ipv6.mtu = tmp;
}
break;
}
#endif
}

#if defined(MODULE_CC110X) || defined(MODULE_NRFMIN)
static void _create_iid_from_short(const uint8_t *addr, size_t addr_len,
eui64_t *iid)
Expand Down

0 comments on commit cc0bc9c

Please sign in to comment.