Skip to content

Commit 3a5c6c5

Browse files
jukkarnashif
authored andcommitted
tests: net: ipv6: Add tests for stable IIDs
Add tests that verify that stable IIDs generate a proper IPv6 interface identifier described in RFC 7217. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 94177a2 commit 3a5c6c5

File tree

2 files changed

+73
-5
lines changed

2 files changed

+73
-5
lines changed

tests/net/iface/src/main.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static struct net_if *iface1;
6363
static struct net_if *iface2;
6464
static struct net_if *iface3;
6565
static struct net_if *iface4;
66+
static struct net_if *eth_iface;
6667

6768
static bool test_failed;
6869
static 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+
13351398
ZTEST_SUITE(net_iface, NULL, iface_setup, NULL, NULL, iface_teardown);

tests/net/iface/testcase.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
common:
22
min_ram: 16
33
depends_on: netif
4+
tags:
5+
- net
6+
- iface
7+
- userspace
48
tests:
5-
net.iface:
6-
tags:
7-
- net
8-
- iface
9-
- userspace
9+
net.iface.iid.eui64:
10+
extra_configs:
11+
- CONFIG_NET_IPV6_IID_EUI_64=y
12+
net.iface.iid.stable:
13+
extra_configs:
14+
- CONFIG_NET_IPV6_IID_STABLE=y

0 commit comments

Comments
 (0)