]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_vty.c
Merge pull request #12646 from pguibert6WIND/mpls_alloc_per_nh
[mirror_frr.git] / bgpd / bgp_vty.c
index 3b5721387b23759a8df49aa22e39a052b05ccf5b..1be44adde8034e4acc718463ec25eb45d36c0c56 100644 (file)
@@ -16,7 +16,7 @@
 #include "buffer.h"
 #include "linklist.h"
 #include "stream.h"
-#include "thread.h"
+#include "frrevent.h"
 #include "log.h"
 #include "memory.h"
 #include "lib_vty.h"
@@ -1675,28 +1675,46 @@ DEFUN (no_router_bgp,
                        for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
                                if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
                                        continue;
-                               if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
-                                              BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
-                                   CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
-                                              BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
-                                   CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
-                                              BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
-                                   CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
-                                              BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
-                                   CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
+                               if (CHECK_FLAG(
+                                           tmp_bgp->af_flags[AFI_IP]
+                                                            [SAFI_UNICAST],
+                                           BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
+                                   CHECK_FLAG(
+                                           tmp_bgp->af_flags[AFI_IP6]
+                                                            [SAFI_UNICAST],
+                                           BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
+                                   CHECK_FLAG(
+                                           tmp_bgp->af_flags[AFI_IP]
+                                                            [SAFI_UNICAST],
+                                           BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
+                                   CHECK_FLAG(
+                                           tmp_bgp->af_flags[AFI_IP6]
+                                                            [SAFI_UNICAST],
+                                           BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
+                                   CHECK_FLAG(tmp_bgp->af_flags[AFI_IP]
+                                                               [SAFI_UNICAST],
                                               BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
-                                   CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
+                                   CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6]
+                                                               [SAFI_UNICAST],
                                               BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
                                    (bgp == bgp_get_evpn() &&
-                                   (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
-                                               BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
-                                    CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
-                                               BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
-                                    CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
-                                               BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
-                                    CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
-                                               BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
-                                   (hashcount(tmp_bgp->vnihash))) {
+                                    (CHECK_FLAG(
+                                             tmp_bgp->af_flags[AFI_L2VPN]
+                                                              [SAFI_EVPN],
+                                             BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
+                                     CHECK_FLAG(
+                                             tmp_bgp->af_flags[AFI_L2VPN]
+                                                              [SAFI_EVPN],
+                                             BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
+                                     CHECK_FLAG(
+                                             tmp_bgp->af_flags[AFI_L2VPN]
+                                                              [SAFI_EVPN],
+                                             BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
+                                     CHECK_FLAG(
+                                             tmp_bgp->af_flags[AFI_L2VPN]
+                                                              [SAFI_EVPN],
+                                             BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
+                                   (tmp_bgp->l3vni)) {
                                        vty_out(vty,
                                                "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
                                        return CMD_WARNING_CONFIG_FAILED;
@@ -2194,7 +2212,7 @@ DEFUN (no_bgp_maxmed_onstartup,
 
        /* Cancel max-med onstartup if its on */
        if (bgp->t_maxmed_onstartup) {
-               THREAD_OFF(bgp->t_maxmed_onstartup);
+               EVENT_OFF(bgp->t_maxmed_onstartup);
                bgp->maxmed_onstartup_over = 1;
        }
 
@@ -2802,6 +2820,31 @@ DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
        return CMD_SUCCESS;
 }
 
+DEFPY(bgp_lu_uses_explicit_null, bgp_lu_uses_explicit_null_cmd,
+      "[no] bgp labeled-unicast <explicit-null|ipv4-explicit-null|ipv6-explicit-null>$value",
+      NO_STR BGP_STR
+      "BGP Labeled-unicast options\n"
+      "Use explicit-null label values for all local prefixes\n"
+      "Use the IPv4 explicit-null label value for IPv4 local prefixes\n"
+      "Use the IPv6 explicit-null label value for IPv6 local prefixes\n")
+{
+       VTY_DECLVAR_CONTEXT(bgp, bgp);
+       uint64_t label_mode;
+
+       if (strmatch(value, "ipv4-explicit-null"))
+               label_mode = BGP_FLAG_LU_IPV4_EXPLICIT_NULL;
+       else if (strmatch(value, "ipv6-explicit-null"))
+               label_mode = BGP_FLAG_LU_IPV6_EXPLICIT_NULL;
+       else
+               label_mode = BGP_FLAG_LU_IPV4_EXPLICIT_NULL |
+                            BGP_FLAG_LU_IPV6_EXPLICIT_NULL;
+       if (no)
+               UNSET_FLAG(bgp->flags, label_mode);
+       else
+               SET_FLAG(bgp->flags, label_mode);
+       return CMD_SUCCESS;
+}
+
 DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
       "bgp suppress-duplicates",
       BGP_STR
@@ -7518,9 +7561,9 @@ DEFUN (bgp_set_route_map_delay_timer,
                 * fired.
                 */
                if (!rmap_delay_timer && bm->t_rmap_update) {
-                       THREAD_OFF(bm->t_rmap_update);
-                       thread_execute(bm->master, bgp_route_map_update_timer,
-                                      NULL, 0);
+                       EVENT_OFF(bm->t_rmap_update);
+                       event_execute(bm->master, bgp_route_map_update_timer,
+                                     NULL, 0);
                }
                return CMD_SUCCESS;
        } else {
@@ -9306,9 +9349,24 @@ DEFPY (af_sid_vpn_export,
                return CMD_WARNING_CONFIG_FAILED;
 
        if (!yes) {
-               /* implement me */
-               vty_out(vty, "It's not implemented\n");
-               return CMD_WARNING_CONFIG_FAILED;
+               /* when SID is not set, do nothing */
+               if ((bgp->vpn_policy[afi].tovpn_sid_index == 0) &&
+                   !CHECK_FLAG(bgp->vpn_policy[afi].flags,
+                               BGP_VPN_POLICY_TOVPN_SID_AUTO))
+                       return CMD_SUCCESS;
+
+               /* pre-change */
+               vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
+                                  bgp_get_default(), bgp);
+               bgp->vpn_policy[afi].tovpn_sid_index = 0;
+               UNSET_FLAG(bgp->vpn_policy[afi].flags,
+                          BGP_VPN_POLICY_TOVPN_SID_AUTO);
+
+               /* post-change */
+               vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
+                                   bgp_get_default(), bgp);
+
+               return CMD_SUCCESS;
        }
 
        if (bgp->tovpn_sid_index != 0 ||
@@ -9347,7 +9405,7 @@ DEFPY (af_sid_vpn_export,
                        zlog_debug("%s: auto sid alloc.", __func__);
                SET_FLAG(bgp->vpn_policy[afi].flags,
                         BGP_VPN_POLICY_TOVPN_SID_AUTO);
-       } else {
+       } else if (sid_idx != 0) {
                /* SID allocation index-mode */
                if (debug)
                        zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
@@ -11093,10 +11151,10 @@ static char *bgp_peer_description_stripped(char *desc, uint32_t size)
 {
        static char stripped[BUFSIZ];
        uint32_t i = 0;
-       uint32_t last_space = 0;
+       uint32_t last_space = size;
 
        while (i < size) {
-               if (*(desc + i) == 0) {
+               if (*(desc + i) == '\0') {
                        stripped[i] = '\0';
                        return stripped;
                }
@@ -11106,10 +11164,7 @@ static char *bgp_peer_description_stripped(char *desc, uint32_t size)
                i++;
        }
 
-       if (last_space > size)
-               stripped[size + 1] = '\0';
-       else
-               stripped[last_space] = '\0';
+       stripped[last_space] = '\0';
 
        return stripped;
 }
@@ -12387,7 +12442,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
                        if (peer->t_gr_stale != NULL) {
                                json_object_int_add(json_timer,
                                                    "stalePathTimerRemaining",
-                                                   thread_timer_remain_second(
+                                                   event_timer_remain_second(
                                                            peer->t_gr_stale));
                        }
 
@@ -12408,7 +12463,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
                                json_object_int_add(
                                        json_timer,
                                        "selectionDeferralTimerRemaining",
-                                       thread_timer_remain_second(
+                                       event_timer_remain_second(
                                                peer->bgp->gr_info[afi][safi]
                                                        .t_select_deferral));
                        }
@@ -12421,7 +12476,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
                        if (peer->t_gr_stale != NULL)
                                vty_out(vty,
                                        "      Stale Path Remaining(sec): %ld\n",
-                                       thread_timer_remain_second(
+                                       event_timer_remain_second(
                                                peer->t_gr_stale));
                        /* Display Configured Selection
                         * Deferral only when when
@@ -12436,7 +12491,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
                            NULL)
                                vty_out(vty,
                                        "        Selection Deferral Time Remaining(sec): %ld\n",
-                                       thread_timer_remain_second(
+                                       event_timer_remain_second(
                                                peer->bgp->gr_info[afi][safi]
                                                        .t_select_deferral));
                }
@@ -12470,7 +12525,7 @@ static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
                if (p->t_gr_restart != NULL)
                        json_object_int_add(
                                json_timer, "restartTimerRemaining",
-                               thread_timer_remain_second(p->t_gr_restart));
+                               event_timer_remain_second(p->t_gr_restart));
 
                json_object_object_add(json, "timers", json_timer);
        } else {
@@ -12483,10 +12538,10 @@ static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
                        p->v_gr_restart);
                if (p->t_gr_restart != NULL)
                        vty_out(vty, "      Restart Time Remaining(sec): %ld\n",
-                               thread_timer_remain_second(p->t_gr_restart));
+                               event_timer_remain_second(p->t_gr_restart));
                if (p->t_gr_restart != NULL) {
                        vty_out(vty, "      Restart Time Remaining(sec): %ld\n",
-                               thread_timer_remain_second(p->t_gr_restart));
+                               event_timer_remain_second(p->t_gr_restart));
                }
        }
 }
@@ -13517,11 +13572,11 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
                        json_neigh,
                        "bgpTimerConfiguredConditionalAdvertisementsSec",
                        bgp->condition_check_period);
-               if (thread_is_scheduled(bgp->t_condition_check))
+               if (event_is_scheduled(bgp->t_condition_check))
                        json_object_int_add(
                                json_neigh,
                                "bgpTimerUntilConditionalAdvertisementsSec",
-                               thread_timer_remain_second(
+                               event_timer_remain_second(
                                        bgp->t_condition_check));
        } else {
                /* Administrative shutdown. */
@@ -13598,10 +13653,10 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
                vty_out(vty,
                        "  Configured conditional advertisements interval is %d seconds\n",
                        bgp->condition_check_period);
-               if (thread_is_scheduled(bgp->t_condition_check))
+               if (event_is_scheduled(bgp->t_condition_check))
                        vty_out(vty,
                                "  Time until conditional advertisements begin is %lu seconds\n",
-                               thread_timer_remain_second(
+                               event_timer_remain_second(
                                        bgp->t_condition_check));
        }
        /* Capability. */
@@ -14538,13 +14593,13 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
                if (p->t_gr_restart)
                        json_object_int_add(
                                json_grace, "gracefulRestartTimerMsecs",
-                               thread_timer_remain_second(p->t_gr_restart) *
+                               event_timer_remain_second(p->t_gr_restart) *
                                        1000);
 
                if (p->t_gr_stale)
                        json_object_int_add(
                                json_grace, "gracefulStalepathTimerMsecs",
-                               thread_timer_remain_second(p->t_gr_stale) *
+                               event_timer_remain_second(p->t_gr_stale) *
                                        1000);
                /* more gr info in new format */
                BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
@@ -14585,12 +14640,12 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
                if (p->t_gr_restart)
                        vty_out(vty,
                                "    The remaining time of restart timer is %ld\n",
-                               thread_timer_remain_second(p->t_gr_restart));
+                               event_timer_remain_second(p->t_gr_restart));
 
                if (p->t_gr_stale)
                        vty_out(vty,
                                "    The remaining time of stalepath timer is %ld\n",
-                               thread_timer_remain_second(p->t_gr_stale));
+                               event_timer_remain_second(p->t_gr_stale));
 
                /* more gr info in new format */
                BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
@@ -14824,14 +14879,15 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
                                        json_neigh, "reducePrefixNumFrom");
                                json_object_int_add(json_neigh,
                                                    "restartInTimerMsec",
-                                                   thread_timer_remain_second(
-                                                           p->t_pmax_restart)
-                                                           1000);
+                                                   event_timer_remain_second(
+                                                           p->t_pmax_restart) *
+                                                           1000);
                        } else
                                vty_out(vty,
                                        "  Reduce the no. of prefix from %s, will restart in %ld seconds\n",
-                                       p->host, thread_timer_remain_second(
-                                                        p->t_pmax_restart));
+                                       p->host,
+                                       event_timer_remain_second(
+                                               p->t_pmax_restart));
                } else {
                        if (use_json)
                                json_object_boolean_true_add(
@@ -14983,19 +15039,18 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
                if (p->t_start)
                        json_object_int_add(
                                json_neigh, "nextStartTimerDueInMsecs",
-                               thread_timer_remain_second(p->t_start) * 1000);
+                               event_timer_remain_second(p->t_start) * 1000);
                if (p->t_connect)
                        json_object_int_add(
                                json_neigh, "nextConnectTimerDueInMsecs",
-                               thread_timer_remain_second(p->t_connect)
-                                       * 1000);
+                               event_timer_remain_second(p->t_connect) * 1000);
                if (p->t_routeadv) {
                        json_object_int_add(json_neigh, "mraiInterval",
                                            p->v_routeadv);
                        json_object_int_add(
                                json_neigh, "mraiTimerExpireInMsecs",
-                               thread_timer_remain_second(p->t_routeadv)
-                                       1000);
+                               event_timer_remain_second(p->t_routeadv) *
+                                       1000);
                }
                if (p->password)
                        json_object_int_add(json_neigh, "authenticationEnabled",
@@ -15024,15 +15079,15 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
                }
                if (p->t_start)
                        vty_out(vty, "Next start timer due in %ld seconds\n",
-                               thread_timer_remain_second(p->t_start));
+                               event_timer_remain_second(p->t_start));
                if (p->t_connect)
                        vty_out(vty, "Next connect timer due in %ld seconds\n",
-                               thread_timer_remain_second(p->t_connect));
+                               event_timer_remain_second(p->t_connect));
                if (p->t_routeadv)
                        vty_out(vty,
                                "MRAI (interval %u) timer expires in %ld seconds\n",
                                p->v_routeadv,
-                               thread_timer_remain_second(p->t_routeadv));
+                               event_timer_remain_second(p->t_routeadv));
                if (p->password)
                        vty_out(vty, "Peer Authentication Enabled\n");
 
@@ -18283,6 +18338,18 @@ int bgp_config_write(struct vty *vty)
                                        ? ""
                                        : "no ");
 
+               if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_IPV4_EXPLICIT_NULL) &&
+                   !!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_IPV6_EXPLICIT_NULL))
+                       vty_out(vty, " bgp labeled-unicast explicit-null\n");
+               else if (!!CHECK_FLAG(bgp->flags,
+                                     BGP_FLAG_LU_IPV4_EXPLICIT_NULL))
+                       vty_out(vty,
+                               " bgp labeled-unicast ipv4-explicit-null\n");
+               else if (!!CHECK_FLAG(bgp->flags,
+                                     BGP_FLAG_LU_IPV6_EXPLICIT_NULL))
+                       vty_out(vty,
+                               " bgp labeled-unicast ipv6-explicit-null\n");
+
                /* draft-ietf-idr-deprecate-as-set-confed-set */
                if (bgp->reject_as_sets)
                        vty_out(vty, " bgp reject-as-sets\n");
@@ -18827,14 +18894,14 @@ static const struct cmd_variable_handler bgp_var_peergroup[] = {
 
 DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
 
-static struct thread *t_bgp_cfg;
+static struct event *t_bgp_cfg;
 
 bool bgp_config_inprocess(void)
 {
-       return thread_is_scheduled(t_bgp_cfg);
+       return event_is_scheduled(t_bgp_cfg);
 }
 
-static void bgp_config_finish(struct thread *t)
+static void bgp_config_finish(struct event *t)
 {
        struct listnode *node;
        struct bgp *bgp;
@@ -18846,9 +18913,9 @@ static void bgp_config_finish(struct thread *t)
 static void bgp_config_start(void)
 {
 #define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
-       THREAD_OFF(t_bgp_cfg);
-       thread_add_timer(bm->master, bgp_config_finish, NULL,
-                        BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
+       EVENT_OFF(t_bgp_cfg);
+       event_add_timer(bm->master, bgp_config_finish, NULL,
+                       BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
 }
 
 /* When we receive a hook the configuration is read,
@@ -18860,8 +18927,8 @@ static void bgp_config_end(void)
 {
 #define BGP_POST_CONFIG_DELAY_SECONDS 1
        uint32_t bgp_post_config_delay =
-               thread_is_scheduled(bm->t_rmap_update)
-                       ? thread_timer_remain_second(bm->t_rmap_update)
+               event_is_scheduled(bm->t_rmap_update)
+                       ? event_timer_remain_second(bm->t_rmap_update)
                        : BGP_POST_CONFIG_DELAY_SECONDS;
 
        /* If BGP config processing thread isn't running, then
@@ -18870,13 +18937,13 @@ static void bgp_config_end(void)
        if (!bgp_config_inprocess())
                return;
 
-       THREAD_OFF(t_bgp_cfg);
+       EVENT_OFF(t_bgp_cfg);
 
        /* Start a new timer to make sure we don't send EoR
         * before route-maps are processed.
         */
-       thread_add_timer(bm->master, bgp_config_finish, NULL,
-                        bgp_post_config_delay, &t_bgp_cfg);
+       event_add_timer(bm->master, bgp_config_finish, NULL,
+                       bgp_post_config_delay, &t_bgp_cfg);
 }
 
 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
@@ -19202,6 +19269,9 @@ void bgp_vty_init(void)
        install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
        install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
 
+       /* bgp labeled-unicast explicit-null */
+       install_element(BGP_NODE, &bgp_lu_uses_explicit_null_cmd);
+
        /* bgp suppress-duplicates */
        install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
        install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);