Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions subsys/net/ip/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,30 @@ net_route_mcast_lookup(struct in6_addr *group)

return NULL;
}

struct net_route_entry_mcast *
net_route_mcast_lookup_by_iface(struct in6_addr *group, struct net_if *iface)
{
ARRAY_FOR_EACH_PTR(route_mcast_entries, route) {
if (!route->is_used) {
continue;
}

ARRAY_FOR_EACH(route->ifaces, i) {
if (route->ifaces[i] == NULL || route->ifaces[i] != iface) {
continue;
}

if (net_ipv6_is_prefix(group->s6_addr,
route->group.s6_addr,
route->prefix_len)) {
return route;
}
}
}

return NULL;
}
#endif /* CONFIG_NET_ROUTE_MCAST */

bool net_route_get_info(struct net_if *iface,
Expand Down
11 changes: 11 additions & 0 deletions subsys/net/ip/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,17 @@ bool net_route_mcast_del(struct net_route_entry_mcast *route);
struct net_route_entry_mcast *
net_route_mcast_lookup(struct in6_addr *group);

/**
* @brief Lookup a multicast routing entry on a given interface.
*
* @param group IPv6 multicast group address
* @param iface Network interface to check
*
* @return Routing entry corresponding to this multicast group and interface.
*/
struct net_route_entry_mcast *
net_route_mcast_lookup_by_iface(struct in6_addr *group, struct net_if *iface);

/**
* @brief Add an interface to multicast routing entry.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/net/route_mcast/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,23 @@ static void test_route_mcast_lookup(void)
zassert_equal_ptr(test_mcast_routes[3], route,
"mcast lookup failed");
}

static void test_route_mcast_lookup_by_iface(void)
{
struct net_route_entry_mcast *route =
net_route_mcast_lookup_by_iface(&mcast_prefix_admin, iface_1);

zassert_not_null(route, "mcast lookup by iface failed");

route = net_route_mcast_lookup_by_iface(&mcast_prefix_site_local, iface_2);

zassert_not_null(route, "mcast lookup by iface failed");

route = net_route_mcast_lookup_by_iface(&mcast_prefix_site_local, iface_1);

zassert_is_null(route, "mcast lookup by iface should not find a route on this interface");
}

static void test_route_mcast_route_del(void)
{
struct net_route_entry_mcast *route;
Expand Down Expand Up @@ -752,6 +769,7 @@ ZTEST(route_mcast_test_suite, test_route_mcast)
test_route_mcast_scenario3();
test_route_mcast_multiple_route_ifaces();
test_route_mcast_lookup();
test_route_mcast_lookup_by_iface();
test_route_mcast_route_del();
}
ZTEST_SUITE(route_mcast_test_suite, NULL, NULL, NULL, NULL, NULL);