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 */
2328int 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
331393ZTEST_SUITE (net_offloaded_netdev , NULL , NULL , net_offloaded_netdev_before , NULL , NULL );
0 commit comments