summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorclaudio <claudio@openbsd.org>2017-03-13 20:18:21 +0000
committerclaudio <claudio@openbsd.org>2017-03-13 20:18:21 +0000
commit3d7f610ca455928a1a6266ec779dbfc0c033fe19 (patch)
tree38477a0682053bcaa34bd606f2a7d94c05b5153d /sys
parentPrint title="..." in addition to id="..." attributes for macro keys (diff)
downloadwireguard-openbsd-3d7f610ca455928a1a6266ec779dbfc0c033fe19.tar.xz
wireguard-openbsd-3d7f610ca455928a1a6266ec779dbfc0c033fe19.zip
Move PRU_ATTACH out of the pr_usrreq functions into pr_attach.
Attach is quite a different thing to the other PRU functions and this should make locking a bit simpler. This also removes the ugly hack on how proto was passed to the attach function. OK bluhm@ and mpi@ on a previous version
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/uipc_proto.c5
-rw-r--r--sys/kern/uipc_socket.c8
-rw-r--r--sys/kern/uipc_socket2.c5
-rw-r--r--sys/kern/uipc_usrreq.c16
-rw-r--r--sys/net/pfkey.c34
-rw-r--r--sys/net/raw_usrreq.c16
-rw-r--r--sys/net/rtsock.c88
-rw-r--r--sys/netinet/in_proto.c31
-rw-r--r--sys/netinet/ip_divert.c45
-rw-r--r--sys/netinet/ip_divert.h3
-rw-r--r--sys/netinet/ip_var.h3
-rw-r--r--sys/netinet/raw_ip.c45
-rw-r--r--sys/netinet/tcp_usrreq.c30
-rw-r--r--sys/netinet/tcp_var.h4
-rw-r--r--sys/netinet/udp_usrreq.c40
-rw-r--r--sys/netinet/udp_var.h3
-rw-r--r--sys/netinet6/in6_proto.c24
-rw-r--r--sys/netinet6/ip6_divert.c45
-rw-r--r--sys/netinet6/ip6_divert.h3
-rw-r--r--sys/netinet6/ip6_var.h3
-rw-r--r--sys/netinet6/raw_ip6.c67
-rw-r--r--sys/sys/protosw.h7
-rw-r--r--sys/sys/socketvar.h4
-rw-r--r--sys/sys/unpcb.h7
24 files changed, 287 insertions, 249 deletions
diff --git a/sys/kern/uipc_proto.c b/sys/kern/uipc_proto.c
index e1965b3f1e8..1e86120f374 100644
--- a/sys/kern/uipc_proto.c
+++ b/sys/kern/uipc_proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_proto.c,v 1.13 2017/03/02 08:58:24 mpi Exp $ */
+/* $OpenBSD: uipc_proto.c,v 1.14 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: uipc_proto.c,v 1.8 1996/02/13 21:10:47 christos Exp $ */
/*-
@@ -55,6 +55,7 @@ struct protosw unixsw[] = {
.pr_protocol = PF_LOCAL,
.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS,
.pr_usrreq = uipc_usrreq,
+ .pr_attach = uipc_attach,
},
{
.pr_type = SOCK_SEQPACKET,
@@ -62,6 +63,7 @@ struct protosw unixsw[] = {
.pr_protocol = PF_LOCAL,
.pr_flags = PR_ATOMIC|PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS,
.pr_usrreq = uipc_usrreq,
+ .pr_attach = uipc_attach,
},
{
.pr_type = SOCK_DGRAM,
@@ -69,6 +71,7 @@ struct protosw unixsw[] = {
.pr_protocol = PF_LOCAL,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_RIGHTS,
.pr_usrreq = uipc_usrreq,
+ .pr_attach = uipc_attach,
}
};
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index 93162a4e256..1bb5874d1fa 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket.c,v 1.179 2017/03/07 09:23:27 mpi Exp $ */
+/* $OpenBSD: uipc_socket.c,v 1.180 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */
/*
@@ -119,7 +119,7 @@ socreate(int dom, struct socket **aso, int type, int proto)
prp = pffindproto(dom, proto, type);
else
prp = pffindtype(dom, type);
- if (prp == NULL || prp->pr_usrreq == 0)
+ if (prp == NULL || prp->pr_attach == NULL)
return (EPROTONOSUPPORT);
if (prp->pr_type != type)
return (EPROTOTYPE);
@@ -135,9 +135,9 @@ socreate(int dom, struct socket **aso, int type, int proto)
so->so_egid = p->p_ucred->cr_gid;
so->so_cpid = p->p_p->ps_pid;
so->so_proto = prp;
+
s = solock(so);
- error = (*prp->pr_usrreq)(so, PRU_ATTACH, NULL,
- (struct mbuf *)(long)proto, NULL, p);
+ error = (*prp->pr_attach)(so, proto);
if (error) {
so->so_state |= SS_NOFDREF;
sofree(so);
diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c
index aca06097411..2da9a6a61d6 100644
--- a/sys/kern/uipc_socket2.c
+++ b/sys/kern/uipc_socket2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket2.c,v 1.73 2017/03/07 09:23:27 mpi Exp $ */
+/* $OpenBSD: uipc_socket2.c,v 1.74 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */
/*
@@ -187,8 +187,7 @@ sonewconn(struct socket *head, int connstatus)
so->so_rcv.sb_timeo = head->so_rcv.sb_timeo;
soqinsque(head, so, soqueue);
- if ((*so->so_proto->pr_usrreq)(so, PRU_ATTACH, NULL, NULL, NULL,
- curproc)) {
+ if ((*so->so_proto->pr_attach)(so, 0)) {
(void) soqremque(so, soqueue);
pool_put(&socket_pool, so);
return (NULL);
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index 01fee7121f8..9a6d192ac62 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_usrreq.c,v 1.116 2017/02/14 09:46:21 mpi Exp $ */
+/* $OpenBSD: uipc_usrreq.c,v 1.117 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */
/*
@@ -117,7 +117,7 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
error = EOPNOTSUPP;
goto release;
}
- if (unp == NULL && req != PRU_ATTACH) {
+ if (unp == NULL) {
error = EINVAL;
goto release;
}
@@ -126,14 +126,6 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
switch (req) {
- case PRU_ATTACH:
- if (unp) {
- error = EISCONN;
- break;
- }
- error = unp_attach(so);
- break;
-
case PRU_DETACH:
unp_detach(unp);
break;
@@ -351,11 +343,13 @@ u_long unpdg_recvspace = 4*1024;
int unp_rights; /* file descriptors in flight */
int
-unp_attach(struct socket *so)
+uipc_attach(struct socket *so, int proto)
{
struct unpcb *unp;
int error;
+ if (so->so_pcb)
+ return EISCONN;
if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
switch (so->so_type) {
diff --git a/sys/net/pfkey.c b/sys/net/pfkey.c
index 3dfcfad0412..0f77d2d8654 100644
--- a/sys/net/pfkey.c
+++ b/sys/net/pfkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkey.c,v 1.39 2017/03/03 15:48:02 bluhm Exp $ */
+/* $OpenBSD: pfkey.c,v 1.40 2017/03/13 20:18:21 claudio Exp $ */
/*
* @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
@@ -189,31 +189,39 @@ ret:
return (error);
}
-static int
-pfkey_attach(struct socket *socket, struct mbuf *proto, struct proc *p)
+int
+pfkey_attach(struct socket *so, int proto)
{
int rval;
- if (!(socket->so_pcb = malloc(sizeof(struct rawcb),
+ if ((so->so_state & SS_PRIV) == 0)
+ return EACCES;
+
+ if ((so->so_proto->pr_protocol > PFKEY_PROTOCOL_MAX) ||
+ (so->so_proto->pr_protocol < 0) ||
+ !pfkey_versions[so->so_proto->pr_protocol])
+ return (EPROTONOSUPPORT);
+
+ if (!(so->so_pcb = malloc(sizeof(struct rawcb),
M_PCB, M_DONTWAIT | M_ZERO)))
return (ENOMEM);
- rval = raw_usrreq(socket, PRU_ATTACH, NULL, proto, NULL, p);
+ rval = raw_attach(so, so->so_proto->pr_protocol);
if (rval)
goto ret;
- ((struct rawcb *)socket->so_pcb)->rcb_faddr = &pfkey_addr;
- soisconnected(socket);
+ ((struct rawcb *)so->so_pcb)->rcb_faddr = &pfkey_addr;
+ soisconnected(so);
- socket->so_options |= SO_USELOOPBACK;
+ so->so_options |= SO_USELOOPBACK;
if ((rval =
- pfkey_versions[socket->so_proto->pr_protocol]->create(socket)) != 0)
+ pfkey_versions[so->so_proto->pr_protocol]->create(so)) != 0)
goto ret;
return (0);
ret:
- free(socket->so_pcb, M_PCB, sizeof(struct rawcb));
+ free(so->so_pcb, M_PCB, sizeof(struct rawcb));
return (rval);
}
@@ -243,9 +251,6 @@ pfkey_usrreq(struct socket *socket, int req, struct mbuf *mbuf,
return (EPROTONOSUPPORT);
switch (req) {
- case PRU_ATTACH:
- return (pfkey_attach(socket, nam, p));
-
case PRU_DETACH:
return (pfkey_detach(socket, p));
@@ -268,7 +273,8 @@ static struct protosw pfkey_protosw_template = {
.pr_protocol = -1,
.pr_flags = PR_ATOMIC | PR_ADDR,
.pr_output = pfkey_output,
- .pr_usrreq = pfkey_usrreq
+ .pr_usrreq = pfkey_usrreq,
+ .pr_attach = pfkey_attach,
};
int
diff --git a/sys/net/raw_usrreq.c b/sys/net/raw_usrreq.c
index de4b7836a92..cbf137a43af 100644
--- a/sys/net/raw_usrreq.c
+++ b/sys/net/raw_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: raw_usrreq.c,v 1.30 2017/03/07 09:23:27 mpi Exp $ */
+/* $OpenBSD: raw_usrreq.c,v 1.31 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: raw_usrreq.c,v 1.11 1996/02/13 22:00:43 christos Exp $ */
/*
@@ -76,20 +76,6 @@ raw_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
return (EINVAL);
}
switch (req) {
-
- /*
- * Allocate a raw control block and fill in the
- * necessary info to allow packets to be routed to
- * the appropriate raw interface routine.
- */
- case PRU_ATTACH:
- if ((so->so_state & SS_PRIV) == 0) {
- error = EACCES;
- break;
- }
- error = raw_attach(so, (int)(long)nam);
- break;
-
/*
* Destroy state just before socket deallocation.
* Flush data or not depending on the options.
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 62b3d495f19..2887bfd5e8e 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtsock.c,v 1.233 2017/03/09 16:53:20 mpi Exp $ */
+/* $OpenBSD: rtsock.c,v 1.234 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
@@ -166,46 +166,6 @@ route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
rp = sotorawcb(so);
switch (req) {
- case PRU_ATTACH:
- /*
- * use the rawcb but allocate a routecb, this
- * code does not care about the additional fields
- * and works directly on the raw socket.
- */
- rop = malloc(sizeof(struct routecb), M_PCB, M_WAITOK|M_ZERO);
- rp = &rop->rcb;
- so->so_pcb = rp;
- /* Init the timeout structure */
- timeout_set(&rop->timeout, route_senddesync, rp);
- /*
- * Don't call raw_usrreq() in the attach case, because
- * we want to allow non-privileged processes to listen
- * on and send "safe" commands to the routing socket.
- */
- if (curproc == 0)
- error = EACCES;
- else
- error = raw_attach(so, (int)(long)nam);
- if (error) {
- free(rop, M_PCB, sizeof(struct routecb));
- return (error);
- }
- rop->rtableid = curproc->p_p->ps_rtableid;
- af = rp->rcb_proto.sp_protocol;
- if (af == AF_INET)
- route_cb.ip_count++;
- else if (af == AF_INET6)
- route_cb.ip6_count++;
-#ifdef MPLS
- else if (af == AF_MPLS)
- route_cb.mpls_count++;
-#endif
- rp->rcb_faddr = &route_src;
- route_cb.any_count++;
- soisconnected(so);
- so->so_options |= SO_USELOOPBACK;
- break;
-
case PRU_RCVD:
rop = (struct routecb *)rp;
@@ -242,6 +202,51 @@ route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
}
int
+route_attach(struct socket *so, int proto)
+{
+ struct rawcb *rp;
+ struct routecb *rop;
+ int af;
+ int error = 0;
+
+ /*
+ * use the rawcb but allocate a routecb, this
+ * code does not care about the additional fields
+ * and works directly on the raw socket.
+ */
+ rop = malloc(sizeof(struct routecb), M_PCB, M_WAITOK|M_ZERO);
+ rp = &rop->rcb;
+ so->so_pcb = rp;
+ /* Init the timeout structure */
+ timeout_set(&rop->timeout, route_senddesync, rp);
+
+ if (curproc == NULL)
+ error = EACCES;
+ else
+ error = raw_attach(so, proto);
+ if (error) {
+ free(rop, M_PCB, sizeof(struct routecb));
+ return (error);
+ }
+ rop->rtableid = curproc->p_p->ps_rtableid;
+ af = rp->rcb_proto.sp_protocol;
+ if (af == AF_INET)
+ route_cb.ip_count++;
+ else if (af == AF_INET6)
+ route_cb.ip6_count++;
+#ifdef MPLS
+ else if (af == AF_MPLS)
+ route_cb.mpls_count++;
+#endif
+ rp->rcb_faddr = &route_src;
+ route_cb.any_count++;
+ soisconnected(so);
+ so->so_options |= SO_USELOOPBACK;
+
+ return (error);
+}
+
+int
route_ctloutput(int op, struct socket *so, int level, int optname,
struct mbuf *m)
{
@@ -1762,6 +1767,7 @@ struct protosw routesw[] = {
.pr_output = route_output,
.pr_ctloutput = route_ctloutput,
.pr_usrreq = route_usrreq,
+ .pr_attach = route_attach,
.pr_init = raw_init,
.pr_sysctl = sysctl_rtable
}
diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c
index 9ebe465ef4a..5d9f07363fc 100644
--- a/sys/netinet/in_proto.c
+++ b/sys/netinet/in_proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in_proto.c,v 1.75 2017/03/10 07:29:25 jca Exp $ */
+/* $OpenBSD: in_proto.c,v 1.76 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: in_proto.c,v 1.14 1996/02/18 18:58:32 christos Exp $ */
/*
@@ -191,6 +191,7 @@ struct protosw inetsw[] = {
.pr_ctlinput = udp_ctlinput,
.pr_ctloutput = ip_ctloutput,
.pr_usrreq = udp_usrreq,
+ .pr_attach = udp_attach,
.pr_init = udp_init,
.pr_sysctl = udp_sysctl
},
@@ -203,6 +204,7 @@ struct protosw inetsw[] = {
.pr_ctlinput = tcp_ctlinput,
.pr_ctloutput = tcp_ctloutput,
.pr_usrreq = tcp_usrreq,
+ .pr_attach = tcp_attach,
.pr_init = tcp_init,
.pr_slowtimo = tcp_slowtimo,
.pr_sysctl = tcp_sysctl
@@ -215,7 +217,8 @@ struct protosw inetsw[] = {
.pr_input = rip_input,
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = rip_usrreq
+ .pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach
},
{
.pr_type = SOCK_RAW,
@@ -226,6 +229,7 @@ struct protosw inetsw[] = {
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach,
.pr_init = icmp_init,
.pr_sysctl = icmp_sysctl
},
@@ -239,6 +243,7 @@ struct protosw inetsw[] = {
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach,
.pr_sysctl = ipip_sysctl,
.pr_init = ipip_init
},
@@ -251,6 +256,7 @@ struct protosw inetsw[] = {
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach,
.pr_sysctl = etherip_sysctl
},
#ifdef INET6
@@ -261,7 +267,8 @@ struct protosw inetsw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = in_gif_input,
.pr_output = rip_output,
- .pr_usrreq = rip_usrreq /* XXX */
+ .pr_usrreq = rip_usrreq, /* XXX */
+ .pr_attach = rip_attach
},
#endif
#ifdef MPLS
@@ -272,7 +279,8 @@ struct protosw inetsw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = etherip_input,
.pr_output = rip_output,
- .pr_usrreq = rip_usrreq
+ .pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach
},
#endif
#else /* NGIF */
@@ -285,6 +293,7 @@ struct protosw inetsw[] = {
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach,
.pr_sysctl = ipip_sysctl,
.pr_init = ipip_init
},
@@ -297,7 +306,8 @@ struct protosw inetsw[] = {
.pr_input = ip4_input,
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
- .pr_usrreq = rip_usrreq /* XXX */
+ .pr_usrreq = rip_usrreq, /* XXX */
+ .pr_attach = rip_attach
},
#endif
#endif /*NGIF*/
@@ -310,6 +320,7 @@ struct protosw inetsw[] = {
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach,
.pr_init = igmp_init,
.pr_fasttimo = igmp_fasttimo,
.pr_slowtimo = igmp_slowtimo,
@@ -326,6 +337,7 @@ struct protosw inetsw[] = {
.pr_ctlinput = ah4_ctlinput,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach,
.pr_sysctl = ah_sysctl
},
{
@@ -338,6 +350,7 @@ struct protosw inetsw[] = {
.pr_ctlinput = esp4_ctlinput,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach,
.pr_sysctl = esp_sysctl
},
{
@@ -349,6 +362,7 @@ struct protosw inetsw[] = {
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach,
.pr_sysctl = ipcomp_sysctl
},
#endif /* IPSEC */
@@ -362,6 +376,7 @@ struct protosw inetsw[] = {
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = gre_usrreq,
+ .pr_attach = rip_attach,
.pr_sysctl = gre_sysctl
},
{
@@ -373,6 +388,7 @@ struct protosw inetsw[] = {
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach,
.pr_sysctl = ipmobile_sysctl
},
#endif /* NGRE > 0 */
@@ -386,6 +402,7 @@ struct protosw inetsw[] = {
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach,
.pr_sysctl = carp_sysctl
},
#endif /* NCARP > 0 */
@@ -399,6 +416,7 @@ struct protosw inetsw[] = {
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach,
.pr_sysctl = pfsync_sysctl
},
#endif /* NPFSYNC > 0 */
@@ -410,6 +428,7 @@ struct protosw inetsw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = divert_usrreq,
+ .pr_attach = divert_attach,
.pr_init = divert_init,
.pr_sysctl = divert_sysctl
},
@@ -424,6 +443,7 @@ struct protosw inetsw[] = {
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach,
.pr_sysctl = ip_etherip_sysctl
},
#endif /* NETHERIP */
@@ -436,6 +456,7 @@ struct protosw inetsw[] = {
.pr_output = rip_output,
.pr_ctloutput = rip_ctloutput,
.pr_usrreq = rip_usrreq,
+ .pr_attach = rip_attach,
.pr_init = rip_init
}
};
diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c
index 7c4c247de66..ffa0b3b0e2c 100644
--- a/sys/netinet/ip_divert.c
+++ b/sys/netinet/ip_divert.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_divert.c,v 1.44 2017/02/09 15:32:56 jca Exp $ */
+/* $OpenBSD: ip_divert.c,v 1.45 2017/03/13 20:18:21 claudio Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -249,31 +249,12 @@ divert_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr,
return (in_control(so, (u_long)m, (caddr_t)addr,
(struct ifnet *)control));
}
- if (inp == NULL && req != PRU_ATTACH) {
+ if (inp == NULL) {
error = EINVAL;
goto release;
}
switch (req) {
- case PRU_ATTACH:
- if (inp != NULL) {
- error = EINVAL;
- break;
- }
- if ((so->so_state & SS_PRIV) == 0) {
- error = EACCES;
- break;
- }
- error = in_pcballoc(so, &divbtable);
- if (error)
- break;
-
- error = soreserve(so, divert_sendspace, divert_recvspace);
- if (error)
- break;
- sotoinpcb(so)->inp_flags |= INP_HDRINCL;
- break;
-
case PRU_DETACH:
in_pcbdetach(inp);
break;
@@ -333,6 +314,28 @@ release:
}
int
+divert_attach(struct socket *so, int proto)
+{
+ int error;
+
+ if (so->so_pcb != NULL)
+ return EINVAL;
+ if ((so->so_state & SS_PRIV) == 0)
+ return EACCES;
+
+ error = in_pcballoc(so, &divbtable);
+ if (error)
+ return error;
+
+ error = soreserve(so, divert_sendspace, divert_recvspace);
+ if (error)
+ return error;
+
+ sotoinpcb(so)->inp_flags |= INP_HDRINCL;
+ return (0);
+}
+
+int
divert_sysctl_divstat(void *oldp, size_t *oldlenp, void *newp)
{
uint64_t counters[divs_ncounters];
diff --git a/sys/netinet/ip_divert.h b/sys/netinet/ip_divert.h
index 7706feab5df..6ba83e6a553 100644
--- a/sys/netinet/ip_divert.h
+++ b/sys/netinet/ip_divert.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_divert.h,v 1.8 2017/02/09 15:32:56 jca Exp $ */
+/* $OpenBSD: ip_divert.h,v 1.9 2017/03/13 20:18:21 claudio Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -78,6 +78,7 @@ int divert_packet(struct mbuf *, int, u_int16_t);
int divert_sysctl(int *, u_int, void *, size_t *, void *, size_t);
int divert_usrreq(struct socket *,
int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
+int divert_attach(struct socket *, int);
#endif /* _KERNEL */
#endif /* _IP_DIVERT_H_ */
diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h
index 2f3d791c52a..d47b672c961 100644
--- a/sys/netinet/ip_var.h
+++ b/sys/netinet/ip_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_var.h,v 1.69 2017/03/03 15:48:02 bluhm Exp $ */
+/* $OpenBSD: ip_var.h,v 1.70 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */
/*
@@ -257,6 +257,7 @@ int rip_output(struct mbuf *, struct socket *, struct sockaddr *,
struct mbuf *);
int rip_usrreq(struct socket *,
int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
+int rip_attach(struct socket *, int);
#endif /* _KERNEL */
#endif /* _NETINET_IP_VAR_H_ */
diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c
index 7c8dc5625aa..90236833f70 100644
--- a/sys/netinet/raw_ip.c
+++ b/sys/netinet/raw_ip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: raw_ip.c,v 1.96 2017/03/03 15:48:02 bluhm Exp $ */
+/* $OpenBSD: raw_ip.c,v 1.97 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */
/*
@@ -403,32 +403,13 @@ rip_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
return (in_control(so, (u_long)m, (caddr_t)nam,
(struct ifnet *)control));
- if (inp == NULL && req != PRU_ATTACH) {
+ if (inp == NULL) {
error = EINVAL;
goto release;
}
switch (req) {
- case PRU_ATTACH:
- if (inp)
- panic("rip_attach");
- if ((so->so_state & SS_PRIV) == 0) {
- error = EACCES;
- break;
- }
- if ((long)nam < 0 || (long)nam >= IPPROTO_MAX) {
- error = EPROTONOSUPPORT;
- break;
- }
- if ((error = soreserve(so, rip_sendspace, rip_recvspace)) ||
- (error = in_pcballoc(so, &rawcbtable))) {
- break;
- }
- inp = sotoinpcb(so);
- inp->inp_ip.ip_p = (long)nam;
- break;
-
case PRU_DISCONNECT:
if ((so->so_state & SS_ISCONNECTED) == 0) {
error = ENOTCONN;
@@ -564,3 +545,25 @@ release:
m_freem(m);
return (error);
}
+
+int
+rip_attach(struct socket *so, int proto)
+{
+ struct inpcb *inp;
+ int error;
+
+ if (so->so_pcb)
+ panic("rip_attach");
+ if ((so->so_state & SS_PRIV) == 0)
+ return EACCES;
+ if (proto < 0 || proto >= IPPROTO_MAX)
+ return EPROTONOSUPPORT;
+
+ if ((error = soreserve(so, rip_sendspace, rip_recvspace)) ||
+ (error = in_pcballoc(so, &rawcbtable))) {
+ return error;
+ }
+ inp = sotoinpcb(so);
+ inp->inp_ip.ip_p = proto;
+ return 0;
+}
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index c4898de92dd..cf1e088ac72 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcp_usrreq.c,v 1.144 2017/02/09 15:19:32 jca Exp $ */
+/* $OpenBSD: tcp_usrreq.c,v 1.145 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */
/*
@@ -157,7 +157,7 @@ tcp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
* a (struct inpcb) pointed at by the socket, and this
* structure will point at a subsidiary (struct tcpcb).
*/
- if (inp == NULL && req != PRU_ATTACH) {
+ if (inp == NULL) {
error = so->so_error;
if (error == 0)
error = EINVAL;
@@ -184,23 +184,6 @@ tcp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
switch (req) {
/*
- * TCP attaches to socket via PRU_ATTACH, reserving space,
- * and an internet control block.
- */
- case PRU_ATTACH:
- if (inp) {
- error = EISCONN;
- break;
- }
- error = tcp_attach(so);
- if (error)
- break;
- if ((so->so_options & SO_LINGER) && so->so_linger == 0)
- so->so_linger = TCP_LINGERTIME;
- tp = sototcpcb(so);
- break;
-
- /*
* PRU_DETACH detaches the TCP protocol from the socket.
* If the protocol state is non-embryonic, then can't
* do this directly: have to initiate a PRU_DISCONNECT,
@@ -608,12 +591,14 @@ tcp_ctloutput(int op, struct socket *so, int level, int optname,
* bufer space, and entering LISTEN state if to accept connections.
*/
int
-tcp_attach(struct socket *so)
+tcp_attach(struct socket *so, int proto)
{
struct tcpcb *tp;
struct inpcb *inp;
int error;
+ if (so->so_pcb)
+ return EISCONN;
if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0 ||
sbcheckreserve(so->so_snd.sb_wat, tcp_sendspace) ||
sbcheckreserve(so->so_rcv.sb_wat, tcp_recvspace)) {
@@ -645,6 +630,11 @@ tcp_attach(struct socket *so)
#else
tp->pf = PF_INET;
#endif
+ if ((so->so_options & SO_LINGER) && so->so_linger == 0)
+ so->so_linger = TCP_LINGERTIME;
+
+ if (tp && (so->so_options & SO_DEBUG))
+ tcp_trace(TA_USER, 0, tp, (caddr_t)0, 0 /* XXX */, 0);
return (0);
}
diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h
index 2b2184a046d..36f18f647ce 100644
--- a/sys/netinet/tcp_var.h
+++ b/sys/netinet/tcp_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcp_var.h,v 1.122 2017/02/09 15:19:32 jca Exp $ */
+/* $OpenBSD: tcp_var.h,v 1.123 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */
/*
@@ -716,7 +716,6 @@ extern int tcp_syn_use_limit; /* number of uses before reseeding hash */
extern struct syn_cache_set tcp_syn_cache[];
extern int tcp_syn_cache_active; /* active syn cache, may be 0 or 1 */
-int tcp_attach(struct socket *);
void tcp_canceltimers(struct tcpcb *);
struct tcpcb *
tcp_close(struct tcpcb *);
@@ -765,6 +764,7 @@ struct tcpcb *
int tcp_sysctl(int *, u_int, void *, size_t *, void *, size_t);
int tcp_usrreq(struct socket *,
int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
+int tcp_attach(struct socket *, int);
void tcp_xmit_timer(struct tcpcb *, int);
void tcpdropoldhalfopen(struct tcpcb *, u_int16_t);
#ifdef TCP_SACK
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index 4de18ddc0eb..4bf87700c17 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: udp_usrreq.c,v 1.231 2017/02/05 16:23:38 jca Exp $ */
+/* $OpenBSD: udp_usrreq.c,v 1.232 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */
/*
@@ -1115,7 +1115,7 @@ udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr,
}
inp = sotoinpcb(so);
- if (inp == NULL && req != PRU_ATTACH) {
+ if (inp == NULL) {
error = EINVAL;
goto release;
}
@@ -1126,22 +1126,6 @@ udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr,
*/
switch (req) {
- case PRU_ATTACH:
- if (inp != NULL) {
- error = EINVAL;
- break;
- }
- if ((error = soreserve(so, udp_sendspace, udp_recvspace)) ||
- (error = in_pcballoc(so, &udbtable)))
- break;
-#ifdef INET6
- if (sotoinpcb(so)->inp_flags & INP_IPV6)
- sotoinpcb(so)->inp_ipv6.ip6_hlim = ip6_defhlim;
- else
-#endif /* INET6 */
- sotoinpcb(so)->inp_ip.ip_ttl = ip_defttl;
- break;
-
case PRU_DETACH:
in_pcbdetach(inp);
break;
@@ -1307,6 +1291,26 @@ release:
return (error);
}
+int
+udp_attach(struct socket *so, int proto)
+{
+ int error;
+
+ if (so->so_pcb != NULL)
+ return EINVAL;
+
+ if ((error = soreserve(so, udp_sendspace, udp_recvspace)) ||
+ (error = in_pcballoc(so, &udbtable)))
+ return error;
+#ifdef INET6
+ if (sotoinpcb(so)->inp_flags & INP_IPV6)
+ sotoinpcb(so)->inp_ipv6.ip6_hlim = ip6_defhlim;
+ else
+#endif /* INET6 */
+ sotoinpcb(so)->inp_ip.ip_ttl = ip_defttl;
+ return 0;
+}
+
/*
* Sysctl for udp variables.
*/
diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h
index 1194da4c42f..63bbdac98b0 100644
--- a/sys/netinet/udp_var.h
+++ b/sys/netinet/udp_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: udp_var.h,v 1.31 2017/01/29 19:58:47 bluhm Exp $ */
+/* $OpenBSD: udp_var.h,v 1.32 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: udp_var.h,v 1.12 1996/02/13 23:44:41 christos Exp $ */
/*
@@ -149,5 +149,6 @@ int udp6_output(struct inpcb *, struct mbuf *, struct mbuf *,
int udp_sysctl(int *, u_int, void *, size_t *, void *, size_t);
int udp_usrreq(struct socket *,
int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
+int udp_attach(struct socket *, int);
#endif /* _KERNEL */
#endif /* _NETINET_UDP_VAR_H_ */
diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c
index dd3c74713f5..a3699763204 100644
--- a/sys/netinet6/in6_proto.c
+++ b/sys/netinet6/in6_proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6_proto.c,v 1.90 2017/03/02 08:58:24 mpi Exp $ */
+/* $OpenBSD: in6_proto.c,v 1.91 2017/03/13 20:18:21 claudio Exp $ */
/* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */
/*
@@ -139,6 +139,7 @@ struct protosw inet6sw[] = {
.pr_ctlinput = udp6_ctlinput,
.pr_ctloutput = ip6_ctloutput,
.pr_usrreq = udp_usrreq,
+ .pr_attach = udp_attach,
.pr_sysctl = udp_sysctl
},
{
@@ -150,6 +151,7 @@ struct protosw inet6sw[] = {
.pr_ctlinput = tcp6_ctlinput,
.pr_ctloutput = tcp_ctloutput,
.pr_usrreq = tcp_usrreq,
+ .pr_attach = tcp_attach,
.pr_sysctl = tcp_sysctl
},
{
@@ -162,6 +164,7 @@ struct protosw inet6sw[] = {
.pr_ctlinput = rip6_ctlinput,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreq = rip6_usrreq,
+ .pr_attach = rip6_attach,
.pr_sysctl = rip6_sysctl
},
{
@@ -174,6 +177,7 @@ struct protosw inet6sw[] = {
.pr_ctlinput = rip6_ctlinput,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreq = rip6_usrreq,
+ .pr_attach = rip6_attach,
.pr_init = icmp6_init,
.pr_fasttimo = icmp6_fasttimo,
.pr_sysctl = icmp6_sysctl
@@ -209,6 +213,7 @@ struct protosw inet6sw[] = {
.pr_output = rip6_output,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreq = rip6_usrreq,
+ .pr_attach = rip6_attach,
.pr_sysctl = ah_sysctl
},
{
@@ -220,6 +225,7 @@ struct protosw inet6sw[] = {
.pr_output = rip6_output,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreq = rip6_usrreq,
+ .pr_attach = rip6_attach,
.pr_sysctl = esp_sysctl
},
{
@@ -231,6 +237,7 @@ struct protosw inet6sw[] = {
.pr_output = rip6_output,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreq = rip6_usrreq,
+ .pr_attach = rip6_attach,
.pr_sysctl = ipcomp_sysctl
},
#endif /* IPSEC */
@@ -244,6 +251,7 @@ struct protosw inet6sw[] = {
.pr_output = rip6_output,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreq = rip6_usrreq,
+ .pr_attach = rip6_attach,
.pr_sysctl = etherip_sysctl
},
{
@@ -254,7 +262,8 @@ struct protosw inet6sw[] = {
.pr_input = in6_gif_input,
.pr_output = rip6_output,
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq /* XXX */
+ .pr_usrreq = rip6_usrreq, /* XXX */
+ .pr_attach = rip6_attach
},
{
.pr_type = SOCK_RAW,
@@ -264,7 +273,8 @@ struct protosw inet6sw[] = {
.pr_input = in6_gif_input,
.pr_output = rip6_output,
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq /* XXX */
+ .pr_usrreq = rip6_usrreq, /* XXX */
+ .pr_attach = rip6_attach
},
#else /* NGIF */
{
@@ -276,6 +286,7 @@ struct protosw inet6sw[] = {
.pr_output = rip6_output,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreq = rip6_usrreq, /* XXX */
+ .pr_attach = rip6_attach,
.pr_sysctl = ipip_sysctl
},
{
@@ -286,7 +297,8 @@ struct protosw inet6sw[] = {
.pr_input = ip4_input,
.pr_output = rip6_output,
.pr_ctloutput = rip6_ctloutput,
- .pr_usrreq = rip6_usrreq /* XXX */
+ .pr_usrreq = rip6_usrreq, /* XXX */
+ .pr_attach = rip6_attach
},
#endif /* GIF */
#if NCARP > 0
@@ -299,6 +311,7 @@ struct protosw inet6sw[] = {
.pr_output = rip6_output,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreq = rip6_usrreq,
+ .pr_attach = rip6_attach,
.pr_sysctl = carp_sysctl
},
#endif /* NCARP */
@@ -310,6 +323,7 @@ struct protosw inet6sw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreq = divert6_usrreq,
+ .pr_attach = divert6_attach,
.pr_init = divert6_init,
.pr_sysctl = divert6_sysctl
},
@@ -324,6 +338,7 @@ struct protosw inet6sw[] = {
.pr_output = rip6_output,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreq = rip6_usrreq,
+ .pr_attach = rip6_attach,
.pr_sysctl = ip_etherip_sysctl
},
#endif /* NETHERIP */
@@ -336,6 +351,7 @@ struct protosw inet6sw[] = {
.pr_output = rip6_output,
.pr_ctloutput = rip6_ctloutput,
.pr_usrreq = rip6_usrreq,
+ .pr_attach = rip6_attach,
.pr_init = rip6_init
}
};
diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c
index 5585c5b733a..386c4e8cff1 100644
--- a/sys/netinet6/ip6_divert.c
+++ b/sys/netinet6/ip6_divert.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_divert.c,v 1.45 2017/02/09 15:32:56 jca Exp $ */
+/* $OpenBSD: ip6_divert.c,v 1.46 2017/03/13 20:18:21 claudio Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -250,31 +250,12 @@ divert6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr,
return (in6_control(so, (u_long)m, (caddr_t)addr,
(struct ifnet *)control));
}
- if (inp == NULL && req != PRU_ATTACH) {
+ if (inp == NULL) {
error = EINVAL;
goto release;
}
switch (req) {
- case PRU_ATTACH:
- if (inp != NULL) {
- error = EINVAL;
- break;
- }
- if ((so->so_state & SS_PRIV) == 0) {
- error = EACCES;
- break;
- }
- error = in_pcballoc(so, &divb6table);
- if (error)
- break;
-
- error = soreserve(so, divert6_sendspace, divert6_recvspace);
- if (error)
- break;
- sotoinpcb(so)->inp_flags |= INP_HDRINCL;
- break;
-
case PRU_DETACH:
in_pcbdetach(inp);
break;
@@ -334,6 +315,28 @@ release:
}
int
+divert6_attach(struct socket *so, int proto)
+{
+ int error;
+
+ if (so->so_pcb != NULL)
+ return EINVAL;
+
+ if ((so->so_state & SS_PRIV) == 0)
+ return EACCES;
+
+ error = in_pcballoc(so, &divb6table);
+ if (error)
+ return (error);
+
+ error = soreserve(so, divert6_sendspace, divert6_recvspace);
+ if (error)
+ return (error);
+ sotoinpcb(so)->inp_flags |= INP_HDRINCL;
+ return (0);
+}
+
+int
divert6_sysctl_div6stat(void *oldp, size_t *oldlenp, void *newp)
{
uint64_t counters[div6s_ncounters];
diff --git a/sys/netinet6/ip6_divert.h b/sys/netinet6/ip6_divert.h
index 69224648383..a6009214fc7 100644
--- a/sys/netinet6/ip6_divert.h
+++ b/sys/netinet6/ip6_divert.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_divert.h,v 1.6 2017/02/09 15:32:56 jca Exp $ */
+/* $OpenBSD: ip6_divert.h,v 1.7 2017/03/13 20:18:21 claudio Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -78,6 +78,7 @@ int divert6_packet(struct mbuf *, int, u_int16_t);
int divert6_sysctl(int *, u_int, void *, size_t *, void *, size_t);
int divert6_usrreq(struct socket *,
int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
+int divert6_attach(struct socket *, int);
#endif /* _KERNEL */
#endif /* _IP6_DIVERT_H_ */
diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h
index 70c57d70536..2275e76f607 100644
--- a/sys/netinet6/ip6_var.h
+++ b/sys/netinet6/ip6_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_var.h,v 1.70 2017/03/03 15:48:02 bluhm Exp $ */
+/* $OpenBSD: ip6_var.h,v 1.71 2017/03/13 20:18:21 claudio Exp $ */
/* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */
/*
@@ -349,6 +349,7 @@ int rip6_output(struct mbuf *, struct socket *, struct sockaddr *,
struct mbuf *);
int rip6_usrreq(struct socket *,
int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
+int rip6_attach(struct socket *, int);
int rip6_sysctl(int *, u_int, void *, size_t *, void *, size_t);
int dest6_input(struct mbuf **, int *, int);
diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c
index c53e88912c9..e473484dae5 100644
--- a/sys/netinet6/raw_ip6.c
+++ b/sys/netinet6/raw_ip6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: raw_ip6.c,v 1.107 2017/03/03 15:48:02 bluhm Exp $ */
+/* $OpenBSD: raw_ip6.c,v 1.108 2017/03/13 20:18:21 claudio Exp $ */
/* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */
/*
@@ -556,48 +556,14 @@ rip6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
{
struct inpcb *in6p = sotoinpcb(so);
int error = 0;
- int priv;
NET_ASSERT_LOCKED();
- priv = 0;
- if ((so->so_state & SS_PRIV) != 0)
- priv++;
-
if (req == PRU_CONTROL)
return (in6_control(so, (u_long)m, (caddr_t)nam,
(struct ifnet *)control));
switch (req) {
- case PRU_ATTACH:
- if (in6p)
- panic("rip6_attach");
- if (!priv) {
- error = EACCES;
- break;
- }
- if ((long)nam < 0 || (long)nam >= IPPROTO_MAX) {
- error = EPROTONOSUPPORT;
- break;
- }
- if ((error = soreserve(so, rip6_sendspace, rip6_recvspace)) ||
- (error = in_pcballoc(so, &rawin6pcbtable))) {
- break;
- }
- in6p = sotoinpcb(so);
- in6p->inp_ipv6.ip6_nxt = (long)nam;
- in6p->inp_cksum6 = -1;
-
- in6p->inp_icmp6filt = malloc(sizeof(struct icmp6_filter),
- M_PCB, M_NOWAIT);
- if (in6p->inp_icmp6filt == NULL) {
- in_pcbdetach(in6p);
- error = ENOMEM;
- break;
- }
- ICMP6_FILTER_SETPASSALL(in6p->inp_icmp6filt);
- break;
-
case PRU_DISCONNECT:
if ((so->so_state & SS_ISCONNECTED) == 0) {
error = ENOTCONN;
@@ -760,6 +726,37 @@ rip6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
}
int
+rip6_attach(struct socket *so, int proto)
+{
+ struct inpcb *in6p;
+ int error;
+
+ if (so->so_pcb)
+ panic("rip6_attach");
+ if ((so->so_state & SS_PRIV) == 0)
+ return (EACCES);
+ if (proto < 0 || proto >= IPPROTO_MAX)
+ return EPROTONOSUPPORT;
+
+ if ((error = soreserve(so, rip6_sendspace, rip6_recvspace)) ||
+ (error = in_pcballoc(so, &rawin6pcbtable)))
+ return error;
+
+ in6p = sotoinpcb(so);
+ in6p->inp_ipv6.ip6_nxt = proto;
+ in6p->inp_cksum6 = -1;
+
+ in6p->inp_icmp6filt = malloc(sizeof(struct icmp6_filter),
+ M_PCB, M_NOWAIT);
+ if (in6p->inp_icmp6filt == NULL) {
+ in_pcbdetach(in6p);
+ return ENOMEM;
+ }
+ ICMP6_FILTER_SETPASSALL(in6p->inp_icmp6filt);
+ return 0;
+}
+
+int
rip6_sysctl_rip6stat(void *oldp, size_t *oldplen, void *newp)
{
struct rip6stat rip6stat;
diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h
index bf4dca17aae..2b9b66d9899 100644
--- a/sys/sys/protosw.h
+++ b/sys/sys/protosw.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: protosw.h,v 1.23 2017/03/03 15:48:02 bluhm Exp $ */
+/* $OpenBSD: protosw.h,v 1.24 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */
/*-
@@ -83,6 +83,8 @@ struct protosw {
int (*pr_usrreq)(struct socket *, int, struct mbuf *,
struct mbuf *, struct mbuf *, struct proc *);
+ int (*pr_attach)(struct socket *, int);
+
/* utility hooks */
void (*pr_init)(void); /* initialization hook */
void (*pr_fasttimo)(void); /* fast timeout (200ms) */
@@ -121,7 +123,6 @@ struct protosw {
* A non-zero return from usrreq gives an
* UNIX error number which should be passed to higher level software.
*/
-#define PRU_ATTACH 0 /* attach protocol to up */
#define PRU_DETACH 1 /* detach protocol from up */
#define PRU_BIND 2 /* bind socket to address */
#define PRU_LISTEN 3 /* listen for connection */
@@ -149,7 +150,7 @@ struct protosw {
#ifdef PRUREQUESTS
char *prurequests[] = {
- "ATTACH", "DETACH", "BIND", "LISTEN",
+ "", "DETACH", "BIND", "LISTEN",
"CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN",
"RCVD", "SEND", "ABORT", "CONTROL",
"SENSE", "RCVOOB", "SENDOOB", "SOCKADDR",
diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h
index 1dd21b9499d..32967536f53 100644
--- a/sys/sys/socketvar.h
+++ b/sys/sys/socketvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: socketvar.h,v 1.68 2017/02/14 09:46:21 mpi Exp $ */
+/* $OpenBSD: socketvar.h,v 1.69 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */
/*-
@@ -258,8 +258,6 @@ int soo_poll(struct file *fp, int events, struct proc *p);
int soo_kqfilter(struct file *fp, struct knote *kn);
int soo_close(struct file *fp, struct proc *p);
int soo_stat(struct file *, struct stat *, struct proc *);
-int uipc_usrreq(struct socket *, int , struct mbuf *,
- struct mbuf *, struct mbuf *, struct proc *);
void sbappend(struct sockbuf *sb, struct mbuf *m);
void sbappendstream(struct sockbuf *sb, struct mbuf *m);
int sbappendaddr(struct sockbuf *sb, struct sockaddr *asa,
diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h
index 4213297d47a..cae4f5af505 100644
--- a/sys/sys/unpcb.h
+++ b/sys/sys/unpcb.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: unpcb.h,v 1.14 2017/01/27 20:31:42 bluhm Exp $ */
+/* $OpenBSD: unpcb.h,v 1.15 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */
/*
@@ -91,7 +91,10 @@ struct fdpass {
int flags;
};
-int unp_attach(struct socket *);
+int uipc_usrreq(struct socket *, int , struct mbuf *,
+ struct mbuf *, struct mbuf *, struct proc *);
+int uipc_attach(struct socket *, int);
+
int unp_bind(struct unpcb *, struct mbuf *, struct proc *);
int unp_connect(struct socket *, struct mbuf *, struct proc *);
int unp_connect2(struct socket *, struct socket *);