Give proper prototype to ip_output.

This commit is contained in:
riastradh 2016-01-21 15:27:48 +00:00
parent 93abc59558
commit b41d562bd0
16 changed files with 300 additions and 177 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if.c,v 1.320 2016/01/04 09:08:38 ozaki-r Exp $ */
/* $NetBSD: if.c,v 1.321 2016/01/21 15:27:48 riastradh 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.320 2016/01/04 09:08:38 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.321 2016/01/21 15:27:48 riastradh Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@ -745,7 +745,8 @@ if_detach(struct ifnet *ifp)
#endif
struct domain *dp;
const struct protosw *pr;
int s, i, family, purged;
size_t i;
int s, family, purged;
uint64_t xc;
/*
@ -828,8 +829,9 @@ again:
* ifp->if_addrlist.
*/
purged = 0;
for (pr = dp->dom_protosw;
pr < dp->dom_protoswNPROTOSW; pr++) {
for (i = 0; i < dp->dom_nprotosw; i++) {
pr = dp->dom_protosw[i];
KASSERT(pr != NULL);
so.so_proto = pr;
if (pr->pr_usrreqs) {
(void) (*pr->pr_usrreqs->pr_purgeif)(&so, ifp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: link_proto.c,v 1.28 2015/05/02 17:18:03 rtr Exp $ */
/* $NetBSD: link_proto.c,v 1.29 2016/01/21 15:27:48 riastradh Exp $ */
/*-
* Copyright (c) 1982, 1986, 1993
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: link_proto.c,v 1.28 2015/05/02 17:18:03 rtr Exp $");
__KERNEL_RCSID(0, "$NetBSD: link_proto.c,v 1.29 2016/01/21 15:27:48 riastradh Exp $");
#include <sys/param.h>
#include <sys/socket.h>
@ -98,7 +98,7 @@ static const struct pr_usrreqs link_usrreqs = {
.pr_purgeif = link_purgeif,
};
const struct protosw linksw[] = {
const struct protosw *const linksw[] = {
{ .pr_type = SOCK_DGRAM,
.pr_domain = &linkdomain,
.pr_protocol = 0, /* XXX */
@ -117,7 +117,7 @@ struct domain linkdomain = {
.dom_externalize = NULL,
.dom_dispose = NULL,
.dom_protosw = linksw,
.dom_protoswNPROTOSW = &linksw[__arraycount(linksw)],
.dom_nprotosw = __arraycount(linksw),
.dom_sockaddr_cmp = sockaddr_dl_cmp
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsock.c,v 1.175 2016/01/20 21:43:59 riastradh Exp $ */
/* $NetBSD: rtsock.c,v 1.176 2016/01/21 15:27:48 riastradh Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.175 2016/01/20 21:43:59 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.176 2016/01/21 15:27:48 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -1532,7 +1532,7 @@ static const struct pr_usrreqs route_usrreqs = {
.pr_purgeif = COMPATNAME(route_purgeif_wrapper),
};
static const struct protosw COMPATNAME(route_protosw)[] = {
static const struct protosw *const COMPATNAME(route_protosw)[] = {
{
.pr_type = SOCK_RAW,
.pr_domain = &COMPATNAME(routedomain),
@ -1549,8 +1549,7 @@ struct domain COMPATNAME(routedomain) = {
.dom_name = DOMAINNAME,
.dom_init = COMPATNAME(route_init),
.dom_protosw = COMPATNAME(route_protosw),
.dom_protoswNPROTOSW =
&COMPATNAME(route_protosw)[__arraycount(COMPATNAME(route_protosw))],
.dom_nprotosw = __arraycount(COMPATNAME(route_protosw)),
};
static void

View File

@ -1,4 +1,4 @@
/* $NetBSD: at_proto.c,v 1.19 2016/01/20 21:43:59 riastradh Exp $ */
/* $NetBSD: at_proto.c,v 1.20 2016/01/21 15:27:48 riastradh Exp $ */
/*
* Copyright (c) 1990,1991 Regents of The University of Michigan.
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: at_proto.c,v 1.19 2016/01/20 21:43:59 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: at_proto.c,v 1.20 2016/01/21 15:27:48 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -49,8 +49,8 @@ __KERNEL_RCSID(0, "$NetBSD: at_proto.c,v 1.19 2016/01/20 21:43:59 riastradh Exp
DOMAIN_DEFINE(atalkdomain); /* forward declare and add to link set */
const struct protosw atalksw[] = {
{
const struct protosw *const atalksw[] = {
&(const struct protosw) {
.pr_type = SOCK_DGRAM,
.pr_domain = &atalkdomain,
.pr_protocol = ATPROTO_DDP,
@ -67,7 +67,7 @@ struct domain atalkdomain = {
.dom_externalize = NULL,
.dom_dispose = NULL,
.dom_protosw = atalksw,
.dom_protoswNPROTOSW = &atalksw[__arraycount(atalksw)],
.dom_nprotosw = __arraycount(atalksw),
.dom_rtattach = rt_inithead,
.dom_rtoffset = 32,
.dom_maxrtkey = sizeof(struct sockaddr_at),

View File

@ -1,4 +1,4 @@
/* $NetBSD: bt_proto.c,v 1.14 2014/05/19 02:51:24 rmind Exp $ */
/* $NetBSD: bt_proto.c,v 1.15 2016/01/21 15:27:48 riastradh Exp $ */
/*-
* Copyright (c) 2005 Iain Hibbert.
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: bt_proto.c,v 1.14 2014/05/19 02:51:24 rmind Exp $");
__KERNEL_RCSID(0, "$NetBSD: bt_proto.c,v 1.15 2016/01/21 15:27:48 riastradh Exp $");
#include <sys/param.h>
#include <sys/domain.h>
@ -62,8 +62,8 @@ PR_WRAP_CTLOUTPUT(rfcomm_ctloutput)
#define l2cap_ctloutput l2cap_ctloutput_wrapper
#define rfcomm_ctloutput rfcomm_ctloutput_wrapper
static const struct protosw btsw[] = {
{ /* raw HCI commands */
static const struct protosw *const btsw[] = {
&(const struct protosw) { /* raw HCI commands */
.pr_type = SOCK_RAW,
.pr_domain = &btdomain,
.pr_protocol = BTPROTO_HCI,
@ -72,7 +72,7 @@ static const struct protosw btsw[] = {
.pr_ctloutput = hci_ctloutput,
.pr_usrreqs = &hci_usrreqs,
},
{ /* HCI SCO data (audio) */
&(const struct protosw) { /* HCI SCO data (audio) */
.pr_type = SOCK_SEQPACKET,
.pr_domain = &btdomain,
.pr_protocol = BTPROTO_SCO,
@ -80,7 +80,7 @@ static const struct protosw btsw[] = {
.pr_ctloutput = sco_ctloutput,
.pr_usrreqs = &sco_usrreqs,
},
{ /* L2CAP Connection Oriented */
&(const struct protosw) { /* L2CAP Connection Oriented */
.pr_type = SOCK_SEQPACKET,
.pr_domain = &btdomain,
.pr_protocol = BTPROTO_L2CAP,
@ -89,7 +89,7 @@ static const struct protosw btsw[] = {
.pr_usrreqs = &l2cap_usrreqs,
.pr_init = l2cap_init,
},
{ /* RFCOMM */
&(const struct protosw) { /* RFCOMM */
.pr_type = SOCK_STREAM,
.pr_domain = &btdomain,
.pr_protocol = BTPROTO_RFCOMM,
@ -105,7 +105,7 @@ struct domain btdomain = {
.dom_name = "bluetooth",
.dom_init = bt_init,
.dom_protosw = btsw,
.dom_protoswNPROTOSW = &btsw[__arraycount(btsw)],
.dom_nprotosw = __arraycount(btsw),
};
kmutex_t *bt_lock;

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_arp.c,v 1.200 2016/01/20 21:43:59 riastradh Exp $ */
/* $NetBSD: if_arp.c,v 1.201 2016/01/21 15:27:48 riastradh Exp $ */
/*-
* Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.200 2016/01/20 21:43:59 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.201 2016/01/21 15:27:48 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@ -264,8 +264,9 @@ arp_fasttimo(void)
}
}
const struct protosw arpsw[] = {
{ .pr_type = 0,
const struct protosw *const arpsw[] = {
&(const struct protosw) {
.pr_type = 0,
.pr_domain = &arpdomain,
.pr_protocol = 0,
.pr_flags = 0,
@ -284,7 +285,7 @@ struct domain arpdomain = {
.dom_family = PF_ARP,
.dom_name = "arp",
.dom_protosw = arpsw,
.dom_protoswNPROTOSW = &arpsw[__arraycount(arpsw)],
.dom_nprotosw = __arraycount(arpsw),
};
static void sysctl_net_inet_arp_setup(struct sysctllog **);

View File

@ -1,4 +1,4 @@
/* $NetBSD: in_proto.c,v 1.116 2016/01/20 21:43:59 riastradh Exp $ */
/* $NetBSD: in_proto.c,v 1.117 2016/01/21 15:27:48 riastradh 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.116 2016/01/20 21:43:59 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.117 2016/01/21 15:27:48 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_mrouting.h"
@ -196,214 +196,277 @@ PR_WRAP_CTLINPUT(esp4_ctlinput)
#define esp4_ctlinput esp4_ctlinput_wrapper
#endif
const struct protosw inetsw[] = {
{ .pr_domain = &inetdomain,
const struct ipprotosw inetsw[] = {
{
.ippr_protosw = {
.pr_domain = &inetdomain,
.pr_init = ip_init,
.pr_fasttimo = ip_fasttimo,
.pr_slowtimo = ip_slowtimo,
.pr_drain = ip_drainstub,
},
},
{ .pr_type = SOCK_DGRAM,
{
.ippr_protosw = {
.pr_type = SOCK_DGRAM,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_UDP,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
.pr_input = udp_input,
.pr_ctlinput = udp_ctlinput,
.pr_ctloutput = udp_ctloutput,
.pr_usrreqs = &udp_usrreqs,
.pr_init = udp_init,
},
.ippr_input = udp_input,
},
{ .pr_type = SOCK_STREAM,
{
.ippr_protosw = {
.pr_type = SOCK_STREAM,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_TCP,
.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS|PR_PURGEIF,
.pr_input = tcp_input,
.pr_ctlinput = tcp_ctlinput,
.pr_ctloutput = tcp_ctloutput,
.pr_usrreqs = &tcp_usrreqs,
.pr_init = tcp_init,
.pr_fasttimo = tcp_fasttimo,
.pr_drain = tcp_drainstub,
},
.ippr_input = tcp_input,
},
#ifdef DCCP
{ .pr_type = SOCK_CONN_DGRAM,
{
.ippr_protosw = {
.pr_type = SOCK_CONN_DGRAM,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_DCCP,
.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_ATOMIC|PR_LISTEN|PR_ABRTACPTDIS,
.pr_input = dccp_input,
.pr_ctlinput = dccp_ctlinput,
.pr_ctloutput = dccp_ctloutput,
.pr_usrreqs = &dccp_usrreqs,
.pr_init = dccp_init,
},
.ippr_input = dccp_input,
},
#endif
#ifdef SCTP
{ .pr_type = SOCK_DGRAM,
{
.ippr_protosw = {
.pr_type = SOCK_DGRAM,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_SCTP,
.pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
.pr_input = sctp_input,
.pr_ctlinput = sctp_ctlinput,
.pr_ctloutput = sctp_ctloutput,
.pr_usrreqs = &sctp_usrreqs,
.pr_init = sctp_init,
.pr_drain = sctp_drain
},
.ippr_input = sctp_input,
},
{ .pr_type = SOCK_SEQPACKET,
{
.ippr_protosw = {
.pr_type = SOCK_SEQPACKET,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_SCTP,
.pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
.pr_input = sctp_input,
.pr_ctlinput = sctp_ctlinput,
.pr_ctloutput = sctp_ctloutput,
.pr_usrreqs = &sctp_usrreqs,
.pr_drain = sctp_drain
},
.ippr_input = sctp_input,
},
{ .pr_type = SOCK_STREAM,
{
.ippr_protosw = {
.pr_type = SOCK_STREAM,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_SCTP,
.pr_flags = PR_CONNREQUIRED|PR_ADDR_OPT|PR_WANTRCVD|PR_LISTEN,
.pr_input = sctp_input,
.pr_ctlinput = sctp_ctlinput,
.pr_ctloutput = sctp_ctloutput,
.pr_usrreqs = &sctp_usrreqs,
.pr_drain = sctp_drain
},
.ippr_input = sctp_input,
},
#endif /* SCTP */
{ .pr_type = SOCK_RAW,
{
.ippr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_RAW,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
.pr_input = rip_input,
.pr_ctlinput = rip_ctlinput,
.pr_ctloutput = rip_ctloutput,
.pr_usrreqs = &rip_usrreqs,
},
.ippr_input = rip_input,
},
{ .pr_type = SOCK_RAW,
{
.ippr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_ICMP,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
.pr_input = icmp_input,
.pr_ctlinput = rip_ctlinput,
.pr_ctloutput = rip_ctloutput,
.pr_usrreqs = &rip_usrreqs,
.pr_init = icmp_init,
},
.ippr_input = icmp_input,
},
#ifdef GATEWAY
{ .pr_domain = &inetdomain,
{
.ippr_protosw = {
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_IP,
.pr_slowtimo = ipflow_slowtimo,
.pr_init = ipflow_poolinit,
},
},
#endif /* GATEWAY */
#ifdef IPSEC
{ .pr_type = SOCK_RAW,
{
.ippr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_AH,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = ipsec4_common_input,
.pr_ctlinput = ah4_ctlinput,
},
.ippr_input = ipsec4_common_input,
},
{ .pr_type = SOCK_RAW,
{
.ippr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_ESP,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = ipsec4_common_input,
.pr_ctlinput = esp4_ctlinput,
},
.ippr_input = ipsec4_common_input,
},
{ .pr_type = SOCK_RAW,
{
.ippr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_IPCOMP,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = ipsec4_common_input,
},
.ippr_input = ipsec4_common_input,
},
#endif /* IPSEC */
{ .pr_type = SOCK_RAW,
{
.ippr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_IPV4,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
.pr_input = encap4_input,
.pr_ctlinput = rip_ctlinput,
.pr_ctloutput = rip_ctloutput,
.pr_usrreqs = &rip_usrreqs,
.pr_init = encap_init,
},
.ippr_input = encap4_input,
},
#ifdef INET6
{ .pr_type = SOCK_RAW,
{
.ippr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_IPV6,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
.pr_input = encap4_input,
.pr_ctlinput = rip_ctlinput,
.pr_ctloutput = rip_ctloutput,
.pr_usrreqs = &rip_usrreqs,
.pr_init = encap_init,
},
.ippr_input = encap4_input,
},
#endif /* INET6 */
#if NETHERIP > 0
{ .pr_type = SOCK_RAW,
{
.ippr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_ETHERIP,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
.pr_input = ip_etherip_input,
.pr_ctlinput = rip_ctlinput,
.pr_ctloutput = rip_ctloutput,
.pr_usrreqs = &rip_usrreqs,
},
.ippr_inpput = ip_etherip_input,
},
#endif /* NETHERIP > 0 */
#if NCARP > 0
{ .pr_type = SOCK_RAW,
{
.ippr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_CARP,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = carp_proto_input,
.pr_ctloutput = rip_ctloutput,
.pr_usrreqs = &rip_usrreqs,
.pr_init = carp_init,
},
.ippr_input = carp_proto_input,
},
#endif /* NCARP > 0 */
#if NPFSYNC > 0
{ .pr_type = SOCK_RAW,
{
.ippr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_PFSYNC,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = pfsync_input,
.pr_ctloutput = rip_ctloutput,
.pr_usrreqs = &rip_usrreqs,
},
.ippr_input = pfsync_input,
},
#endif /* NPFSYNC > 0 */
{ .pr_type = SOCK_RAW,
{
.ippr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_IGMP,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
.pr_input = igmp_input,
.pr_ctloutput = rip_ctloutput,
.pr_ctlinput = rip_ctlinput,
.pr_usrreqs = &rip_usrreqs,
.pr_fasttimo = igmp_fasttimo,
.pr_slowtimo = igmp_slowtimo,
.pr_init = igmp_init,
},
.ippr_input = igmp_input,
},
#ifdef PIM
{ .pr_type = SOCK_RAW,
{
.ippr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_PIM,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
.pr_input = pim_input,
.pr_ctloutput = rip_ctloutput,
.pr_ctlinput = rip_ctlinput,
.pr_usrreqs = &rip_usrreqs,
},
.ippr_input = pim_input,
},
#endif /* PIM */
/* raw wildcard */
{ .pr_type = SOCK_RAW,
{
.ippr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inetdomain,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
.pr_input = rip_input,
.pr_ctloutput = rip_ctloutput,
.pr_ctlinput = rip_ctlinput,
.pr_usrreqs = &rip_usrreqs,
.pr_init = rip_init,
},
.ippr_input = rip_input,
},
};
@ -414,11 +477,13 @@ const struct sockaddr_in in_any = {
, .sin_addr = {.s_addr = 0 /* INADDR_ANY */}
};
static const struct protosw *inetprotosw[__arraycount(inetsw)];
struct domain inetdomain = {
.dom_family = PF_INET, .dom_name = "internet", .dom_init = NULL,
.dom_externalize = NULL, .dom_dispose = NULL,
.dom_protosw = inetsw,
.dom_protoswNPROTOSW = &inetsw[__arraycount(inetsw)],
.dom_protosw = inetprotosw,
.dom_nprotosw = __arraycount(inetprotosw),
.dom_rtattach = rt_inithead,
.dom_rtoffset = 32,
.dom_maxrtkey = sizeof(struct ip_pack4),

View File

@ -1,4 +1,4 @@
/* $NetBSD: in_proto.h,v 1.2 2005/12/10 23:36:23 elad Exp $ */
/* $NetBSD: in_proto.h,v 1.3 2016/01/21 15:27:48 riastradh Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
@ -34,6 +34,11 @@
#ifndef _NETINET_IN_PROTO_H_
#define _NETINET_IN_PROTO_H_
extern const struct protosw inetsw[];
struct ipprotosw {
struct protosw ippr_protosw;
void (*ippr_input)(struct mbuf *, int, int);
};
extern const struct ipprotosw inetsw[];
#endif /* !_NETINET_IN_PROTO_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_icmp.c,v 1.142 2015/08/31 06:25:15 ozaki-r Exp $ */
/* $NetBSD: ip_icmp.c,v 1.143 2016/01/21 15:27:48 riastradh Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -94,7 +94,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.142 2015/08/31 06:25:15 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.143 2016/01/21 15:27:48 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_ipsec.h"
@ -395,6 +395,7 @@ icmp_input(struct mbuf *m, ...)
void *(*ctlfunc)(int, const struct sockaddr *, void *);
int code;
int hlen;
unsigned char protox;
va_list ap;
struct rtentry *rt;
@ -526,7 +527,8 @@ icmp_input(struct mbuf *m, ...)
printf("deliver to protocol %d\n", icp->icmp_ip.ip_p);
#endif
icmpsrc.sin_addr = icp->icmp_ip.ip_dst;
ctlfunc = inetsw[ip_protox[icp->icmp_ip.ip_p]].pr_ctlinput;
protox = ip_protox[icp->icmp_ip.ip_p];
ctlfunc = inetsw[protox].ippr_protosw.pr_ctlinput;
if (ctlfunc)
(void) (*ctlfunc)(code, sintosa(&icmpsrc),
&icp->icmp_ip);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_input.c,v 1.326 2016/01/08 03:55:39 knakahara Exp $ */
/* $NetBSD: ip_input.c,v 1.327 2016/01/21 15:27:48 riastradh Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -91,7 +91,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.326 2016/01/08 03:55:39 knakahara Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.327 2016/01/21 15:27:48 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -301,24 +301,33 @@ void
ip_init(void)
{
const struct protosw *pr;
const struct ipprotosw *ippr;
size_t i;
in_init();
sysctl_net_inet_ip_setup(NULL);
for (i = 0; i < inetdomain.dom_nprotosw; i++) {
inetdomain.dom_protosw[i] = &inetsw[i].ippr_protosw;
}
pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW);
KASSERT(pr != NULL);
ippr = container_of(pr, struct ipprotosw, ippr_protosw);
ip_pktq = pktq_create(IFQ_MAXLEN, ipintr, NULL);
KASSERT(ip_pktq != NULL);
for (u_int i = 0; i < IPPROTO_MAX; i++) {
ip_protox[i] = pr - inetsw;
for (i = 0; i < IPPROTO_MAX; i++) {
ip_protox[i] = ippr - inetsw;
}
for (pr = inetdomain.dom_protosw;
pr < inetdomain.dom_protoswNPROTOSW; pr++)
for (i = 0; i < inetdomain.dom_nprotosw; i++) {
pr = inetdomain.dom_protosw[i];
ippr = container_of(pr, struct ipprotosw, ippr_protosw);
if (pr->pr_domain->dom_family == PF_INET &&
pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW)
ip_protox[pr->pr_protocol] = pr - inetsw;
ip_protox[pr->pr_protocol] = ippr - inetsw;
}
ip_reass_init();
@ -755,7 +764,8 @@ ours:
* code - like UDP/TCP/raw IP.
*/
if (ipsec_used &&
(inetsw[ip_protox[ip->ip_p]].pr_flags & PR_LASTHDR) != 0) {
((inetsw[ip_protox[ip->ip_p]].ippr_protosw.pr_flags & PR_LASTHDR)
!= 0)) {
SOFTNET_LOCK();
if (ipsec4_input(m, 0) != 0) {
SOFTNET_UNLOCK();
@ -777,7 +787,7 @@ ours:
const int off = hlen, nh = ip->ip_p;
SOFTNET_LOCK();
(*inetsw[ip_protox[nh]].pr_input)(m, off, nh);
(*inetsw[ip_protox[nh]].ippr_input)(m, off, nh);
SOFTNET_UNLOCK();
return;
bad:

View File

@ -1,4 +1,4 @@
/* $NetBSD: raw_ip.c,v 1.154 2016/01/20 22:02:54 riastradh Exp $ */
/* $NetBSD: raw_ip.c,v 1.155 2016/01/21 15:27:48 riastradh Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -65,7 +65,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.154 2016/01/20 22:02:54 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.155 2016/01/21 15:27:48 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -237,7 +237,7 @@ rip_input(struct mbuf *m, ...)
#endif /*IPSEC*/
if (last != NULL)
rip_sbappendaddr(last, ip, sintosa(&ripsrc), hlen, opts, m);
else if (inetsw[ip_protox[ip->ip_p]].pr_input == rip_input) {
else if (inetsw[ip_protox[ip->ip_p]].ippr_input == rip_input) {
uint64_t *ips;
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PROTOCOL,

View File

@ -1,4 +1,4 @@
/* $NetBSD: icmp6.c,v 1.177 2015/09/14 05:34:28 ozaki-r Exp $ */
/* $NetBSD: icmp6.c,v 1.178 2016/01/21 15:27:48 riastradh Exp $ */
/* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */
/*
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.177 2015/09/14 05:34:28 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.178 2016/01/21 15:27:48 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -1060,8 +1060,7 @@ icmp6_notify_error(struct mbuf *m, int off, int icmp6len, int code)
ip6cp.ip6c_cmdarg = (void *)&notifymtu;
}
ctlfunc = (void (*)(int, struct sockaddr *, void *))
(inet6sw[ip6_protox[nxt]].pr_ctlinput);
ctlfunc = (inet6sw[ip6_protox[nxt]].ip6pr_protosw.pr_ctlinput);
if (ctlfunc) {
(void) (*ctlfunc)(code, (struct sockaddr *)&icmp6dst,
&ip6cp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: in6_proto.c,v 1.108 2016/01/20 21:44:00 riastradh Exp $ */
/* $NetBSD: in6_proto.c,v 1.109 2016/01/21 15:27:48 riastradh 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.108 2016/01/20 21:44:00 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.109 2016/01/21 15:27:48 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_gateway.h"
@ -210,205 +210,271 @@ tcp6_init(void)
}
const struct ip6protosw inet6sw[] = {
{ .pr_domain = &inet6domain,
{
.ip6pr_protosw = {
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_IPV6,
.pr_init = ip6_init,
.pr_fasttimo = frag6_fasttimo,
.pr_slowtimo = frag6_slowtimo,
.pr_drain = frag6_drainstub,
},
},
{ .pr_type = SOCK_DGRAM,
{
.ip6pr_protosw = {
.pr_type = SOCK_DGRAM,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_UDP,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
.pr_input = udp6_input,
.pr_ctlinput = udp6_ctlinput,
.pr_ctloutput = udp6_ctloutput,
.pr_usrreqs = &udp6_usrreqs,
.pr_init = udp6_init,
},
.ip6pr_input = udp6_input,
},
{ .pr_type = SOCK_STREAM,
{
.ip6pr_protosw = {
.pr_type = SOCK_STREAM,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_TCP,
.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS|PR_PURGEIF,
.pr_input = tcp6_input,
.pr_ctlinput = tcp6_ctlinput,
.pr_ctloutput = tcp_ctloutput,
.pr_usrreqs = &tcp_usrreqs,
.pr_init = tcp6_init,
.pr_fasttimo = tcp_fasttimo,
.pr_drain = tcp_drainstub,
},
.ip6pr_input = tcp6_input,
},
#ifdef DCCP
{ .pr_type = SOCK_CONN_DGRAM,
{
.ip6pr_protosw = {
.pr_type = SOCK_CONN_DGRAM,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_DCCP,
.pr_flags = PR_CONNREQUIRED|PR_ATOMIC|PR_LISTEN,
.pr_input = dccp6_input,
.pr_ctlinput = dccp6_ctlinput,
.pr_ctloutput = dccp_ctloutput,
.pr_usrreqs = &dccp6_usrreqs,
#ifndef INET
.pr_init = dccp_init,
#endif
},
.ip6pr_input = dccp6_input,
},
#endif /* DCCP */
#ifdef SCTP
{ .pr_type = SOCK_DGRAM,
{
.ip6pr_protosw = {
.pr_type = SOCK_DGRAM,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_SCTP,
.pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
.pr_input = sctp6_input,
.pr_ctlinput = sctp6_ctlinput,
.pr_ctloutput = sctp_ctloutput,
.pr_usrreqs = &sctp6_usrreqs,
.pr_drain = sctp_drain,
},
.ip6pr_input = sctp6_input,
},
{ .pr_type = SOCK_SEQPACKET,
{
.ip6pr_protosw = {
.pr_type = SOCK_SEQPACKET,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_SCTP,
.pr_flags = PR_ADDR_OPT|PR_WANTRCVD,
.pr_input = sctp6_input,
.pr_ctlinput = sctp6_ctlinput,
.pr_ctloutput = sctp_ctloutput,
.pr_drain = sctp_drain,
},
.ip6pr_input = sctp6_input,
},
{ .pr_type = SOCK_STREAM,
{
.ip6pr_protosw = {
.pr_type = SOCK_STREAM,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_SCTP,
.pr_flags = PR_CONNREQUIRED|PR_ADDR_OPT|PR_WANTRCVD|PR_LISTEN,
.pr_input = sctp6_input,
.pr_ctlinput = sctp6_ctlinput,
.pr_ctloutput = sctp_ctloutput,
.pr_drain = sctp_drain,
},
.ip6pr_input = sctp6_input,
},
#endif /* SCTP */
{ .pr_type = SOCK_RAW,
{
.ip6pr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_RAW,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
.pr_input = rip6_input,
.pr_ctlinput = rip6_ctlinput,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreqs = &rip6_usrreqs,
},
.ip6pr_input = rip6_input,
},
#ifdef GATEWAY
{ .pr_domain = &inet6domain,
{
.ip6pr_protosw = {
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_IPV6,
.pr_slowtimo = ip6flow_slowtimo,
.pr_init = ip6flow_poolinit,
},
},
#endif /* GATEWAY */
{ .pr_type = SOCK_RAW,
{
.ip6pr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_ICMPV6,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
.pr_input = icmp6_input,
.pr_ctlinput = rip6_ctlinput,
.pr_ctloutput = icmp6_ctloutput,
.pr_usrreqs = &rip6_usrreqs,
.pr_init = icmp6_init,
},
.ip6pr_input = icmp6_input,
},
{ .pr_type = SOCK_RAW,
{
.ip6pr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_DSTOPTS,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = dest6_input,
},
.ip6pr_input = dest6_input,
},
{ .pr_type = SOCK_RAW,
{
.ip6pr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_ROUTING,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = route6_input,
},
.ip6pr_input = route6_input,
},
{ .pr_type = SOCK_RAW,
{
.ip6pr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_FRAGMENT,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = frag6_input,
},
.ip6pr_input = frag6_input,
},
#ifdef IPSEC
{ .pr_type = SOCK_RAW,
{
.ip6pr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_AH,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = ipsec6_common_input,
.pr_ctlinput = ah6_ctlinput,
},
.ip6pr_input = ipsec6_common_input,
},
{ .pr_type = SOCK_RAW,
{
.ip6pr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_ESP,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = ipsec6_common_input,
.pr_ctlinput = esp6_ctlinput,
},
.ip6pr_input = ipsec6_common_input,
},
{ .pr_type = SOCK_RAW,
{
.ip6pr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_IPCOMP,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = ipsec6_common_input,
},
.ip6pr_input = ipsec6_common_input,
},
#endif /* IPSEC */
#ifdef INET
{ .pr_type = SOCK_RAW,
{
.ip6pr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_IPV4,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
.pr_input = encap6_input,
.pr_ctlinput = encap6_ctlinput,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreqs = &rip6_usrreqs,
.pr_init = encap_init,
},
.ip6pr_input = encap6_input,
},
#endif
{ .pr_type = SOCK_RAW,
{
.ip6pr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_IPV6,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
.pr_input = encap6_input,
.pr_ctlinput = encap6_ctlinput,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreqs = &rip6_usrreqs,
.pr_init = encap_init,
},
.ip6pr_input = encap6_input,
},
#if NETHERIP > 0
{ .pr_type = SOCK_RAW,
{
.ip6pr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_ETHERIP,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
.pr_input = ip6_etherip_input,
.pr_ctlinput = rip6_ctlinput,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreqs = &rip6_usrreqs,
},
.ip6pr_input = ip6_etherip_input,
},
#endif
#if NCARP > 0
{ .pr_type = SOCK_RAW,
{
.ip6pr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_CARP,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = carp6_proto_input,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreqs = &rip6_usrreqs,
},
.ip6pr_input = carp6_proto_input,
},
#endif /* NCARP */
{ .pr_type = SOCK_RAW,
{
.ip6pr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_protocol = IPPROTO_PIM,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
.pr_input = pim6_input,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreqs = &rip6_usrreqs,
.pr_init = pim6_init,
},
.ip6pr_input = pim6_input,
},
/* raw wildcard */
{ .pr_type = SOCK_RAW,
{
.ip6pr_protosw = {
.pr_type = SOCK_RAW,
.pr_domain = &inet6domain,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
.pr_input = rip6_input,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreqs = &rip6_usrreqs,
.pr_init = rip6_init,
},
.ip6pr_input = rip6_input,
},
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip6protosw.h,v 1.23 2016/01/20 21:44:00 riastradh Exp $ */
/* $NetBSD: ip6protosw.h,v 1.24 2016/01/21 15:27:48 riastradh Exp $ */
/* $KAME: ip6protosw.h,v 1.22 2001/02/08 18:02:08 itojun Exp $ */
/*
@ -112,32 +112,8 @@ struct ip6ctlparam {
};
struct ip6protosw {
int pr_type; /* socket type used for */
struct domain *pr_domain; /* domain protocol a member of */
short pr_protocol; /* protocol number */
short pr_flags; /* see below */
/* protocol-protocol hooks */
int (*pr_input) /* input to protocol (from below) */
(struct mbuf **, int *, int);
void *(*pr_ctlinput) /* control input (from below) */
(int, const struct sockaddr *, void *);
int (*pr_ctloutput) /* control output (from above) */
(int, struct socket *, struct sockopt *);
/* user-protocol hook */
const struct pr_usrreqs *pr_usrreqs;
/* utility hooks */
void (*pr_init) /* initialization hook */
(void);
void (*pr_fasttimo) /* fast timeout (200ms) */
(void);
void (*pr_slowtimo) /* slow timeout (500ms) */
(void);
void (*pr_drain) /* flush any excess space possible */
(void);
struct protosw ip6pr_protosw;
int (*ip6pr_input)(struct mbuf **, int *, int);
};
extern const struct ip6protosw inet6sw[];

View File

@ -1,5 +1,5 @@
/* $KAME: sctp6_usrreq.c,v 1.38 2005/08/24 08:08:56 suz Exp $ */
/* $NetBSD: sctp6_usrreq.c,v 1.1 2015/10/13 21:28:35 rjs Exp $ */
/* $NetBSD: sctp6_usrreq.c,v 1.2 2016/01/21 15:27:48 riastradh Exp $ */
/*
* Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
@ -33,7 +33,7 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sctp6_usrreq.c,v 1.1 2015/10/13 21:28:35 rjs Exp $");
__KERNEL_RCSID(0, "$NetBSD: sctp6_usrreq.c,v 1.2 2016/01/21 15:27:48 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -94,8 +94,6 @@ __KERNEL_RCSID(0, "$NetBSD: sctp6_usrreq.c,v 1.1 2015/10/13 21:28:35 rjs Exp $")
#include <net/net_osdep.h>
extern struct protosw inetsw[];
#if defined(HAVE_NRL_INPCB) || defined(__FreeBSD__)
#ifndef in6pcb
#define in6pcb inpcb

View File

@ -1,4 +1,4 @@
/* $NetBSD: ipsec_input.c,v 1.33 2015/03/30 03:51:50 ozaki-r Exp $ */
/* $NetBSD: ipsec_input.c,v 1.34 2016/01/21 15:27:48 riastradh Exp $ */
/* $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/netipsec/ipsec_input.c,v 1.2.4.2 2003/03/28 20:32:53 sam Exp $ */
/* $OpenBSD: ipsec_input.c,v 1.63 2003/02/20 18:35:43 deraadt Exp $ */
@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ipsec_input.c,v 1.33 2015/03/30 03:51:50 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: ipsec_input.c,v 1.34 2016/01/21 15:27:48 riastradh Exp $");
/*
* IPsec input processing.
@ -431,12 +431,12 @@ ipsec4_common_input_cb(struct mbuf *m, struct secasvar *sav,
key_sa_recordxfer(sav, m); /* record data transfer */
if ((inetsw[ip_protox[prot]].pr_flags & PR_LASTHDR) != 0 &&
if ((inetsw[ip_protox[prot]].ippr_proto.pr_flags & PR_LASTHDR) != 0 &&
ipsec4_in_reject(m, NULL)) {
error = EINVAL;
goto bad;
}
(*inetsw[ip_protox[prot]].pr_input)(m, skip, prot);
(*inetsw[ip_protox[prot]].ippr_input)(m, skip, prot);
return 0;
bad:
m_freem(m);