add class D, experimental; don't forward those, net 0 or loopback
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Fri, 5 Jun 1987 12:48:43 +0000 (04:48 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Fri, 5 Jun 1987 12:48:43 +0000 (04:48 -0800)
SCCS-vsn: sys/netinet/in.c 7.5
SCCS-vsn: sys/netinet/in.h 7.3

usr/src/sys/netinet/in.c
usr/src/sys/netinet/in.h

index 34c0475..cdacec3 100644 (file)
@@ -3,7 +3,7 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)in.c        7.4 (Berkeley) %G%
+ *     @(#)in.c        7.5 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -85,8 +85,10 @@ in_netof(in)
                net = i & IN_CLASSA_NET;
        else if (IN_CLASSB(i))
                net = i & IN_CLASSB_NET;
                net = i & IN_CLASSA_NET;
        else if (IN_CLASSB(i))
                net = i & IN_CLASSB_NET;
-       else
+       else if (IN_CLASSC(i))
                net = i & IN_CLASSC_NET;
                net = i & IN_CLASSC_NET;
+       else
+               return (0);
 
        /*
         * Check whether network is a subnet;
 
        /*
         * Check whether network is a subnet;
@@ -115,10 +117,11 @@ in_lnaof(in)
        } else if (IN_CLASSB(i)) {
                net = i & IN_CLASSB_NET;
                host = i & IN_CLASSB_HOST;
        } else if (IN_CLASSB(i)) {
                net = i & IN_CLASSB_NET;
                host = i & IN_CLASSB_HOST;
-       } else {
+       } else if (IN_CLASSC(i)) {
                net = i & IN_CLASSC_NET;
                host = i & IN_CLASSC_HOST;
                net = i & IN_CLASSC_NET;
                host = i & IN_CLASSC_HOST;
-       }
+       } else
+               return (i);
 
        /*
         * Check whether network is a subnet;
 
        /*
         * Check whether network is a subnet;
@@ -158,6 +161,27 @@ in_localaddr(in)
        return (0);
 }
 
        return (0);
 }
 
+/*
+ * Determine whether an IP address is in a reserved set of addresses
+ * that may not be forwarded, or whether datagrams to that destination
+ * may be forwarded.
+ */
+in_canforward(in)
+       struct in_addr in;
+{
+       register u_long i = ntohl(in.s_addr);
+       register u_long net;
+
+       if (IN_EXPERIMENTAL(i))
+               return (0);
+       if (IN_CLASSA(i)) {
+               net = i & IN_CLASSA_NET;
+               if (net == 0 || net == IN_LOOPBACKNET)
+                       return (0);
+       }
+       return (1);
+}
+
 int    in_interfaces;          /* number of external internet interfaces */
 extern struct ifnet loif;
 
 int    in_interfaces;          /* number of external internet interfaces */
 extern struct ifnet loif;
 
index eb1dc62..bd273b8 100644 (file)
@@ -3,7 +3,7 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)in.h        7.2 (Berkeley) %G%
+ *     @(#)in.h        7.3 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -67,17 +67,25 @@ struct in_addr {
 #define        IN_CLASSB_HOST          0x0000ffff
 #define        IN_CLASSB_MAX           65536
 
 #define        IN_CLASSB_HOST          0x0000ffff
 #define        IN_CLASSB_MAX           65536
 
-#define        IN_CLASSC(i)            (((long)(i) & 0xc0000000) == 0xc0000000)
+#define        IN_CLASSC(i)            (((long)(i) & 0xe0000000) == 0xc0000000)
 #define        IN_CLASSC_NET           0xffffff00
 #define        IN_CLASSC_NSHIFT        8
 #define        IN_CLASSC_HOST          0x000000ff
 
 #define        IN_CLASSC_NET           0xffffff00
 #define        IN_CLASSC_NSHIFT        8
 #define        IN_CLASSC_HOST          0x000000ff
 
+#define        IN_CLASSD(i)            (((long)(i) & 0xf0000000) == 0xe0000000)
+#define        IN_MULTICAST(i)         IN_CLASSD(i)
+
+#define        IN_EXPERIMENTAL(i)      (((long)(i) & 0xe0000000) == 0xe0000000)
+#define        IN_BADCLASS(i)          (((long)(i) & 0xf0000000) == 0xf0000000)
+
 #define        INADDR_ANY              (u_long)0x00000000
 #define        INADDR_BROADCAST        (u_long)0xffffffff      /* must be masked */
 #ifndef KERNEL
 #define        INADDR_NONE             0xffffffff              /* -1 return */
 #endif
 
 #define        INADDR_ANY              (u_long)0x00000000
 #define        INADDR_BROADCAST        (u_long)0xffffffff      /* must be masked */
 #ifndef KERNEL
 #define        INADDR_NONE             0xffffffff              /* -1 return */
 #endif
 
+#define        IN_LOOPBACKNET          127                     /* official! */
+
 /*
  * Socket address, internet style.
  */
 /*
  * Socket address, internet style.
  */