]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Keep extcommunity bandwidth commands persistent in route-maps
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Tue, 3 Aug 2021 08:02:49 +0000 (11:02 +0300)
committermergify-bot <noreply@mergify.io>
Mon, 16 Aug 2021 09:27:00 +0000 (09:27 +0000)
~/frr# vtysh -c 'conf' -c 'route-map testas permit 10' -c 'set extcommunity bandwidth 321'
~/frr# vtysh -c 'show route-map testas' | grep 321
    extcommunity bandwidth 321 non-transitive
~/frr# vtysh -c 'sh run' | grep 321
~/frr#

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
(cherry picked from commit 71bdae66b2c105302f7af9fc0c1deb657e2418d9)

bgpd/bgp_ecommunity.h
bgpd/bgp_routemap_nb_config.c
lib/routemap.h
lib/routemap_cli.c

index 03b23fcd37405e6d10d02474cc5b14fbe54aab20..a9dc2aeaa1f5a3c15e7880d0842dbb992d5fe845 100644 (file)
@@ -151,6 +151,12 @@ struct ecommunity_val_ipv6 {
        char val[IPV6_ECOMMUNITY_SIZE];
 };
 
+enum ecommunity_lb_type {
+       EXPLICIT_BANDWIDTH,
+       CUMULATIVE_BANDWIDTH,
+       COMPUTED_BANDWIDTH
+};
+
 #define ecom_length_size(X, Y)    ((X)->size * (Y))
 
 /*
index ff08c16a829231dfab0ec75201c1a3317253c6ec..1b58dcb53427ce9f1bd26091c838d666adf69b89 100644 (file)
@@ -25,6 +25,7 @@
 #include "lib/routemap.h"
 #include "bgpd/bgpd.h"
 #include "bgpd/bgp_routemap_nb.h"
+#include "bgpd/bgp_ecommunity.h"
 
 /* Add bgp route map rule. */
 static int bgp_route_match_add(struct route_map_index *index,
@@ -2536,12 +2537,6 @@ lib_route_map_entry_set_action_rmap_set_action_comm_list_name_destroy(
        return NB_OK;
 }
 
-enum e_community_lb_type {
-       EXPLICIT_BANDWIDTH,
-       CUMULATIVE_BANDWIDTH,
-       COMPUTED_BANDWIDTH
-};
-
 /*
  * XPath:
  * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-lb
@@ -2551,7 +2546,7 @@ lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_finish(
        struct nb_cb_apply_finish_args *args)
 {
        struct routemap_hook_context *rhc;
-       int lb_type;
+       enum ecommunity_lb_type lb_type;
        char str[VTY_BUFSIZ];
        uint16_t bandwidth;
 
index 5b6b64eaebba560c8f0f84204e17922424a1c995..97a62c8ace657cc448c76f132f0ba3c943e71756 100644 (file)
@@ -348,6 +348,8 @@ DECLARE_QOBJ_TYPE(route_map);
        (strmatch(A, "frr-bgp-route-map:set-extcommunity-rt"))
 #define IS_SET_EXTCOMMUNITY_SOO(A)                                             \
        (strmatch(A, "frr-bgp-route-map:set-extcommunity-soo"))
+#define IS_SET_EXTCOMMUNITY_LB(A)                                              \
+       (strmatch(A, "frr-bgp-route-map:set-extcommunity-lb"))
 #define IS_SET_AGGREGATOR(A)                                                   \
        (strmatch(A, "frr-bgp-route-map:aggregator"))
 #define IS_SET_AS_PREPEND(A)                                                   \
index e11b9eea7416cc5d8d45ad55e34220fb35fa88ca..7c788a4e7901f6d708254426cdd5bd8c5367bc39 100644 (file)
@@ -25,6 +25,7 @@
 #include "lib/command.h"
 #include "lib/northbound_cli.h"
 #include "lib/routemap.h"
+#include "bgpd/bgp_ecommunity.h"
 
 #ifndef VTYSH_EXTRACT_PL
 #include "lib/routemap_cli_clippy.c"
@@ -1189,6 +1190,34 @@ void route_map_action_show(struct vty *vty, struct lyd_node *dnode,
                        yang_dnode_get_string(
                                dnode,
                                "./rmap-set-action/frr-bgp-route-map:extcommunity-soo"));
+       } else if (IS_SET_EXTCOMMUNITY_LB(action)) {
+               enum ecommunity_lb_type lb_type;
+               char str[VTY_BUFSIZ];
+               uint16_t bandwidth;
+
+               lb_type = yang_dnode_get_enum(
+                       dnode,
+                       "./rmap-set-action/frr-bgp-route-map:extcommunity-lb/lb-type");
+               switch (lb_type) {
+               case EXPLICIT_BANDWIDTH:
+                       bandwidth = yang_dnode_get_uint16(
+                               dnode,
+                               "./rmap-set-action/frr-bgp-route-map:extcommunity-lb/bandwidth");
+                       snprintf(str, sizeof(str), "%d", bandwidth);
+                       break;
+               case CUMULATIVE_BANDWIDTH:
+                       snprintf(str, sizeof(str), "%s", "cumulative");
+                       break;
+               case COMPUTED_BANDWIDTH:
+                       snprintf(str, sizeof(str), "%s", "num-multipaths");
+               }
+
+               if (yang_dnode_get_bool(
+                           dnode,
+                           "./rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific"))
+                       strlcat(str, " non-transitive", sizeof(str));
+
+               vty_out(vty, " set extcommunity bandwidth %s\n", str);
        } else if (IS_SET_AGGREGATOR(action)) {
                vty_out(vty, " set aggregator as %s %s\n",
                        yang_dnode_get_string(