]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/plist.c
frr: Remove HAVE_IPV6 from code base
[mirror_frr.git] / lib / plist.c
index 0d1cafde66517dd8eaa0bdfdd899bc2dbf28d19f..279c85d6d6e416864b29dbdcd8cc713e966c9dfd 100644 (file)
@@ -103,7 +103,6 @@ static struct prefix_master prefix_master_ipv4 =
   PLC_MAXLEVELV4,
 };
 
-#ifdef HAVE_IPV6
 /* Static structure of IPv6 prefix-list's master. */
 static struct prefix_master prefix_master_ipv6 = 
 { 
@@ -115,7 +114,6 @@ static struct prefix_master prefix_master_ipv6 =
   NULL,
   PLC_MAXLEVELV6,
 };
-#endif /* HAVE_IPV6*/
 
 /* Static structure of BGP ORF prefix_list's master. */
 static struct prefix_master prefix_master_orf_v4 =
@@ -408,9 +406,7 @@ void
 prefix_list_add_hook (void (*func) (struct prefix_list *plist))
 {
   prefix_master_ipv4.add_hook = func;
-#ifdef HAVE_IPV6
   prefix_master_ipv6.add_hook = func;
-#endif /* HAVE_IPV6 */
 }
 
 /* Delete hook function. */
@@ -418,9 +414,7 @@ void
 prefix_list_delete_hook (void (*func) (struct prefix_list *plist))
 {
   prefix_master_ipv4.delete_hook = func;
-#ifdef HAVE_IPV6
   prefix_master_ipv6.delete_hook = func;
-#endif /* HAVE_IPVt6 */
 }
 
 /* Calculate new sequential number. */
@@ -899,7 +893,7 @@ vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name,
   struct prefix_list *plist;
   struct prefix_list_entry *pentry;
   struct prefix_list_entry *dup;
-  struct prefix p;
+  struct prefix p, p_tmp;
   int any = 0;
   int seqnum = -1;
   int lenum = 0;
@@ -945,6 +939,11 @@ vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name,
          vty_out (vty, "%% Malformed IPv4 prefix%s", VTY_NEWLINE);
          return CMD_WARNING;
        }
+
+      /* 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)
@@ -962,6 +961,11 @@ vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name,
          vty_out (vty, "%% Malformed IPv6 prefix%s", VTY_NEWLINE);
          return CMD_WARNING;
        }
+
+      /* 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_ETHER:
     default:
@@ -970,6 +974,18 @@ vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name,
       break;
     }
 
+  /* 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));
+      zlog_warn ("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);
@@ -995,14 +1011,6 @@ vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name,
   if (dup)
     {
       prefix_list_entry_free (pentry);
-      vty_out (vty, "%% Insertion failed - prefix-list entry exists:%s",
-              VTY_NEWLINE);
-      vty_out (vty, "   seq %u %s %s", dup->seq, typestr, prefix);
-      if (! any && genum)
-       vty_out (vty, " ge %d", genum);
-      if (! any && lenum)
-       vty_out (vty, " le %d", lenum);
-      vty_out (vty, "%s", VTY_NEWLINE);
       return CMD_SUCCESS;
     }
 
@@ -1088,7 +1096,6 @@ vty_prefix_list_uninstall (struct vty *vty, afi_t afi, const char *name,
          return CMD_WARNING;
        }
     }
-#ifdef HAVE_IPV6
   else if (afi == AFI_IP6)
     {
       if (strncmp ("any", prefix, strlen (prefix)) == 0)
@@ -1106,7 +1113,6 @@ vty_prefix_list_uninstall (struct vty *vty, afi_t afi, const char *name,
          return CMD_WARNING;
        }
     }
-#endif /* HAVE_IPV6 */
 
   /* Lookup prefix entry. */
   pentry = prefix_list_entry_lookup(plist, &p, type, seqnum, lenum, genum);
@@ -1906,6 +1912,7 @@ DEFUN (ip_prefix_list_description,
        "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);
@@ -1915,7 +1922,7 @@ DEFUN (ip_prefix_list_description,
       XFREE (MTYPE_TMP, plist->desc);
       plist->desc = NULL;
     }
-  plist->desc = argv_concat(argv, argc, 1);
+  plist->desc = argv_concat(argv, argc, idx_line);
 
   return CMD_SUCCESS;
 }
@@ -2113,7 +2120,6 @@ DEFUN (clear_ip_prefix_list_name_prefix,
   return vty_clear_prefix_list (vty, AFI_IP, argv[idx_word]->arg, argv[idx_ipv4_prefixlen]->arg);
 }
 
-#ifdef HAVE_IPV6
 DEFUN (ipv6_prefix_list,
        ipv6_prefix_list_cmd,
        "ipv6 prefix-list WORD <deny|permit> <X:X::X:X/M|any>",
@@ -2617,6 +2623,7 @@ DEFUN (ipv6_prefix_list_description,
        "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);
@@ -2626,7 +2633,7 @@ DEFUN (ipv6_prefix_list_description,
       XFREE (MTYPE_TMP, plist->desc);
       plist->desc = NULL;
     }
-  plist->desc = argv_concat(argv, argc, 1);
+  plist->desc = argv_concat(argv, argc, iddx_line);
 
   return CMD_SUCCESS;
 }
@@ -2655,7 +2662,7 @@ DEFUN (no_ipv6_prefix_list_description_comment,
        "Prefix-list specific description\n"
        "Up to 80 characters describing this prefix-list\n")
 {
-  return no_ipv6_prefix_list_description_comment (self, vty, argc, argv);
+  return no_ipv6_prefix_list_description (self, vty, argc, argv);
 }
 
 
@@ -2823,7 +2830,6 @@ DEFUN (clear_ipv6_prefix_list_name_prefix,
   int idx_ipv6_prefixlen = 4;
   return vty_clear_prefix_list (vty, AFI_IP6, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg);
 }
-#endif /* HAVE_IPV6 */
 
 /* Configuration write function. */
 static int
@@ -3070,7 +3076,7 @@ prefix_bgp_show_prefix_list (struct vty *vty, afi_t afi, char *name, u_char use_
       else
         json_object_object_add(json, "ipv6PrefixList", json_prefix);
 
-      vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
+      vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
       json_object_free(json);
     }
   else
@@ -3193,23 +3199,11 @@ prefix_list_init_ipv4 (void)
   install_element (VIEW_NODE, &show_ip_prefix_list_detail_cmd);
   install_element (VIEW_NODE, &show_ip_prefix_list_detail_name_cmd);
 
-  install_element (ENABLE_NODE, &show_ip_prefix_list_cmd);
-  install_element (ENABLE_NODE, &show_ip_prefix_list_name_cmd);
-  install_element (ENABLE_NODE, &show_ip_prefix_list_name_seq_cmd);
-  install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_cmd);
-  install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_longer_cmd);
-  install_element (ENABLE_NODE, &show_ip_prefix_list_prefix_first_match_cmd);
-  install_element (ENABLE_NODE, &show_ip_prefix_list_summary_cmd);
-  install_element (ENABLE_NODE, &show_ip_prefix_list_summary_name_cmd);
-  install_element (ENABLE_NODE, &show_ip_prefix_list_detail_cmd);
-  install_element (ENABLE_NODE, &show_ip_prefix_list_detail_name_cmd);
-
   install_element (ENABLE_NODE, &clear_ip_prefix_list_cmd);
   install_element (ENABLE_NODE, &clear_ip_prefix_list_name_cmd);
   install_element (ENABLE_NODE, &clear_ip_prefix_list_name_prefix_cmd);
 }
 
-#ifdef HAVE_IPV6
 /* Prefix-list node. */
 static struct cmd_node prefix_ipv6_node =
 {
@@ -3270,30 +3264,16 @@ prefix_list_init_ipv6 (void)
   install_element (VIEW_NODE, &show_ipv6_prefix_list_detail_cmd);
   install_element (VIEW_NODE, &show_ipv6_prefix_list_detail_name_cmd);
 
-  install_element (ENABLE_NODE, &show_ipv6_prefix_list_cmd);
-  install_element (ENABLE_NODE, &show_ipv6_prefix_list_name_cmd);
-  install_element (ENABLE_NODE, &show_ipv6_prefix_list_name_seq_cmd);
-  install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_cmd);
-  install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_longer_cmd);
-  install_element (ENABLE_NODE, &show_ipv6_prefix_list_prefix_first_match_cmd);
-  install_element (ENABLE_NODE, &show_ipv6_prefix_list_summary_cmd);
-  install_element (ENABLE_NODE, &show_ipv6_prefix_list_summary_name_cmd);
-  install_element (ENABLE_NODE, &show_ipv6_prefix_list_detail_cmd);
-  install_element (ENABLE_NODE, &show_ipv6_prefix_list_detail_name_cmd);
-
   install_element (ENABLE_NODE, &clear_ipv6_prefix_list_cmd);
   install_element (ENABLE_NODE, &clear_ipv6_prefix_list_name_cmd);
   install_element (ENABLE_NODE, &clear_ipv6_prefix_list_name_prefix_cmd);
 }
-#endif /* HAVE_IPV6 */
 
 void
 prefix_list_init ()
 {
   prefix_list_init_ipv4 ();
-#ifdef HAVE_IPV6
   prefix_list_init_ipv6 ();
-#endif /* HAVE_IPV6 */
 }
 
 void