提交 04afd8b2 编写于 作者: A Al Viro 提交者: David S. Miller

[SCTP]: Beginning of sin_port fixes.

That's going to be a long series.  Introduced temporary helpers
doing copy-and-convert for sctp_addr; they are used to kill
flip-in-place in global data structures and will be used
to gradually push host-endian uses of sctp_addr out of existence.
Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 dbc16db1
...@@ -74,6 +74,28 @@ union sctp_addr { ...@@ -74,6 +74,28 @@ union sctp_addr {
struct sockaddr sa; struct sockaddr sa;
}; };
static inline void flip_to_n(union sctp_addr *to, const union sctp_addr *from)
{
size_t len;
if (from->sa.sa_family == AF_INET6)
len = sizeof(struct sockaddr_in6);
else
len = sizeof(struct sockaddr);
memcpy(to, from, len);
to->v4.sin_port = htons(from->v4.sin_port);
}
static inline void flip_to_h(union sctp_addr *to, const union sctp_addr *from)
{
size_t len;
if (from->sa.sa_family == AF_INET6)
len = sizeof(struct sockaddr_in6);
else
len = sizeof(struct sockaddr);
memcpy(to, from, len);
to->v4.sin_port = ntohs(from->v4.sin_port);
}
/* Forward declarations for data structures. */ /* Forward declarations for data structures. */
struct sctp_globals; struct sctp_globals;
struct sctp_endpoint; struct sctp_endpoint;
......
...@@ -228,12 +228,12 @@ static struct sctp_transport *sctp_addr_id2transport(struct sock *sk, ...@@ -228,12 +228,12 @@ static struct sctp_transport *sctp_addr_id2transport(struct sock *sk,
struct sctp_association *addr_asoc = NULL, *id_asoc = NULL; struct sctp_association *addr_asoc = NULL, *id_asoc = NULL;
struct sctp_transport *transport; struct sctp_transport *transport;
union sctp_addr *laddr = (union sctp_addr *)addr; union sctp_addr *laddr = (union sctp_addr *)addr;
union sctp_addr tmp;
laddr->v4.sin_port = ntohs(laddr->v4.sin_port); flip_to_h(&tmp, laddr);
addr_asoc = sctp_endpoint_lookup_assoc(sctp_sk(sk)->ep, addr_asoc = sctp_endpoint_lookup_assoc(sctp_sk(sk)->ep,
(union sctp_addr *)addr, &tmp,
&transport); &transport);
laddr->v4.sin_port = htons(laddr->v4.sin_port);
if (!addr_asoc) if (!addr_asoc)
return NULL; return NULL;
...@@ -313,6 +313,7 @@ SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len) ...@@ -313,6 +313,7 @@ SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
struct sctp_af *af; struct sctp_af *af;
unsigned short snum; unsigned short snum;
int ret = 0; int ret = 0;
union sctp_addr tmp;
/* Common sockaddr verification. */ /* Common sockaddr verification. */
af = sctp_sockaddr_af(sp, addr, len); af = sctp_sockaddr_af(sp, addr, len);
...@@ -368,9 +369,8 @@ SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len) ...@@ -368,9 +369,8 @@ SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
sctp_write_lock(&ep->base.addr_lock); sctp_write_lock(&ep->base.addr_lock);
/* Use GFP_ATOMIC since BHs are disabled. */ /* Use GFP_ATOMIC since BHs are disabled. */
addr->v4.sin_port = ntohs(addr->v4.sin_port); flip_to_h(&tmp, addr);
ret = sctp_add_bind_addr(bp, addr, 1, GFP_ATOMIC); ret = sctp_add_bind_addr(bp, &tmp, 1, GFP_ATOMIC);
addr->v4.sin_port = htons(addr->v4.sin_port);
sctp_write_unlock(&ep->base.addr_lock); sctp_write_unlock(&ep->base.addr_lock);
sctp_local_bh_enable(); sctp_local_bh_enable();
...@@ -4194,12 +4194,8 @@ static int sctp_getsockopt_primary_addr(struct sock *sk, int len, ...@@ -4194,12 +4194,8 @@ static int sctp_getsockopt_primary_addr(struct sock *sk, int len,
if (!asoc->peer.primary_path) if (!asoc->peer.primary_path)
return -ENOTCONN; return -ENOTCONN;
asoc->peer.primary_path->ipaddr.v4.sin_port = flip_to_n((union sctp_addr *)&prim.ssp_addr,
htons(asoc->peer.primary_path->ipaddr.v4.sin_port); &asoc->peer.primary_path->ipaddr);
memcpy(&prim.ssp_addr, &asoc->peer.primary_path->ipaddr,
sizeof(union sctp_addr));
asoc->peer.primary_path->ipaddr.v4.sin_port =
ntohs(asoc->peer.primary_path->ipaddr.v4.sin_port);
sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp,
(union sctp_addr *)&prim.ssp_addr); (union sctp_addr *)&prim.ssp_addr);
...@@ -4642,12 +4638,12 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr) ...@@ -4642,12 +4638,12 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
{ {
struct sctp_bind_hashbucket *head; /* hash list */ struct sctp_bind_hashbucket *head; /* hash list */
struct sctp_bind_bucket *pp; /* hash list port iterator */ struct sctp_bind_bucket *pp; /* hash list port iterator */
union sctp_addr tmp;
unsigned short snum; unsigned short snum;
int ret; int ret;
/* NOTE: Remember to put this back to net order. */ flip_to_h(&tmp, addr);
addr->v4.sin_port = ntohs(addr->v4.sin_port); snum = ntohs(addr->v4.sin_port);
snum = addr->v4.sin_port;
SCTP_DEBUG_PRINTK("sctp_get_port() begins, snum=%d\n", snum); SCTP_DEBUG_PRINTK("sctp_get_port() begins, snum=%d\n", snum);
sctp_local_bh_disable(); sctp_local_bh_disable();
...@@ -4744,7 +4740,7 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr) ...@@ -4744,7 +4740,7 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
if (reuse && sk2->sk_reuse) if (reuse && sk2->sk_reuse)
continue; continue;
if (sctp_bind_addr_match(&ep2->base.bind_addr, addr, if (sctp_bind_addr_match(&ep2->base.bind_addr, &tmp,
sctp_sk(sk))) { sctp_sk(sk))) {
ret = (long)sk2; ret = (long)sk2;
goto fail_unlock; goto fail_unlock;
...@@ -4784,7 +4780,6 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr) ...@@ -4784,7 +4780,6 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
fail: fail:
sctp_local_bh_enable(); sctp_local_bh_enable();
addr->v4.sin_port = htons(addr->v4.sin_port);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册