Author: glebius
Date: Thu Oct 20 15:58:05 2011
New Revision: 226572
URL: http://svn.freebsd.org/changeset/base/226572

Log:
  MFhead 226401,226402:
  
    Remove last remnants of classful addressing:
  
    - Remove ia_net, ia_netmask, ia_netbroadcast from struct in_ifaddr.
    - Remove net.inet.ip.subnetsarelocal, I bet no one need it in 2011.
    - fix bug when we were not forwarding to a host which matches classful
      net address. For example router having 192.168.x.y/16 network attached,
      would not forward traffic to 192.168.*.0, which are legal IPs in
      CIDR world.
    - For compatibility, leave autoguessing of mask based on class.
  
    Reviewed by:  andre, bz, rwatson
  
    Add support for IPv4 /31 prefixes, as described in RFC3021.
  
    To run a /31 network, participating hosts MUST drop support
    for directed broadcasts, and treat the first and last addresses
    on subnet as unicast. The broadcast address for the prefix
    should be the link local broadcast address, INADDR_BROADCAST.
  
  Approved by:  re (kib)

Modified:
  stable/9/sys/netinet/in.c
  stable/9/sys/netinet/in.h
  stable/9/sys/netinet/in_debug.c
  stable/9/sys/netinet/in_var.h
  stable/9/sys/netinet/ip_input.c
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/amd64/include/xen/   (props changed)
  stable/9/sys/boot/   (props changed)
  stable/9/sys/boot/i386/efi/   (props changed)
  stable/9/sys/boot/ia64/efi/   (props changed)
  stable/9/sys/boot/ia64/ski/   (props changed)
  stable/9/sys/boot/powerpc/boot1.chrp/   (props changed)
  stable/9/sys/boot/powerpc/ofw/   (props changed)
  stable/9/sys/cddl/contrib/opensolaris/   (props changed)
  stable/9/sys/conf/   (props changed)
  stable/9/sys/contrib/dev/acpica/   (props changed)
  stable/9/sys/contrib/octeon-sdk/   (props changed)
  stable/9/sys/contrib/pf/   (props changed)
  stable/9/sys/contrib/x86emu/   (props changed)

Modified: stable/9/sys/netinet/in.c
==============================================================================
--- stable/9/sys/netinet/in.c   Thu Oct 20 15:55:01 2011        (r226571)
+++ stable/9/sys/netinet/in.c   Thu Oct 20 15:58:05 2011        (r226572)
@@ -76,11 +76,6 @@ static int   in_ifinit(struct ifnet *,
            struct in_ifaddr *, struct sockaddr_in *, int);
 static void    in_purgemaddrs(struct ifnet *);
 
-static VNET_DEFINE(int, subnetsarelocal);
-#define        V_subnetsarelocal               VNET(subnetsarelocal)
-SYSCTL_VNET_INT(_net_inet_ip, OID_AUTO, subnets_are_local, CTLFLAG_RW,
-       &VNET_NAME(subnetsarelocal), 0,
-       "Treat all subnets as directly connected");
 static VNET_DEFINE(int, sameprefixcarponly);
 #define        V_sameprefixcarponly            VNET(sameprefixcarponly)
 SYSCTL_VNET_INT(_net_inet_ip, OID_AUTO, same_prefix_carp_only, CTLFLAG_RW,
@@ -95,9 +90,7 @@ VNET_DECLARE(struct arpstat, arpstat);  
 
 /*
  * Return 1 if an internet address is for a ``local'' host
- * (one to which we have a connection).  If subnetsarelocal
- * is true, this includes other subnets of the local net.
- * Otherwise, it includes only the directly-connected (sub)nets.
+ * (one to which we have a connection).
  */
 int
 in_localaddr(struct in_addr in)
@@ -106,19 +99,10 @@ in_localaddr(struct in_addr in)
        register struct in_ifaddr *ia;
 
        IN_IFADDR_RLOCK();
-       if (V_subnetsarelocal) {
-               TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) {
-                       if ((i & ia->ia_netmask) == ia->ia_net) {
-                               IN_IFADDR_RUNLOCK();
-                               return (1);
-                       }
-               }
-       } else {
-               TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) {
-                       if ((i & ia->ia_subnetmask) == ia->ia_subnet) {
-                               IN_IFADDR_RUNLOCK();
-                               return (1);
-                       }
+       TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) {
+               if ((i & ia->ia_subnetmask) == ia->ia_subnet) {
+                       IN_IFADDR_RUNLOCK();
+                       return (1);
                }
        }
        IN_IFADDR_RUNLOCK();
@@ -890,23 +874,19 @@ in_ifinit(struct ifnet *ifp, struct in_i
                in_ifscrub(ifp, ia, LLE_STATIC);
                ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
        }
-       if (IN_CLASSA(i))
-               ia->ia_netmask = IN_CLASSA_NET;
-       else if (IN_CLASSB(i))
-               ia->ia_netmask = IN_CLASSB_NET;
-       else
-               ia->ia_netmask = IN_CLASSC_NET;
        /*
-        * The subnet mask usually includes at least the standard network part,
-        * but may may be smaller in the case of supernetting.
-        * If it is set, we believe it.
+        * Be compatible with network classes, if netmask isn't supplied,
+        * guess it based on classes.
         */
        if (ia->ia_subnetmask == 0) {
-               ia->ia_subnetmask = ia->ia_netmask;
+               if (IN_CLASSA(i))
+                       ia->ia_subnetmask = IN_CLASSA_NET;
+               else if (IN_CLASSB(i))
+                       ia->ia_subnetmask = IN_CLASSB_NET;
+               else
+                       ia->ia_subnetmask = IN_CLASSC_NET;
                ia->ia_sockmask.sin_addr.s_addr = htonl(ia->ia_subnetmask);
-       } else
-               ia->ia_netmask &= ia->ia_subnetmask;
-       ia->ia_net = i & ia->ia_netmask;
+       }
        ia->ia_subnet = i & ia->ia_subnetmask;
        in_socktrim(&ia->ia_sockmask);
        /*
@@ -919,10 +899,11 @@ in_ifinit(struct ifnet *ifp, struct in_i
         */
        ia->ia_ifa.ifa_metric = ifp->if_metric;
        if (ifp->if_flags & IFF_BROADCAST) {
-               ia->ia_broadaddr.sin_addr.s_addr =
-                       htonl(ia->ia_subnet | ~ia->ia_subnetmask);
-               ia->ia_netbroadcast.s_addr =
-                       htonl(ia->ia_net | ~ ia->ia_netmask);
+               if (ia->ia_subnetmask == IN_RFC3021_MASK)
+                       ia->ia_broadaddr.sin_addr.s_addr = INADDR_BROADCAST;
+               else
+                       ia->ia_broadaddr.sin_addr.s_addr =
+                           htonl(ia->ia_subnet | ~ia->ia_subnetmask);
        } else if (ifp->if_flags & IFF_LOOPBACK) {
                ia->ia_dstaddr = ia->ia_addr;
                flags |= RTF_HOST;
@@ -1253,11 +1234,12 @@ in_broadcast(struct in_addr in, struct i
        TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
                if (ifa->ifa_addr->sa_family == AF_INET &&
                    (in.s_addr == ia->ia_broadaddr.sin_addr.s_addr ||
-                    in.s_addr == ia->ia_netbroadcast.s_addr ||
                     /*
-                     * Check for old-style (host 0) broadcast.
+                     * Check for old-style (host 0) broadcast, but
+                     * taking into account that RFC 3021 obsoletes it.
                      */
-                    t == ia->ia_subnet || t == ia->ia_net) &&
+                    (ia->ia_subnetmask != IN_RFC3021_MASK &&
+                    t == ia->ia_subnet)) &&
                     /*
                      * Check for an all one subnetmask. These
                      * only exist when an interface gets a secondary

Modified: stable/9/sys/netinet/in.h
==============================================================================
--- stable/9/sys/netinet/in.h   Thu Oct 20 15:55:01 2011        (r226571)
+++ stable/9/sys/netinet/in.h   Thu Oct 20 15:58:05 2011        (r226572)
@@ -392,6 +392,8 @@ __END_DECLS
 
 #define        IN_LOOPBACKNET          127                     /* official! */
 
+#define        IN_RFC3021_MASK         (u_int32_t)0xfffffffe
+
 /*
  * Options for use with [gs]etsockopt at the IP level.
  * First word of comment is data type; bool is stored in int.

Modified: stable/9/sys/netinet/in_debug.c
==============================================================================
--- stable/9/sys/netinet/in_debug.c     Thu Oct 20 15:55:01 2011        
(r226571)
+++ stable/9/sys/netinet/in_debug.c     Thu Oct 20 15:58:05 2011        
(r226572)
@@ -86,11 +86,8 @@ in_show_in_ifaddr(struct in_ifaddr *ia)
 #define        IA_DB_RPINTF_DPTR(f, e) db_printf("\t  *%s = " f "\n", #e, 
*ia->e);
        db_printf("\tin_ifaddr = %p\n", ia);
        IA_DB_RPINTF_PTR("%p", ia_ifa);
-       IA_DB_RPINTF("0x%08lx", ia_net);
-       IA_DB_RPINTF("0x%08lx", ia_netmask);
        IA_DB_RPINTF("0x%08lx", ia_subnet);
        IA_DB_RPINTF("0x%08lx", ia_subnetmask);
-       IA_DB_RPINTF("0x%08x", ia_netbroadcast.s_addr);
        IA_DB_RPINTF("%p", ia_hash.le_next);
        IA_DB_RPINTF("%p", ia_hash.le_prev);
        IA_DB_RPINTF_DPTR("%p", ia_hash.le_prev);

Modified: stable/9/sys/netinet/in_var.h
==============================================================================
--- stable/9/sys/netinet/in_var.h       Thu Oct 20 15:55:01 2011        
(r226571)
+++ stable/9/sys/netinet/in_var.h       Thu Oct 20 15:58:05 2011        
(r226572)
@@ -60,12 +60,9 @@ struct in_ifaddr {
        struct  ifaddr ia_ifa;          /* protocol-independent info */
 #define        ia_ifp          ia_ifa.ifa_ifp
 #define ia_flags       ia_ifa.ifa_flags
-                                       /* ia_{,sub}net{,mask} in host order */
-       u_long  ia_net;                 /* network number of interface */
-       u_long  ia_netmask;             /* mask of net part */
-       u_long  ia_subnet;              /* subnet number, including net */
-       u_long  ia_subnetmask;          /* mask of subnet part */
-       struct  in_addr ia_netbroadcast; /* to recognize net broadcasts */
+                                       /* ia_subnet{,mask} in host order */
+       u_long  ia_subnet;              /* subnet address */
+       u_long  ia_subnetmask;          /* mask of subnet */
        LIST_ENTRY(in_ifaddr) ia_hash;  /* entry in bucket of inet addresses */
        TAILQ_ENTRY(in_ifaddr) ia_link; /* list of internet addresses */
        struct  sockaddr_in ia_addr;    /* reserve space for interface name */

Modified: stable/9/sys/netinet/ip_input.c
==============================================================================
--- stable/9/sys/netinet/ip_input.c     Thu Oct 20 15:55:01 2011        
(r226571)
+++ stable/9/sys/netinet/ip_input.c     Thu Oct 20 15:58:05 2011        
(r226572)
@@ -622,11 +622,6 @@ passin:
                                IF_ADDR_UNLOCK(ifp);
                                goto ours;
                        }
-                       if (ia->ia_netbroadcast.s_addr == ip->ip_dst.s_addr) {
-                               ifa_ref(ifa);
-                               IF_ADDR_UNLOCK(ifp);
-                               goto ours;
-                       }
 #ifdef BOOTP_COMPAT
                        if (IA_SIN(ia)->sin_addr.s_addr == INADDR_ANY) {
                                ifa_ref(ifa);
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to