Author: glebius
Date: Sat Oct 15 16:28:06 2011
New Revision: 226401
URL: http://svn.freebsd.org/changeset/base/226401

Log:
  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

Modified:
  head/sys/netinet/in.c
  head/sys/netinet/in_debug.c
  head/sys/netinet/in_var.h
  head/sys/netinet/ip_input.c

Modified: head/sys/netinet/in.c
==============================================================================
--- head/sys/netinet/in.c       Sat Oct 15 16:18:35 2011        (r226400)
+++ head/sys/netinet/in.c       Sat Oct 15 16:28:06 2011        (r226401)
@@ -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();
@@ -888,23 +872,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,8 +899,6 @@ in_ifinit(struct ifnet *ifp, struct in_i
        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);
        } else if (ifp->if_flags & IFF_LOOPBACK) {
                ia->ia_dstaddr = ia->ia_addr;
                flags |= RTF_HOST;
@@ -1251,11 +1229,10 @@ 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.
                      */
-                    t == ia->ia_subnet || t == ia->ia_net) &&
+                    t == ia->ia_subnet) &&
                     /*
                      * Check for an all one subnetmask. These
                      * only exist when an interface gets a secondary

Modified: head/sys/netinet/in_debug.c
==============================================================================
--- head/sys/netinet/in_debug.c Sat Oct 15 16:18:35 2011        (r226400)
+++ head/sys/netinet/in_debug.c Sat Oct 15 16:28:06 2011        (r226401)
@@ -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: head/sys/netinet/in_var.h
==============================================================================
--- head/sys/netinet/in_var.h   Sat Oct 15 16:18:35 2011        (r226400)
+++ head/sys/netinet/in_var.h   Sat Oct 15 16:28:06 2011        (r226401)
@@ -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: head/sys/netinet/ip_input.c
==============================================================================
--- head/sys/netinet/ip_input.c Sat Oct 15 16:18:35 2011        (r226400)
+++ head/sys/netinet/ip_input.c Sat Oct 15 16:28:06 2011        (r226401)
@@ -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);
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to