gnrc_ipv6_netif: initialize MTU from device, if possible
This commit is contained in:
parent
04e7a7e509
commit
f1864fd2b6
@ -28,6 +28,7 @@
|
|||||||
#include "kernel_macros.h"
|
#include "kernel_macros.h"
|
||||||
#include "kernel_types.h"
|
#include "kernel_types.h"
|
||||||
#include "mutex.h"
|
#include "mutex.h"
|
||||||
|
#include "net/ipv6.h"
|
||||||
#include "net/ipv6/addr.h"
|
#include "net/ipv6/addr.h"
|
||||||
#include "vtimer.h"
|
#include "vtimer.h"
|
||||||
|
|
||||||
@ -51,11 +52,19 @@ extern "C" {
|
|||||||
/**
|
/**
|
||||||
* @brief Default MTU
|
* @brief Default MTU
|
||||||
*
|
*
|
||||||
* @see <a href="https://tools.ietf.org/html/rfc2460#section-5">
|
* An interface will choose this MTU if the link-layer's maximum packet size
|
||||||
* RFC 2460, section 5
|
* (see @ref NETOPT_MAX_PACKET_SIZE) is lesser than the @ref IPV6_MIN_MTU or if it just not
|
||||||
* </a>
|
* 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
|
* @brief Default hop limit
|
||||||
|
|||||||
@ -32,6 +32,15 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief minimum **M**aximum **T**ransition **U**nit
|
||||||
|
*
|
||||||
|
* @see <a href="https://tools.ietf.org/html/rfc4944#section-5.3">
|
||||||
|
* RFC 2460, section 5.3
|
||||||
|
* </a>
|
||||||
|
*/
|
||||||
|
#define IPV6_MIN_MTU (1280)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -695,6 +695,7 @@ void gnrc_ipv6_netif_init_by_dev(void)
|
|||||||
for (size_t i = 0; i < ifnum; i++) {
|
for (size_t i = 0; i < ifnum; i++) {
|
||||||
ipv6_addr_t addr;
|
ipv6_addr_t addr;
|
||||||
eui64_t iid;
|
eui64_t iid;
|
||||||
|
uint16_t mtu;
|
||||||
gnrc_ipv6_netif_t *ipv6_if = gnrc_ipv6_netif_get(ifs[i]);
|
gnrc_ipv6_netif_t *ipv6_if = gnrc_ipv6_netif_get(ifs[i]);
|
||||||
|
|
||||||
if (ipv6_if == NULL) {
|
if (ipv6_if == NULL) {
|
||||||
@ -730,6 +731,7 @@ void gnrc_ipv6_netif_init_by_dev(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* set link-local address */
|
||||||
if ((gnrc_netapi_get(ifs[i], NETOPT_IPV6_IID, 0, &iid,
|
if ((gnrc_netapi_get(ifs[i], NETOPT_IPV6_IID, 0, &iid,
|
||||||
sizeof(eui64_t)) < 0)) {
|
sizeof(eui64_t)) < 0)) {
|
||||||
mutex_unlock(&ipv6_if->mutex);
|
mutex_unlock(&ipv6_if->mutex);
|
||||||
@ -740,6 +742,16 @@ void gnrc_ipv6_netif_init_by_dev(void)
|
|||||||
ipv6_addr_set_link_local_prefix(&addr);
|
ipv6_addr_set_link_local_prefix(&addr);
|
||||||
_add_addr_to_entry(ipv6_if, &addr, 64, 0);
|
_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);
|
mutex_unlock(&ipv6_if->mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user