From fb8d7625d1d15eb8354b6eda2ad979fc4c652ca2 Mon Sep 17 00:00:00 2001 From: Sebastien Griffoul Date: Mon, 23 May 2016 17:12:53 +0200 Subject: [PATCH] net: ipv6: Fix net_set_mac function The ethernet driver calls net_set_mac before net_init is called (ie before the uip stack has been fully initialized). Unfortunately net_set_mac calls the function uip_ds6_set_lladdr. Therefore this function is called before uip_ds6_init: this is an issue as uip_ds6_set_lladdr is setting some static data which are going to be erased by uip_ds6_init. In some case it could even lead to a system hang due to a timer set twice. To fix this issue net_set_mac should check whether net_init has been already called. If not net_set_mac should simply copies the mac address into uip_lladdr. Indeed uip_ds6_init automatically calls uip_ds6_set_lladdr for the address stored into uip_lladdr. Change-Id: Ifbcb07e7cd493b6284a85d70f2439d434cebbb00 Signed-off-by: Sebastien Griffoul --- net/ip/net_core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/ip/net_core.c b/net/ip/net_core.c index 27103533ec7..774cee5a121 100644 --- a/net/ip/net_core.c +++ b/net/ip/net_core.c @@ -97,6 +97,8 @@ static char __noinit __stack tx_fiber_stack[CONFIG_IP_TX_STACK_SIZE]; static char __noinit __stack timer_fiber_stack[CONFIG_IP_TIMER_STACK_SIZE]; static nano_thread_id_t timer_fiber_id, tx_fiber_id; +static uint8_t initialized; + static struct net_dev { /* Queue for incoming packets from driver */ struct nano_fifo rx_queue; @@ -999,7 +1001,9 @@ int net_set_mac(uint8_t *mac, uint8_t len) NET_DBG("MAC "); PRINTLLADDR((uip_lladdr_t *)&linkaddr_node_addr); PRINTF("\n"); #ifdef CONFIG_NETWORKING_WITH_IPV6 - { + if (!initialized) { + memcpy(&uip_lladdr, mac, len); + } else { uip_ds6_addr_t *lladdr; uip_ds6_set_lladdr((uip_lladdr_t *)mac); @@ -1104,8 +1108,6 @@ void net_unregister_driver(struct net_driver *drv) int net_init(void) { - static uint8_t initialized; - if (initialized) return -EALREADY;