66
77#include "openthread_border_router.h"
88#include <openthread.h>
9+ #include <openthread/border_agent.h>
910#include <openthread/backbone_router_ftd.h>
1011#include <openthread/border_router.h>
1112#include <openthread/border_routing.h>
@@ -55,7 +56,7 @@ K_MEM_SLAB_DEFINE_STATIC(border_router_messages_slab, sizeof(struct otbr_msg_ctx
5556 CONFIG_OPENTHREAD_ZEPHYR_BORDER_ROUTER_MSG_POOL_NUM , sizeof (void * ));
5657
5758static const char * create_base_name (otInstance * ot_instance , char * base_name );
58- static void openthread_border_router_add_route_to_multicast_groups ( void );
59+ static void openthread_border_router_add_or_rm_route_to_multicast_groups ( bool add );
5960
6061#if defined(CONFIG_NET_IPV4 )
6162static void openthread_border_router_check_for_dhcpv4_addr (struct net_if * iface ,
@@ -74,7 +75,7 @@ int openthread_start_border_router_services(struct net_if *ot_iface, struct net_
7475 net_if_flag_set (ot_iface , NET_IF_FORWARD_MULTICASTS );
7576 net_if_flag_set (ail_iface , NET_IF_FORWARD_MULTICASTS );
7677
77- openthread_border_router_add_route_to_multicast_groups ( );
78+ openthread_border_router_add_or_rm_route_to_multicast_groups (true );
7879
7980 openthread_mutex_lock ();
8081
@@ -127,6 +128,9 @@ int openthread_start_border_router_services(struct net_if *ot_iface, struct net_
127128 error = - EIO ;
128129 goto exit ;
129130 }
131+ if (!otBorderAgentIsEnabled (instance )) {
132+ otBorderAgentSetEnabled (instance , true);
133+ }
130134 if (otPlatInfraIfStateChanged (instance , ail_iface_index , true) != OT_ERROR_NONE ) {
131135 error = - EIO ;
132136 goto exit ;
@@ -173,8 +177,11 @@ static int openthread_stop_border_router_services(struct net_if *ot_iface,
173177 }
174178 otBackboneRouterSetEnabled (instance , false);
175179 border_agent_deinit ();
180+ (void )infra_if_deinit ();
176181 infra_if_stop_icmp6_listener ();
182+ otBorderAgentSetEnabled (instance , false);
177183 udp_plat_deinit ();
184+ openthread_border_router_add_or_rm_route_to_multicast_groups (false);
178185
179186 }
180187exit :
@@ -586,7 +593,7 @@ bool openthread_border_router_check_packet_forwarding_rules(struct net_pkt *pkt)
586593 return true;
587594}
588595
589- static void openthread_border_router_add_route_to_multicast_groups ( void )
596+ static void openthread_border_router_add_or_rm_route_to_multicast_groups ( bool add )
590597{
591598 static uint8_t mcast_group_idx [] = {
592599 0x04 , /** Admin-Local scope multicast address */
@@ -601,12 +608,29 @@ static void openthread_border_router_add_route_to_multicast_groups(void)
601608 ARRAY_FOR_EACH (mcast_group_idx , i ) {
602609
603610 net_ipv6_addr_create (& addr , (0xff << 8 ) | mcast_group_idx [i ], 0 , 0 , 0 , 0 , 0 , 0 , 0 );
604- entry = net_route_mcast_add (ail_iface_ptr , & addr , 16 );
605- if (entry != NULL ) {
606- mcast_addr = net_if_ipv6_maddr_add (ail_iface_ptr ,
607- (const struct in6_addr * )& addr );
611+ if (add ) {
612+ entry = net_route_mcast_add (ail_iface_ptr , & addr , 16 );
613+ if (entry != NULL ) {
614+ mcast_addr = net_if_ipv6_maddr_add (ail_iface_ptr ,
615+ (const struct in6_addr * )& addr );
616+ if (mcast_addr != NULL ) {
617+ net_if_ipv6_maddr_join (ail_iface_ptr , mcast_addr );
618+ }
619+ }
620+ } else {
621+ entry = net_route_mcast_lookup (& addr );
622+ mcast_addr = net_if_ipv6_maddr_lookup (& addr , & (ail_iface_ptr ));
623+ if (entry != NULL ) {
624+ net_route_mcast_del (entry );
625+ }
626+ /* There is no need to check if address is joined,
627+ * as `clear_joined_ipv6_mcast_groups` was previously
628+ * called
629+ */
608630 if (mcast_addr != NULL ) {
609- net_if_ipv6_maddr_join (ail_iface_ptr , mcast_addr );
631+ net_if_ipv6_maddr_leave (ail_iface_ptr , mcast_addr );
632+ net_if_ipv6_maddr_rm (ail_iface_ptr ,
633+ (const struct in6_addr * )& addr );
610634 }
611635 }
612636 }
0 commit comments