@@ -140,10 +140,6 @@ void IntfsOrch::doTask(Consumer &consumer)
140
140
141
141
/* Creating intfRoutes associated to this interface being added */
142
142
createIntfRoutes (IntfRouteEntry (ip_prefix, alias), port);
143
- if (port.m_type == Port::VLAN && ip_prefix.isV4 ())
144
- {
145
- addDirectedBroadcast (port, ip_prefix.getBroadcastIp ());
146
- }
147
143
148
144
m_syncdIntfses[alias].ip_addresses .insert (ip_prefix);
149
145
it = consumer.m_toSync .erase (it);
@@ -179,11 +175,7 @@ void IntfsOrch::doTask(Consumer &consumer)
179
175
{
180
176
if (iter->second .ip_addresses .count (ip_prefix))
181
177
{
182
- if (port.m_type == Port::VLAN && ip_prefix.isV4 ())
183
- {
184
- removeDirectedBroadcast (port, ip_prefix.getBroadcastIp ());
185
- }
186
- iter->second .ip_addresses .erase (ip_prefix);
178
+ iter->second .ip_addresses .erase (ip_prefix);
187
179
}
188
180
189
181
/* Remove router interface if there's no ip-address left. */
@@ -566,6 +558,24 @@ void IntfsOrch::createIntfRoutes(const IntfRouteEntry &ifRoute,
566
558
}
567
559
}
568
560
}
561
+
562
+ /*
563
+ * A directed-broadcast route is expected in vlan-ipv4 scenarios. Proceed to
564
+ * push the route down if no overlap is detected.
565
+ */
566
+ if (port.m_type == Port::VLAN && ifRoute.prefix .isV4 ())
567
+ {
568
+ IntfRouteEntry ifBcastRoute (getBcastPrefix (ifRoute.prefix ),
569
+ ifRoute.ifName ,
570
+ " bcast" );
571
+
572
+ bool bcastOverlap = trackIntfRouteOverlap (ifBcastRoute);
573
+
574
+ if (!bcastOverlap)
575
+ {
576
+ addDirectedBroadcast (port, ifBcastRoute.prefix .getIp ());
577
+ }
578
+ }
569
579
}
570
580
571
581
/*
@@ -656,6 +666,16 @@ void IntfsOrch::deleteIntfRoutes(const IntfRouteEntry &ifRoute,
656
666
deleteIntfRoute (ifSubnetRoute, port);
657
667
}
658
668
deleteIntfRoute (ifIp2meRoute, port);
669
+
670
+ /* Also remove the directed-bcast route if applicable. */
671
+ if (port.m_type == Port::VLAN && ifRoute.prefix .isV4 ())
672
+ {
673
+ IntfRouteEntry ifBcastRoute (getBcastPrefix (ifRoute.prefix ),
674
+ ifRoute.ifName ,
675
+ " bcast" );
676
+
677
+ deleteIntfRoute (ifBcastRoute, port);
678
+ }
659
679
}
660
680
661
681
void IntfsOrch::deleteIntfRoute (const IntfRouteEntry &ifRoute, const Port &port)
@@ -706,6 +726,10 @@ void IntfsOrch::deleteIntfRoute(const IntfRouteEntry &ifRoute, const Port &port)
706
726
{
707
727
removeIp2MeRoute (ifRoute.prefix );
708
728
}
729
+ else if (it->type == " bcast" )
730
+ {
731
+ removeDirectedBroadcast (port, ifRoute.prefix .getIp ());
732
+ }
709
733
710
734
/*
711
735
* Notice that the resurrection-order is vital here. We must
@@ -774,10 +798,15 @@ void IntfsOrch::resurrectIntfRoute(const IntfRouteEntry &ifRoute)
774
798
{
775
799
addIp2MeRoute (ifRoute.prefix );
776
800
}
801
+ else if (ifRoute.type == " bcast" )
802
+ {
803
+ addDirectedBroadcast (port, ifRoute.prefix .getIp ());
804
+ }
777
805
}
778
806
779
807
/*
780
- * Perhaps to be moved to a more appropriate location (e.g. IpPrefix class).
808
+ * Helper functions. Perhaps to be moved to a more appropriate location (e.g.
809
+ * IpPrefix class).
781
810
*/
782
811
IpPrefix IntfsOrch::getIp2mePrefix (const IpPrefix &ip_prefix)
783
812
{
@@ -787,3 +816,12 @@ IpPrefix IntfsOrch::getIp2mePrefix(const IpPrefix &ip_prefix)
787
816
788
817
return (IpPrefix (newRoutePrefixStr));
789
818
}
819
+
820
+ IpPrefix IntfsOrch::getBcastPrefix (const IpPrefix &ip_prefix)
821
+ {
822
+ string newRoutePrefixStr = ip_prefix.isV4 () ?
823
+ ip_prefix.getBroadcastIp ().to_string () + " /32" :
824
+ ip_prefix.getBroadcastIp ().to_string () + " /128" ;
825
+
826
+ return (IpPrefix (newRoutePrefixStr));
827
+ }
0 commit comments