]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib/ospf/eigrp: enable ospf and eigrp to use more specific network statements 763/head
authorDon Slice <dslice@cumulusnetworks.com>
Wed, 28 Jun 2017 18:53:27 +0000 (14:53 -0400)
committerDon Slice <dslice@cumulusnetworks.com>
Wed, 28 Jun 2017 18:57:36 +0000 (14:57 -0400)
Issue reported that a configuration commonly used on other routing implementations
fails in frr.  If under ospf, "network 172.16.1.1/32 area 0" or under eigrp, "network
172.16.1.1/32" is entered, the appropriate interfaces are not included in the routing
protocol.  This was because the code was calling prefix_match, which did not match if
the network statement had a longer mask than the interface being matched.  This fix
takes away that restriction by creating a "lib/prefix_match_network_statement" function
which doesn't care about the mask of the interface.  Manual testing shows both ospf and
eigrp now can be defined with more specific network statements.

Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
eigrpd/eigrp_network.c
lib/prefix.c
lib/prefix.h
ospfd/ospfd.c

index cfed11a9eb6745e2bfb07aedf96ed0512937091e..c4e0b8435c858e08434ab4df828fc0fe5a346242 100644 (file)
@@ -262,7 +262,7 @@ static int
 eigrp_network_match_iface(const struct connected *co, const struct prefix *net)
 {
   /* new approach: more elegant and conceptually clean */
-  return prefix_match(net, CONNECTED_PREFIX (co));
+  return prefix_match_network_statement(net, CONNECTED_PREFIX (co));
 }
 
 static void
index 9c228cf9548c1a42609fa27a9109a57fd34b22cb..4131f37fbd51143c143e3afc41fa1ab3e7dcb310 100644 (file)
@@ -292,6 +292,31 @@ prefix_match (const struct prefix *n, const struct prefix *p)
   return 1;
 }
 
+/* If n includes p then return 1 else return 0. Prefix mask is not considered */
+int
+prefix_match_network_statement (const struct prefix *n, const struct prefix *p)
+{
+  int offset;
+  int shift;
+  const u_char *np, *pp;
+
+  /* Set both prefix's head pointer. */
+  np = (const u_char *)&n->u.prefix;
+  pp = (const u_char *)&p->u.prefix;
+
+  offset = n->prefixlen / PNBBY;
+  shift =  n->prefixlen % PNBBY;
+
+  if (shift)
+    if (maskbit[shift] & (np[offset] ^ pp[offset]))
+      return 0;
+
+  while (offset--)
+    if (np[offset] != pp[offset])
+      return 0;
+  return 1;
+}
+
 /* Copy prefix from src to dest. */
 void
 prefix_copy (struct prefix *dest, const struct prefix *src)
index 35dfddd9d346701a8f55731e3c65cfd7e353bd6e..24144e80a3e9751a8b58054fb2236d3efdfde080 100644 (file)
@@ -279,6 +279,7 @@ extern int str2prefix (const char *, struct prefix *);
 
 extern const char *prefix2str (union prefixconstptr, char *, int);
 extern int prefix_match (const struct prefix *, const struct prefix *);
+extern int prefix_match_network_statement (const struct prefix *, const struct prefix *);
 extern int prefix_same (const struct prefix *, const struct prefix *);
 extern int prefix_cmp (const struct prefix *, const struct prefix *);
 extern int prefix_common_bits (const struct prefix *, const struct prefix *);
index 27cedc8705b1cda926aeaee22454c79870fc4d22..aeb7600d693c0db5e417ed5671eecf6b59746c88 100644 (file)
@@ -1116,7 +1116,7 @@ static int
 ospf_network_match_iface(const struct connected *co, const struct prefix *net)
 {
   /* new approach: more elegant and conceptually clean */
-  return prefix_match(net, CONNECTED_PREFIX(co));
+  return prefix_match_network_statement(net, CONNECTED_PREFIX(co));
 }
 
 static void