diff --git a/sys/net/if.c b/sys/net/if.c index b21a126c6ca9..0b6db67811e8 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -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 -__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 @@ if_link_state_change(struct ifnet *ifp, int link_state) * 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 @@ if_link_state_change(struct ifnet *ifp, int link_state) #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 @@ if_down(struct ifnet *ifp) #endif rt_ifmsg(ifp); #ifdef INET6 - in6_if_down(ifp); + if (in6_present) + in6_if_down(ifp); #endif } @@ -1431,7 +1434,8 @@ if_up(struct ifnet *ifp) #endif rt_ifmsg(ifp); #ifdef INET6 - in6_if_up(ifp); + if (in6_present) + in6_if_up(ifp); #endif } @@ -1906,7 +1910,7 @@ ifioctl(struct socket *so, u_long cmd, void *data, struct lwp *l) 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 --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c index 51320b4fa2a7..c8e2f7cfc516 100644 --- a/sys/netinet/in_proto.c +++ b/sys/netinet/in_proto.c @@ -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 -__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 @@ const struct protosw inetsw[] = { .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 --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index af8acb8b94ad..b58e8bca73b9 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -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 -__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 @@ __KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.252 2013/11/23 14:20:21 christos Exp #include #include #include +#include #include #include #include @@ -241,10 +242,7 @@ struct syn_cache_head tcp_syn_cache[TCP_SYN_HASH_SIZE]; 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_rx_mowner = MOWNER_INIT("tcp", "sock rx"); 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 @@ tcp_init(void) 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 --git a/sys/netinet/tcp_timer.c b/sys/netinet/tcp_timer.c index 2f3add11edc8..596479f3b4d2 100644 --- a/sys/netinet/tcp_timer.c +++ b/sys/netinet/tcp_timer.c @@ -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 -__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 @@ tcp_delack(void *arg) * 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 --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 1f2c66b31352..7c6f6ccd83d1 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -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_drain(void); 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 tcp_quench(struct inpcb *, int); 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 @@ void tcp_setpersist(struct tcpcb *); 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 --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index b9494c6239c9..e873052ceee3 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -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 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.191 2013/11/23 14:20:21 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.192 2014/01/02 18:29:01 pooka Exp $"); #include "opt_inet.h" #include "opt_compat_netbsd.h" @@ -73,6 +73,7 @@ __KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.191 2013/11/23 14:20:21 christos Ex #include #include #include +#include #include #include #include @@ -225,24 +226,35 @@ EVCNT_ATTACH_STATIC(udp6_swcsum); static void sysctl_net_inet_udp_setup(struct sysctllog **); -void -udp_init(void) +static int +do_udpinit(void) { - sysctl_net_inet_udp_setup(NULL); - in_pcbinit(&udbtable, udbhashsize, udbhashsize); MOWNER_ATTACH(&udp_tx_mowner); MOWNER_ATTACH(&udp_rx_mowner); MOWNER_ATTACH(&udp_mowner); -#ifdef INET + return 0; +} + +void +udp_init_common(void) +{ + static ONCE_DECL(doudpinit); + + RUN_ONCE(&doudpinit, do_udpinit); +} + +void +udp_init(void) +{ + + sysctl_net_inet_udp_setup(NULL); udpstat_percpu = percpu_alloc(sizeof(uint64_t) * UDP_NSTATS); -#endif -#ifdef INET6 - udp6stat_percpu = percpu_alloc(sizeof(uint64_t) * UDP6_NSTATS); -#endif + + udp_init_common(); } /* diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h index 49c1306772c5..7d1c2f82065e 100644 --- a/sys/netinet/udp_var.h +++ b/sys/netinet/udp_var.h @@ -1,4 +1,4 @@ -/* $NetBSD: udp_var.h,v 1.38 2012/06/22 14:54:35 christos Exp $ */ +/* $NetBSD: udp_var.h,v 1.39 2014/01/02 18:29:01 pooka Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -92,6 +92,7 @@ extern struct inpcbtable udbtable; void *udp_ctlinput(int, const struct sockaddr *, void *); int udp_ctloutput(int, struct socket *, struct sockopt *); void udp_init(void); +void udp_init_common(void); void udp_input(struct mbuf *, ...); int udp_output(struct mbuf *, ...); int udp_sysctl(int *, u_int, void *, size_t *, void *, size_t); diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c index d48fe00fd06d..2ff834439d51 100644 --- a/sys/netinet6/in6_proto.c +++ b/sys/netinet6/in6_proto.c @@ -1,4 +1,4 @@ -/* $NetBSD: in6_proto.c,v 1.99 2013/06/05 19:01:26 christos Exp $ */ +/* $NetBSD: in6_proto.c,v 1.100 2014/01/02 18:29:01 pooka Exp $ */ /* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.99 2013/06/05 19:01:26 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.100 2014/01/02 18:29:01 pooka Exp $"); #include "opt_gateway.h" #include "opt_inet.h" @@ -175,6 +175,15 @@ PR_WRAP_CTLINPUT(esp6_ctlinput) #define esp6_ctlinput esp6_ctlinput_wrapper #endif +static void +tcp6_init(void) +{ + + icmp6_mtudisc_callback_register(tcp6_mtudisc_callback); + + tcp_init_common(sizeof(struct ip6_hdr)); +} + const struct ip6protosw inet6sw[] = { { .pr_domain = &inet6domain, .pr_protocol = IPPROTO_IPV6, @@ -201,12 +210,9 @@ const struct ip6protosw inet6sw[] = { .pr_ctlinput = tcp6_ctlinput, .pr_ctloutput = tcp_ctloutput, .pr_usrreq = tcp_usrreq, -#ifndef INET /* don't call initialization and timeout routines twice */ - .pr_init = tcp_init, + .pr_init = tcp6_init, .pr_fasttimo = tcp_fasttimo, - .pr_slowtimo = tcp_slowtimo, .pr_drain = tcp_drainstub, -#endif }, { .pr_type = SOCK_RAW, .pr_domain = &inet6domain, @@ -354,9 +360,17 @@ static const struct sockaddr_in6 in6_any = { , .sin6_scope_id = 0 }; +bool in6_present = false; +static void +in6_init(void) +{ + + in6_present = true; +} + struct domain inet6domain = { .dom_family = AF_INET6, .dom_name = "internet6", - .dom_init = NULL, .dom_externalize = NULL, .dom_dispose = NULL, + .dom_init = in6_init, .dom_externalize = NULL, .dom_dispose = NULL, .dom_protosw = (const struct protosw *)inet6sw, .dom_protoswNPROTOSW = (const struct protosw *)&inet6sw[sizeof(inet6sw)/sizeof(inet6sw[0])], .dom_rtattach = rt_inithead, diff --git a/sys/netinet6/in6_var.h b/sys/netinet6/in6_var.h index c5017679cae7..6d7ae83594db 100644 --- a/sys/netinet6/in6_var.h +++ b/sys/netinet6/in6_var.h @@ -1,4 +1,4 @@ -/* $NetBSD: in6_var.h,v 1.66 2012/10/11 20:05:50 christos Exp $ */ +/* $NetBSD: in6_var.h,v 1.67 2014/01/02 18:29:01 pooka Exp $ */ /* $KAME: in6_var.h,v 1.81 2002/06/08 11:16:51 itojun Exp $ */ /* @@ -493,6 +493,7 @@ extern struct ifqueue ip6intrq; /* IP6 packet input queue */ extern const struct in6_addr zeroin6_addr; extern const u_char inet6ctlerrmap[]; extern unsigned long in6_maxmtu; +extern bool in6_present; /* * Macro for finding the internet address structure (in6_ifaddr) corresponding diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c index 0df70b43a968..d6642d5ec93a 100644 --- a/sys/netinet6/udp6_usrreq.c +++ b/sys/netinet6/udp6_usrreq.c @@ -1,4 +1,4 @@ -/* $NetBSD: udp6_usrreq.c,v 1.91 2012/06/22 14:54:35 christos Exp $ */ +/* $NetBSD: udp6_usrreq.c,v 1.92 2014/01/02 18:29:01 pooka Exp $ */ /* $KAME: udp6_usrreq.c,v 1.86 2001/05/27 17:33:00 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.91 2012/06/22 14:54:35 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.92 2014/01/02 18:29:01 pooka Exp $"); #include "opt_inet.h" @@ -123,6 +123,9 @@ udp6_init(void) { sysctl_net_inet6_udp6_setup(NULL); + udp6stat_percpu = percpu_alloc(sizeof(uint64_t) * UDP6_NSTATS); + + udp_init_common(); } /* diff --git a/sys/rump/net/lib/libnetinet/component.c b/sys/rump/net/lib/libnetinet/component.c index f93b5f525839..6365c8a6b6ec 100644 --- a/sys/rump/net/lib/libnetinet/component.c +++ b/sys/rump/net/lib/libnetinet/component.c @@ -1,4 +1,4 @@ -/* $NetBSD: component.c,v 1.8 2013/08/14 09:55:05 pooka Exp $ */ +/* $NetBSD: component.c,v 1.9 2014/01/02 18:29:01 pooka Exp $ */ /* * Copyright (c) 2009 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: component.c,v 1.8 2013/08/14 09:55:05 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: component.c,v 1.9 2014/01/02 18:29:01 pooka Exp $"); #include #include @@ -46,11 +46,10 @@ int carpattach(int); RUMP_COMPONENT(RUMP_COMPONENT_NET) { - extern struct domain arpdomain, inetdomain, inet6domain; + extern struct domain arpdomain, inetdomain; DOMAINADD(arpdomain); DOMAINADD(inetdomain); - DOMAINADD(inet6domain); carpattach(1); } diff --git a/sys/rump/net/lib/libnetinet6/component.c b/sys/rump/net/lib/libnetinet6/component.c index 77846b8f8c60..f7aa371701e9 100644 --- a/sys/rump/net/lib/libnetinet6/component.c +++ b/sys/rump/net/lib/libnetinet6/component.c @@ -1,4 +1,4 @@ -/* $NetBSD: component.c,v 1.2 2013/08/14 09:55:05 pooka Exp $ */ +/* $NetBSD: component.c,v 1.3 2014/01/02 18:29:01 pooka Exp $ */ /* * Copyright (c) 2013 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: component.c,v 1.2 2013/08/14 09:55:05 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: component.c,v 1.3 2014/01/02 18:29:01 pooka Exp $"); #include #include @@ -38,14 +38,12 @@ __KERNEL_RCSID(0, "$NetBSD: component.c,v 1.2 2013/08/14 09:55:05 pooka Exp $"); #include "rump_private.h" #include "rump_net_private.h" -#ifdef notyet RUMP_COMPONENT(RUMP_COMPONENT_NET) { extern struct domain inet6domain; DOMAINADD(inet6domain); } -#endif RUMP_COMPONENT(RUMP_COMPONENT_NET_IFCFG) {