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

This commit is contained in:
pooka 2014-01-02 18:29:01 +00:00
parent 8531f75b5e
commit acb676442c
12 changed files with 126 additions and 77 deletions

View File

@ -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 @@ 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);

View File

@ -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 @@ 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,

View File

@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.252 2013/11/23 14:20:21 christos Exp
#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 @@ 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));
}
/*

View File

@ -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 @@ 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);
}
/*

View File

@ -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 *);

View File

@ -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 <sys/cdefs.h>
__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 <sys/param.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/once.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
@ -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();
}
/*

View File

@ -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);

View File

@ -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 <sys/cdefs.h>
__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,

View File

@ -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

View File

@ -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 <sys/cdefs.h>
__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();
}
/*

View File

@ -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 <sys/cdefs.h>
__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 <sys/param.h>
#include <sys/domain.h>
@ -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);
}

View File

@ -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 <sys/cdefs.h>
__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 <sys/param.h>
#include <sys/domain.h>
@ -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)
{