tests: net: iface: Test foreach multicast helper functions
Add test cases for IPv4/IPv6 foreach functions that iterate all multicast addresses assigned to an interface. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
This commit is contained in:
parent
d9d710e6d3
commit
408babb00f
|
@ -56,6 +56,7 @@ static struct in6_addr ll_addr = { { { 0xfe, 0x80, 0x43, 0xb8, 0, 0, 0, 0,
|
|||
0, 0, 0, 0xf2, 0xaa, 0x29, 0x02,
|
||||
0x04 } } };
|
||||
|
||||
static struct in_addr inaddr_mcast = { { { 224, 0, 0, 1 } } };
|
||||
static struct in6_addr in6addr_mcast;
|
||||
|
||||
static struct net_if *iface1;
|
||||
|
@ -439,6 +440,13 @@ static void *iface_setup(void)
|
|||
|
||||
ifaddr->addr_state = NET_ADDR_PREFERRED;
|
||||
|
||||
maddr = net_if_ipv4_maddr_add(iface1, &inaddr_mcast);
|
||||
if (!maddr) {
|
||||
DBG("Cannot add multicast IPv4 address %s\n",
|
||||
net_sprint_ipv4_addr(&inaddr_mcast));
|
||||
zassert_not_null(maddr, "mcast");
|
||||
}
|
||||
|
||||
net_ipv6_addr_create(&in6addr_mcast, 0xff02, 0, 0, 0, 0, 0, 0, 0x0001);
|
||||
|
||||
maddr = net_if_ipv6_maddr_add(iface1, &in6addr_mcast);
|
||||
|
@ -1174,6 +1182,34 @@ ZTEST(net_iface, test_ipv4_addr_foreach)
|
|||
zassert_equal(count, 0, "Incorrect number of callback calls");
|
||||
}
|
||||
|
||||
static void foreach_ipv4_maddr_check(struct net_if *iface,
|
||||
struct net_if_mcast_addr *if_addr,
|
||||
void *user_data)
|
||||
{
|
||||
int *count = (int *)user_data;
|
||||
|
||||
(*count)++;
|
||||
|
||||
zassert_equal_ptr(iface, iface1, "Callback called on wrong interface");
|
||||
zassert_mem_equal(&if_addr->address.in_addr, &inaddr_mcast,
|
||||
sizeof(struct in_addr), "Wrong IPv4 multicast address");
|
||||
}
|
||||
|
||||
ZTEST(net_iface, test_ipv4_maddr_foreach)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
/* iface1 has one IPv4 multicast address configured */
|
||||
net_if_ipv4_maddr_foreach(iface1, foreach_ipv4_maddr_check, &count);
|
||||
zassert_equal(count, 1, "Incorrect number of callback calls");
|
||||
|
||||
count = 0;
|
||||
|
||||
/* iface4 has no IPv4 multicast address configured */
|
||||
net_if_ipv4_maddr_foreach(iface4, foreach_ipv4_maddr_check, &count);
|
||||
zassert_equal(count, 0, "Incorrect number of callback calls");
|
||||
}
|
||||
|
||||
static void foreach_ipv6_addr_check(struct net_if *iface,
|
||||
struct net_if_addr *if_addr,
|
||||
void *user_data)
|
||||
|
@ -1208,6 +1244,34 @@ ZTEST(net_iface, test_ipv6_addr_foreach)
|
|||
zassert_equal(count, 0, "Incorrect number of callback calls");
|
||||
}
|
||||
|
||||
static void foreach_ipv6_maddr_check(struct net_if *iface,
|
||||
struct net_if_mcast_addr *if_addr,
|
||||
void *user_data)
|
||||
{
|
||||
int *count = (int *)user_data;
|
||||
|
||||
(*count)++;
|
||||
|
||||
zassert_equal_ptr(iface, iface1, "Callback called on wrong interface");
|
||||
zassert_mem_equal(&if_addr->address.in6_addr, &in6addr_mcast, sizeof(struct in6_addr),
|
||||
"Wrong IPv6 multicast address");
|
||||
}
|
||||
|
||||
ZTEST(net_iface, test_ipv6_maddr_foreach)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
/* iface1 has one IPv6 multicast address configured */
|
||||
net_if_ipv6_maddr_foreach(iface1, foreach_ipv6_maddr_check, &count);
|
||||
zassert_equal(count, 1, "Incorrect number of callback calls");
|
||||
|
||||
count = 0;
|
||||
|
||||
/* iface4 has no IPv6 multicast address configured */
|
||||
net_if_ipv6_maddr_foreach(iface4, foreach_ipv6_maddr_check, &count);
|
||||
zassert_equal(count, 0, "Incorrect number of callback calls");
|
||||
}
|
||||
|
||||
ZTEST(net_iface, test_interface_name)
|
||||
{
|
||||
int ret;
|
||||
|
|
Loading…
Reference in New Issue