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>
@@ -60,7 +61,7 @@ K_MEM_SLAB_DEFINE_STATIC(border_router_messages_slab, sizeof(struct otbr_msg_ctx
6061 CONFIG_OPENTHREAD_ZEPHYR_BORDER_ROUTER_MSG_POOL_NUM , sizeof (void * ));
6162
6263static const char * create_base_name (otInstance * ot_instance , char * base_name );
63- static void openthread_border_router_add_route_to_multicast_groups ( void );
64+ static void openthread_border_router_add_or_rm_route_to_multicast_groups ( bool add );
6465#if defined(CONFIG_OPENTHREAD_NAT64_TRANSLATOR )
6566static void openthread_border_router_start_nat64_service (void );
6667static void openthread_border_router_stop_nat64_service (void );
@@ -83,7 +84,7 @@ int openthread_start_border_router_services(struct net_if *ot_iface, struct net_
8384 net_if_flag_set (ot_iface , NET_IF_FORWARD_MULTICASTS );
8485 net_if_flag_set (ail_iface , NET_IF_FORWARD_MULTICASTS );
8586
86- openthread_border_router_add_route_to_multicast_groups ( );
87+ openthread_border_router_add_or_rm_route_to_multicast_groups (true );
8788
8889 openthread_mutex_lock ();
8990
@@ -136,6 +137,9 @@ int openthread_start_border_router_services(struct net_if *ot_iface, struct net_
136137 error = - EIO ;
137138 goto exit ;
138139 }
140+ if (!otBorderAgentIsEnabled (instance )) {
141+ otBorderAgentSetEnabled (instance , true);
142+ }
139143 if (otPlatInfraIfStateChanged (instance , ail_iface_index , true) != OT_ERROR_NONE ) {
140144 error = - EIO ;
141145 goto exit ;
@@ -187,11 +191,14 @@ static int openthread_stop_border_router_services(struct net_if *ot_iface,
187191 }
188192 otBackboneRouterSetEnabled (instance , false);
189193 border_agent_deinit ();
194+ (void )infra_if_deinit ();
190195 infra_if_stop_icmp6_listener ();
196+ otBorderAgentSetEnabled (instance , false);
191197 udp_plat_deinit ();
192198#if defined(CONFIG_OPENTHREAD_NAT64_TRANSLATOR )
193199 openthread_border_router_stop_nat64_service ();
194200#endif /* CONFIG_OPENTHREAD_NAT64_TRANSLATOR */
201+ openthread_border_router_add_or_rm_route_to_multicast_groups (false);
195202
196203 }
197204exit :
@@ -606,7 +613,7 @@ bool openthread_border_router_check_packet_forwarding_rules(struct net_pkt *pkt)
606613 return true;
607614}
608615
609- static void openthread_border_router_add_route_to_multicast_groups ( void )
616+ static void openthread_border_router_add_or_rm_route_to_multicast_groups ( bool add )
610617{
611618 static uint8_t mcast_group_idx [] = {
612619 0x04 , /** Admin-Local scope multicast address */
@@ -621,12 +628,29 @@ static void openthread_border_router_add_route_to_multicast_groups(void)
621628 ARRAY_FOR_EACH (mcast_group_idx , i ) {
622629
623630 net_ipv6_addr_create (& addr , (0xff << 8 ) | mcast_group_idx [i ], 0 , 0 , 0 , 0 , 0 , 0 , 0 );
624- entry = net_route_mcast_add (ail_iface_ptr , & addr , 16 );
625- if (entry != NULL ) {
626- mcast_addr = net_if_ipv6_maddr_add (ail_iface_ptr ,
627- (const struct net_in6_addr * )& addr );
631+ if (add ) {
632+ entry = net_route_mcast_add (ail_iface_ptr , & addr , 16 );
633+ if (entry != NULL ) {
634+ mcast_addr = net_if_ipv6_maddr_add (ail_iface_ptr ,
635+ (const struct in6_addr * )& addr );
636+ if (mcast_addr != NULL ) {
637+ net_if_ipv6_maddr_join (ail_iface_ptr , mcast_addr );
638+ }
639+ }
640+ } else {
641+ entry = net_route_mcast_lookup (& addr );
642+ mcast_addr = net_if_ipv6_maddr_lookup (& addr , & (ail_iface_ptr ));
643+ if (entry != NULL ) {
644+ net_route_mcast_del (entry );
645+ }
646+ /* There is no need to check if address is joined,
647+ * as `clear_joined_ipv6_mcast_groups` was previously
648+ * called
649+ */
628650 if (mcast_addr != NULL ) {
629- net_if_ipv6_maddr_join (ail_iface_ptr , mcast_addr );
651+ net_if_ipv6_maddr_leave (ail_iface_ptr , mcast_addr );
652+ net_if_ipv6_maddr_rm (ail_iface_ptr ,
653+ (const struct in6_addr * )& addr );
630654 }
631655 }
632656 }
0 commit comments