Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: bt: fix 6lowpan over BLE regression #31075

Merged
merged 5 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions samples/bluetooth/ipsp/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ Sample can be built and executed for the nRF52840 DK NRF52840 as follows:
:goals: build flash
fabiobaltieri marked this conversation as resolved.
Show resolved Hide resolved
: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::
Expand Down
2 changes: 1 addition & 1 deletion samples/bluetooth/ipsp/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion samples/bluetooth/ipsp/prj_dbg.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion samples/bluetooth/ipsp/prj_zep1656.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 2 additions & 31 deletions samples/bluetooth/ipsp/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ LOG_MODULE_REGISTER(ipsp);
#include <net/net_context.h>
#include <net/udp.h>

/* 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 } } }
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions subsys/net/ip/net_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion subsys/net/l2/bluetooth/bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions tests/net/iface/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down