]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Better support for /31 networks.
authorOndrej Zajicek <santiago@crfreenet.org>
Tue, 27 Apr 2010 22:39:57 +0000 (00:39 +0200)
committerOndrej Zajicek <santiago@crfreenet.org>
Tue, 27 Apr 2010 22:39:57 +0000 (00:39 +0200)
lib/ip.c
lib/ipv4.h
lib/ipv6.h
nest/neighbor.c
proto/ospf/iface.c
sysdep/bsd/krt-sock.c
sysdep/linux/netlink/netlink.c
sysdep/unix/krt-iface.c

index 0afe97967409c5700ec04f6a77ae7ba60c39af95..791a6013a0a90ac9686f2285827ade8d61bdf589 100644 (file)
--- a/lib/ip.c
+++ b/lib/ip.c
@@ -150,18 +150,6 @@ void ipa_ntoh(ip_addr x) { DUMMY }
  */
 int ipa_classify(ip_addr x) { DUMMY }
 
-/**
- * ipa_opposite - return address of point-to-point neighbor
- * @x: IP address of our end of the link
- * @pxlen: network prefix length
- *
- * ipa_opposite() returns an address of the opposite end of a numbered
- * point-to-point link.
- *
- * This function is available in IPv4 version only.
- */
-ip_addr ipa_opposite(ip_addr x, int pxlen) { DUMMY }
-
 /**
  * ipa_class_mask - guess netmask according to address class
  * @x: IP address
@@ -172,7 +160,7 @@ ip_addr ipa_opposite(ip_addr x, int pxlen) { DUMMY }
  * routing protocols transferring no prefix lengths nor netmasks
  * and this function could be useful to them.
  */
-ip_addr ipa_classify(ip_addr x) { DUMMY }
+ip_addr ipa_class_mask(ip_addr x) { DUMMY }
 
 /**
  * ipa_from_u32 - convert IPv4 address to an integer
index 74f1e88fe17e21cf662a2d3f35698e2ee830fe3a..f258d37e9f728dfa4904511dd555d2e1fd9ca285 100644 (file)
@@ -56,7 +56,8 @@ typedef u32 ip_addr;
 #define ipa_ntoh(x) x = _MI(ntohl(_I(x)))
 #define ipa_classify(x) ipv4_classify(_I(x))
 #define ipa_has_link_scope(x) ipv4_has_link_scope(_I(x))
-#define ipa_opposite(x,len) _MI(_I(x) ^ (len == 30 ? 3 : 1))
+#define ipa_opposite_m1(x) _MI(_I(x) ^ 1)
+#define ipa_opposite_m2(x) _MI(_I(x) ^ 3)
 #define ipa_class_mask(x) _MI(ipv4_class_mask(_I(x)))
 #define ipa_from_u32(x) _MI(x)
 #define ipa_to_u32(x) _I(x)
index e15c57af3ab4a70cf537d56cc4a79c3c39f48f6c..6f8e7b3c9afc73fa1869cd7a0b72593e730c8ad3 100644 (file)
@@ -62,7 +62,9 @@ typedef struct ipv6_addr {
 #define ipa_ntoh(x) ipv6_ntoh(&(x))
 #define ipa_classify(x) ipv6_classify(&(x))
 #define ipa_has_link_scope(x) ipv6_has_link_scope(&(x))
-/* ipa_opposite and ipa_class_mask don't make sense with IPv6 */
+#define ipa_opposite_m1(x) ({ ip_addr _a=(x); _MI(_I0(_a),_I1(_a),_I2(_a),_I3(_a) ^ 1); })
+#define ipa_opposite_m2(x) ({ ip_addr _a=(x); _MI(_I0(_a),_I1(_a),_I2(_a),_I3(_a) ^ 3); })
+/* ipa_class_mask don't make sense with IPv6 */
 /* ipa_from_u32 and ipa_to_u32 replaced by ipa_build */
 #define ipa_build(a,b,c,d) _MI(a,b,c,d)
 #define ipa_compare(x,y) ipv6_compare(x,y)
index 25b98dbd91a187eeceda2b0597b61915e58fd9f3..7e7cc491f41427b4dd23ac2dc366d7ce131d57c1 100644 (file)
@@ -75,9 +75,13 @@ if_connected(ip_addr *a, struct iface *i) /* -1=error, 1=match, 0=no match */
        {
          if (ipa_in_net(*a, b->prefix, b->pxlen))
            {
-             if (ipa_equal(*a, b->prefix) ||   /* Network address */
-                 ipa_equal(*a, b->brd))        /* Broadcast */
+#ifndef IPV6
+             if ((b->pxlen < (BITS_PER_IP_ADDRESS - 1)) &&
+                 (ipa_equal(*a, b->prefix) ||  /* Network address */
+                  ipa_equal(*a, b->brd)))      /* Broadcast */
                return -1;
+#endif
+
              return b->scope;
            }
        }
index b5a509a7c26de5559113834d7af1e6d761dfabef..6faed3a56b4de189d2d32154004562eaa3c4d708 100644 (file)
@@ -361,7 +361,7 @@ ospf_iface_sm(struct ospf_iface *ifa, int event)
 u8
 ospf_iface_clasify(struct iface *ifa, struct ifa *addr)
 {
-  if (addr->flags & IA_UNNUMBERED)
+  if (ipa_nonzero(addr->opposite))
     return OSPF_IT_PTP;
 
   if ((ifa->flags & (IF_MULTIACCESS | IF_MULTICAST)) ==
index 4817df393e4db6b463428a6ed1fdc0a06fcbc09e..12ebe6deccf05d4b4a26dcc3f86adaa1259f8028 100644 (file)
@@ -546,7 +546,17 @@ krt_read_addr(struct ks_msg *msg)
 #endif
 
   if (iface->flags & IF_MULTIACCESS)
+  {
     ifa.prefix = ipa_and(ifa.ip, ipa_mkmask(masklen));
+
+    if (i->ifa_prefixlen == BITS_PER_IP_ADDRESS - 1)
+      ifa.opposite = ipa_opposite_m1(ifa.ip);
+
+#ifndef IPV6
+    if (i->ifa_prefixlen == BITS_PER_IP_ADDRESS - 2)
+      ifa.opposite = ipa_opposite_m2(ifa.ip);
+#endif
+  }
   else         /* PtP iface */
   {
     ifa.flags |= IA_UNNUMBERED;
index aa0f2c45b6acd6c5b633e0ec6e1271214074b14d..72f06cc21154f3ce8ad27176235d7424102ce7bb 100644 (file)
@@ -390,9 +390,13 @@ nl_parse_addr(struct nlmsghdr *h)
       ip_addr netmask = ipa_mkmask(ifa.pxlen);
       ifa.prefix = ipa_and(ifa.ip, netmask);
       ifa.brd = ipa_or(ifa.ip, ipa_not(netmask));
+      if (i->ifa_prefixlen == BITS_PER_IP_ADDRESS - 1)
+       ifa.opposite = ipa_opposite_m1(ifa.ip);
+
 #ifndef IPV6
       if (i->ifa_prefixlen == BITS_PER_IP_ADDRESS - 2)
-       ifa.opposite = ipa_opposite(ifa.ip, i->ifa_prefixlen);
+       ifa.opposite = ipa_opposite_m2(ifa.ip);
+
       if ((ifi->flags & IF_BROADCAST) && a[IFA_BROADCAST])
        {
          ip_addr xbrd;
index e0158b6baf163f8ee36260c4884551fe7e80d1ac..5fda0d1d8eb99c4ea6ddfc8c32b4a47d1e8f552b 100644 (file)
@@ -89,7 +89,7 @@ scan_ifs(struct ifreq *r, int cnt)
        { err = "SIOCGIFNETMASK"; goto faulty; }
       get_sockaddr((struct sockaddr_in *) &r->ifr_addr, &netmask, NULL, 0);
       l = ipa_mklen(netmask);
-      if (l < 0 || l == 31)
+      if (l < 0)
        {
          log(L_ERR "%s: Invalid netmask (%x)", i.name, netmask);
          goto bad;
@@ -139,8 +139,10 @@ scan_ifs(struct ifreq *r, int cnt)
            i.flags |= IF_BROADCAST;
          if (a.pxlen < 30)
            i.flags |= IF_MULTIACCESS;
-         else
-           a.opposite = ipa_opposite(a.ip, a.pxlen);
+         if (a.pxlen == 30)
+           ifa.opposite = ipa_opposite_m2(ifa.ip);
+         if (a.pxlen == 31)
+           ifa.opposite = ipa_opposite_m1(ifa.ip);
        }
       else
        a.brd = a.opposite;