From 04ef24d21bacadd148100956b851423c0ecfcb10 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Tue, 16 Feb 2016 16:55:21 +0200 Subject: [PATCH] net: apps: Comment out code if IPv6 ND is in use If neighbor discovery is in use, then we do not need to do various route etc setup. Normally ND needs to be active but in some specific scenarios it can be turned off. One such scenario is if an application is run inside qemu which uses slip and host tun0 interface for communication, in this case host typically do not activate ND for tun0 so we need to disable it also in zephyr side. Change-Id: I8ac59990c5bbcdb06cca98bde7be3a0ad6e807a8 Signed-off-by: Jukka Rissanen --- .../coap_observe_client/src/coap-observe-client.c | 6 +++++- samples/net/coap_server/src/coap-server.c | 13 +++---------- samples/net/dtls_client/src/dtls-client.c | 6 +++++- samples/net/dtls_server/src/dtls-server.c | 4 +++- samples/net/echo_client/src/echo-client.c | 12 +++--------- samples/net/echo_server/src/echo-server.c | 12 +++--------- 6 files changed, 22 insertions(+), 31 deletions(-) diff --git a/samples/net/coap_observe_client/src/coap-observe-client.c b/samples/net/coap_observe_client/src/coap-observe-client.c index 228ab2d728e..9dc86dc12c4 100644 --- a/samples/net/coap_observe_client/src/coap-observe-client.c +++ b/samples/net/coap_observe_client/src/coap-observe-client.c @@ -50,11 +50,13 @@ char fiberStack[STACKSIZE]; static coap_observee_t *obs; +#ifdef CONFIG_NETWORKING_IPV6_NO_ND /* The peer is the server in our case. Just invent a mac * address for it because lower parts of the stack cannot set it * in this test as we do not have any radios. */ static uint8_t peer_mac[] = { 0x15, 0x0a, 0xbe, 0xef, 0xf0, 0x0d }; +#endif /* This is my mac address */ @@ -105,7 +107,9 @@ static inline void init_app(void) uip_ipaddr(&addr, 192,0,2,2); uip_sethostaddr(&addr); } -#else +#endif + +#ifdef CONFIG_NETWORKING_IPV6_NO_ND { uip_ipaddr_t *addr; const uip_lladdr_t *lladdr = (const uip_lladdr_t *)&peer_mac; diff --git a/samples/net/coap_server/src/coap-server.c b/samples/net/coap_server/src/coap-server.c index db6a611cd93..7c36a7f2cce 100644 --- a/samples/net/coap_server/src/coap-server.c +++ b/samples/net/coap_server/src/coap-server.c @@ -115,11 +115,12 @@ static inline void init_app(void) uip_ipaddr(&addr, 192,0,2,2); uip_sethostaddr(&addr); } -#else +#endif + +#ifdef CONFIG_NETWORKING_IPV6_NO_ND { uip_ipaddr_t *addr; -#ifdef CONFIG_NETWORKING_IPV6_NO_ND /* Set the routes and neighbor cache only if we do not have * neighbor discovery enabled. This setting should only be * used if running in qemu and using slip (tun device). @@ -135,14 +136,6 @@ static inline void init_app(void) */ uip_ds6_nbr_add(addr, lladdr, 0, NBR_REACHABLE); -#else - /* Hard code the route to peer just in case, not to - * be done in real life applications. - */ - addr = (uip_ipaddr_t *)&in6addr_peer; - uip_ds6_defrt_add(addr, 0); -#endif - addr = (uip_ipaddr_t *)&in6addr_my; uip_ds6_addr_add(addr, 0, ADDR_MANUAL); } diff --git a/samples/net/dtls_client/src/dtls-client.c b/samples/net/dtls_client/src/dtls-client.c index 21f59442d93..589b7d174be 100644 --- a/samples/net/dtls_client/src/dtls-client.c +++ b/samples/net/dtls_client/src/dtls-client.c @@ -79,11 +79,13 @@ static const unsigned char ecdsa_pub_key_y[] = { 0xD0, 0x43, 0xB1, 0xFB, 0x03, 0xE2, 0x2F, 0x4D, 0x17, 0xDE, 0x43, 0xF9, 0xF9, 0xAD, 0xEE, 0x70}; +#ifdef CONFIG_NETWORKING_IPV6_NO_ND /* The peer is the server in our case. Just invent a mac * address for it because lower parts of the stack cannot set it * in this test as we do not have any radios. */ static uint8_t peer_mac[] = { 0x15, 0x0a, 0xbe, 0xef, 0xf0, 0x0d }; +#endif /* This is my mac address */ @@ -127,7 +129,9 @@ static inline void init_app(void) uip_ipaddr(&addr, 192,0,2,2); uip_sethostaddr(&addr); } -#else +#endif + +#ifdef CONFIG_NETWORKING_IPV6_NO_ND { uip_ipaddr_t *addr; const uip_lladdr_t *lladdr = (const uip_lladdr_t *)&peer_mac; diff --git a/samples/net/dtls_server/src/dtls-server.c b/samples/net/dtls_server/src/dtls-server.c index f4412bc1081..ca9ebacf21f 100644 --- a/samples/net/dtls_server/src/dtls-server.c +++ b/samples/net/dtls_server/src/dtls-server.c @@ -96,7 +96,9 @@ static inline void init_app(void) uip_ipaddr(&addr, 192,0,2,2); uip_sethostaddr(&addr); } -#else +#endif + +#ifdef CONFIG_NETWORKING_IPV6_NO_ND { uip_ipaddr_t *addr; diff --git a/samples/net/echo_client/src/echo-client.c b/samples/net/echo_client/src/echo-client.c index ab059805e13..02825cef1ca 100644 --- a/samples/net/echo_client/src/echo-client.c +++ b/samples/net/echo_client/src/echo-client.c @@ -115,11 +115,12 @@ static inline void init_app(void) uip_ipaddr(&addr, 192,0,2,2); uip_sethostaddr(&addr); } -#else /* IPv6 */ +#endif + +#ifdef CONFIG_NETWORKING_IPV6_NO_ND { uip_ipaddr_t *addr; -#ifdef CONFIG_NETWORKING_IPV6_NO_ND /* Set the routes and neighbor cache only if we do not have * neighbor discovery enabled. This setting should only be * used if running in qemu and using slip (tun device). @@ -134,13 +135,6 @@ static inline void init_app(void) * but do it here so that test works from first packet. */ uip_ds6_nbr_add(addr, lladdr, 0, NBR_REACHABLE); -#else - /* Hard code the route to peer just in case, not to - * be done in real life applications. - */ - addr = (uip_ipaddr_t *)&in6addr_peer; - uip_ds6_defrt_add(addr, 0); -#endif addr = (uip_ipaddr_t *)&in6addr_my; uip_ds6_addr_add(addr, 0, ADDR_MANUAL); diff --git a/samples/net/echo_server/src/echo-server.c b/samples/net/echo_server/src/echo-server.c index 6b15e1c21dc..8896a2405ab 100644 --- a/samples/net/echo_server/src/echo-server.c +++ b/samples/net/echo_server/src/echo-server.c @@ -89,11 +89,12 @@ static inline void init_app(void) uip_ipaddr(&addr, 192,0,2,2); uip_sethostaddr(&addr); } -#else /* IPv6 */ +#endif + +#if defined(CONFIG_NETWORKING_IPV6_NO_ND) { uip_ipaddr_t *addr; -#if defined(CONFIG_NETWORKING_IPV6_NO_ND) /* Set the routes and neighbor cache only if we do not have * neighbor discovery enabled. This setting should only be * used if running in qemu and using slip (tun device). @@ -108,13 +109,6 @@ static inline void init_app(void) * but do it here so that test works from first packet. */ uip_ds6_nbr_add(addr, lladdr, 0, NBR_REACHABLE); -#else - /* Hard code the route to peer just in case, not to - * be done in real life applications. - */ - addr = (uip_ipaddr_t *)&in6addr_peer; - uip_ds6_defrt_add(addr, 0); -#endif addr = (uip_ipaddr_t *)&in6addr_my; uip_ds6_addr_add(addr, 0, ADDR_MANUAL);