summaryrefslogtreecommitdiffstats
path: root/sys/netinet6
diff options
context:
space:
mode:
authortruckman <truckman@FreeBSD.org>2002-08-21 11:57:12 +0000
committertruckman <truckman@FreeBSD.org>2002-08-21 11:57:12 +0000
commit7199888e8f06576febc8146d51d09b781470e8ce (patch)
tree20c70efb8a65a6f9c615daec57afaba3656fe3cc /sys/netinet6
parent2d2341a634a0d5c812cce6d8552614bd05f799c4 (diff)
downloadFreeBSD-src-7199888e8f06576febc8146d51d09b781470e8ce.zip
FreeBSD-src-7199888e8f06576febc8146d51d09b781470e8ce.tar.gz
Create new functions in_sockaddr(), in6_sockaddr(), and
in6_v4mapsin6_sockaddr() which allocate the appropriate sockaddr_in* structure and initialize it with the address and port information passed as arguments. Use calls to these new functions to replace code that is replicated multiple times in in_setsockaddr(), in_setpeeraddr(), in6_setsockaddr(), in6_setpeeraddr(), in6_mapped_sockaddr(), and in6_mapped_peeraddr(). Inline COMMON_END in tcp_usr_accept() so that we can call in_sockaddr() with temporary copies of the address and port after the PCB is unlocked. Fix the lock violation in tcp6_usr_accept() (caused by calling MALLOC() inside in6_mapped_peeraddr() while the PCB is locked) by changing the implementation of tcp6_usr_accept() to match tcp_usr_accept(). Reviewed by: suz
Diffstat (limited to 'sys/netinet6')
-rw-r--r--sys/netinet6/in6_pcb.c92
-rw-r--r--sys/netinet6/in6_pcb.h4
2 files changed, 58 insertions, 38 deletions
diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c
index 083ed03..2d7baab 100644
--- a/sys/netinet6/in6_pcb.c
+++ b/sys/netinet6/in6_pcb.c
@@ -626,6 +626,50 @@ in6_pcbdetach(inp)
uma_zfree(ipi->ipi_zone, inp);
}
+struct sockaddr *
+in6_sockaddr(port, addr_p)
+ in_port_t port;
+ struct in6_addr *addr_p;
+{
+ struct sockaddr_in6 *sin6;
+
+ MALLOC(sin6, struct sockaddr_in6 *, sizeof *sin6, M_SONAME, M_WAITOK);
+ bzero(sin6, sizeof *sin6);
+ sin6->sin6_family = AF_INET6;
+ sin6->sin6_len = sizeof(*sin6);
+ sin6->sin6_port = port;
+ sin6->sin6_addr = *addr_p;
+ if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
+ sin6->sin6_scope_id = ntohs(sin6->sin6_addr.s6_addr16[1]);
+ else
+ sin6->sin6_scope_id = 0; /*XXX*/
+ if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
+ sin6->sin6_addr.s6_addr16[1] = 0;
+
+ return (struct sockaddr *)sin6;
+}
+
+struct sockaddr *
+in6_v4mapsin6_sockaddr(port, addr_p)
+ in_port_t port;
+ struct in_addr *addr_p;
+{
+ struct sockaddr_in sin;
+ struct sockaddr_in6 *sin6_p;
+
+ bzero(&sin, sizeof sin);
+ sin.sin_family = AF_INET;
+ sin.sin_len = sizeof(sin);
+ sin.sin_port = port;
+ sin.sin_addr = *addr_p;
+
+ MALLOC(sin6_p, struct sockaddr_in6 *, sizeof *sin6_p, M_SONAME,
+ M_WAITOK);
+ in6_sin_2_v4mapsin6(&sin, sin6_p);
+
+ return (struct sockaddr *)sin6_p;
+}
+
/*
* The calling convention of in6_setsockaddr() and in6_setpeeraddr() was
* modified to match the pru_sockaddr() and pru_peeraddr() entry points
@@ -643,34 +687,20 @@ in6_setsockaddr(so, nam)
{
int s;
register struct inpcb *inp;
- register struct sockaddr_in6 *sin6;
-
- /*
- * Do the malloc first in case it blocks.
- */
- MALLOC(sin6, struct sockaddr_in6 *, sizeof *sin6, M_SONAME, M_WAITOK);
- bzero(sin6, sizeof *sin6);
- sin6->sin6_family = AF_INET6;
- sin6->sin6_len = sizeof(*sin6);
+ struct in6_addr addr;
+ in_port_t port;
s = splnet();
inp = sotoinpcb(so);
if (!inp) {
splx(s);
- free(sin6, M_SONAME);
return EINVAL;
}
- sin6->sin6_port = inp->inp_lport;
- sin6->sin6_addr = inp->in6p_laddr;
+ port = inp->inp_lport;
+ addr = inp->in6p_laddr;
splx(s);
- if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
- sin6->sin6_scope_id = ntohs(sin6->sin6_addr.s6_addr16[1]);
- else
- sin6->sin6_scope_id = 0; /*XXX*/
- if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
- sin6->sin6_addr.s6_addr16[1] = 0;
- *nam = (struct sockaddr *)sin6;
+ *nam = in6_sockaddr(port, &addr);
return 0;
}
@@ -681,34 +711,20 @@ in6_setpeeraddr(so, nam)
{
int s;
struct inpcb *inp;
- register struct sockaddr_in6 *sin6;
-
- /*
- * Do the malloc first in case it blocks.
- */
- MALLOC(sin6, struct sockaddr_in6 *, sizeof(*sin6), M_SONAME, M_WAITOK);
- bzero((caddr_t)sin6, sizeof (*sin6));
- sin6->sin6_family = AF_INET6;
- sin6->sin6_len = sizeof(struct sockaddr_in6);
+ struct in6_addr addr;
+ in_port_t port;
s = splnet();
inp = sotoinpcb(so);
if (!inp) {
splx(s);
- free(sin6, M_SONAME);
return EINVAL;
}
- sin6->sin6_port = inp->inp_fport;
- sin6->sin6_addr = inp->in6p_faddr;
+ port = inp->inp_fport;
+ addr = inp->in6p_faddr;
splx(s);
- if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
- sin6->sin6_scope_id = ntohs(sin6->sin6_addr.s6_addr16[1]);
- else
- sin6->sin6_scope_id = 0; /*XXX*/
- if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
- sin6->sin6_addr.s6_addr16[1] = 0;
- *nam = (struct sockaddr *)sin6;
+ *nam = in6_sockaddr(port, &addr);
return 0;
}
diff --git a/sys/netinet6/in6_pcb.h b/sys/netinet6/in6_pcb.h
index 5098a12..6d5c609 100644
--- a/sys/netinet6/in6_pcb.h
+++ b/sys/netinet6/in6_pcb.h
@@ -95,6 +95,10 @@ void in6_pcbnotify __P((struct inpcbhead *, struct sockaddr *,
struct inpcb *(*)(struct inpcb *, int)));
struct inpcb *
in6_rtchange __P((struct inpcb *, int));
+struct sockaddr *
+ in6_sockaddr __P((in_port_t port, struct in6_addr *addr_p));
+struct sockaddr *
+ in6_v4mapsin6_sockaddr __P((in_port_t port, struct in_addr *addr_p));
int in6_setpeeraddr __P((struct socket *so, struct sockaddr **nam));
int in6_setsockaddr __P((struct socket *so, struct sockaddr **nam));
int in6_mapped_sockaddr __P((struct socket *so, struct sockaddr **nam));
OpenPOWER on IntegriCloud