diff options
Diffstat (limited to 'sys/netinet')
-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 |
9 files changed, 132 insertions, 36 deletions
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_ */ |