@@ -158,9 +158,9 @@ bool IntfsOrch::setIntf(const string& alias, sai_object_id_t vrf_id, const IpPre
158158 addSubnetRoute (port, *ip_prefix);
159159 addIp2MeRoute (vrf_id, *ip_prefix);
160160
161- if (port.m_type == Port::VLAN && ip_prefix-> isV4 () )
161+ if (port.m_type == Port::VLAN)
162162 {
163- addDirectedBroadcast (port, ip_prefix-> getBroadcastIp () );
163+ addDirectedBroadcast (port, * ip_prefix);
164164 }
165165
166166 m_syncdIntfses[alias].ip_addresses .insert (*ip_prefix);
@@ -344,9 +344,10 @@ void IntfsOrch::doTask(Consumer &consumer)
344344 {
345345 removeSubnetRoute (port, ip_prefix);
346346 removeIp2MeRoute (vrf_id, ip_prefix);
347- if (port.m_type == Port::VLAN && ip_prefix.isV4 ())
347+
348+ if (port.m_type == Port::VLAN)
348349 {
349- removeDirectedBroadcast (port, ip_prefix. getBroadcastIp () );
350+ removeDirectedBroadcast (port, ip_prefix);
350351 }
351352
352353 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
623624 }
624625}
625626
626- void IntfsOrch::addDirectedBroadcast (const Port &port, const IpAddress &ip_addr )
627+ void IntfsOrch::addDirectedBroadcast (const Port &port, const IpPrefix &ip_prefix )
627628{
628629 sai_status_t status;
629630 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+
630641 neighbor_entry.rif_id = port.m_rif_id ;
631642 neighbor_entry.switch_id = gSwitchId ;
632643 copy (neighbor_entry.ip_address , ip_addr);
@@ -646,10 +657,19 @@ void IntfsOrch::addDirectedBroadcast(const Port &port, const IpAddress &ip_addr)
646657 SWSS_LOG_NOTICE (" Add broadcast route for ip:%s" , ip_addr.to_string ().c_str ());
647658}
648659
649- void IntfsOrch::removeDirectedBroadcast (const Port &port, const IpAddress &ip_addr )
660+ void IntfsOrch::removeDirectedBroadcast (const Port &port, const IpPrefix &ip_prefix )
650661{
651662 sai_status_t status;
652663 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+
653673 neighbor_entry.rif_id = port.m_rif_id ;
654674 neighbor_entry.switch_id = gSwitchId ;
655675 copy (neighbor_entry.ip_address , ip_addr);
0 commit comments