bgpd: convert neighbor plist to transactional cli

- Move vtysh handler to DEFPY
- Convert neighbor prefix-list command to transactional cli.
- After nb conversion, remove not used apis.
- implement NB apis for ipv4 afi-safis

Signed-off-by: Chirag Shah <chirag@nvidia.com>
This commit is contained in:
Chirag Shah 2020-12-20 11:48:28 -08:00
parent f467218fd6
commit d9986d26c0
2 changed files with 169 additions and 120 deletions

View File

@ -15194,6 +15194,64 @@ int bgp_neighbors_neighbor_afi_safis_afi_safi_ipv4_unicast_filter_config_rmap_ex
return NB_OK;
}
static int bgp_neighbor_afi_safi_plist_modify(struct nb_cb_modify_args *args,
int direct)
{
struct bgp *bgp;
const char *peer_str;
struct peer *peer;
const struct lyd_node *nbr_dnode;
const struct lyd_node *nbr_af_dnode;
const char *af_name;
afi_t afi;
safi_t safi;
const char *name_str;
nbr_af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi");
af_name = yang_dnode_get_string(nbr_af_dnode, "./afi-safi-name");
yang_afi_safi_identity2value(af_name, &afi, &safi);
nbr_dnode = yang_dnode_get_parent(nbr_af_dnode, "neighbor");
bgp = nb_running_get_entry(nbr_dnode, NULL, true);
peer_str = yang_dnode_get_string(nbr_dnode, "./remote-address");
peer = bgp_neighbor_peer_lookup(bgp, peer_str, args->errmsg,
args->errmsg_len);
name_str = yang_dnode_get_string(args->dnode, NULL);
if (peer_prefix_list_set(peer, afi, safi, direct, name_str) < 0)
return NB_ERR_INCONSISTENCY;
return NB_OK;
}
static int bgp_neighbor_afi_safi_plist_destroy(struct nb_cb_destroy_args *args,
int direct)
{
struct bgp *bgp;
const char *peer_str;
struct peer *peer;
const struct lyd_node *nbr_dnode;
const struct lyd_node *nbr_af_dnode;
const char *af_name;
afi_t afi;
safi_t safi;
nbr_af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi");
af_name = yang_dnode_get_string(nbr_af_dnode, "./afi-safi-name");
yang_afi_safi_identity2value(af_name, &afi, &safi);
nbr_dnode = yang_dnode_get_parent(nbr_af_dnode, "neighbor");
bgp = nb_running_get_entry(nbr_dnode, NULL, true);
peer_str = yang_dnode_get_string(nbr_dnode, "./remote-address");
peer = bgp_neighbor_peer_lookup(bgp, peer_str, args->errmsg,
args->errmsg_len);
if (peer_prefix_list_unset(peer, afi, safi, direct) < 0)
return NB_ERR_INCONSISTENCY;
return NB_OK;
}
/*
* XPath:
* /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/neighbors/neighbor/afi-safis/afi-safi/ipv4-unicast/filter-config/plist-import
@ -15205,9 +15263,9 @@ int bgp_neighbors_neighbor_afi_safis_afi_safi_ipv4_unicast_filter_config_plist_i
case NB_EV_VALIDATE:
case NB_EV_PREPARE:
case NB_EV_ABORT:
case NB_EV_APPLY:
/* TODO: implement me. */
break;
case NB_EV_APPLY:
return bgp_neighbor_afi_safi_plist_modify(args, FILTER_IN);
}
return NB_OK;
@ -15220,9 +15278,9 @@ int bgp_neighbors_neighbor_afi_safis_afi_safi_ipv4_unicast_filter_config_plist_i
case NB_EV_VALIDATE:
case NB_EV_PREPARE:
case NB_EV_ABORT:
case NB_EV_APPLY:
/* TODO: implement me. */
break;
case NB_EV_APPLY:
return bgp_neighbor_afi_safi_plist_destroy(args, FILTER_IN);
}
return NB_OK;
@ -15239,9 +15297,9 @@ int bgp_neighbors_neighbor_afi_safis_afi_safi_ipv4_unicast_filter_config_plist_e
case NB_EV_VALIDATE:
case NB_EV_PREPARE:
case NB_EV_ABORT:
case NB_EV_APPLY:
/* TODO: implement me. */
break;
case NB_EV_APPLY:
return bgp_neighbor_afi_safi_plist_modify(args, FILTER_OUT);
}
return NB_OK;
@ -15254,9 +15312,9 @@ int bgp_neighbors_neighbor_afi_safis_afi_safi_ipv4_unicast_filter_config_plist_e
case NB_EV_VALIDATE:
case NB_EV_PREPARE:
case NB_EV_ABORT:
case NB_EV_APPLY:
/* TODO: implement me. */
break;
case NB_EV_APPLY:
return bgp_neighbor_afi_safi_plist_destroy(args, FILTER_OUT);
}
return NB_OK;
@ -23512,6 +23570,65 @@ int bgp_neighbors_unnumbered_neighbor_afi_safis_afi_safi_ipv4_unicast_filter_con
return NB_OK;
}
static int
bgp_unnumbered_neighbor_afi_safi_plist_modify(struct nb_cb_modify_args *args,
int direct)
{
struct bgp *bgp;
const char *peer_str;
struct peer *peer;
const struct lyd_node *nbr_dnode;
const struct lyd_node *nbr_af_dnode;
const char *af_name;
afi_t afi;
safi_t safi;
const char *name_str;
nbr_af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi");
af_name = yang_dnode_get_string(nbr_af_dnode, "./afi-safi-name");
yang_afi_safi_identity2value(af_name, &afi, &safi);
nbr_dnode = yang_dnode_get_parent(nbr_af_dnode, "unnumbered-neighbor");
bgp = nb_running_get_entry(nbr_dnode, NULL, true);
peer_str = yang_dnode_get_string(nbr_dnode, "./interface");
peer = bgp_unnumbered_neighbor_peer_lookup(bgp, peer_str, args->errmsg,
args->errmsg_len);
name_str = yang_dnode_get_string(args->dnode, NULL);
if (peer_prefix_list_set(peer, afi, safi, direct, name_str) < 0)
return NB_ERR_INCONSISTENCY;
return NB_OK;
}
static int
bgp_unnumbered_neighbor_afi_safi_plist_destroy(struct nb_cb_destroy_args *args,
int direct)
{
struct bgp *bgp;
const char *peer_str;
struct peer *peer;
const struct lyd_node *nbr_dnode;
const struct lyd_node *nbr_af_dnode;
const char *af_name;
afi_t afi;
safi_t safi;
nbr_af_dnode = yang_dnode_get_parent(args->dnode, "afi-safi");
af_name = yang_dnode_get_string(nbr_af_dnode, "./afi-safi-name");
yang_afi_safi_identity2value(af_name, &afi, &safi);
nbr_dnode = yang_dnode_get_parent(nbr_af_dnode, "unnumbered-neighbor");
bgp = nb_running_get_entry(nbr_dnode, NULL, true);
peer_str = yang_dnode_get_string(nbr_dnode, "./interface");
peer = bgp_unnumbered_neighbor_peer_lookup(bgp, peer_str, args->errmsg,
args->errmsg_len);
if (peer_prefix_list_unset(peer, afi, safi, direct) < 0)
return NB_ERR_INCONSISTENCY;
return NB_OK;
}
/*
* XPath:
* /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/neighbors/unnumbered-neighbor/afi-safis/afi-safi/ipv4-unicast/filter-config/plist-import
@ -23523,9 +23640,10 @@ int bgp_neighbors_unnumbered_neighbor_afi_safis_afi_safi_ipv4_unicast_filter_con
case NB_EV_VALIDATE:
case NB_EV_PREPARE:
case NB_EV_ABORT:
case NB_EV_APPLY:
/* TODO: implement me. */
break;
case NB_EV_APPLY:
return bgp_unnumbered_neighbor_afi_safi_plist_modify(args,
FILTER_IN);
}
return NB_OK;
@ -23538,9 +23656,10 @@ int bgp_neighbors_unnumbered_neighbor_afi_safis_afi_safi_ipv4_unicast_filter_con
case NB_EV_VALIDATE:
case NB_EV_PREPARE:
case NB_EV_ABORT:
case NB_EV_APPLY:
/* TODO: implement me. */
break;
case NB_EV_APPLY:
return bgp_unnumbered_neighbor_afi_safi_plist_destroy(
args, FILTER_IN);
}
return NB_OK;
@ -23557,9 +23676,10 @@ int bgp_neighbors_unnumbered_neighbor_afi_safis_afi_safi_ipv4_unicast_filter_con
case NB_EV_VALIDATE:
case NB_EV_PREPARE:
case NB_EV_ABORT:
case NB_EV_APPLY:
/* TODO: implement me. */
break;
case NB_EV_APPLY:
return bgp_unnumbered_neighbor_afi_safi_plist_modify(
args, FILTER_OUT);
}
return NB_OK;
@ -23572,9 +23692,10 @@ int bgp_neighbors_unnumbered_neighbor_afi_safis_afi_safi_ipv4_unicast_filter_con
case NB_EV_VALIDATE:
case NB_EV_PREPARE:
case NB_EV_ABORT:
case NB_EV_APPLY:
/* TODO: implement me. */
break;
case NB_EV_APPLY:
return bgp_unnumbered_neighbor_afi_safi_plist_destroy(
args, FILTER_OUT);
}
return NB_OK;

View File

@ -5528,7 +5528,6 @@ DEFUN_YANG (neighbor_nexthop_self,
afi_t afi = bgp_node_afi(vty);
safi_t safi = bgp_node_safi(vty);
snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
yang_afi_safi_value2identity(afi, safi));
@ -5567,7 +5566,6 @@ DEFUN_YANG(neighbor_nexthop_self_force,
afi_t afi = bgp_node_afi(vty);
safi_t safi = bgp_node_safi(vty);
snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
yang_afi_safi_value2identity(afi, safi));
@ -5652,7 +5650,6 @@ DEFUN_YANG (no_neighbor_nexthop_self_force,
afi_t afi = bgp_node_afi(vty);
safi_t safi = bgp_node_safi(vty);
snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
yang_afi_safi_value2identity(afi, safi));
@ -5810,7 +5807,6 @@ DEFUN_YANG (neighbor_remove_private_as_all,
afi_t afi = bgp_node_afi(vty);
safi_t safi = bgp_node_safi(vty);
snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
yang_afi_safi_value2identity(afi, safi));
@ -5850,7 +5846,6 @@ DEFUN_YANG (neighbor_remove_private_as_replace_as,
afi_t afi = bgp_node_afi(vty);
safi_t safi = bgp_node_safi(vty);
snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
yang_afi_safi_value2identity(afi, safi));
@ -5891,7 +5886,6 @@ DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
afi_t afi = bgp_node_afi(vty);
safi_t safi = bgp_node_safi(vty);
snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
yang_afi_safi_value2identity(afi, safi));
@ -5972,7 +5966,6 @@ DEFUN_YANG (no_neighbor_remove_private_as_all,
afi_t afi = bgp_node_afi(vty);
safi_t safi = bgp_node_safi(vty);
snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
yang_afi_safi_value2identity(afi, safi));
@ -6013,7 +6006,6 @@ DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
afi_t afi = bgp_node_afi(vty);
safi_t safi = bgp_node_safi(vty);
snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
yang_afi_safi_value2identity(afi, safi));
@ -6055,7 +6047,6 @@ DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
afi_t afi = bgp_node_afi(vty);
safi_t safi = bgp_node_safi(vty);
snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
yang_afi_safi_value2identity(afi, safi));
@ -6345,7 +6336,6 @@ DEFUN_YANG (neighbor_soft_reconfiguration,
afi_t afi = bgp_node_afi(vty);
safi_t safi = bgp_node_safi(vty);
snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
yang_afi_safi_value2identity(afi, safi));
@ -7732,69 +7722,44 @@ ALIAS_HIDDEN(
"Filter outgoing updates\n")
/* Set prefix list to the peer. */
static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
afi_t afi, safi_t safi,
const char *name_str,
const char *direct_str)
DEFPY_YANG(
neighbor_prefix_list, neighbor_prefix_list_cmd,
"[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str prefix-list WORD$prefix_str <in|out>$direction",
NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
"Filter updates to/from this neighbor\n"
"Name of a prefix list\n"
"Filter incoming updates\n"
"Filter outgoing updates\n")
{
int ret;
int direct = FILTER_IN;
struct peer *peer;
char base_xpath[XPATH_MAXLEN];
char af_xpath[XPATH_MAXLEN];
char plist_xpath[80];
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, "i", 1) == 0)
direct = FILTER_IN;
else if (strncmp(direct_str, "o", 1) == 0)
direct = FILTER_OUT;
if (strmatch(direction, "in"))
snprintf(plist_xpath, sizeof(plist_xpath),
"./%s/filter-config/plist-import",
bgp_afi_safi_get_container_str(afi, safi));
else if (strmatch(direction, "out"))
snprintf(plist_xpath, sizeof(plist_xpath),
"./%s/filter-config/plist-export",
bgp_afi_safi_get_container_str(afi, safi));
ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
if (!no)
nb_cli_enqueue_change(vty, plist_xpath, NB_OP_MODIFY,
prefix_str);
else
nb_cli_enqueue_change(vty, plist_xpath, NB_OP_DESTROY, NULL);
return bgp_vty_return(vty, ret);
}
static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
afi_t afi, safi_t safi,
const char *direct_str)
{
int ret;
struct peer *peer;
int direct = FILTER_IN;
peer = peer_and_group_lookup_vty(vty, ip_str);
if (!peer)
return CMD_WARNING_CONFIG_FAILED;
/* Check filter direction. */
if (strncmp(direct_str, "i", 1) == 0)
direct = FILTER_IN;
else if (strncmp(direct_str, "o", 1) == 0)
direct = FILTER_OUT;
ret = peer_prefix_list_unset(peer, afi, safi, direct);
return bgp_vty_return(vty, ret);
}
DEFUN (neighbor_prefix_list,
neighbor_prefix_list_cmd,
"neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
NEIGHBOR_STR
NEIGHBOR_ADDR_STR2
"Filter updates to/from this neighbor\n"
"Name of a prefix list\n"
"Filter incoming updates\n"
"Filter outgoing updates\n")
{
int idx_peer = 1;
int idx_word = 3;
int idx_in_out = 4;
return peer_prefix_list_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_prefix_list, neighbor_prefix_list_hidden_cmd,
@ -7805,32 +7770,6 @@ ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
"Filter incoming updates\n"
"Filter outgoing updates\n")
DEFUN (no_neighbor_prefix_list,
no_neighbor_prefix_list_cmd,
"no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
NO_STR
NEIGHBOR_STR
NEIGHBOR_ADDR_STR2
"Filter updates to/from this neighbor\n"
"Name of a prefix list\n"
"Filter incoming updates\n"
"Filter outgoing updates\n")
{
int idx_peer = 2;
int idx_in_out = 5;
return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
bgp_node_afi(vty), bgp_node_safi(vty),
argv[idx_in_out]->arg);
}
ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
"no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
"Filter updates to/from this neighbor\n"
"Name of a prefix list\n"
"Filter incoming updates\n"
"Filter outgoing updates\n")
static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
safi_t safi, const char *name_str,
const char *direct_str)
@ -18483,27 +18422,16 @@ void bgp_vty_init(void)
/* "neighbor prefix-list" commands. */
install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
/* "neighbor filter-list" commands. */
install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);