summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_vty.c
diff options
context:
space:
mode:
authorChirag Shah <chirag@nvidia.com>2020-12-22 02:11:50 +0100
committerChirag Shah <chirag@nvidia.com>2021-01-10 08:06:02 +0100
commitc6685575336566680aeb537e8ed5abb164be0268 (patch)
tree4f44e32ad0e822efc6d9adb459e3992305634207 /bgpd/bgp_vty.c
parentyang: nbr plist nb conversion for more afi-safis (diff)
downloadfrr-c6685575336566680aeb537e8ed5abb164be0268.tar.xz
frr-c6685575336566680aeb537e8ed5abb164be0268.zip
bgpd: convert nbr rmap transactional cli
- Move vtysh handler to DEFPY - Convert neighbor route-map command to transactional cli. - After nb conversion, remove not used apis. - Implement NB callbacks for afi-safis Signed-off-by: Chirag Shah <chirag@nvidia.com>
Diffstat (limited to 'bgpd/bgp_vty.c')
-rw-r--r--bgpd/bgp_vty.c131
1 files changed, 42 insertions, 89 deletions
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 38b2abae9..450b9aab5 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -7733,7 +7733,7 @@ DEFPY_YANG(
{
char base_xpath[XPATH_MAXLEN];
char af_xpath[XPATH_MAXLEN];
- char plist_xpath[80];
+ char plist_xpath[XPATH_MAXLEN];
afi_t afi = bgp_node_afi(vty);
safi_t safi = bgp_node_safi(vty);
@@ -7930,70 +7930,52 @@ ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
"Name of the exist or non exist map\n")
/* Set route-map to the peer. */
-static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
- afi_t afi, safi_t safi, const char *name_str,
- const char *direct_str)
-{
- int ret;
- struct peer *peer;
- int direct = RMAP_IN;
- struct route_map *route_map;
-
- peer = peer_and_group_lookup_vty(vty, ip_str);
- if (!peer)
- return CMD_WARNING_CONFIG_FAILED;
-
- /* Check filter direction. */
- if (strncmp(direct_str, "in", 2) == 0)
- direct = RMAP_IN;
- else if (strncmp(direct_str, "o", 1) == 0)
- direct = RMAP_OUT;
-
- route_map = route_map_lookup_warn_noexist(vty, name_str);
- ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
-
- return bgp_vty_return(vty, ret);
-}
-
-static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
- afi_t afi, safi_t safi,
- const char *direct_str)
+DEFPY_YANG(
+ neighbor_route_map, neighbor_route_map_cmd,
+ "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str route-map WORD$rmap_str <in|out>$direction",
+ NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
+ "Apply route map to neighbor\n"
+ "Name of route map\n"
+ "Apply map to incoming routes\n"
+ "Apply map to outbound routes\n")
{
- int ret;
- struct peer *peer;
- int direct = RMAP_IN;
+ char base_xpath[XPATH_MAXLEN];
+ char af_xpath[XPATH_MAXLEN];
+ char rmap_xpath[XPATH_MAXLEN];
+ afi_t afi = bgp_node_afi(vty);
+ safi_t safi = bgp_node_safi(vty);
- peer = peer_and_group_lookup_vty(vty, ip_str);
- if (!peer)
+ snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
+ yang_afi_safi_value2identity(afi, safi));
+ if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
+ sizeof(base_xpath), af_xpath)
+ < 0)
return CMD_WARNING_CONFIG_FAILED;
- /* Check filter direction. */
- if (strncmp(direct_str, "in", 2) == 0)
- direct = RMAP_IN;
- else if (strncmp(direct_str, "o", 1) == 0)
- direct = RMAP_OUT;
-
- ret = peer_route_map_unset(peer, afi, safi, direct);
+ if (strmatch(direction, "in"))
+ snprintf(rmap_xpath, sizeof(rmap_xpath),
+ "./%s/filter-config/rmap-import",
+ bgp_afi_safi_get_container_str(afi, safi));
+ else if (strmatch(direction, "out"))
+ snprintf(rmap_xpath, sizeof(rmap_xpath),
+ "./%s/filter-config/rmap-export",
+ bgp_afi_safi_get_container_str(afi, safi));
- return bgp_vty_return(vty, ret);
-}
+ if (!no) {
+ if (!yang_dnode_exists(
+ vty->candidate_config->dnode,
+ "/frr-route-map:lib/route-map[name='%s']",
+ rmap_str)) {
+ if (vty_shell_serv(vty))
+ vty_out(vty,
+ "The route-map '%s' does not exist.\n",
+ rmap_str);
+ }
+ nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_MODIFY, rmap_str);
+ } else
+ nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_DESTROY, NULL);
-DEFUN (neighbor_route_map,
- neighbor_route_map_cmd,
- "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
- NEIGHBOR_STR
- NEIGHBOR_ADDR_STR2
- "Apply route map to neighbor\n"
- "Name of route map\n"
- "Apply map to incoming routes\n"
- "Apply map to outbound routes\n")
-{
- int idx_peer = 1;
- int idx_word = 3;
- int idx_in_out = 4;
- return peer_route_map_set_vty(
- vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
- argv[idx_word]->arg, argv[idx_in_out]->arg);
+ return nb_cli_apply_changes(vty, base_xpath);
}
ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
@@ -8004,25 +7986,7 @@ ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
"Apply map to incoming routes\n"
"Apply map to outbound routes\n")
-DEFUN (no_neighbor_route_map,
- no_neighbor_route_map_cmd,
- "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
- NO_STR
- NEIGHBOR_STR
- NEIGHBOR_ADDR_STR2
- "Apply route map to neighbor\n"
- "Name of route map\n"
- "Apply map to incoming routes\n"
- "Apply map to outbound routes\n")
-{
- int idx_peer = 2;
- int idx_in_out = 5;
- return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
- bgp_node_afi(vty), bgp_node_safi(vty),
- argv[idx_in_out]->arg);
-}
-
-ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
+ALIAS_HIDDEN(neighbor_route_map, no_neighbor_route_map_hidden_cmd,
"no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
"Apply route map to neighbor\n"
@@ -18461,27 +18425,16 @@ void bgp_vty_init(void)
install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
- install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
- install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
- install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
- install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
- install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
- install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
- install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
- install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
- install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
- install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
- install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
/* "neighbor unsuppress-map" commands. */
install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);