Skip to content

Commit 4595295

Browse files
rlubosfabiobaltieri
authored andcommitted
test: net: offloaded_netdev: Add tests for IPv4/6 address registration
Make sure it's possible to register IPv4/6 addresses on an offloaded interface. Add an extra build configuration to make sure it's also possible when native IP stack is disabled. Signed-off-by: Robert Lubos <[email protected]>
1 parent 8d296ba commit 4595295

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

tests/net/offloaded_netdev/prj.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ CONFIG_ZTEST=y
77
CONFIG_TEST_USERSPACE=y
88
CONFIG_NET_OFFLOAD=y
99
CONFIG_TEST_RANDOM_GENERATOR=y
10+
CONFIG_NET_IPV4=y
11+
CONFIG_NET_IPV6=y
12+
CONFIG_NET_IPV6_NBR_CACHE=n
13+
CONFIG_NET_IPV6_MLD=n
14+
CONFIG_NET_IF_MAX_IPV4_COUNT=4
15+
CONFIG_NET_IF_MAX_IPV6_COUNT=4

tests/net/offloaded_netdev/src/main.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
#include <zephyr/net/net_if.h>
2020
#include <zephyr/net/net_l2.h>
2121

22+
static struct in_addr test_addr_ipv4 = { { { 192, 0, 2, 1 } } };
23+
static struct in6_addr test_addr_ipv6 = { { {
24+
0x20, 0x01, 0x0d, 0xb8, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1
25+
} } };
26+
2227
/* Dummy socket creator for socket-offloaded ifaces */
2328
int offload_socket(int family, int type, int proto)
2429
{
@@ -36,6 +41,8 @@ static void sock_offload_l2_iface_init(struct net_if *iface)
3641
*/
3742
net_if_socket_offload_set(iface, offload_socket);
3843
net_if_flag_set(iface, NET_IF_NO_AUTO_START);
44+
net_if_flag_set(iface, NET_IF_IPV4);
45+
net_if_flag_set(iface, NET_IF_IPV6);
3946
}
4047

4148
/* Dummy init function for net-offloaded ifaces */
@@ -46,6 +53,8 @@ static void net_offload_l2_iface_init(struct net_if *iface)
4653
*/
4754
iface->if_dev->offload = &net_offload_api;
4855
net_if_flag_set(iface, NET_IF_NO_AUTO_START);
56+
net_if_flag_set(iface, NET_IF_IPV4);
57+
net_if_flag_set(iface, NET_IF_IPV6);
4958
}
5059

5160
/* Tracks the total number of ifaces that are up (theoretically). */
@@ -327,5 +336,58 @@ ZTEST(net_offloaded_netdev, test_up_down_sock_off_impl_fail_down)
327336
"Iface under test should have failed to go up");
328337
}
329338

339+
static void test_addr_add_common(struct net_if *test_iface, const char *off_type)
340+
{
341+
struct net_if *lookup_iface;
342+
struct net_if_addr *ipv4_addr;
343+
struct net_if_addr *ipv6_addr;
344+
345+
/* Bring iface up before test */
346+
(void)net_if_up(test_iface);
347+
348+
ipv4_addr = net_if_ipv4_addr_add(test_iface, &test_addr_ipv4,
349+
NET_ADDR_MANUAL, 0);
350+
zassert_not_null(ipv4_addr,
351+
"Failed to add IPv4 address to a %s offloaded interface",
352+
off_type);
353+
ipv6_addr = net_if_ipv6_addr_add(test_iface, &test_addr_ipv6,
354+
NET_ADDR_MANUAL, 0);
355+
zassert_not_null(ipv6_addr,
356+
"Failed to add IPv6 address to a socket %s interface",
357+
off_type);
358+
359+
lookup_iface = NULL;
360+
zassert_equal_ptr(net_if_ipv4_addr_lookup(&test_addr_ipv4, &lookup_iface),
361+
ipv4_addr,
362+
"Failed to find IPv4 address on a %s offloaded interface");
363+
zassert_equal_ptr(lookup_iface, test_iface, "Wrong interface");
364+
365+
lookup_iface = NULL;
366+
zassert_equal_ptr(net_if_ipv6_addr_lookup(&test_addr_ipv6, &lookup_iface),
367+
ipv6_addr,
368+
"Failed to find IPv6 address on a %s offloaded interface");
369+
zassert_equal_ptr(lookup_iface, test_iface, "Wrong interface");
370+
371+
zassert_true(net_if_ipv4_addr_rm(test_iface, &test_addr_ipv4),
372+
"Failed to remove IPv4 address from a %s offloaded interface",
373+
off_type);
374+
zassert_true(net_if_ipv6_addr_rm(test_iface, &test_addr_ipv6),
375+
"Failed to remove IPv4 address from a %s offloaded interface",
376+
off_type);
377+
}
378+
379+
ZTEST(net_offloaded_netdev, test_addr_add_sock_off_impl)
380+
{
381+
struct net_if *test_iface = NET_IF_GET(sock_offload_test_impl, 0);
382+
383+
test_addr_add_common(test_iface, "offloaded");
384+
}
385+
386+
ZTEST(net_offloaded_netdev, test_addr_add_net_off_impl)
387+
{
388+
struct net_if *test_iface = NET_IF_GET(net_offload_test_impl, 0);
389+
390+
test_addr_add_common(test_iface, "net");
391+
}
330392

331393
ZTEST_SUITE(net_offloaded_netdev, NULL, NULL, net_offloaded_netdev_before, NULL, NULL);
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
common:
22
min_ram: 16
33
depends_on: netif
4+
tags:
5+
- net
6+
- iface
7+
- userspace
48
tests:
5-
net.offloaded_netdev:
6-
tags:
7-
- net
8-
- iface
9-
- userspace
9+
net.offloaded_netdev: {}
10+
net.offloaded_netdev.no_native:
11+
extra_configs:
12+
- CONFIG_NET_NATIVE=n

0 commit comments

Comments
 (0)