@@ -63,6 +63,7 @@ static struct net_if *iface1;
6363static struct net_if * iface2 ;
6464static struct net_if * iface3 ;
6565static struct net_if * iface4 ;
66+ static struct net_if * eth_iface ;
6667
6768static bool test_failed ;
6869static bool test_started ;
@@ -303,6 +304,7 @@ static void iface_cb(struct net_if *iface, void *user_data)
303304 if (api -> get_capabilities ==
304305 eth_fake_api_funcs .get_capabilities ) {
305306 iface4 = iface ;
307+ eth_iface = iface ;
306308 }
307309 } else {
308310 switch (if_count ) {
@@ -1332,4 +1334,65 @@ ZTEST(net_iface, test_interface_name)
13321334#endif
13331335}
13341336
1337+ static void generate_iid (struct net_if * iface ,
1338+ struct in6_addr * expected_addr ,
1339+ struct in6_addr * iid_addr )
1340+ {
1341+ const struct in6_addr prefix = { { { 0x20 , 0x01 , 0x1b , 0x98 , 0x24 , 0xb8 , 0x7e , 0xbb ,
1342+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } } };
1343+ struct net_linkaddr * lladdr = net_if_get_link_addr (iface );
1344+ uint8_t * mac ;
1345+ int ret ;
1346+
1347+ (void )net_iface_get_mac (net_if_get_device (iface ));
1348+
1349+ lladdr = net_if_get_link_addr (eth_iface );
1350+ mac = lladdr -> addr ;
1351+
1352+ memcpy (expected_addr , & prefix , sizeof (struct in6_addr ));
1353+ memcpy (& expected_addr -> s6_addr [8 ], & mac [0 ], 3 );
1354+ expected_addr -> s6_addr [11 ] = 0xff ;
1355+ expected_addr -> s6_addr [12 ] = 0xfe ;
1356+ memcpy (& expected_addr -> s6_addr [13 ], & mac [3 ], 3 );
1357+
1358+ expected_addr -> s6_addr [8 ] ^= 0x02 ; /* Universal bit toggle */
1359+
1360+ ret = net_ipv6_addr_generate_iid (iface , & prefix , NULL , 0 , 0 , iid_addr ,
1361+ net_if_get_link_addr (eth_iface ));
1362+ zassert_equal (ret , 0 , "Unexpected value (%d) returned" , ret );
1363+ }
1364+
1365+ ZTEST (net_iface , test_ipv6_iid_eui64 )
1366+ {
1367+ #if defined(CONFIG_NET_IPV6_IID_EUI_64 )
1368+ struct in6_addr iid_addr = { };
1369+ struct in6_addr expected_addr = { };
1370+
1371+ generate_iid (eth_iface , & expected_addr , & iid_addr );
1372+
1373+ zassert_mem_equal (& expected_addr , & iid_addr , sizeof (struct in6_addr ));
1374+ #else
1375+ ztest_test_skip ();
1376+ #endif
1377+ }
1378+
1379+ ZTEST (net_iface , test_ipv6_iid_stable )
1380+ {
1381+ #if defined(CONFIG_NET_IPV6_IID_STABLE )
1382+ struct in6_addr iid_addr = { };
1383+ struct in6_addr expected_addr = { };
1384+
1385+ generate_iid (eth_iface , & expected_addr , & iid_addr );
1386+
1387+ /* Make sure that EUI-64 bytes are not there */
1388+ zassert_not_equal (iid_addr .s6_addr [11 ], 0xff );
1389+ zassert_not_equal (iid_addr .s6_addr [12 ], 0xfe );
1390+
1391+ zassert_true (memcmp (& expected_addr , & iid_addr , sizeof (struct in6_addr )) != 0 ,
1392+ "IID is EUI-64 instead of randomized" );
1393+ #else
1394+ ztest_test_skip ();
1395+ #endif
1396+ }
1397+
13351398ZTEST_SUITE (net_iface , NULL , iface_setup , NULL , NULL , iface_teardown );
0 commit comments