]> git.puffer.fish Git - mirror/frr.git/commitdiff
Block martian address configuration on an interface and also block from
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 20 May 2015 00:47:23 +0000 (17:47 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 20 May 2015 00:47:23 +0000 (17:47 -0700)
getting installed into the zebra tables.

lib/prefix.h
zebra/connected.c
zebra/interface.c

index 45889e0862521a9cc6027d15ddebbc1da37ad4c7..c02317a5874c09665597085e57e219c9956ff39d 100644 (file)
@@ -220,13 +220,26 @@ extern void masklen2ip6 (const int, struct in6_addr *);
 extern void str2in6_addr (const char *, struct in6_addr *);
 extern const char *inet6_ntoa (struct in6_addr);
 
+static inline int ipv6_martian (struct in6_addr *addr)
+{
+  struct in6_addr localhost_addr;
+
+  inet_pton (AF_INET6, "::1", &localhost_addr);
+
+  if (IPV6_ADDR_SAME(&localhost_addr, addr))
+    return 1;
+
+  return 0;
+}
+
 #endif /* HAVE_IPV6 */
 
 extern int all_digit (const char *);
 
+/* NOTE: This routine expects the address argument in network byte order. */
 static inline int ipv4_martian (struct in_addr *addr)
 {
-  in_addr_t ip = addr->s_addr;
+  in_addr_t ip = ntohl(addr->s_addr);
 
   if (IPV4_NET0(ip) || IPV4_NET127(ip) || IPV4_CLASS_DE(ip)) {
     return 1;
index c4f87f4cb8f51cacd26dd50e8ed2fb8bd54b0f84..4d6224cc9be4975df7315c970ccf18d901b2f3a1 100644 (file)
@@ -209,6 +209,9 @@ connected_add_ipv4 (struct interface *ifp, int flags, struct in_addr *addr,
   struct prefix_ipv4 *p;
   struct connected *ifc;
 
+  if (ipv4_martian(addr))
+    return;
+
   /* Make connected structure. */
   ifc = connected_new ();
   ifc->ifp = ifp;
@@ -368,6 +371,9 @@ connected_add_ipv6 (struct interface *ifp, int flags, struct in6_addr *addr,
   struct prefix_ipv6 *p;
   struct connected *ifc;
 
+  if (ipv6_martian(addr))
+    return;
+
   /* Make connected structure. */
   ifc = connected_new ();
   ifc->ifp = ifp;
index da5e41e8dcebdfe042fe563d23a4f3cd232b410e..9f7ec0a527b660b449d92523666789b792ec01c6 100644 (file)
@@ -1285,6 +1285,12 @@ ip_address_install (struct vty *vty, struct interface *ifp,
       return CMD_WARNING;
     }
 
+  if (ipv4_martian(&cp.prefix))
+    {
+      vty_out (vty, "%% Invalid address%s", VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
   ifc = connected_check (ifp, (struct prefix *) &cp);
   if (! ifc)
     {
@@ -1469,6 +1475,12 @@ ipv6_address_install (struct vty *vty, struct interface *ifp,
       return CMD_WARNING;
     }
 
+  if (ipv6_martian(&cp.prefix))
+    {
+      vty_out (vty, "%% Invalid address%s", VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
   ifc = connected_check (ifp, (struct prefix *) &cp);
   if (! ifc)
     {