summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_vty.c
diff options
context:
space:
mode:
Diffstat (limited to 'bgpd/bgp_vty.c')
-rw-r--r--bgpd/bgp_vty.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 0347f49cb..7cd36ef53 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -46,6 +46,7 @@
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_aspath.h"
#include "bgpd/bgp_community.h"
+#include "bgpd/bgp_community_alias.h"
#include "bgpd/bgp_ecommunity.h"
#include "bgpd/bgp_lcommunity.h"
#include "bgpd/bgp_damp.h"
@@ -1497,6 +1498,62 @@ void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
}
+DEFPY(bgp_community_alias, bgp_community_alias_cmd,
+ "[no$no] bgp community alias WORD$community WORD$alias",
+ NO_STR BGP_STR
+ "Add community specific parameters\n"
+ "Create an alias for a community\n"
+ "Community (AA:BB or AA:BB:CC)\n"
+ "Alias name\n")
+{
+ struct community_alias ca1;
+ struct community_alias ca2;
+ struct community_alias *lookup_community;
+ struct community_alias *lookup_alias;
+
+ if (!community_str2com(community) && !lcommunity_str2com(community)) {
+ vty_out(vty, "Invalid community format\n");
+ return CMD_WARNING;
+ }
+
+ memset(&ca1, 0, sizeof(ca1));
+ memset(&ca2, 0, sizeof(ca2));
+ strlcpy(ca1.community, community, sizeof(ca1.community));
+ strlcpy(ca1.alias, alias, sizeof(ca1.alias));
+
+ lookup_community = bgp_ca_community_lookup(&ca1);
+ lookup_alias = bgp_ca_alias_lookup(&ca1);
+
+ if (no) {
+ bgp_ca_alias_delete(&ca1);
+ bgp_ca_community_delete(&ca1);
+ } else {
+ if (lookup_alias) {
+ /* Lookup if community hash table has an item
+ * with the same alias name.
+ */
+ strlcpy(ca2.community, lookup_alias->community,
+ sizeof(ca2.community));
+ if (bgp_ca_community_lookup(&ca2)) {
+ vty_out(vty,
+ "community (%s) already has this alias (%s)\n",
+ lookup_alias->community,
+ lookup_alias->alias);
+ return CMD_WARNING;
+ }
+ bgp_ca_alias_delete(&ca1);
+ }
+
+ if (lookup_community)
+ bgp_ca_community_delete(&ca1);
+
+ bgp_ca_alias_insert(&ca1);
+ bgp_ca_community_insert(&ca1);
+ }
+
+ return CMD_SUCCESS;
+}
+
DEFPY (bgp_global_suppress_fib_pending,
bgp_global_suppress_fib_pending_cmd,
"[no] bgp suppress-fib-pending",
@@ -19261,6 +19318,8 @@ void bgp_vty_init(void)
/* Community-list. */
community_list_vty();
+ community_alias_vty();
+
/* vpn-policy commands */
install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
@@ -20467,3 +20526,18 @@ static void community_list_vty(void)
install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
}
+
+static struct cmd_node community_alias_node = {
+ .name = "community alias",
+ .node = COMMUNITY_ALIAS_NODE,
+ .prompt = "",
+ .config_write = bgp_community_alias_write,
+};
+
+void community_alias_vty(void)
+{
+ install_node(&community_alias_node);
+
+ /* Community-list. */
+ install_element(CONFIG_NODE, &bgp_community_alias_cmd);
+}