Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys - Add in_init() and move some functions, variables and s...



details:   https://anonhg.NetBSD.org/src/rev/4a7de01058a0
branches:  trunk
changeset: 329393:4a7de01058a0
user:      rmind <rmind%NetBSD.org@localhost>
date:      Thu May 22 22:01:12 2014 +0000

description:
- Add in_init() and move some functions, variables and sysctls into in.c
  where they belong to.  Make some functions and variables static.
- ip_input.c: reduce some #ifdefs, cleanup a little.
- Move some sysctls into ip_flow.c as they belong there.

No functional change.

diffstat:

 sys/net/if_tokensubr.c |   13 +-
 sys/netinet/in.c       |  158 ++++++++++++++++++++++++++++-
 sys/netinet/in.h       |    8 +-
 sys/netinet/in_pcb.c   |   84 +---------------
 sys/netinet/in_pcb.h   |    4 +-
 sys/netinet/in_var.h   |    6 +-
 sys/netinet/ip_flow.c  |  117 ++++++++++++++++++++-
 sys/netinet/ip_input.c |  258 ++++++++----------------------------------------
 sys/netinet/ip_var.h   |   18 +--
 9 files changed, 329 insertions(+), 337 deletions(-)

diffs (truncated from 1119 to 300 lines):

diff -r e32b19268021 -r 4a7de01058a0 sys/net/if_tokensubr.c
--- a/sys/net/if_tokensubr.c    Thu May 22 16:47:31 2014 +0000
+++ b/sys/net/if_tokensubr.c    Thu May 22 22:01:12 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_tokensubr.c,v 1.63 2014/05/15 09:23:03 msaitoh Exp $        */
+/*     $NetBSD: if_tokensubr.c,v 1.64 2014/05/22 22:01:12 rmind Exp $  */
 
 /*
  * Copyright (c) 1982, 1989, 1993
@@ -92,7 +92,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_tokensubr.c,v 1.63 2014/05/15 09:23:03 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tokensubr.c,v 1.64 2014/05/22 22:01:12 rmind Exp $");
 
 #include "opt_inet.h"
 #include "opt_atalk.h"
@@ -124,17 +124,16 @@
 #include <net/if_ether.h>
 #include <net/if_token.h>
 
-#include "carp.h"
-#if NCARP > 0
-#include <netinet/ip_carp.h>
-#endif
-
 #ifdef INET
 #include <netinet/in.h>
 #include <netinet/in_var.h>
 #include <netinet/if_inarp.h>
 #endif
 
+#include "carp.h"
+#if NCARP > 0
+#include <netinet/ip_carp.h>
+#endif
 
 #ifdef DECNET
 #include <netdnet/dn.h>
diff -r e32b19268021 -r 4a7de01058a0 sys/netinet/in.c
--- a/sys/netinet/in.c  Thu May 22 16:47:31 2014 +0000
+++ b/sys/netinet/in.c  Thu May 22 22:01:12 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in.c,v 1.144 2013/06/29 21:06:58 rmind Exp $   */
+/*     $NetBSD: in.c,v 1.145 2014/05/22 22:01:12 rmind Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.144 2013/06/29 21:06:58 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.145 2014/05/22 22:01:12 rmind Exp $");
 
 #include "opt_inet.h"
 #include "opt_inet_conf.h"
@@ -132,13 +132,14 @@
 #include <netinet/in_selsrc.h>
 #endif
 
-static u_int in_mask2len(struct in_addr *);
-static void in_len2mask(struct in_addr *, u_int);
-static int in_lifaddr_ioctl(struct socket *, u_long, void *,
+static u_int   in_mask2len(struct in_addr *);
+static void    in_len2mask(struct in_addr *, u_int);
+static int     in_lifaddr_ioctl(struct socket *, u_long, void *,
        struct ifnet *, struct lwp *);
 
-static int in_addprefix(struct in_ifaddr *, int);
-static int in_scrubprefix(struct in_ifaddr *);
+static int     in_addprefix(struct in_ifaddr *, int);
+static int     in_scrubprefix(struct in_ifaddr *);
+static void    in_sysctl_init(struct sysctllog **);
 
 #ifndef SUBNETSARELOCAL
 #define        SUBNETSARELOCAL 1
@@ -148,15 +149,39 @@
 #define HOSTZEROBROADCAST 1
 #endif
 
-int subnetsarelocal = SUBNETSARELOCAL;
-int hostzeroisbroadcast = HOSTZEROBROADCAST;
+static int                     subnetsarelocal = SUBNETSARELOCAL;
+static int                     hostzeroisbroadcast = HOSTZEROBROADCAST;
 
 /*
  * This list is used to keep track of in_multi chains which belong to
  * deleted interface addresses.  We use in_ifaddr so that a chain head
  * won't be deallocated until all multicast address record are deleted.
  */
-static TAILQ_HEAD(, in_ifaddr) in_mk = TAILQ_HEAD_INITIALIZER(in_mk);
+static TAILQ_HEAD(, in_ifaddr) in_mk = TAILQ_HEAD_INITIALIZER(in_mk);
+
+static struct pool             inmulti_pool;
+static u_int                   in_multientries;
+struct in_multihashhead *      in_multihashtbl;
+
+u_long                         in_multihash;
+struct in_ifaddrhashhead *     in_ifaddrhashtbl;
+u_long                         in_ifaddrhash;
+struct in_ifaddrhead           in_ifaddrhead;
+
+void
+in_init(void)
+{
+       pool_init(&inmulti_pool, sizeof(struct in_multi), 0, 0, 0, "inmltpl",
+           NULL, IPL_SOFTNET);
+       TAILQ_INIT(&in_ifaddrhead);
+
+       in_ifaddrhashtbl = hashinit(IN_IFADDR_HASH_SIZE, HASH_LIST, true,
+           &in_ifaddrhash);
+       in_multihashtbl = hashinit(IN_IFADDR_HASH_SIZE, HASH_LIST, true,
+           &in_multihash);
+
+       in_sysctl_init(NULL);
+}
 
 /*
  * Return 1 if an internet address is for a ``local'' host
@@ -1132,3 +1157,116 @@
        }
        splx(s);
 }
+
+struct sockaddr_in *
+in_selectsrc(struct sockaddr_in *sin, struct route *ro,
+    int soopts, struct ip_moptions *mopts, int *errorp)
+{
+       struct rtentry *rt = NULL;
+       struct in_ifaddr *ia = NULL;
+
+       /*
+         * If route is known or can be allocated now, take the
+         * source address from the interface.  Otherwise, punt.
+        */
+       if ((soopts & SO_DONTROUTE) != 0)
+               rtcache_free(ro);
+       else {
+               union {
+                       struct sockaddr         dst;
+                       struct sockaddr_in      dst4;
+               } u;
+
+               sockaddr_in_init(&u.dst4, &sin->sin_addr, 0);
+               rt = rtcache_lookup(ro, &u.dst);
+       }
+       /*
+        * If we found a route, use the address
+        * corresponding to the outgoing interface
+        * unless it is the loopback (in case a route
+        * to our address on another net goes to loopback).
+        *
+        * XXX Is this still true?  Do we care?
+        */
+       if (rt != NULL && (rt->rt_ifp->if_flags & IFF_LOOPBACK) == 0)
+               ia = ifatoia(rt->rt_ifa);
+       if (ia == NULL) {
+               u_int16_t fport = sin->sin_port;
+
+               sin->sin_port = 0;
+               ia = ifatoia(ifa_ifwithladdr(sintosa(sin)));
+               sin->sin_port = fport;
+               if (ia == NULL) {
+                       /* Find 1st non-loopback AF_INET address */
+                       TAILQ_FOREACH(ia, &in_ifaddrhead, ia_list) {
+                               if (!(ia->ia_ifp->if_flags & IFF_LOOPBACK))
+                                       break;
+                       }
+               }
+               if (ia == NULL) {
+                       *errorp = EADDRNOTAVAIL;
+                       return NULL;
+               }
+       }
+       /*
+        * If the destination address is multicast and an outgoing
+        * interface has been set as a multicast option, use the
+        * address of that interface as our source address.
+        */
+       if (IN_MULTICAST(sin->sin_addr.s_addr) && mopts != NULL) {
+               struct ip_moptions *imo;
+               struct ifnet *ifp;
+
+               imo = mopts;
+               if (imo->imo_multicast_ifp != NULL) {
+                       ifp = imo->imo_multicast_ifp;
+                       IFP_TO_IA(ifp, ia);             /* XXX */
+                       if (ia == 0) {
+                               *errorp = EADDRNOTAVAIL;
+                               return NULL;
+                       }
+               }
+       }
+       if (ia->ia_ifa.ifa_getifa != NULL) {
+               ia = ifatoia((*ia->ia_ifa.ifa_getifa)(&ia->ia_ifa,
+                                                     sintosa(sin)));
+       }
+#ifdef GETIFA_DEBUG
+       else
+               printf("%s: missing ifa_getifa\n", __func__);
+#endif
+       return satosin(&ia->ia_addr);
+}
+
+static void
+in_sysctl_init(struct sysctllog **clog)
+{
+       sysctl_createv(clog, 0, NULL, NULL,
+                      CTLFLAG_PERMANENT,
+                      CTLTYPE_NODE, "inet",
+                      SYSCTL_DESCR("PF_INET related settings"),
+                      NULL, 0, NULL, 0,
+                      CTL_NET, PF_INET, CTL_EOL);
+       sysctl_createv(clog, 0, NULL, NULL,
+                      CTLFLAG_PERMANENT,
+                      CTLTYPE_NODE, "ip",
+                      SYSCTL_DESCR("IPv4 related settings"),
+                      NULL, 0, NULL, 0,
+                      CTL_NET, PF_INET, IPPROTO_IP, CTL_EOL);
+
+       sysctl_createv(clog, 0, NULL, NULL,
+                      CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+                      CTLTYPE_INT, "subnetsarelocal",
+                      SYSCTL_DESCR("Whether logical subnets are considered "
+                                   "local"),
+                      NULL, 0, &subnetsarelocal, 0,
+                      CTL_NET, PF_INET, IPPROTO_IP,
+                      IPCTL_SUBNETSARELOCAL, CTL_EOL);
+       sysctl_createv(clog, 0, NULL, NULL,
+                      CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+                      CTLTYPE_INT, "hostzerobroadcast",
+                      SYSCTL_DESCR("All zeroes address is broadcast address"),
+                      NULL, 0, &hostzeroisbroadcast, 0,
+                      CTL_NET, PF_INET, IPPROTO_IP,
+                      IPCTL_HOSTZEROBROADCAST, CTL_EOL);
+}
diff -r e32b19268021 -r 4a7de01058a0 sys/netinet/in.h
--- a/sys/netinet/in.h  Thu May 22 16:47:31 2014 +0000
+++ b/sys/netinet/in.h  Thu May 22 22:01:12 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in.h,v 1.89 2013/06/27 19:38:16 christos Exp $ */
+/*     $NetBSD: in.h,v 1.90 2014/05/22 22:01:12 rmind Exp $    */
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -564,6 +564,12 @@
 int    in_localaddr(struct in_addr);
 void   in_socktrim(struct sockaddr_in *);
 
+struct route;
+struct ip_moptions;
+
+struct sockaddr_in *in_selectsrc(struct sockaddr_in *,
+       struct route *, int, struct ip_moptions *, int *);
+
 #define        in_hosteq(s,t)  ((s).s_addr == (t).s_addr)
 #define        in_nullhost(x)  ((x).s_addr == INADDR_ANY)
 
diff -r e32b19268021 -r 4a7de01058a0 sys/netinet/in_pcb.c
--- a/sys/netinet/in_pcb.c      Thu May 22 16:47:31 2014 +0000
+++ b/sys/netinet/in_pcb.c      Thu May 22 22:01:12 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_pcb.c,v 1.146 2013/11/23 14:20:21 christos Exp $    */
+/*     $NetBSD: in_pcb.c,v 1.147 2014/05/22 22:01:12 rmind Exp $       */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.146 2013/11/23 14:20:21 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.147 2014/05/22 22:01:12 rmind Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -1053,83 +1053,3 @@
        sockaddr_in_init(&u.dst4, &inp->inp_faddr, 0);
        return rtcache_lookup(ro, &u.dst);
 }
-
-struct sockaddr_in *
-in_selectsrc(struct sockaddr_in *sin, struct route *ro,
-    int soopts, struct ip_moptions *mopts, int *errorp)
-{
-       struct rtentry *rt = NULL;
-       struct in_ifaddr *ia = NULL;
-
-       /*
-         * If route is known or can be allocated now, take the
-         * source address from the interface.  Otherwise, punt.
-        */
-       if ((soopts & SO_DONTROUTE) != 0)
-               rtcache_free(ro);
-       else {
-               union {
-                       struct sockaddr         dst;
-                       struct sockaddr_in      dst4;



Home | Main Index | Thread Index | Old Index