summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Gross <vgross@cvs.openbsd.org>2016-03-23 15:50:37 +0000
committerVincent Gross <vgross@cvs.openbsd.org>2016-03-23 15:50:37 +0000
commitaa5b36d245eb6e6c6d8c0ef010bfa31e702ee74d (patch)
treec15c2a2e670a7df39180b527363cd5c3622b96ae
parente4c85e46c603d0c49c75020156eecc3b5db53ada (diff)
Merge in_pcbbind() and in6_pcbbind(), and change every call to
in6_pcbbind() into in_pcbbind(). Ok jca@ mpi@
-rw-r--r--sys/netinet/in_pcb.c64
-rw-r--r--sys/netinet/in_pcb.h3
-rw-r--r--sys/netinet/tcp_usrreq.c21
-rw-r--r--sys/netinet/udp_usrreq.c9
-rw-r--r--sys/netinet6/in6_pcb.c61
-rw-r--r--sys/netinet6/ip6_divert.c4
-rw-r--r--sys/netinet6/udp6_output.c4
7 files changed, 58 insertions, 108 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:
diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c
index 66a59f8e618..617150eac6c 100644
--- a/sys/netinet6/in6_pcb.c
+++ b/sys/netinet6/in6_pcb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6_pcb.c,v 1.88 2016/03/21 21:21:35 vgross Exp $ */
+/* $OpenBSD: in6_pcb.c,v 1.89 2016/03/23 15:50:36 vgross Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -150,63 +150,6 @@ u_char inet6ctlerrmap[PRC_NCMDS] = {
};
#endif
-/*
- * Bind an address (or at least a port) to an PF_INET6 socket.
- */
-int
-in6_pcbbind(struct inpcb *inp, struct mbuf *nam, struct proc *p)
-{
- struct socket *so = inp->inp_socket;
-
- struct sockaddr_in6 *sin6;
- u_short lport = 0;
- int wild = INPLOOKUP_IPV6;
- int error;
-
- /*
- * REMINDER: Once up to speed, flow label processing should go here,
- * too. (Same with in6_pcbconnect.)
- */
- if (TAILQ_EMPTY(&in6_ifaddr))
- return EADDRNOTAVAIL;
-
- if (inp->inp_lport != 0 || !IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6))
- return EINVAL; /* If already bound, 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 I did get a sockaddr passed in...
- */
- if (nam) {
- sin6 = mtod(nam, struct sockaddr_in6 *);
- if (nam->m_len != sizeof (*sin6))
- return EINVAL;
-
- /*
- * Unlike v4, I have no qualms about EAFNOSUPPORT if the
- * wretched family is not filled in!
- */
- 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;
- }
-
- if (lport == 0)
- if ((error = in_pcbpickport(&lport, wild, inp, p)))
- return (error);
- inp->inp_lport = lport;
- in_pcbrehash(inp);
- return 0;
-}
-
int
in6_pcbaddrisavail(struct inpcb *inp, struct sockaddr_in6 *sin6, int wild,
struct proc *p)
@@ -371,7 +314,7 @@ in6_pcbconnect(struct inpcb *inp, struct mbuf *nam)
if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) {
if (inp->inp_lport == 0 &&
- in6_pcbbind(inp, NULL, curproc) == EADDRNOTAVAIL)
+ in_pcbbind(inp, NULL, curproc) == EADDRNOTAVAIL)
return (EADDRNOTAVAIL);
inp->inp_laddr6 = *in6a;
}
diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c
index 02dd7fbe8cb..8208b937f5a 100644
--- a/sys/netinet6/ip6_divert.c
+++ b/sys/netinet6/ip6_divert.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_divert.c,v 1.39 2016/03/07 18:44:00 naddy Exp $ */
+/* $OpenBSD: ip6_divert.c,v 1.40 2016/03/23 15:50:36 vgross Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -292,7 +292,7 @@ divert6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr,
case PRU_BIND:
s = splsoftnet();
- error = in6_pcbbind(inp, addr, p);
+ error = in_pcbbind(inp, addr, p);
splx(s);
break;
diff --git a/sys/netinet6/udp6_output.c b/sys/netinet6/udp6_output.c
index a56bdd9a5a1..f9473d8c10f 100644
--- a/sys/netinet6/udp6_output.c
+++ b/sys/netinet6/udp6_output.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: udp6_output.c,v 1.45 2016/03/21 21:21:35 vgross Exp $ */
+/* $OpenBSD: udp6_output.c,v 1.46 2016/03/23 15:50:36 vgross Exp $ */
/* $KAME: udp6_output.c,v 1.21 2001/02/07 11:51:54 itojun Exp $ */
/*
@@ -162,7 +162,7 @@ udp6_output(struct inpcb *in6p, struct mbuf *m, struct mbuf *addr6,
if (in6p->inp_lport == 0){
int s = splsoftnet();
- error = in6_pcbbind(in6p, NULL, p);
+ error = in_pcbbind(in6p, NULL, p);
splx(s);
if (error)
goto release;