]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: router bgp export leaked vpn routes
authorChirag Shah <chirag@cumulusnetworks.com>
Tue, 11 Jun 2019 00:19:26 +0000 (17:19 -0700)
committerChirag Shah <chirag@cumulusnetworks.com>
Mon, 17 Jun 2019 22:41:50 +0000 (15:41 -0700)
two bgp vrf instance has vrf route leak configured,
when a source vrf x is deleted, its leaked routes are cleaned
up from the destination and vpn table.

With this change when a source bgp instance is reconfigured,
export its routes back to destination vrfs where it is configured
as leak.

Ticket:CM-20534 CM-24484
Reviewed By:
Testing Done:

configure vrf leak between two vrf intances,
delete and readd source vrf and checked its routes
exported to vpn table and leaked vrfs table.

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
bgpd/bgp_mplsvpn.c
bgpd/bgp_mplsvpn.h
bgpd/bgp_vty.c

index e5408159289c1d2e11352b3de97925d80d3d8475..1156810510d3c744ba416bd3702032b22412df6a 100644 (file)
@@ -2598,3 +2598,75 @@ int bgp_vpn_leak_unimport(struct bgp *from_bgp, struct vty *vty)
        }
        return 0;
 }
+
+/* When a router bgp is configured, there could be a bgp vrf
+ * instance importing routes from this newly configured
+ * bgp vrf instance. Export routes from configured
+ * bgp vrf to VPN.
+ * VRF Y has import from bgp vrf x,
+ * when a bgp vrf x instance is created, export its routes
+ * to VRF Y instance.
+ */
+void bgp_vpn_leak_export(struct bgp *from_bgp)
+{
+       afi_t afi;
+       const char *export_name;
+       char *vname;
+       struct listnode *node, *next;
+       struct ecommunity *ecom;
+       vpn_policy_direction_t idir, edir;
+       safi_t safi = SAFI_UNICAST;
+       struct bgp *to_bgp;
+       int debug;
+
+       debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
+                    BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
+
+       idir = BGP_VPN_POLICY_DIR_FROMVPN;
+       edir = BGP_VPN_POLICY_DIR_TOVPN;
+
+       export_name = (from_bgp->name ? XSTRDUP(MTYPE_TMP, from_bgp->name)
+                              : XSTRDUP(MTYPE_TMP, VRF_DEFAULT_NAME));
+
+       for (afi = 0; afi < AFI_MAX; ++afi) {
+               /* vrf leak is for IPv4 and IPv6 Unicast only */
+               if (afi != AFI_IP && afi != AFI_IP6)
+                       continue;
+
+               for (ALL_LIST_ELEMENTS_RO(bm->bgp, next, to_bgp)) {
+                       if (from_bgp == to_bgp)
+                               continue;
+
+                       /* bgp instance has import list, check to see if newly
+                        * configured bgp instance is the list.
+                        */
+                       struct vpn_policy *to_vpolicy;
+
+                       to_vpolicy = &(to_bgp->vpn_policy[afi]);
+                       for (ALL_LIST_ELEMENTS_RO(to_vpolicy->import_vrf,
+                                                 node, vname)) {
+                               if (strcmp(vname, export_name) != 0)
+                                       continue;
+
+                               if (debug)
+                                       zlog_debug("%s: found from_bgp %s in to_bgp %s import list, import routes.",
+                                          __func__,
+                                          export_name, to_bgp->name_pretty);
+
+                               ecom = from_bgp->vpn_policy[afi].rtlist[edir];
+                               /* remove import rt, it will be readded
+                                * as part of import from vrf.
+                                */
+                               if (ecom)
+                                       ecommunity_del_val(
+                                               to_vpolicy->rtlist[idir],
+                                               (struct ecommunity_val *)
+                                                       ecom->val);
+                               vrf_import_from_vrf(to_bgp, from_bgp,
+                                                   afi, safi);
+                               break;
+
+                       }
+               }
+       }
+}
index 154eb2be065e47f590defe402d4a891af012f6f2..3234f7fc9db284559016a480c4a6a430200eea86 100644 (file)
@@ -267,5 +267,6 @@ extern void vpn_leak_postchange_all(void);
 extern void vpn_handle_router_id_update(struct bgp *bgp, bool withdraw,
                                        bool is_config);
 extern int bgp_vpn_leak_unimport(struct bgp *from_bgp, struct vty *vty);
+extern void bgp_vpn_leak_export(struct bgp *from_bgp);
 
 #endif /* _QUAGGA_BGP_MPLSVPN_H */
index 2e836fb40f51920dd39c870c5bfa91f7a35185b3..bde4b52af528b0074274607f2edb2e916d250e9a 100644 (file)
@@ -1003,6 +1003,8 @@ DEFUN_NOSH (router_bgp,
                if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
                        vpn_leak_postchange_all();
 
+               if (inst_type == BGP_INSTANCE_TYPE_VRF)
+                       bgp_vpn_leak_export(bgp);
                /* Pending: handle when user tries to change a view to vrf n vv.
                 */
        }