diff --git a/samples/bluetooth/ipsp/README.rst b/samples/bluetooth/ipsp/README.rst index b57a6ab5a06d..650638ab62f7 100644 --- a/samples/bluetooth/ipsp/README.rst +++ b/samples/bluetooth/ipsp/README.rst @@ -22,6 +22,16 @@ Sample can be built and executed for the nRF52840 DK NRF52840 as follows: :goals: build flash :compact: +To build a debug version, with logging and shell support, use the config file +:file:`prj_dbg.conf`: + +.. zephyr-app-commands:: + :zephyr-app: samples/bluetooth/ipsp + :board: nrf52840dk_nrf52840 + :conf: prj_dbg.conf + :goals: build flash + :compact: + Building and Running for Linux kernels released before 4.12 =========================================================== .. note:: diff --git a/samples/bluetooth/ipsp/prj.conf b/samples/bluetooth/ipsp/prj.conf index 6cf0a5c878f7..5dc407b3ad19 100644 --- a/samples/bluetooth/ipsp/prj.conf +++ b/samples/bluetooth/ipsp/prj.conf @@ -18,7 +18,7 @@ CONFIG_NET_PKT_TX_COUNT=10 CONFIG_NET_BUF_RX_COUNT=20 CONFIG_NET_BUF_TX_COUNT=20 CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3 -CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=2 +CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4 CONFIG_NET_MAX_CONTEXTS=6 CONFIG_NET_CONFIG_AUTO_INIT=y diff --git a/samples/bluetooth/ipsp/prj_dbg.conf b/samples/bluetooth/ipsp/prj_dbg.conf index 1cff8531b0e3..40474ed00b27 100644 --- a/samples/bluetooth/ipsp/prj_dbg.conf +++ b/samples/bluetooth/ipsp/prj_dbg.conf @@ -20,7 +20,7 @@ CONFIG_NET_PKT_TX_COUNT=10 CONFIG_NET_BUF_RX_COUNT=20 CONFIG_NET_BUF_TX_COUNT=20 CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3 -CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=2 +CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4 CONFIG_NET_MAX_CONTEXTS=6 CONFIG_NET_SHELL=y diff --git a/samples/bluetooth/ipsp/prj_zep1656.conf b/samples/bluetooth/ipsp/prj_zep1656.conf index a65ab43de2c0..992bf35866d6 100644 --- a/samples/bluetooth/ipsp/prj_zep1656.conf +++ b/samples/bluetooth/ipsp/prj_zep1656.conf @@ -19,7 +19,7 @@ CONFIG_NET_PKT_TX_COUNT=10 CONFIG_NET_BUF_RX_COUNT=20 CONFIG_NET_BUF_TX_COUNT=20 CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3 -CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=2 +CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4 CONFIG_NET_MAX_CONTEXTS=6 CONFIG_NET_CONFIG_AUTO_INIT=y diff --git a/samples/bluetooth/ipsp/src/main.c b/samples/bluetooth/ipsp/src/main.c index 25980448a7e6..c095feaa7306 100644 --- a/samples/bluetooth/ipsp/src/main.c +++ b/samples/bluetooth/ipsp/src/main.c @@ -25,12 +25,6 @@ LOG_MODULE_REGISTER(ipsp); #include #include -/* admin-local, dynamically allocated multicast address */ -#define MCAST_IP6ADDR { { { 0xff, 0x02, 0, 0, 0, 0, 0, 0, \ - 0, 0, 0, 0, 0, 0, 0, 0x1 } } } - -struct in6_addr in6addr_mcast = MCAST_IP6ADDR; - /* Define my IP address where to expect messages */ #define MY_IP6ADDR { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0x1 } } } @@ -87,21 +81,14 @@ static inline void init_app(void) ifaddr = net_if_ipv6_addr_add(net_if_get_default(), &in6addr_my, NET_ADDR_MANUAL, 0); } while (0); - - net_if_ipv6_maddr_add(net_if_get_default(), &in6addr_mcast); } static inline bool get_context(struct net_context **udp_recv6, - struct net_context **tcp_recv6, - struct net_context **mcast_recv6) + struct net_context **tcp_recv6) { int ret; - struct sockaddr_in6 mcast_addr6 = { 0 }; struct sockaddr_in6 my_addr6 = { 0 }; - net_ipaddr_copy(&mcast_addr6.sin6_addr, &in6addr_mcast); - mcast_addr6.sin6_family = AF_INET6; - my_addr6.sin6_family = AF_INET6; my_addr6.sin6_port = htons(MY_PORT); @@ -119,20 +106,6 @@ static inline bool get_context(struct net_context **udp_recv6, return false; } - ret = net_context_get(AF_INET6, SOCK_DGRAM, IPPROTO_UDP, mcast_recv6); - if (ret < 0) { - LOG_ERR("Cannot get receiving IPv6 mcast network context (%d)", - ret); - return false; - } - - ret = net_context_bind(*mcast_recv6, (struct sockaddr *)&mcast_addr6, - sizeof(struct sockaddr_in6)); - if (ret < 0) { - LOG_ERR("Cannot bind IPv6 mcast (%d)", ret); - return false; - } - ret = net_context_get(AF_INET6, SOCK_STREAM, IPPROTO_TCP, tcp_recv6); if (ret < 0) { LOG_ERR("Cannot get network context for IPv6 TCP (%d)", ret); @@ -314,9 +287,8 @@ static void listen(void) { struct net_context *udp_recv6 = { 0 }; struct net_context *tcp_recv6 = { 0 }; - struct net_context *mcast_recv6 = { 0 }; - if (!get_context(&udp_recv6, &tcp_recv6, &mcast_recv6)) { + if (!get_context(&udp_recv6, &tcp_recv6)) { LOG_ERR("Cannot get network contexts"); return; } @@ -331,7 +303,6 @@ static void listen(void) LOG_INF("Stopping..."); net_context_put(udp_recv6); - net_context_put(mcast_recv6); net_context_put(tcp_recv6); } diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 67921d5aa252..b546523204bd 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -1672,6 +1672,12 @@ struct net_if_mcast_addr *net_if_ipv6_maddr_add(struct net_if *iface, return NULL; } + if (net_if_ipv6_maddr_lookup(addr, &iface)) { + NET_WARN("Multicast address %s is is already registered.", + log_strdup(net_sprint_ipv6_addr(addr))); + return NULL; + } + for (i = 0; i < NET_IF_MAX_IPV6_MADDR; i++) { if (ipv6->mcast[i].is_used) { continue; diff --git a/subsys/net/l2/bluetooth/bluetooth.c b/subsys/net/l2/bluetooth/bluetooth.c index 51ed1f244dd9..562fceec3668 100644 --- a/subsys/net/l2/bluetooth/bluetooth.c +++ b/subsys/net/l2/bluetooth/bluetooth.c @@ -139,7 +139,10 @@ static int net_bt_enable(struct net_if *iface, bool state) static enum net_l2_flags net_bt_flags(struct net_if *iface) { - return NET_L2_MULTICAST | NET_L2_MULTICAST_SKIP_JOIN_SOLICIT_NODE; + /* TODO: add NET_L2_MULTICAST_SKIP_JOIN_SOLICIT_NODE once the stack + * supports Address Registration Option for neighbor discovery. + */ + return NET_L2_MULTICAST; } NET_L2_INIT(BLUETOOTH_L2, net_bt_recv, net_bt_send, diff --git a/tests/net/iface/src/main.c b/tests/net/iface/src/main.c index 5a6d15918382..162631d65db1 100644 --- a/tests/net/iface/src/main.c +++ b/tests/net/iface/src/main.c @@ -718,6 +718,14 @@ static void test_v6_addr_add(void) zassert_true(ret, "Cannot add IPv6 address"); } +static void test_v6_addr_add_mcast_twice(void) +{ + struct net_if_mcast_addr *maddr; + + maddr = net_if_ipv6_maddr_add(iface1, &in6addr_mcast); + zassert_equal(maddr, NULL, "Address was added twice"); +} + static void test_v6_addr_lookup(void) { int ret; @@ -859,6 +867,7 @@ void test_main(void) ztest_user_unit_test(test_v4_addr_lookup_user), ztest_unit_test(test_v4_addr_rm_user_from_userspace), ztest_unit_test(test_v6_addr_add), + ztest_unit_test(test_v6_addr_add_mcast_twice), ztest_unit_test(test_v6_addr_lookup), ztest_unit_test(test_v6_addr_rm), ztest_unit_test(test_v6_addr_add_user_from_userspace),