A default route 0.0.0.0/0 for the VPNv4 address family can be set via the
network command.

bgpd# configure terminal
bgpd(config)# router bgp 64603
bgpd(config-router)#  address-family vpnv4
bgpd(config-router-af)# network 0.0.0.0/0 rd 64600:111 tag 200
bgpd(config-router-af)# no network 0.0.0.0/0 rd 64600:111 tag 200

This default route is not installed within RIB, the command only trigs
the send of UPDATE message containing it to peers. The nexthop attribute
is set to ip address of the bgp router itself.

Signed-off-by: Julien Courtat <julien.cour...@6wind.com>
---
 bgpd/bgp_route.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index cd96815..37b6552 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -4497,6 +4497,7 @@ bgp_static_set_safi (safi_t safi, struct vty *vty, const 
char *ip_str,
   struct bgp_vrf *vrf;
   uint32_t labels[BGP_MAX_LABELS];
   size_t nlabels;
+  struct prefix def_route;
 
   bgp = vty->index;
 
@@ -4521,6 +4522,47 @@ bgp_static_set_safi (safi_t safi, struct vty *vty, const 
char *ip_str,
       return CMD_WARNING;
     }
 
+  str2prefix ("0.0.0.0/0", &def_route);
+
+  /* if we try to install a default route, set flag accordingly */
+  if (0 == prefix_cmp(&def_route, &p) && (safi == SAFI_MPLS_VPN))
+    {
+      struct bgp_vrf *v;
+      struct listnode *iter;
+      int ret = CMD_WARNING;
+
+      /* list all peers that have VPNv4 family enabled */
+      vrf = bgp_vrf_lookup(bgp, &prd);
+      if (!vrf)
+        {
+          vty_out (vty, "%% Unknown rd %s %s", rd_str, VTY_NEWLINE);
+          return ret;
+        }
+
+      /* Lookup in list of configured VRF with Route Distinguisher given as 
parameter */
+      v = (struct bgp_vrf*) listnode_lookup(bgp->vrfs, vrf);
+      if (v)
+        {
+          /* We should find peer list linked to this RD */
+          for (iter = listhead(bgp->peer); iter; iter = listnextnode(iter))
+            {
+              struct peer *peer;
+
+              /* Retrieve peer and set DEFAULT_ORIGINATE flag */
+              peer = listgetdata(iter);
+              /* Only send UPDATE messages to VPNv4 and EVPN peers */
+              if (peer && peer->status == Established && 
peer->afc_nego[AFI_IP][safi])
+                {
+                  SET_FLAG (peer->af_flags[AFI_IP][safi], 
PEER_FLAG_DEFAULT_ORIGINATE);
+                  peer_default_originate_set_rd (peer, &vrf->outbound_rd, 
AFI_IP,
+                                                 NULL, nlabels, labels);
+                  ret = CMD_SUCCESS;
+                }
+            }
+        }
+      return ret;
+    }
+
   prn = bgp_node_get (bgp->route[AFI_IP][safi],
                        (struct prefix *)&prd);
   if (prn->info == NULL)
@@ -4584,6 +4626,7 @@ bgp_static_unset_safi(safi_t safi, struct vty *vty, const 
char *ip_str,
   struct bgp_static *bgp_static;
   uint32_t labels[BGP_MAX_LABELS];
   size_t nlabels;
+  struct prefix def_route;
 
   bgp = vty->index;
 
@@ -4609,6 +4652,45 @@ bgp_static_unset_safi(safi_t safi, struct vty *vty, 
const char *ip_str,
       return CMD_WARNING;
     }
 
+  str2prefix ("0.0.0.0/0", &def_route);
+
+  /* if we try to withdraw a default route, unset flag accordingly */
+  if (0 == prefix_cmp(&def_route, &p) && (safi == SAFI_MPLS_VPN))
+    {
+      int ret = CMD_WARNING;
+      struct bgp_vrf *vrf, *v;
+      struct listnode *iter;
+
+      /* list all peers that have VPNv4 family enabled */
+      vrf = bgp_vrf_lookup(bgp, &prd);
+      if (!vrf)
+        {
+          vty_out (vty, "%% Unknown rd %s %s", rd_str, VTY_NEWLINE);
+          return ret;
+        }
+
+      /* Lookup in list of configured VRF with Route Distinguisher given as 
parameter */
+      v = (struct bgp_vrf*) listnode_lookup(bgp->vrfs, vrf);
+      if (v)
+        {
+          /* We should find peer list linked to this RD */
+          for (iter = listhead(bgp->peer); iter; iter = listnextnode(iter))
+            {
+              struct peer *peer;
+
+              /* Retrieve peer and set DEFAULT_ORIGINATE flag */
+              peer = listgetdata(iter);
+              /* Only send UPDATE messages to VPNv4 and EVPN peers */
+              if (peer && peer->status == Established && 
peer->afc_nego[AFI_IP][safi])
+                {
+                  peer_default_originate_unset_rd (peer, AFI_IP, 
&vrf->outbound_rd);
+                  ret = CMD_SUCCESS;
+                }
+            }
+        }
+      return ret;
+    }
+
   prn = bgp_node_get (bgp->route[AFI_IP][safi],
                        (struct prefix *)&prd);
   if (prn->info == NULL)
-- 
2.1.4


_______________________________________________
Quagga-dev mailing list
Quagga-dev@lists.quagga.net
https://lists.quagga.net/mailman/listinfo/quagga-dev

Reply via email to