Skip to content

Commit

Permalink
[SCTP]: Switch sctp_add_bind_addr() to net-endian.
Browse files Browse the repository at this point in the history
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Al Viro authored and David S. Miller committed Dec 3, 2006
1 parent 4bdf4b5 commit 5ab7b85
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
16 changes: 10 additions & 6 deletions net/sctp/bind_addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ int sctp_add_bind_addr(struct sctp_bind_addr *bp, union sctp_addr *new,
if (!addr)
return -ENOMEM;

memcpy(&addr->a_h, new, sizeof(*new));
memcpy(&addr->a, new, sizeof(*new));

/* Fix up the port if it has not yet been set.
* Both v4 and v6 have the port at the same offset.
*/
if (!addr->a_h.v4.sin_port)
addr->a_h.v4.sin_port = bp->port;
if (!addr->a.v4.sin_port)
addr->a.v4.sin_port = htons(bp->port);

flip_to_n(&addr->a, &addr->a_h);
flip_to_h(&addr->a_h, &addr->a);

addr->use_as_src = use_as_src;

Expand Down Expand Up @@ -264,6 +264,7 @@ int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw_addr_list,
int retval = 0;
int len;
struct sctp_af *af;
union sctp_addr tmp;

/* Convert the raw address to standard address format */
while (addrs_len) {
Expand All @@ -278,7 +279,8 @@ int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw_addr_list,
}

af->from_addr_param(&addr, rawaddr, port, 0);
retval = sctp_add_bind_addr(bp, &addr, 1, gfp);
flip_to_n(&tmp, &addr);
retval = sctp_add_bind_addr(bp, &tmp, 1, gfp);
if (retval) {
/* Can't finish building the list, clean up. */
sctp_bind_addr_clean(bp);
Expand Down Expand Up @@ -358,6 +360,8 @@ static int sctp_copy_one_addr(struct sctp_bind_addr *dest,
int flags)
{
int error = 0;
union sctp_addr tmp;
flip_to_n(&tmp, addr);

if (sctp_is_any(addr)) {
error = sctp_copy_local_addr_list(dest, scope, gfp, flags);
Expand All @@ -371,7 +375,7 @@ static int sctp_copy_one_addr(struct sctp_bind_addr *dest,
(((AF_INET6 == addr->sa.sa_family) &&
(flags & SCTP_ADDR6_ALLOWED) &&
(flags & SCTP_ADDR6_PEERSUPP))))
error = sctp_add_bind_addr(dest, addr, 1, gfp);
error = sctp_add_bind_addr(dest, &tmp, 1, gfp);
}

return error;
Expand Down
2 changes: 1 addition & 1 deletion net/sctp/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ int sctp_copy_local_addr_list(struct sctp_bind_addr *bp, sctp_scope_t scope,
(((AF_INET6 == addr->a_h.sa.sa_family) &&
(copy_flags & SCTP_ADDR6_ALLOWED) &&
(copy_flags & SCTP_ADDR6_PEERSUPP)))) {
error = sctp_add_bind_addr(bp, &addr->a_h, 1,
error = sctp_add_bind_addr(bp, &addr->a, 1,
GFP_ATOMIC);
if (error)
goto end_copy;
Expand Down
4 changes: 3 additions & 1 deletion net/sctp/sm_make_chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,9 @@ struct sctp_association *sctp_unpack_cookie(

/* Also, add the destination address. */
if (list_empty(&retval->base.bind_addr.address_list)) {
sctp_add_bind_addr(&retval->base.bind_addr, &chunk->dest, 1,
union sctp_addr tmp;
flip_to_n(&tmp, &chunk->dest);
sctp_add_bind_addr(&retval->base.bind_addr, &tmp, 1,
GFP_ATOMIC);
}

Expand Down
5 changes: 1 addition & 4 deletions net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
struct sctp_af *af;
unsigned short snum;
int ret = 0;
union sctp_addr tmp;

/* Common sockaddr verification. */
af = sctp_sockaddr_af(sp, addr, len);
Expand Down Expand Up @@ -369,8 +368,7 @@ SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
sctp_write_lock(&ep->base.addr_lock);

/* Use GFP_ATOMIC since BHs are disabled. */
flip_to_h(&tmp, addr);
ret = sctp_add_bind_addr(bp, &tmp, 1, GFP_ATOMIC);
ret = sctp_add_bind_addr(bp, addr, 1, GFP_ATOMIC);
sctp_write_unlock(&ep->base.addr_lock);
sctp_local_bh_enable();

Expand Down Expand Up @@ -572,7 +570,6 @@ static int sctp_send_asconf_add_ip(struct sock *sk,
addr = (union sctp_addr *)addr_buf;
af = sctp_get_af_specific(addr->v4.sin_family);
memcpy(&saveaddr, addr, af->sockaddr_len);
saveaddr.v4.sin_port = ntohs(saveaddr.v4.sin_port);
retval = sctp_add_bind_addr(bp, &saveaddr, 0,
GFP_ATOMIC);
addr_buf += af->sockaddr_len;
Expand Down

0 comments on commit 5ab7b85

Please sign in to comment.