diff options
author | Vincent Gross <vgross@cvs.openbsd.org> | 2016-03-23 15:50:37 +0000 |
---|---|---|
committer | Vincent Gross <vgross@cvs.openbsd.org> | 2016-03-23 15:50:37 +0000 |
commit | aa5b36d245eb6e6c6d8c0ef010bfa31e702ee74d (patch) | |
tree | c15c2a2e670a7df39180b527363cd5c3622b96ae /sys/netinet | |
parent | e4c85e46c603d0c49c75020156eecc3b5db53ada (diff) |
Merge in_pcbbind() and in6_pcbbind(), and change every call to
in6_pcbbind() into in_pcbbind().
Ok jca@ mpi@
Diffstat (limited to 'sys/netinet')
-rw-r--r-- | sys/netinet/in_pcb.c | 64 | ||||
-rw-r--r-- | sys/netinet/in_pcb.h | 3 | ||||
-rw-r--r-- | sys/netinet/tcp_usrreq.c | 21 | ||||
-rw-r--r-- | sys/netinet/udp_usrreq.c | 9 |
4 files changed, 52 insertions, 45 deletions
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index fc406998d2d..f485fa39d1c 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.c,v 1.196 2016/03/23 00:07:31 vgross Exp $ */ +/* $OpenBSD: in_pcb.c,v 1.197 2016/03/23 15:50:36 vgross Exp $ */ /* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */ /* @@ -284,35 +284,61 @@ int in_pcbbind(struct inpcb *inp, struct mbuf *nam, struct proc *p) { struct socket *so = inp->inp_socket; - struct sockaddr_in *sin; u_int16_t lport = 0; int wild = 0; int error; -#ifdef INET6 - if (sotopf(so) == PF_INET6) - return in6_pcbbind(inp, nam, p); -#endif /* INET6 */ - - if (inp->inp_lport || inp->inp_laddr.s_addr != INADDR_ANY) + if (inp->inp_lport) return (EINVAL); + if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT)) == 0 && ((so->so_proto->pr_flags & PR_CONNREQUIRED) == 0 || (so->so_options & SO_ACCEPTCONN) == 0)) wild = INPLOOKUP_WILDCARD; + if (nam) { - sin = mtod(nam, struct sockaddr_in *); - if (nam->m_len != sizeof(*sin)) + switch (sotopf(so)) { +#ifdef INET6 + case PF_INET6: { + struct sockaddr_in6 *sin6; + if (TAILQ_EMPTY(&in6_ifaddr)) + return (EADDRNOTAVAIL); + if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) + return (EINVAL); + + sin6 = mtod(nam, struct sockaddr_in6 *); + if (nam->m_len != sizeof(struct sockaddr_in6)) + return (EINVAL); + if (sin6->sin6_family != AF_INET6) + return (EAFNOSUPPORT); + + if ((error = in6_pcbaddrisavail(inp, sin6, wild, p))) + return (error); + inp->inp_laddr6 = sin6->sin6_addr; + lport = sin6->sin6_port; + break; + } +#endif + case PF_INET: { + struct sockaddr_in *sin; + if (inp->inp_laddr.s_addr != INADDR_ANY) + return (EINVAL); + + sin = mtod(nam, struct sockaddr_in *); + if (nam->m_len != sizeof(*sin)) + return (EINVAL); + if (sin->sin_family != AF_INET) + return (EAFNOSUPPORT); + + if ((error = in_pcbaddrisavail(inp, sin, wild, p))) + return (error); + inp->inp_laddr = sin->sin_addr; + lport = sin->sin_port; + break; + } + default: return (EINVAL); - - if (sin->sin_family != AF_INET) - return (EAFNOSUPPORT); - - lport = sin->sin_port; - - if ((error = in_pcbaddrisavail(inp, sin, wild, p))) - return (error); - inp->inp_laddr = sin->sin_addr; + } } if (lport == 0) diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index 71d419a160f..6e7478ca93e 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.h,v 1.95 2016/03/23 00:07:31 vgross Exp $ */ +/* $OpenBSD: in_pcb.h,v 1.96 2016/03/23 15:50:36 vgross Exp $ */ /* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */ /* @@ -263,7 +263,6 @@ struct inpcb * in6_pcblookup_listen(struct inpcbtable *, struct in6_addr *, u_int, int, struct mbuf *, u_int); -int in6_pcbbind(struct inpcb *, struct mbuf *, struct proc *); int in6_pcbaddrisavail(struct inpcb *, struct sockaddr_in6 *, int, struct proc *); int in6_pcbconnect(struct inpcb *, struct mbuf *); diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index c5388a0e2ed..0ece5e179a4 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.128 2015/09/11 07:42:35 claudio Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.129 2016/03/23 15:50:36 vgross Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -220,28 +220,15 @@ tcp_usrreq(so, req, m, nam, control, p) * Give the socket an address. */ case PRU_BIND: -#ifdef INET6 - if (inp->inp_flags & INP_IPV6) - error = in6_pcbbind(inp, nam, p); - else -#endif - error = in_pcbbind(inp, nam, p); - if (error) - break; + error = in_pcbbind(inp, nam, p); break; /* * Prepare to accept connections. */ case PRU_LISTEN: - if (inp->inp_lport == 0) { -#ifdef INET6 - if (inp->inp_flags & INP_IPV6) - error = in6_pcbbind(inp, NULL, p); - else -#endif - error = in_pcbbind(inp, NULL, p); - } + if (inp->inp_lport == 0) + error = in_pcbbind(inp, NULL, p); /* If the in_pcbbind() above is called, the tp->pf should still be whatever it was before. */ if (error == 0) diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index ed6d63d5db8..2db59983d5d 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.209 2016/03/07 18:44:00 naddy Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.210 2016/03/23 15:50:36 vgross Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -1094,12 +1094,7 @@ udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, break; case PRU_BIND: -#ifdef INET6 - if (inp->inp_flags & INP_IPV6) - error = in6_pcbbind(inp, addr, p); - else -#endif - error = in_pcbbind(inp, addr, p); + error = in_pcbbind(inp, addr, p); break; case PRU_LISTEN: |