]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_evpn_vty.c
bgpd: advertise VNI subnet
[mirror_frr.git] / bgpd / bgp_evpn_vty.c
index b463896c493345f2825bd40a734bc50bb8e18a14..932046f7e076739803ac6d4a4a1fdb9ada384a6c 100644 (file)
@@ -2271,6 +2271,32 @@ static void evpn_unset_advertise_default_gw(struct bgp *bgp,
        return;
 }
 
+/*
+ * evpn - enable advertisement of default g/w
+ */
+static void evpn_set_advertise_subnet(struct bgp *bgp,
+                                     struct bgpevpn *vpn)
+{
+       if (vpn->advertise_subnet)
+               return;
+
+       vpn->advertise_subnet = 1;
+       bgp_zebra_advertise_subnet(bgp, vpn->advertise_subnet, vpn->vni);
+}
+
+/*
+ * evpn - disable advertisement of default g/w
+ */
+static void evpn_unset_advertise_subnet(struct bgp *bgp,
+                                       struct bgpevpn *vpn)
+{
+       if (!vpn->advertise_subnet)
+               return;
+
+       vpn->advertise_subnet = 0;
+       bgp_zebra_advertise_subnet(bgp, vpn->advertise_subnet, vpn->vni);
+}
+
 /*
  * EVPN (VNI advertisement) enabled. Register with zebra.
  */
@@ -2330,6 +2356,9 @@ static void write_vni_config(struct vty *vty, struct bgpevpn *vpn)
                if (vpn->advertise_gw_macip)
                        vty_out(vty, "   advertise-default-gw\n");
 
+               if (vpn->advertise_subnet)
+                       vty_out(vty, "   advertise-subnet\n");
+
                vty_out(vty, "  exit-vni\n");
        }
 }
@@ -2440,6 +2469,56 @@ DEFUN (no_bgp_evpn_advertise_all_vni,
        return CMD_SUCCESS;
 }
 
+DEFUN (bgp_evpn_advertise_vni_subnet,
+       bgp_evpn_advertise_vni_subnet_cmd,
+       "advertise-subnet",
+       "Advertise the subnet corresponding to VNI\n")
+{
+       struct bgp *bgp_vrf = NULL;
+       struct bgp *bgp = VTY_GET_CONTEXT(bgp);
+       VTY_DECLVAR_CONTEXT_SUB(bgpevpn, vpn);
+
+       if (!bgp)
+               return CMD_WARNING;
+
+       if (!vpn)
+               return CMD_WARNING;
+
+       bgp_vrf = bgp_lookup_by_vrf_id(vpn->tenant_vrf_id);
+       if (!bgp_vrf)
+               return CMD_WARNING;
+
+       if (!(advertise_type5_routes(bgp_vrf, AFI_IP) ||
+             advertise_type5_routes(bgp_vrf, AFI_IP6))) {
+               vty_out(vty,
+                       "%%Please enable ip prefix advertisement under l2vpn evpn in %s",
+                       vrf_id_to_name(bgp_vrf->vrf_id));
+               return CMD_WARNING;
+       }
+
+       evpn_set_advertise_subnet(bgp, vpn);
+       return CMD_SUCCESS;
+}
+
+DEFUN (no_bgp_evpn_advertise_vni_subnet,
+       no_bgp_evpn_advertise_vni_subnet_cmd,
+       "no advertise-subnet",
+       NO_STR
+       "Advertise All local VNIs\n")
+{
+       struct bgp *bgp = VTY_GET_CONTEXT(bgp);
+       VTY_DECLVAR_CONTEXT_SUB(bgpevpn, vpn);
+
+       if (!bgp)
+               return CMD_WARNING;
+
+       if (!vpn)
+               return CMD_WARNING;
+
+       evpn_unset_advertise_subnet(bgp, vpn);
+       return CMD_SUCCESS;
+}
+
 DEFUN (bgp_evpn_advertise_type5,
        bgp_evpn_advertise_type5_cmd,
        "advertise " BGP_AFI_CMD_STR "" BGP_SAFI_CMD_STR,
@@ -4118,5 +4197,8 @@ void bgp_ethernetvpn_init(void)
                        &bgp_evpn_advertise_default_gw_vni_cmd);
        install_element(BGP_EVPN_VNI_NODE,
                        &no_bgp_evpn_advertise_default_gw_vni_cmd);
+       install_element(BGP_EVPN_VNI_NODE, &bgp_evpn_advertise_vni_subnet_cmd);
+       install_element(BGP_EVPN_VNI_NODE,
+                       &no_bgp_evpn_advertise_vni_subnet_cmd);
 #endif
 }