From f1864fd2b6502cc8f092d715655bfaccb4c6d371 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 20 Aug 2015 15:09:45 +0200 Subject: [PATCH] gnrc_ipv6_netif: initialize MTU from device, if possible --- sys/include/net/gnrc/ipv6/netif.h | 17 +++++++++++++---- sys/include/net/ipv6.h | 9 +++++++++ .../network_layer/ipv6/netif/gnrc_ipv6_netif.c | 12 ++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/sys/include/net/gnrc/ipv6/netif.h b/sys/include/net/gnrc/ipv6/netif.h index e62989b917..64f0f0602d 100644 --- a/sys/include/net/gnrc/ipv6/netif.h +++ b/sys/include/net/gnrc/ipv6/netif.h @@ -28,6 +28,7 @@ #include "kernel_macros.h" #include "kernel_types.h" #include "mutex.h" +#include "net/ipv6.h" #include "net/ipv6/addr.h" #include "vtimer.h" @@ -51,11 +52,19 @@ extern "C" { /** * @brief Default MTU * - * @see - * RFC 2460, section 5 - * + * An interface will choose this MTU if the link-layer's maximum packet size + * (see @ref NETOPT_MAX_PACKET_SIZE) is lesser than the @ref IPV6_MIN_MTU or if it just not + * provide it. For RFC-compatible communication it must be at least @ref IPV6_MIN_MTU. + * + * @note If the scenario the node is used in allows for it and the packet size is predictable, + * a user might choose to set @ref GNRC_IPV6_NETIF_DEFAULT_MTU to a lesser value than + * @ref IPV6_MIN_MTU to optimize for code size (e.g. because it is then possible to omit + * @ref net_gnrc_sixlowpan_frag) and memory usage (e.g. because @ref GNRC_PKTBUF_SIZE + * can be much smaller). */ -#define GNRC_IPV6_NETIF_DEFAULT_MTU (1280) +#ifndef GNRC_IPV6_NETIF_DEFAULT_MTU +#define GNRC_IPV6_NETIF_DEFAULT_MTU (IPV6_MIN_MTU) +#endif /** * @brief Default hop limit diff --git a/sys/include/net/ipv6.h b/sys/include/net/ipv6.h index 973c82555c..ba3e035d7a 100644 --- a/sys/include/net/ipv6.h +++ b/sys/include/net/ipv6.h @@ -32,6 +32,15 @@ extern "C" { #endif +/** + * @brief minimum **M**aximum **T**ransition **U**nit + * + * @see + * RFC 2460, section 5.3 + * + */ +#define IPV6_MIN_MTU (1280) + #ifdef __cplusplus } #endif diff --git a/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c b/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c index b0976f7681..15bf3b81d4 100644 --- a/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c +++ b/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c @@ -695,6 +695,7 @@ void gnrc_ipv6_netif_init_by_dev(void) for (size_t i = 0; i < ifnum; i++) { ipv6_addr_t addr; eui64_t iid; + uint16_t mtu; gnrc_ipv6_netif_t *ipv6_if = gnrc_ipv6_netif_get(ifs[i]); if (ipv6_if == NULL) { @@ -730,6 +731,7 @@ void gnrc_ipv6_netif_init_by_dev(void) } #endif + /* set link-local address */ if ((gnrc_netapi_get(ifs[i], NETOPT_IPV6_IID, 0, &iid, sizeof(eui64_t)) < 0)) { mutex_unlock(&ipv6_if->mutex); @@ -740,6 +742,16 @@ void gnrc_ipv6_netif_init_by_dev(void) ipv6_addr_set_link_local_prefix(&addr); _add_addr_to_entry(ipv6_if, &addr, 64, 0); + /* set link MTU */ + if ((gnrc_netapi_get(ifs[i], NETOPT_MAX_PACKET_SIZE, 0, &mtu, + sizeof(uint16_t)) >= 0)) { + if (mtu >= IPV6_MIN_MTU) { + ipv6_if->mtu = mtu; + } + /* otherwise leave at GNRC_IPV6_NETIF_DEFAULT_MTU as initialized in + * gnrc_ipv6_netif_add() */ + } + mutex_unlock(&ipv6_if->mutex); } }