@@ -158,9 +158,9 @@ bool IntfsOrch::setIntf(const string& alias, sai_object_id_t vrf_id, const IpPre
158
158
addSubnetRoute (port, *ip_prefix);
159
159
addIp2MeRoute (vrf_id, *ip_prefix);
160
160
161
- if (port.m_type == Port::VLAN && ip_prefix-> isV4 () )
161
+ if (port.m_type == Port::VLAN)
162
162
{
163
- addDirectedBroadcast (port, ip_prefix-> getBroadcastIp () );
163
+ addDirectedBroadcast (port, * ip_prefix);
164
164
}
165
165
166
166
m_syncdIntfses[alias].ip_addresses .insert (*ip_prefix);
@@ -344,9 +344,10 @@ void IntfsOrch::doTask(Consumer &consumer)
344
344
{
345
345
removeSubnetRoute (port, ip_prefix);
346
346
removeIp2MeRoute (vrf_id, ip_prefix);
347
- if (port.m_type == Port::VLAN && ip_prefix.isV4 ())
347
+
348
+ if (port.m_type == Port::VLAN)
348
349
{
349
- removeDirectedBroadcast (port, ip_prefix. getBroadcastIp () );
350
+ removeDirectedBroadcast (port, ip_prefix);
350
351
}
351
352
352
353
m_syncdIntfses[alias].ip_addresses .erase (ip_prefix);
@@ -623,10 +624,20 @@ void IntfsOrch::removeIp2MeRoute(sai_object_id_t vrf_id, const IpPrefix &ip_pref
623
624
}
624
625
}
625
626
626
- void IntfsOrch::addDirectedBroadcast (const Port &port, const IpAddress &ip_addr )
627
+ void IntfsOrch::addDirectedBroadcast (const Port &port, const IpPrefix &ip_prefix )
627
628
{
628
629
sai_status_t status;
629
630
sai_neighbor_entry_t neighbor_entry;
631
+ IpAddress ip_addr;
632
+
633
+ /* If not IPv4 subnet or if /31 or /32 subnet, there is no broadcast address, hence don't
634
+ * add a broadcast route. */
635
+ if (!(ip_prefix.isV4 ()) || (ip_prefix.getMaskLength () > 30 ))
636
+ {
637
+ return ;
638
+ }
639
+ ip_addr = ip_prefix.getBroadcastIp ();
640
+
630
641
neighbor_entry.rif_id = port.m_rif_id ;
631
642
neighbor_entry.switch_id = gSwitchId ;
632
643
copy (neighbor_entry.ip_address , ip_addr);
@@ -646,10 +657,19 @@ void IntfsOrch::addDirectedBroadcast(const Port &port, const IpAddress &ip_addr)
646
657
SWSS_LOG_NOTICE (" Add broadcast route for ip:%s" , ip_addr.to_string ().c_str ());
647
658
}
648
659
649
- void IntfsOrch::removeDirectedBroadcast (const Port &port, const IpAddress &ip_addr )
660
+ void IntfsOrch::removeDirectedBroadcast (const Port &port, const IpPrefix &ip_prefix )
650
661
{
651
662
sai_status_t status;
652
663
sai_neighbor_entry_t neighbor_entry;
664
+ IpAddress ip_addr;
665
+
666
+ /* If not IPv4 subnet or if /31 or /32 subnet, there is no broadcast address */
667
+ if (!(ip_prefix.isV4 ()) || (ip_prefix.getMaskLength () > 30 ))
668
+ {
669
+ return ;
670
+ }
671
+ ip_addr = ip_prefix.getBroadcastIp ();
672
+
653
673
neighbor_entry.rif_id = port.m_rif_id ;
654
674
neighbor_entry.switch_id = gSwitchId ;
655
675
copy (neighbor_entry.ip_address , ip_addr);
0 commit comments