Skip to content

Commit 902fdd8

Browse files
author
Mika Tervonen
committed
create multicast forward check for PBBR
1 parent 420c5be commit 902fdd8

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

source/6LoWPAN/Thread/thread_bbr_api.c

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,34 @@ static int thread_border_relay_to_leader_cb(int8_t service_id, uint8_t source_ad
517517
}
518518

519519
#ifdef HAVE_THREAD_BORDER_ROUTER
520+
static bool thread_bbr_default_route_exists(struct protocol_interface_info_entry *cur, uint8_t prefix_ptr[8])
521+
{
522+
uint16_t rloc16 = mac_helper_mac16_address_get(cur);
523+
ns_list_foreach(thread_network_data_prefix_cache_entry_t, prefix, &cur->thread_info->networkDataStorage.localPrefixList) {
524+
525+
if (prefix_ptr &&
526+
(prefix->servicesPrefixLen != 64 ||
527+
memcmp(prefix_ptr, prefix->servicesPrefix, 8) != 0)) {
528+
// Only matching prefixes are counted
529+
continue;
530+
}
531+
532+
ns_list_foreach(thread_network_server_data_entry_t, br, &prefix->borderRouterList) {
533+
if (br->routerID == 0xfffe) {
534+
continue;
535+
}
536+
if (!br->P_default_route) {
537+
continue;
538+
}
539+
if (rloc16 != br->routerID) {
540+
// different default route exists
541+
return true;
542+
}
543+
}
544+
}
545+
return false;
546+
}
547+
520548
static bool thread_bbr_i_host_prefix(struct protocol_interface_info_entry *cur, uint8_t prefix_ptr[8], uint8_t *br_count, bool *i_am_lowest)
521549
{
522550
bool i_host_this_prefix = false;
@@ -600,14 +628,15 @@ static void thread_bbr_network_data_send(thread_bbr_t *this, uint8_t prefix[8],
600628
this->br_info_published = true;
601629
}
602630

603-
static void thread_bbr_routing_enable(thread_bbr_t *this)
631+
static void thread_bbr_routing_enable(thread_bbr_t *this, bool multicast_routing_enabled)
604632
{
605633
if (this->routing_enabled) {
606634
return;
607635
}
608636
tr_info("br: enable routing");
609637
// Start multicast proxying
610-
multicast_fwd_set_forwarding(this->interface_id, true);
638+
// We do not enable multicast forwarding as there is other default router present in network
639+
multicast_fwd_set_forwarding(this->interface_id, multicast_routing_enabled);
611640
this->routing_enabled = true;
612641
}
613642

@@ -663,7 +692,13 @@ static void thread_bbr_status_check(thread_bbr_t *this, uint32_t seconds)
663692

664693
// Check from network data are we currently BR or not and change routing state
665694
if (this->br_hosted) {
666-
thread_bbr_routing_enable(this);
695+
696+
//If there is a default router present in any prefix other than us we do not forward multicast
697+
//This prevents multicasts to different interfaces where Thread Mesh is forwarder
698+
bool forward_multicast = !thread_bbr_default_route_exists(cur, NULL);
699+
thread_extension_bbr_mcast_fwd_check(cur->id, &forward_multicast);
700+
701+
thread_bbr_routing_enable(this, forward_multicast);
667702
} else {
668703
thread_bbr_routing_disable(this);
669704
}

source/6LoWPAN/Thread/thread_extension_bbr.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,4 +1526,26 @@ void thread_extension_bbr_status_override_set(uint8_t dua_status, uint8_t dua_co
15261526
ba_response_status_count = ba_failure_count;
15271527
}
15281528

1529+
void thread_extension_bbr_mcast_fwd_check(int8_t interface_id, bool *multicast_fwd)
1530+
{
1531+
thread_pbbr_t *this = thread_bbr_find_by_interface(interface_id);
1532+
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(this->interface_id);
1533+
1534+
if (!cur || !this || multicast_fwd) {
1535+
return;
1536+
}
1537+
1538+
if (this->pbbr_started) {
1539+
//We are Primary BBR so we always forward multicast
1540+
*multicast_fwd = true;
1541+
return;
1542+
}
1543+
if (0 == thread_extension_primary_bbr_get(cur, NULL, NULL, NULL, NULL)) {
1544+
// We are secondary BBR we newer forward
1545+
*multicast_fwd = false;
1546+
return;
1547+
}
1548+
// No modification made
1549+
}
1550+
15291551
#endif //HAVE_THREAD_BORDER_ROUTER && HAVE_THREAD_V2

source/6LoWPAN/Thread/thread_extension_bbr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void thread_extension_bbr_old_partition_data_clean(int8_t interface_id);
6060
void thread_extension_bbr_status_override_get(uint8_t *dua_status, uint8_t *dua_count, uint8_t *ba_failure_count);
6161
void thread_extension_bbr_status_override_set(uint8_t dua_status, uint8_t dua_count, uint8_t ba_failure_count);
6262
void thread_extension_status_override_count_set(uint8_t value);
63+
void thread_extension_bbr_mcast_fwd_check(int8_t interface_id, bool *multicast_fwd);
6364

6465

6566
#else
@@ -77,6 +78,7 @@ void thread_extension_status_override_count_set(uint8_t value);
7778
#define thread_extension_bbr_status_override_get(dua_status, dua_count, ba_failure_count);
7879
#define thread_extension_bbr_status_override_set(dua_status, dua_count, ba_failure_count);
7980
#define thread_extension_status_override_count_set(value)
81+
#define thread_extension_bbr_mcast_fwd_check(interface_id, multicast_fwd)
8082
#endif
8183

8284
#ifdef __cplusplus

0 commit comments

Comments
 (0)