summaryrefslogtreecommitdiff
path: root/lib/plist.c
diff options
context:
space:
mode:
authorRafael Zalamena <rzalamena@opensourcerouting.org>2019-11-11 20:25:20 -0300
committerRafael Zalamena <rzalamena@opensourcerouting.org>2020-06-05 14:36:52 -0300
commit89b7c834a54ac9bacf0b97e4daa1f3ff85beee63 (patch)
tree844919c428c21cc80b66f23152ea5c18e490d6a8 /lib/plist.c
parente0caeadd486a3062fb94a4e6a96e9671bcf7d53c (diff)
lib: migrate prefix-list to use northbound
Implement all northbound CLI commands for prefix lists. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'lib/plist.c')
-rw-r--r--lib/plist.c516
1 files changed, 0 insertions, 516 deletions
diff --git a/lib/plist.c b/lib/plist.c
index 0addb6fde0..98e02a5f1a 100644
--- a/lib/plist.c
+++ b/lib/plist.c
@@ -832,280 +832,6 @@ prefix_entry_dup_check(struct prefix_list *plist, struct prefix_list_entry *new)
return NULL;
}
-static int vty_invalid_prefix_range(struct vty *vty, const char *prefix)
-{
- vty_out(vty,
- "%% Invalid prefix range for %s, make sure: len < ge-value <= le-value\n",
- prefix);
- return CMD_WARNING_CONFIG_FAILED;
-}
-
-static int vty_prefix_list_install(struct vty *vty, afi_t afi, const char *name,
- const char *seq, const char *typestr,
- const char *prefix, const char *ge,
- const char *le)
-{
- int ret;
- enum prefix_list_type type;
- struct prefix_list *plist;
- struct prefix_list_entry *pentry;
- struct prefix_list_entry *dup;
- struct prefix p, p_tmp;
- bool any = false;
- int64_t seqnum = -1;
- int lenum = 0;
- int genum = 0;
-
- if (name == NULL || prefix == NULL || typestr == NULL) {
- vty_out(vty, "%% Missing prefix or type\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- /* Sequential number. */
- if (seq)
- seqnum = (int64_t)atol(seq);
-
- /* ge and le number */
- if (ge)
- genum = atoi(ge);
- if (le)
- lenum = atoi(le);
-
- /* Check filter type. */
- if (strncmp("permit", typestr, 1) == 0)
- type = PREFIX_PERMIT;
- else if (strncmp("deny", typestr, 1) == 0)
- type = PREFIX_DENY;
- else {
- vty_out(vty, "%% prefix type must be permit or deny\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- /* "any" is special token for matching any IPv4 addresses. */
- switch (afi) {
- case AFI_IP:
- if (strncmp("any", prefix, strlen(prefix)) == 0) {
- ret = str2prefix_ipv4("0.0.0.0/0",
- (struct prefix_ipv4 *)&p);
- genum = 0;
- lenum = IPV4_MAX_BITLEN;
- any = true;
- } else
- ret = str2prefix_ipv4(prefix, (struct prefix_ipv4 *)&p);
-
- if (ret <= 0) {
- vty_out(vty, "%% Malformed IPv4 prefix\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- /* make a copy to verify prefix matches mask length */
- prefix_copy(&p_tmp, &p);
- apply_mask_ipv4((struct prefix_ipv4 *)&p_tmp);
-
- break;
- case AFI_IP6:
- if (strncmp("any", prefix, strlen(prefix)) == 0) {
- ret = str2prefix_ipv6("::/0", (struct prefix_ipv6 *)&p);
- genum = 0;
- lenum = IPV6_MAX_BITLEN;
- any = true;
- } else
- ret = str2prefix_ipv6(prefix, (struct prefix_ipv6 *)&p);
-
- if (ret <= 0) {
- vty_out(vty, "%% Malformed IPv6 prefix\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- /* make a copy to verify prefix matches mask length */
- prefix_copy(&p_tmp, &p);
- apply_mask_ipv6((struct prefix_ipv6 *)&p_tmp);
-
- break;
- case AFI_L2VPN:
- default:
- vty_out(vty, "%% Unrecognized AFI (%d)\n", afi);
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- /* If prefix has bits not under the mask, adjust it to fit */
- if (!prefix_same(&p_tmp, &p)) {
- char buf[PREFIX2STR_BUFFER];
- char buf_tmp[PREFIX2STR_BUFFER];
- prefix2str(&p, buf, sizeof(buf));
- prefix2str(&p_tmp, buf_tmp, sizeof(buf_tmp));
- vty_out(vty,
- "%% Prefix-list %s prefix changed from %s to %s to match length\n",
- name, buf, buf_tmp);
- zlog_info(
- "Prefix-list %s prefix changed from %s to %s to match length",
- name, buf, buf_tmp);
- p = p_tmp;
- }
-
- /* ge and le check. */
- if (genum && (genum <= p.prefixlen))
- return vty_invalid_prefix_range(vty, prefix);
-
- if (lenum && (lenum < p.prefixlen))
- return vty_invalid_prefix_range(vty, prefix);
-
- if (lenum && (genum > lenum))
- return vty_invalid_prefix_range(vty, prefix);
-
- if (genum && (lenum == (afi == AFI_IP ? 32 : 128)))
- lenum = 0;
-
- /* Get prefix_list with name. */
- plist = prefix_list_get(afi, 0, name);
-
- /* Make prefix entry. */
- pentry = prefix_list_entry_make(&p, type, seqnum, lenum, genum, any);
-
- /* Check same policy. */
- dup = prefix_entry_dup_check(plist, pentry);
-
- if (dup) {
- prefix_list_entry_free(pentry);
- return CMD_SUCCESS;
- }
-
- /* Install new filter to the access_list. */
- prefix_list_entry_add(plist, pentry);
-
- return CMD_SUCCESS;
-}
-
-static int vty_prefix_list_uninstall(struct vty *vty, afi_t afi,
- const char *name, const char *seq,
- const char *typestr, const char *prefix,
- const char *ge, const char *le)
-{
- int ret;
- enum prefix_list_type type;
- struct prefix_list *plist;
- struct prefix_list_entry *pentry;
- struct prefix p;
- int64_t seqnum = -1;
- int lenum = 0;
- int genum = 0;
-
- /* Check prefix list name. */
- plist = prefix_list_lookup(afi, name);
- if (!plist) {
- vty_out(vty, "%% Can't find specified prefix-list\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- /* Only prefix-list name specified, delete the entire prefix-list. */
- if (seq == NULL && typestr == NULL && prefix == NULL && ge == NULL
- && le == NULL) {
- prefix_list_delete(plist);
- return CMD_SUCCESS;
- }
-
- /* Check sequence number. */
- if (seq)
- seqnum = (int64_t)atol(seq);
-
- /* Sequence number specified, but nothing else. */
- if (seq && typestr == NULL && prefix == NULL && ge == NULL
- && le == NULL) {
- pentry = prefix_seq_check(plist, seqnum);
-
- if (pentry == NULL) {
- vty_out(vty,
- "%% Can't find prefix-list %s with sequence number %" PRIu64 "\n",
- name, seqnum);
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- prefix_list_entry_delete(plist, pentry, 1);
- return CMD_SUCCESS;
- }
-
- /* ge and le number */
- if (ge)
- genum = atoi(ge);
- if (le)
- lenum = atoi(le);
-
- /* We must have, at a minimum, both the type and prefix here */
- if ((typestr == NULL) || (prefix == NULL))
- return CMD_WARNING_CONFIG_FAILED;
-
- /* Check of filter type. */
- if (strncmp("permit", typestr, 1) == 0)
- type = PREFIX_PERMIT;
- else if (strncmp("deny", typestr, 1) == 0)
- type = PREFIX_DENY;
- else {
- vty_out(vty, "%% prefix type must be permit or deny\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- /* "any" is special token for matching any IPv4 addresses. */
- if (afi == AFI_IP) {
- if (strncmp("any", prefix, strlen(prefix)) == 0) {
- ret = str2prefix_ipv4("0.0.0.0/0",
- (struct prefix_ipv4 *)&p);
- genum = 0;
- lenum = IPV4_MAX_BITLEN;
- } else
- ret = str2prefix_ipv4(prefix, (struct prefix_ipv4 *)&p);
-
- if (ret <= 0) {
- vty_out(vty, "%% Malformed IPv4 prefix\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
- } else if (afi == AFI_IP6) {
- if (strncmp("any", prefix, strlen(prefix)) == 0) {
- ret = str2prefix_ipv6("::/0", (struct prefix_ipv6 *)&p);
- genum = 0;
- lenum = IPV6_MAX_BITLEN;
- } else
- ret = str2prefix_ipv6(prefix, (struct prefix_ipv6 *)&p);
-
- if (ret <= 0) {
- vty_out(vty, "%% Malformed IPv6 prefix\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
- }
-
- /* Lookup prefix entry. */
- pentry =
- prefix_list_entry_lookup(plist, &p, type, seqnum, lenum, genum);
-
- if (pentry == NULL) {
- vty_out(vty, "%% Can't find specified prefix-list\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- /* Install new filter to the access_list. */
- prefix_list_entry_delete(plist, pentry, 1);
-
- return CMD_SUCCESS;
-}
-
-static int vty_prefix_list_desc_unset(struct vty *vty, afi_t afi,
- const char *name)
-{
- struct prefix_list *plist;
-
- plist = prefix_list_lookup(afi, name);
- if (!plist) {
- vty_out(vty, "%% Can't find specified prefix-list\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- XFREE(MTYPE_TMP, plist->desc);
-
- if (plist->head == NULL && plist->tail == NULL && plist->desc == NULL)
- prefix_list_delete(plist);
-
- return CMD_SUCCESS;
-}
-
enum display_type {
normal_display,
summary_display,
@@ -1349,72 +1075,6 @@ static int vty_clear_prefix_list(struct vty *vty, afi_t afi, const char *name,
#include "lib/plist_clippy.c"
#endif
-DEFPY (ip_prefix_list,
- ip_prefix_list_cmd,
- "ip prefix-list WORD [seq (1-4294967295)] <deny|permit>$action <any$dest|A.B.C.D/M$dest [{ge (0-32)|le (0-32)}]>",
- IP_STR
- PREFIX_LIST_STR
- "Name of a prefix list\n"
- "sequence number of an entry\n"
- "Sequence number\n"
- "Specify packets to reject\n"
- "Specify packets to forward\n"
- "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n"
- "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
- "Minimum prefix length to be matched\n"
- "Minimum prefix length\n"
- "Maximum prefix length to be matched\n"
- "Maximum prefix length\n")
-{
- return vty_prefix_list_install(vty, AFI_IP, prefix_list, seq_str,
- action, dest, ge_str, le_str);
-}
-
-DEFPY (no_ip_prefix_list,
- no_ip_prefix_list_cmd,
- "no ip prefix-list WORD [seq (1-4294967295)] <deny|permit>$action <any$dest|A.B.C.D/M$dest [{ge (0-32)|le (0-32)}]>",
- NO_STR
- IP_STR
- PREFIX_LIST_STR
- "Name of a prefix list\n"
- "sequence number of an entry\n"
- "Sequence number\n"
- "Specify packets to reject\n"
- "Specify packets to forward\n"
- "Any prefix match. Same as \"0.0.0.0/0 le 32\"\n"
- "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
- "Minimum prefix length to be matched\n"
- "Minimum prefix length\n"
- "Maximum prefix length to be matched\n"
- "Maximum prefix length\n")
-{
- return vty_prefix_list_uninstall(vty, AFI_IP, prefix_list, seq_str,
- action, dest, ge_str, le_str);
-}
-
-DEFPY(no_ip_prefix_list_seq, no_ip_prefix_list_seq_cmd,
- "no ip prefix-list WORD seq (1-4294967295)",
- NO_STR IP_STR PREFIX_LIST_STR
- "Name of a prefix list\n"
- "sequence number of an entry\n"
- "Sequence number\n")
-{
- return vty_prefix_list_uninstall(vty, AFI_IP, prefix_list, seq_str,
- NULL, NULL, NULL, NULL);
-}
-
-DEFPY (no_ip_prefix_list_all,
- no_ip_prefix_list_all_cmd,
- "no ip prefix-list WORD",
- NO_STR
- IP_STR
- PREFIX_LIST_STR
- "Name of a prefix list\n")
-{
- return vty_prefix_list_uninstall(vty, AFI_IP, prefix_list, NULL, NULL,
- NULL, NULL, NULL);
-}
-
DEFPY (ip_prefix_list_sequence_number,
ip_prefix_list_sequence_number_cmd,
"[no] ip prefix-list sequence-number",
@@ -1427,56 +1087,6 @@ DEFPY (ip_prefix_list_sequence_number,
return CMD_SUCCESS;
}
-DEFUN (ip_prefix_list_description,
- ip_prefix_list_description_cmd,
- "ip prefix-list WORD description LINE...",
- IP_STR
- PREFIX_LIST_STR
- "Name of a prefix list\n"
- "Prefix-list specific description\n"
- "Up to 80 characters describing this prefix-list\n")
-{
- int idx_word = 2;
- int idx_line = 4;
- struct prefix_list *plist;
-
- plist = prefix_list_get(AFI_IP, 0, argv[idx_word]->arg);
-
- if (plist->desc) {
- XFREE(MTYPE_TMP, plist->desc);
- plist->desc = NULL;
- }
- plist->desc = argv_concat(argv, argc, idx_line);
-
- return CMD_SUCCESS;
-}
-
-DEFUN (no_ip_prefix_list_description,
- no_ip_prefix_list_description_cmd,
- "no ip prefix-list WORD description",
- NO_STR
- IP_STR
- PREFIX_LIST_STR
- "Name of a prefix list\n"
- "Prefix-list specific description\n")
-{
- int idx_word = 3;
- return vty_prefix_list_desc_unset(vty, AFI_IP, argv[idx_word]->arg);
-}
-
-/* ALIAS_FIXME */
-DEFUN (no_ip_prefix_list_description_comment,
- no_ip_prefix_list_description_comment_cmd,
- "no ip prefix-list WORD description LINE...",
- NO_STR
- IP_STR
- PREFIX_LIST_STR
- "Name of a prefix list\n"
- "Prefix-list specific description\n"
- "Up to 80 characters describing this prefix-list\n")
-{
- return no_ip_prefix_list_description(self, vty, argc, argv);
-}
DEFPY (show_ip_prefix_list,
show_ip_prefix_list_cmd,
@@ -1554,61 +1164,6 @@ DEFPY (clear_ip_prefix_list,
return vty_clear_prefix_list(vty, AFI_IP, prefix_list, prefix_str);
}
-DEFPY (ipv6_prefix_list,
- ipv6_prefix_list_cmd,
- "ipv6 prefix-list WORD [seq (1-4294967295)] <deny|permit>$action <any$dest|X:X::X:X/M$dest [{ge (0-128)|le (0-128)}]>",
- IPV6_STR
- PREFIX_LIST_STR
- "Name of a prefix list\n"
- "sequence number of an entry\n"
- "Sequence number\n"
- "Specify packets to reject\n"
- "Specify packets to forward\n"
- "Any prefix match. Same as \"::0/0 le 128\"\n"
- "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
- "Maximum prefix length to be matched\n"
- "Maximum prefix length\n"
- "Minimum prefix length to be matched\n"
- "Minimum prefix length\n")
-{
- return vty_prefix_list_install(vty, AFI_IP6, prefix_list, seq_str,
- action, dest, ge_str, le_str);
-}
-
-DEFPY (no_ipv6_prefix_list,
- no_ipv6_prefix_list_cmd,
- "no ipv6 prefix-list WORD [seq (1-4294967295)] <deny|permit>$action <any$dest|X:X::X:X/M$dest [{ge (0-128)|le (0-128)}]>",
- NO_STR
- IPV6_STR
- PREFIX_LIST_STR
- "Name of a prefix list\n"
- "sequence number of an entry\n"
- "Sequence number\n"
- "Specify packets to reject\n"
- "Specify packets to forward\n"
- "Any prefix match. Same as \"::0/0 le 128\"\n"
- "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
- "Maximum prefix length to be matched\n"
- "Maximum prefix length\n"
- "Minimum prefix length to be matched\n"
- "Minimum prefix length\n")
-{
- return vty_prefix_list_uninstall(vty, AFI_IP6, prefix_list, seq_str,
- action, dest, ge_str, le_str);
-}
-
-DEFPY (no_ipv6_prefix_list_all,
- no_ipv6_prefix_list_all_cmd,
- "no ipv6 prefix-list WORD",
- NO_STR
- IPV6_STR
- PREFIX_LIST_STR
- "Name of a prefix list\n")
-{
- return vty_prefix_list_uninstall(vty, AFI_IP6, prefix_list, NULL, NULL,
- NULL, NULL, NULL);
-}
-
DEFPY (ipv6_prefix_list_sequence_number,
ipv6_prefix_list_sequence_number_cmd,
"[no] ipv6 prefix-list sequence-number",
@@ -1621,58 +1176,6 @@ DEFPY (ipv6_prefix_list_sequence_number,
return CMD_SUCCESS;
}
-DEFUN (ipv6_prefix_list_description,
- ipv6_prefix_list_description_cmd,
- "ipv6 prefix-list WORD description LINE...",
- IPV6_STR
- PREFIX_LIST_STR
- "Name of a prefix list\n"
- "Prefix-list specific description\n"
- "Up to 80 characters describing this prefix-list\n")
-{
- int idx_word = 2;
- int iddx_line = 4;
- struct prefix_list *plist;
-
- plist = prefix_list_get(AFI_IP6, 0, argv[idx_word]->arg);
-
- if (plist->desc) {
- XFREE(MTYPE_TMP, plist->desc);
- plist->desc = NULL;
- }
- plist->desc = argv_concat(argv, argc, iddx_line);
-
- return CMD_SUCCESS;
-}
-
-DEFUN (no_ipv6_prefix_list_description,
- no_ipv6_prefix_list_description_cmd,
- "no ipv6 prefix-list WORD description",
- NO_STR
- IPV6_STR
- PREFIX_LIST_STR
- "Name of a prefix list\n"
- "Prefix-list specific description\n")
-{
- int idx_word = 3;
- return vty_prefix_list_desc_unset(vty, AFI_IP6, argv[idx_word]->arg);
-}
-
-/* ALIAS_FIXME */
-DEFUN (no_ipv6_prefix_list_description_comment,
- no_ipv6_prefix_list_description_comment_cmd,
- "no ipv6 prefix-list WORD description LINE...",
- NO_STR
- IPV6_STR
- PREFIX_LIST_STR
- "Name of a prefix list\n"
- "Prefix-list specific description\n"
- "Up to 80 characters describing this prefix-list\n")
-{
- return no_ipv6_prefix_list_description(self, vty, argc, argv);
-}
-
-
DEFPY (show_ipv6_prefix_list,
show_ipv6_prefix_list_cmd,
"show ipv6 prefix-list [WORD [seq$dseq (1-4294967295)$arg]]",
@@ -2090,16 +1593,6 @@ static void prefix_list_init_ipv4(void)
{
install_node(&prefix_node);
- install_element(CONFIG_NODE, &ip_prefix_list_cmd);
- install_element(CONFIG_NODE, &no_ip_prefix_list_cmd);
- install_element(CONFIG_NODE, &no_ip_prefix_list_seq_cmd);
- install_element(CONFIG_NODE, &no_ip_prefix_list_all_cmd);
-
- install_element(CONFIG_NODE, &ip_prefix_list_description_cmd);
- install_element(CONFIG_NODE, &no_ip_prefix_list_description_cmd);
- install_element(CONFIG_NODE,
- &no_ip_prefix_list_description_comment_cmd);
-
install_element(CONFIG_NODE, &ip_prefix_list_sequence_number_cmd);
install_element(VIEW_NODE, &show_ip_prefix_list_cmd);
@@ -2128,15 +1621,6 @@ static void prefix_list_init_ipv6(void)
{
install_node(&prefix_ipv6_node);
- install_element(CONFIG_NODE, &ipv6_prefix_list_cmd);
- install_element(CONFIG_NODE, &no_ipv6_prefix_list_cmd);
- install_element(CONFIG_NODE, &no_ipv6_prefix_list_all_cmd);
-
- install_element(CONFIG_NODE, &ipv6_prefix_list_description_cmd);
- install_element(CONFIG_NODE, &no_ipv6_prefix_list_description_cmd);
- install_element(CONFIG_NODE,
- &no_ipv6_prefix_list_description_comment_cmd);
-
install_element(CONFIG_NODE, &ipv6_prefix_list_sequence_number_cmd);
install_element(VIEW_NODE, &show_ipv6_prefix_list_cmd);