diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/uipc_proto.c | 5 | ||||
-rw-r--r-- | sys/kern/uipc_socket.c | 7 | ||||
-rw-r--r-- | sys/kern/uipc_usrreq.c | 21 | ||||
-rw-r--r-- | sys/net/pfkeyv2.c | 16 | ||||
-rw-r--r-- | sys/net/raw_cb.c | 21 | ||||
-rw-r--r-- | sys/net/raw_cb.h | 5 | ||||
-rw-r--r-- | sys/net/raw_usrreq.c | 10 | ||||
-rw-r--r-- | sys/net/rtsock.c | 45 | ||||
-rw-r--r-- | sys/netinet/in_proto.c | 27 | ||||
-rw-r--r-- | sys/netinet/ip_divert.c | 20 | ||||
-rw-r--r-- | sys/netinet/ip_divert.h | 4 | ||||
-rw-r--r-- | sys/netinet/ip_var.h | 4 | ||||
-rw-r--r-- | sys/netinet/raw_ip.c | 25 | ||||
-rw-r--r-- | sys/netinet/tcp_usrreq.c | 61 | ||||
-rw-r--r-- | sys/netinet/tcp_var.h | 3 | ||||
-rw-r--r-- | sys/netinet/udp_usrreq.c | 21 | ||||
-rw-r--r-- | sys/netinet/udp_var.h | 3 | ||||
-rw-r--r-- | sys/netinet6/in6_proto.c | 18 | ||||
-rw-r--r-- | sys/netinet6/ip6_divert.c | 21 | ||||
-rw-r--r-- | sys/netinet6/ip6_divert.h | 3 | ||||
-rw-r--r-- | sys/netinet6/ip6_var.h | 3 | ||||
-rw-r--r-- | sys/netinet6/raw_ip6.c | 25 | ||||
-rw-r--r-- | sys/sys/protosw.h | 4 | ||||
-rw-r--r-- | sys/sys/unpcb.h | 3 |
24 files changed, 275 insertions, 100 deletions
diff --git a/sys/kern/uipc_proto.c b/sys/kern/uipc_proto.c index 1e86120f374..208359119b7 100644 --- a/sys/kern/uipc_proto.c +++ b/sys/kern/uipc_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_proto.c,v 1.14 2017/03/13 20:18:21 claudio Exp $ */ +/* $OpenBSD: uipc_proto.c,v 1.15 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: uipc_proto.c,v 1.8 1996/02/13 21:10:47 christos Exp $ */ /*- @@ -56,6 +56,7 @@ struct protosw unixsw[] = { .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS, .pr_usrreq = uipc_usrreq, .pr_attach = uipc_attach, + .pr_detach = uipc_detach, }, { .pr_type = SOCK_SEQPACKET, @@ -64,6 +65,7 @@ struct protosw unixsw[] = { .pr_flags = PR_ATOMIC|PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS, .pr_usrreq = uipc_usrreq, .pr_attach = uipc_attach, + .pr_detach = uipc_detach, }, { .pr_type = SOCK_DGRAM, @@ -72,6 +74,7 @@ struct protosw unixsw[] = { .pr_flags = PR_ATOMIC|PR_ADDR|PR_RIGHTS, .pr_usrreq = uipc_usrreq, .pr_attach = uipc_attach, + .pr_detach = uipc_detach, } }; diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 615da029414..ce240b62fe6 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.205 2017/09/15 19:29:28 bluhm Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.206 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -266,8 +266,9 @@ soclose(struct socket *so) } drop: if (so->so_pcb) { - int error2 = (*so->so_proto->pr_usrreq)(so, PRU_DETACH, NULL, - NULL, NULL, curproc); + int error2; + KASSERT(so->so_proto->pr_detach); + error2 = (*so->so_proto->pr_detach)(so); if (error == 0) error = error2; } diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 07e032ca0a3..787287477fe 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.119 2017/08/11 19:53:02 bluhm Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.120 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -126,10 +126,6 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, switch (req) { - case PRU_DETACH: - unp_detach(unp); - break; - case PRU_BIND: error = unp_bind(unp, nam, p); break; @@ -378,6 +374,21 @@ uipc_attach(struct socket *so, int proto) return (0); } +int +uipc_detach(struct socket *so) +{ + struct unpcb *unp = sotounpcb(so); + + if (unp == NULL) + return (EINVAL); + + NET_ASSERT_UNLOCKED(); + + unp_detach(unp); + + return (0); +} + void unp_detach(struct unpcb *unp) { diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c index ac593e4d5f1..9d0194c0570 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.169 2017/10/27 08:27:14 mpi Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.170 2017/11/02 14:01:18 florian Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -159,7 +159,7 @@ static int npromisc = 0; void pfkey_init(void); int pfkeyv2_attach(struct socket *, int); -int pfkeyv2_detach(struct socket *, struct proc *); +int pfkeyv2_detach(struct socket *); int pfkeyv2_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); int pfkeyv2_output(struct mbuf *, struct socket *, struct sockaddr *, @@ -192,6 +192,7 @@ static struct protosw pfkeysw[] = { .pr_output = pfkeyv2_output, .pr_usrreq = pfkeyv2_usrreq, .pr_attach = pfkeyv2_attach, + .pr_detach = pfkeyv2_detach, .pr_sysctl = pfkeyv2_sysctl, } }; @@ -255,7 +256,7 @@ pfkeyv2_attach(struct socket *so, int proto) * Close a PF_KEYv2 socket. */ int -pfkeyv2_detach(struct socket *so, struct proc *p) +pfkeyv2_detach(struct socket *so) { struct keycb *kp; @@ -276,7 +277,7 @@ pfkeyv2_detach(struct socket *so, struct proc *p) mtx_leave(&pfkeyv2_mtx); } - raw_detach(&kp->rcb); + raw_do_detach(&kp->rcb); return (0); } @@ -284,12 +285,7 @@ int pfkeyv2_usrreq(struct socket *so, int req, struct mbuf *mbuf, struct mbuf *nam, struct mbuf *control, struct proc *p) { - switch (req) { - case PRU_DETACH: - return (pfkeyv2_detach(so, p)); - default: - return (raw_usrreq(so, req, mbuf, nam, control, p)); - } + return (raw_usrreq(so, req, mbuf, nam, control, p)); } int diff --git a/sys/net/raw_cb.c b/sys/net/raw_cb.c index e77da50b039..107ccc37964 100644 --- a/sys/net/raw_cb.c +++ b/sys/net/raw_cb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_cb.c,v 1.12 2017/07/03 19:23:47 claudio Exp $ */ +/* $OpenBSD: raw_cb.c,v 1.13 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: raw_cb.c,v 1.9 1996/02/13 22:00:39 christos Exp $ */ /* @@ -76,12 +76,27 @@ raw_attach(struct socket *so, int proto) return (0); } +int +raw_detach(struct socket *so) +{ + struct rawcb *rp = sotorawcb(so); + + soassertlocked(so); + + if (rp == NULL) + return (EINVAL); + + raw_do_detach(rp); + + return (0); +} + /* * Detach the raw connection block and discard * socket resources. */ void -raw_detach(struct rawcb *rp) +raw_do_detach(struct rawcb *rp) { struct socket *so = rp->rcb_socket; @@ -97,5 +112,5 @@ void raw_disconnect(struct rawcb *rp) { if (rp->rcb_socket->so_state & SS_NOFDREF) - raw_detach(rp); + raw_do_detach(rp); } diff --git a/sys/net/raw_cb.h b/sys/net/raw_cb.h index 00c3d30f98a..aba508b1c96 100644 --- a/sys/net/raw_cb.h +++ b/sys/net/raw_cb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_cb.h,v 1.12 2017/07/03 19:23:47 claudio Exp $ */ +/* $OpenBSD: raw_cb.h,v 1.13 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: raw_cb.h,v 1.9 1996/02/13 22:00:41 christos Exp $ */ /* @@ -56,7 +56,8 @@ struct rawcb { #define sotorawcb(so) ((struct rawcb *)(so)->so_pcb) int raw_attach(struct socket *, int); -void raw_detach(struct rawcb *); +int raw_detach(struct socket *); +void raw_do_detach(struct rawcb *); void raw_disconnect(struct rawcb *); void raw_init(void); int raw_usrreq(struct socket *, diff --git a/sys/net/raw_usrreq.c b/sys/net/raw_usrreq.c index d72f242c892..5f1d1c43479 100644 --- a/sys/net/raw_usrreq.c +++ b/sys/net/raw_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_usrreq.c,v 1.32 2017/07/03 19:23:47 claudio Exp $ */ +/* $OpenBSD: raw_usrreq.c,v 1.33 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: raw_usrreq.c,v 1.11 1996/02/13 22:00:43 christos Exp $ */ /* @@ -67,14 +67,6 @@ raw_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, return (EINVAL); } switch (req) { - /* - * Destroy state just before socket deallocation. - * Flush data or not depending on the options. - */ - case PRU_DETACH: - raw_detach(rp); - break; - case PRU_CONNECT: case PRU_BIND: case PRU_CONNECT2: diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index dc77a2411b3..c2adc8d26ce 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.251 2017/10/09 08:35:38 mpi Exp $ */ +/* $OpenBSD: rtsock.c,v 1.252 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -174,7 +174,6 @@ route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct mbuf *control, struct proc *p) { struct routecb *rop; - int af; int error = 0; soassertlocked(so); @@ -198,20 +197,6 @@ route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, rop->flags &= ~ROUTECB_FLAG_FLUSH; break; - case PRU_DETACH: - timeout_del(&rop->timeout); - af = rop->rcb.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 - route_cb.any_count--; - LIST_REMOVE(rop, rcb_list); - /* FALLTHROUGH */ default: error = raw_usrreq(so, req, m, nam, control, p); } @@ -271,6 +256,33 @@ route_attach(struct socket *so, int proto) } int +route_detach(struct socket *so) +{ + struct routecb *rop; + int af; + + soassertlocked(so); + + rop = sotoroutecb(so); + if (rop == NULL) + return (EINVAL); + + timeout_del(&rop->timeout); + af = rop->rcb.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 + route_cb.any_count--; + LIST_REMOVE(rop, rcb_list); + return (raw_detach(so)); +} + +int route_ctloutput(int op, struct socket *so, int level, int optname, struct mbuf *m) { @@ -1922,6 +1934,7 @@ struct protosw routesw[] = { .pr_ctloutput = route_ctloutput, .pr_usrreq = route_usrreq, .pr_attach = route_attach, + .pr_detach = route_detach, .pr_init = route_prinit, .pr_sysctl = sysctl_rtable } diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c index 2c3dbec3ed2..6efbac7da5c 100644 --- a/sys/netinet/in_proto.c +++ b/sys/netinet/in_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_proto.c,v 1.79 2017/05/18 10:56:45 bluhm Exp $ */ +/* $OpenBSD: in_proto.c,v 1.80 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: in_proto.c,v 1.14 1996/02/18 18:58:32 christos Exp $ */ /* @@ -192,6 +192,7 @@ struct protosw inetsw[] = { .pr_ctloutput = ip_ctloutput, .pr_usrreq = udp_usrreq, .pr_attach = udp_attach, + .pr_detach = udp_detach, .pr_init = udp_init, .pr_sysctl = udp_sysctl }, @@ -205,6 +206,7 @@ struct protosw inetsw[] = { .pr_ctloutput = tcp_ctloutput, .pr_usrreq = tcp_usrreq, .pr_attach = tcp_attach, + .pr_detach = tcp_detach, .pr_init = tcp_init, .pr_slowtimo = tcp_slowtimo, .pr_sysctl = tcp_sysctl @@ -217,7 +219,8 @@ struct protosw inetsw[] = { .pr_input = rip_input, .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, - .pr_attach = rip_attach + .pr_attach = rip_attach, + .pr_detach = rip_detach, }, { .pr_type = SOCK_RAW, @@ -228,6 +231,7 @@ struct protosw inetsw[] = { .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_init = icmp_init, .pr_sysctl = icmp_sysctl }, @@ -244,6 +248,7 @@ struct protosw inetsw[] = { .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = ipip_sysctl, .pr_init = ipip_init }, @@ -260,7 +265,8 @@ struct protosw inetsw[] = { #endif .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, /* XXX */ - .pr_attach = rip_attach + .pr_attach = rip_attach, + .pr_detach = rip_detach, }, #endif #if NGIF > 0 @@ -273,6 +279,7 @@ struct protosw inetsw[] = { .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = etherip_sysctl }, #endif /* NGIF */ @@ -284,7 +291,8 @@ struct protosw inetsw[] = { .pr_flags = PR_ATOMIC|PR_ADDR, .pr_input = etherip_input, .pr_usrreq = rip_usrreq, - .pr_attach = rip_attach + .pr_attach = rip_attach, + .pr_detach = rip_detach, }, #endif /* MPLS && GIF */ { @@ -296,6 +304,7 @@ struct protosw inetsw[] = { .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_init = igmp_init, .pr_fasttimo = igmp_fasttimo, .pr_slowtimo = igmp_slowtimo, @@ -312,6 +321,7 @@ struct protosw inetsw[] = { .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = ah_sysctl }, { @@ -324,6 +334,7 @@ struct protosw inetsw[] = { .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = esp_sysctl }, { @@ -335,6 +346,7 @@ struct protosw inetsw[] = { .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = ipcomp_sysctl }, #endif /* IPSEC */ @@ -348,6 +360,7 @@ struct protosw inetsw[] = { .pr_ctloutput = rip_ctloutput, .pr_usrreq = gre_usrreq, .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = gre_sysctl }, { @@ -359,6 +372,7 @@ struct protosw inetsw[] = { .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = ipmobile_sysctl }, #endif /* NGRE > 0 */ @@ -372,6 +386,7 @@ struct protosw inetsw[] = { .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = carp_sysctl }, #endif /* NCARP > 0 */ @@ -385,6 +400,7 @@ struct protosw inetsw[] = { .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = pfsync_sysctl }, #endif /* NPFSYNC > 0 */ @@ -397,6 +413,7 @@ struct protosw inetsw[] = { .pr_ctloutput = rip_ctloutput, .pr_usrreq = divert_usrreq, .pr_attach = divert_attach, + .pr_detach = divert_detach, .pr_init = divert_init, .pr_sysctl = divert_sysctl }, @@ -411,6 +428,7 @@ struct protosw inetsw[] = { .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_sysctl = ip_etherip_sysctl }, #endif /* NETHERIP */ @@ -423,6 +441,7 @@ struct protosw inetsw[] = { .pr_ctloutput = rip_ctloutput, .pr_usrreq = rip_usrreq, .pr_attach = rip_attach, + .pr_detach = rip_detach, .pr_init = rip_init } }; diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 6f1bc3e55ee..1e1c2e200af 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.55 2017/10/09 08:35:38 mpi Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.56 2017/11/02 14:01:18 florian Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -254,10 +254,6 @@ divert_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, } switch (req) { - case PRU_DETACH: - in_pcbdetach(inp); - break; - case PRU_BIND: error = in_pcbbind(inp, addr, p); break; @@ -335,6 +331,20 @@ divert_attach(struct socket *so, int proto) } int +divert_detach(struct socket *so) +{ + struct inpcb *inp = sotoinpcb(so); + + soassertlocked(so); + + if (inp == NULL) + return (EINVAL); + + in_pcbdetach(inp); + 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 31cdc0c09f8..1b47de3d258 100644 --- a/sys/netinet/ip_divert.h +++ b/sys/netinet/ip_divert.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.h,v 1.10 2017/04/14 20:46:31 bluhm Exp $ */ +/* $OpenBSD: ip_divert.h,v 1.11 2017/11/02 14:01:18 florian Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -78,6 +78,6 @@ 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); - +int divert_detach(struct socket *); #endif /* _KERNEL */ #endif /* _IP_DIVERT_H_ */ diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index 23f824b5ed6..26429f9be08 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_var.h,v 1.82 2017/09/05 00:58:16 visa Exp $ */ +/* $OpenBSD: ip_var.h,v 1.83 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */ /* @@ -253,7 +253,7 @@ int rip_output(struct mbuf *, struct socket *, struct sockaddr *, int rip_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); int rip_attach(struct socket *, int); - +int rip_detach(struct socket *); #ifdef MROUTING extern struct socket *ip_mrouter[]; /* multicast routing daemon */ #endif diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 3e4af999eea..775b8a32ed4 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.104 2017/10/06 21:14:55 bluhm Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.105 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -382,10 +382,8 @@ rip_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, /* FALLTHROUGH */ case PRU_ABORT: soisdisconnected(so); - /* FALLTHROUGH */ - case PRU_DETACH: if (inp == NULL) - panic("rip_detach"); + panic("rip_abort"); #ifdef MROUTING if (so == ip_mrouter[inp->inp_rtableid]) ip_mrouter_done(so); @@ -522,3 +520,22 @@ rip_attach(struct socket *so, int proto) inp->inp_ip.ip_p = proto; return 0; } + +int +rip_detach(struct socket *so) +{ + struct inpcb *inp = sotoinpcb(so); + + soassertlocked(so); + + if (inp == NULL) + return (EINVAL); + +#ifdef MROUTING + if (so == ip_mrouter[inp->inp_rtableid]) + ip_mrouter_done(so); +#endif + in_pcbdetach(inp); + + return (0); +} diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index b4333507447..b6ab40112c2 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.158 2017/10/25 12:38:21 job Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.159 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -182,17 +182,6 @@ tcp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, switch (req) { /* - * 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, - * which may finish later; embryonic TCB's can just - * be discarded here. - */ - case PRU_DETACH: - tp = tcp_disconnect(tp); - break; - - /* * Give the socket an address. */ case PRU_BIND: @@ -618,6 +607,54 @@ tcp_attach(struct socket *so, int proto) return (0); } +int +tcp_detach(struct socket *so) +{ + struct inpcb *inp; + struct tcpcb *tp = NULL; + int error = 0; + short ostate; + + soassertlocked(so); + + inp = sotoinpcb(so); + /* + * When a TCP is attached to a socket, then there will be + * a (struct inpcb) pointed at by the socket, and this + * structure will point at a subsidiary (struct tcpcb). + */ + if (inp == NULL) { + error = so->so_error; + if (error == 0) + error = EINVAL; + + return (error); + } + if (inp) { + tp = intotcpcb(inp); + /* tp might get 0 when using socket splicing */ + if (tp == NULL) { + return (0); + } +#ifdef KPROF + tcp_acounts[tp->t_state][req]++; +#endif + ostate = tp->t_state; + } else + ostate = 0; + + /* + * Detache 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, + * which may finish later; embryonic TCB's can just + * be discarded here. + */ + tcp_disconnect(tp); + + return (error); +} + /* * Initiate (or continue) disconnect. * If embryonic state, just send reset (once). diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 54e8aecc262..71bdbb33506 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_var.h,v 1.127 2017/10/25 12:38:21 job Exp $ */ +/* $OpenBSD: tcp_var.h,v 1.128 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */ /* @@ -751,6 +751,7 @@ 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); +int tcp_detach(struct socket *); void tcp_xmit_timer(struct tcpcb *, int); void tcpdropoldhalfopen(struct tcpcb *, u_int16_t); void tcp_sack_option(struct tcpcb *,struct tcphdr *,u_char *,int); diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 95b093bee58..f49f800fca8 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.241 2017/10/09 08:35:38 mpi Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.242 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -1085,10 +1085,6 @@ udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, */ switch (req) { - case PRU_DETACH: - in_pcbdetach(inp); - break; - case PRU_BIND: error = in_pcbbind(inp, addr, p); break; @@ -1270,6 +1266,21 @@ udp_attach(struct socket *so, int proto) return 0; } +int +udp_detach(struct socket *so) +{ + struct inpcb *inp; + + soassertlocked(so); + + inp = sotoinpcb(so); + if (inp == NULL) + return (EINVAL); + + in_pcbdetach(inp); + return (0); +} + /* * Sysctl for udp variables. */ diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h index 7a511e7b05b..8026f935a6c 100644 --- a/sys/netinet/udp_var.h +++ b/sys/netinet/udp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_var.h,v 1.33 2017/04/14 20:46:31 bluhm Exp $ */ +/* $OpenBSD: udp_var.h,v 1.34 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: udp_var.h,v 1.12 1996/02/13 23:44:41 christos Exp $ */ /* @@ -150,5 +150,6 @@ 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); +int udp_detach(struct socket *); #endif /* _KERNEL */ #endif /* _NETINET_UDP_VAR_H_ */ diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c index 2a653e0286e..a112d731163 100644 --- a/sys/netinet6/in6_proto.c +++ b/sys/netinet6/in6_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_proto.c,v 1.95 2017/07/13 17:17:27 florian Exp $ */ +/* $OpenBSD: in6_proto.c,v 1.96 2017/11/02 14:01:18 florian Exp $ */ /* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */ /* @@ -140,6 +140,7 @@ struct protosw inet6sw[] = { .pr_ctloutput = ip6_ctloutput, .pr_usrreq = udp_usrreq, .pr_attach = udp_attach, + .pr_detach = udp_detach, .pr_sysctl = udp_sysctl }, { @@ -152,6 +153,7 @@ struct protosw inet6sw[] = { .pr_ctloutput = tcp_ctloutput, .pr_usrreq = tcp_usrreq, .pr_attach = tcp_attach, + .pr_detach = tcp_detach, .pr_sysctl = tcp_sysctl }, { @@ -164,6 +166,7 @@ struct protosw inet6sw[] = { .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_sysctl = rip6_sysctl }, { @@ -176,6 +179,7 @@ struct protosw inet6sw[] = { .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_init = icmp6_init, .pr_fasttimo = icmp6_fasttimo, .pr_sysctl = icmp6_sysctl @@ -211,6 +215,7 @@ struct protosw inet6sw[] = { .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_sysctl = ah_sysctl }, { @@ -222,6 +227,7 @@ struct protosw inet6sw[] = { .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_sysctl = esp_sysctl }, { @@ -233,6 +239,7 @@ struct protosw inet6sw[] = { .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_sysctl = ipcomp_sysctl }, #endif /* IPSEC */ @@ -248,7 +255,8 @@ struct protosw inet6sw[] = { #endif .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, /* XXX */ - .pr_attach = rip6_attach + .pr_attach = rip6_attach, + .pr_detach = rip6_detach, }, { .pr_type = SOCK_RAW, @@ -263,6 +271,7 @@ struct protosw inet6sw[] = { .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, /* XXX */ .pr_attach = rip6_attach, + .pr_detach = rip6_detach, }, #if NGIF > 0 { @@ -274,6 +283,7 @@ struct protosw inet6sw[] = { .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_sysctl = etherip_sysctl }, #endif /* NGIF */ @@ -287,6 +297,7 @@ struct protosw inet6sw[] = { .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_sysctl = carp_sysctl }, #endif /* NCARP */ @@ -299,6 +310,7 @@ struct protosw inet6sw[] = { .pr_ctloutput = rip6_ctloutput, .pr_usrreq = divert6_usrreq, .pr_attach = divert6_attach, + .pr_detach = divert6_detach, .pr_init = divert6_init, .pr_sysctl = divert6_sysctl }, @@ -313,6 +325,7 @@ struct protosw inet6sw[] = { .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_sysctl = ip_etherip_sysctl }, #endif /* NETHERIP */ @@ -325,6 +338,7 @@ struct protosw inet6sw[] = { .pr_ctloutput = rip6_ctloutput, .pr_usrreq = rip6_usrreq, .pr_attach = rip6_attach, + .pr_detach = rip6_detach, .pr_init = rip6_init } }; diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index 1f20dc64d83..e41e734733c 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.54 2017/10/09 08:35:38 mpi Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.55 2017/11/02 14:01:18 florian Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -257,10 +257,6 @@ divert6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, } switch (req) { - case PRU_DETACH: - in_pcbdetach(inp); - break; - case PRU_BIND: error = in_pcbbind(inp, addr, p); break; @@ -338,6 +334,21 @@ divert6_attach(struct socket *so, int proto) } int +divert6_detach(struct socket *so) +{ + struct inpcb *inp = sotoinpcb(so); + + soassertlocked(so); + + if (inp == NULL) + return (EINVAL); + + in_pcbdetach(inp); + + 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 bbda15b4061..c98a5189136 100644 --- a/sys/netinet6/ip6_divert.h +++ b/sys/netinet6/ip6_divert.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.h,v 1.8 2017/04/14 20:46:31 bluhm Exp $ */ +/* $OpenBSD: ip6_divert.h,v 1.9 2017/11/02 14:01:18 florian Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -78,6 +78,7 @@ 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); +int divert6_detach(struct socket *); #endif /* _KERNEL */ #endif /* _IP6_DIVERT_H_ */ diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h index da11f5a1ee5..09dd373bc3e 100644 --- a/sys/netinet6/ip6_var.h +++ b/sys/netinet6/ip6_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_var.h,v 1.79 2017/10/26 15:39:14 visa Exp $ */ +/* $OpenBSD: ip6_var.h,v 1.80 2017/11/02 14:01:18 florian Exp $ */ /* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */ /* @@ -345,6 +345,7 @@ int rip6_output(struct mbuf *, struct socket *, struct sockaddr *, int rip6_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); int rip6_attach(struct socket *, int); +int rip6_detach(struct socket *); int rip6_sysctl(int *, u_int, void *, size_t *, void *, size_t); int dest6_input(struct mbuf **, int *, int, int); diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index c201852c69e..70461915c2e 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.121 2017/10/08 14:53:25 deraadt Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.122 2017/11/02 14:01:18 florian Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -558,8 +558,6 @@ rip6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, case PRU_ABORT: soisdisconnected(so); - /* FALLTHROUGH */ - case PRU_DETACH: if (in6p == NULL) panic("rip6_detach"); #ifdef MROUTING @@ -716,6 +714,27 @@ rip6_attach(struct socket *so, int proto) } int +rip6_detach(struct socket *so) +{ + struct inpcb *in6p = sotoinpcb(so); + + soassertlocked(so); + + if (in6p == NULL) + panic("rip6_detach"); +#ifdef MROUTING + if (so == ip6_mrouter[in6p->inp_rtableid]) + ip6_mrouter_done(so); +#endif + free(in6p->inp_icmp6filt, M_PCB, sizeof(struct icmp6_filter)); + in6p->inp_icmp6filt = NULL; + + in_pcbdetach(in6p); + + 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 ccb2e004c22..4dd57001f7d 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.25 2017/04/14 20:46:31 bluhm Exp $ */ +/* $OpenBSD: protosw.h,v 1.26 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -84,6 +84,7 @@ struct protosw { struct mbuf *, struct mbuf *, struct proc *); int (*pr_attach)(struct socket *, int); + int (*pr_detach)(struct socket *); /* utility hooks */ void (*pr_init)(void); /* initialization hook */ @@ -123,7 +124,6 @@ struct protosw { * A non-zero return from usrreq gives an * UNIX error number which should be passed to higher level software. */ -#define PRU_DETACH 1 /* detach protocol from up */ #define PRU_BIND 2 /* bind socket to address */ #define PRU_LISTEN 3 /* listen for connection */ #define PRU_CONNECT 4 /* establish connection to peer */ diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h index cae4f5af505..4239c282c63 100644 --- a/sys/sys/unpcb.h +++ b/sys/sys/unpcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unpcb.h,v 1.15 2017/03/13 20:18:21 claudio Exp $ */ +/* $OpenBSD: unpcb.h,v 1.16 2017/11/02 14:01:18 florian Exp $ */ /* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */ /* @@ -94,6 +94,7 @@ struct fdpass { int uipc_usrreq(struct socket *, int , struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); int uipc_attach(struct socket *, int); +int uipc_detach(struct socket *); int unp_bind(struct unpcb *, struct mbuf *, struct proc *); int unp_connect(struct socket *, struct mbuf *, struct proc *); |