Source-Changes-HG archive

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

[src/trunk]: src/sys Allow kernels compiled with INET+INET6 to be booted as I...



details:   https://anonhg.NetBSD.org/src/rev/14d08faf1b00
branches:  trunk
changeset: 792393:14d08faf1b00
user:      pooka <pooka%NetBSD.org@localhost>
date:      Thu Jan 02 18:29:01 2014 +0000

description:
Allow kernels compiled with INET+INET6 to be booted as IPv4-only or IPv6-only.

diffstat:

 sys/net/if.c                             |  24 ++++++----
 sys/netinet/in_proto.c                   |   5 +-
 sys/netinet/tcp_subr.c                   |  69 ++++++++++++++++++-------------
 sys/netinet/tcp_timer.c                  |   8 ++-
 sys/netinet/tcp_var.h                    |   9 +++-
 sys/netinet/udp_usrreq.c                 |  34 ++++++++++-----
 sys/netinet/udp_var.h                    |   3 +-
 sys/netinet6/in6_proto.c                 |  28 +++++++++---
 sys/netinet6/in6_var.h                   |   3 +-
 sys/netinet6/udp6_usrreq.c               |   7 ++-
 sys/rump/net/lib/libnetinet/component.c  |   7 +-
 sys/rump/net/lib/libnetinet6/component.c |   6 +-
 12 files changed, 126 insertions(+), 77 deletions(-)

diffs (truncated from 552 to 300 lines):

diff -r 420b90033d12 -r 14d08faf1b00 sys/net/if.c
--- a/sys/net/if.c      Thu Jan 02 18:26:03 2014 +0000
+++ b/sys/net/if.c      Thu Jan 02 18:29:01 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.269 2013/10/19 21:39:12 mrg Exp $     */
+/*     $NetBSD: if.c,v 1.270 2014/01/02 18:29:01 pooka Exp $   */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.269 2013/10/19 21:39:12 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.270 2014/01/02 18:29:01 pooka Exp $");
 
 #include "opt_inet.h"
 
@@ -1358,7 +1358,7 @@
         * listeners would have an address and expect it to work right
         * away.
         */
-       if (link_state == LINK_STATE_UP &&
+       if (in6_present && link_state == LINK_STATE_UP &&
            old_link_state == LINK_STATE_UNKNOWN)
                in6_if_link_down(ifp);
 #endif
@@ -1372,10 +1372,12 @@
 #endif
 
 #ifdef INET6
-       if (link_state == LINK_STATE_DOWN)
-               in6_if_link_down(ifp);
-       else if (link_state == LINK_STATE_UP)
-               in6_if_link_up(ifp);
+       if (in6_present) {
+               if (link_state == LINK_STATE_DOWN)
+                       in6_if_link_down(ifp);
+               else if (link_state == LINK_STATE_UP)
+                       in6_if_link_up(ifp);
+       }
 #endif
 
        splx(s);
@@ -1402,7 +1404,8 @@
 #endif
        rt_ifmsg(ifp);
 #ifdef INET6
-       in6_if_down(ifp);
+       if (in6_present)
+               in6_if_down(ifp);
 #endif
 }
 
@@ -1431,7 +1434,8 @@
 #endif
        rt_ifmsg(ifp);
 #ifdef INET6
-       in6_if_up(ifp);
+       if (in6_present)
+               in6_if_up(ifp);
 #endif
 }
 
@@ -1906,7 +1910,7 @@
 
        if (((oif_flags ^ ifp->if_flags) & IFF_UP) != 0) {
 #ifdef INET6
-               if ((ifp->if_flags & IFF_UP) != 0) {
+               if (in6_present && (ifp->if_flags & IFF_UP) != 0) {
                        int s = splnet();
                        in6_if_up(ifp);
                        splx(s);
diff -r 420b90033d12 -r 14d08faf1b00 sys/netinet/in_proto.c
--- a/sys/netinet/in_proto.c    Thu Jan 02 18:26:03 2014 +0000
+++ b/sys/netinet/in_proto.c    Thu Jan 02 18:29:01 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_proto.c,v 1.106 2013/06/05 19:01:26 christos Exp $  */
+/*     $NetBSD: in_proto.c,v 1.107 2014/01/02 18:29:01 pooka Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.106 2013/06/05 19:01:26 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.107 2014/01/02 18:29:01 pooka Exp $");
 
 #include "opt_mrouting.h"
 #include "opt_inet.h"
@@ -200,7 +200,6 @@
        .pr_usrreq = tcp_usrreq,
        .pr_init = tcp_init,
        .pr_fasttimo = tcp_fasttimo,
-       .pr_slowtimo = tcp_slowtimo,
        .pr_drain = tcp_drainstub,
 },
 {      .pr_type = SOCK_RAW,
diff -r 420b90033d12 -r 14d08faf1b00 sys/netinet/tcp_subr.c
--- a/sys/netinet/tcp_subr.c    Thu Jan 02 18:26:03 2014 +0000
+++ b/sys/netinet/tcp_subr.c    Thu Jan 02 18:29:01 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_subr.c,v 1.252 2013/11/23 14:20:21 christos Exp $  */
+/*     $NetBSD: tcp_subr.c,v 1.253 2014/01/02 18:29:01 pooka Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.252 2013/11/23 14:20:21 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.253 2014/01/02 18:29:01 pooka Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -104,6 +104,7 @@
 #include <sys/systm.h>
 #include <sys/malloc.h>
 #include <sys/mbuf.h>
+#include <sys/once.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
 #include <sys/protosw.h>
@@ -241,10 +242,7 @@
 int    tcp_freeq(struct tcpcb *);
 
 #ifdef INET
-void   tcp_mtudisc_callback(struct in_addr);
-#endif
-#ifdef INET6
-void   tcp6_mtudisc_callback(struct in6_addr *);
+static void    tcp_mtudisc_callback(struct in_addr);
 #endif
 
 #ifdef INET6
@@ -387,35 +385,16 @@
 struct mowner tcp_sock_tx_mowner = MOWNER_INIT("tcp", "sock tx");
 #endif
 
-/*
- * Tcp initialization
- */
-void
-tcp_init(void)
+callout_t tcp_slowtimo_ch;
+
+static int
+do_tcpinit(void)
 {
-       int hlen;
 
        in_pcbinit(&tcbtable, tcbhashsize, tcbhashsize);
        pool_init(&tcpcb_pool, sizeof(struct tcpcb), 0, 0, 0, "tcpcbpl",
            NULL, IPL_SOFTNET);
 
-       hlen = sizeof(struct ip) + sizeof(struct tcphdr);
-#ifdef INET6
-       if (sizeof(struct ip) < sizeof(struct ip6_hdr))
-               hlen = sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
-#endif
-       if (max_protohdr < hlen)
-               max_protohdr = hlen;
-       if (max_linkhdr + hlen > MHLEN)
-               panic("tcp_init");
-
-#ifdef INET
-       icmp_mtudisc_callback_register(tcp_mtudisc_callback);
-#endif
-#ifdef INET6
-       icmp6_mtudisc_callback_register(tcp6_mtudisc_callback);
-#endif
-
        tcp_usrreq_init();
 
        /* Initialize timer state. */
@@ -447,6 +426,38 @@
        tcpstat_percpu = percpu_alloc(sizeof(uint64_t) * TCP_NSTATS);
 
        vtw_earlyinit();
+
+       callout_init(&tcp_slowtimo_ch, CALLOUT_MPSAFE);
+       callout_reset(&tcp_slowtimo_ch, 1, tcp_slowtimo, NULL);
+
+       return 0;
+}
+
+void
+tcp_init_common(unsigned basehlen)
+{
+       static ONCE_DECL(dotcpinit);
+       unsigned hlen = basehlen + sizeof(struct tcphdr);
+       unsigned oldhlen;
+
+       if (max_linkhdr + hlen > MHLEN)
+               panic("tcp_init");
+       while ((oldhlen = max_protohdr) < hlen)
+               atomic_cas_uint(&max_protohdr, oldhlen, hlen);
+
+       RUN_ONCE(&dotcpinit, do_tcpinit);
+}
+
+/*
+ * Tcp initialization
+ */
+void
+tcp_init(void)
+{
+
+       icmp_mtudisc_callback_register(tcp_mtudisc_callback);
+
+       tcp_init_common(sizeof(struct ip));
 }
 
 /*
diff -r 420b90033d12 -r 14d08faf1b00 sys/netinet/tcp_timer.c
--- a/sys/netinet/tcp_timer.c   Thu Jan 02 18:26:03 2014 +0000
+++ b/sys/netinet/tcp_timer.c   Thu Jan 02 18:29:01 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_timer.c,v 1.86 2011/08/31 18:31:03 plunky Exp $    */
+/*     $NetBSD: tcp_timer.c,v 1.87 2014/01/02 18:29:01 pooka Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.86 2011/08/31 18:31:03 plunky Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.87 2014/01/02 18:29:01 pooka Exp $");
 
 #include "opt_inet.h"
 #include "opt_tcp_debug.h"
@@ -230,13 +230,15 @@
  * causes finite state machine actions if timers expire.
  */
 void
-tcp_slowtimo(void)
+tcp_slowtimo(void *arg)
 {
 
        mutex_enter(softnet_lock);
        tcp_iss_seq += TCP_ISSINCR;                     /* increment iss */
        tcp_now++;                                      /* for timestamps */
        mutex_exit(softnet_lock);
+
+       callout_schedule(&tcp_slowtimo_ch, hz / PR_SLOWHZ);
 }
 
 /*
diff -r 420b90033d12 -r 14d08faf1b00 sys/netinet/tcp_var.h
--- a/sys/netinet/tcp_var.h     Thu Jan 02 18:26:03 2014 +0000
+++ b/sys/netinet/tcp_var.h     Thu Jan 02 18:29:01 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_var.h,v 1.171 2013/11/12 09:02:05 kefren Exp $     */
+/*     $NetBSD: tcp_var.h,v 1.172 2014/01/02 18:29:01 pooka Exp $      */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -912,6 +912,7 @@
 void    tcp_drainstub(void);
 void    tcp_established(struct tcpcb *);
 void    tcp_init(void);
+void    tcp_init_common(unsigned);
 #ifdef INET6
 int     tcp6_input(struct mbuf **, int *, int);
 #endif
@@ -935,6 +936,9 @@
 void    tcp6_quench(struct in6pcb *, int);
 #endif
 void    tcp_mtudisc(struct inpcb *, int);
+#ifdef INET6
+void    tcp6_mtudisc_callback(struct in6_addr *);
+#endif
 
 void   tcpipqent_init(void);
 struct ipqent *tcpipqent_alloc(void);
@@ -948,7 +952,8 @@
 int     tcp_signature_compute(struct mbuf *, struct tcphdr *, int, int,
            int, u_char *, u_int);
 #endif
-void    tcp_slowtimo(void);
+void    tcp_slowtimo(void *);
+extern callout_t tcp_slowtimo_ch;
 void    tcp_fasttimo(void);
 struct mbuf *
         tcp_template(struct tcpcb *);
diff -r 420b90033d12 -r 14d08faf1b00 sys/netinet/udp_usrreq.c
--- a/sys/netinet/udp_usrreq.c  Thu Jan 02 18:26:03 2014 +0000
+++ b/sys/netinet/udp_usrreq.c  Thu Jan 02 18:29:01 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: udp_usrreq.c,v 1.191 2013/11/23 14:20:21 christos Exp $        */
+/*     $NetBSD: udp_usrreq.c,v 1.192 2014/01/02 18:29:01 pooka Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 



Home | Main Index | Thread Index | Old Index