Skip to content

Commit

Permalink
[SCTP]: Switch sctp_assoc_add_peer() to net-endian.
Browse files Browse the repository at this point in the history
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Al Viro authored and David S. Miller committed Dec 3, 2006
1 parent b488c7d commit 4bdf4b5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
12 changes: 5 additions & 7 deletions net/sctp/associola.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,27 +533,25 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
struct sctp_transport *peer;
struct sctp_sock *sp;
unsigned short port;
union sctp_addr tmp;
flip_to_n(&tmp, addr);

sp = sctp_sk(asoc->base.sk);

/* AF_INET and AF_INET6 share common port field. */
port = addr->v4.sin_port;
port = ntohs(addr->v4.sin_port);

SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_add_peer:association %p addr: ",
" port: %d state:%d\n",
asoc,
addr,
addr->v4.sin_port,
port,
peer_state);

/* Set the port if it has not been set yet. */
if (0 == asoc->peer.port)
asoc->peer.port = port;

/* Check to see if this is a duplicate. */
peer = sctp_assoc_lookup_paddr(asoc, &tmp);
peer = sctp_assoc_lookup_paddr(asoc, addr);
if (peer) {
if (peer->state == SCTP_UNKNOWN) {
if (peer_state == SCTP_ACTIVE)
Expand All @@ -564,7 +562,7 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
return peer;
}

peer = sctp_transport_new(&tmp, gfp);
peer = sctp_transport_new(addr, gfp);
if (!peer)
return NULL;

Expand Down Expand Up @@ -1070,7 +1068,7 @@ void sctp_assoc_update(struct sctp_association *asoc,
trans = list_entry(pos, struct sctp_transport,
transports);
if (!sctp_assoc_lookup_paddr(asoc, &trans->ipaddr))
sctp_assoc_add_peer(asoc, &trans->ipaddr_h,
sctp_assoc_add_peer(asoc, &trans->ipaddr,
GFP_ATOMIC, trans->state);
}

Expand Down
15 changes: 10 additions & 5 deletions net/sctp/sm_make_chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,7 @@ int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid,
struct sctp_transport *transport;
struct list_head *pos, *temp;
char *cookie;
union sctp_addr tmp;

/* We must include the address that the INIT packet came from.
* This is the only address that matters for an INIT packet.
Expand All @@ -1853,9 +1854,11 @@ int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid,
* added as the primary transport. The source address seems to
* be a a better choice than any of the embedded addresses.
*/
if (peer_addr)
if(!sctp_assoc_add_peer(asoc, peer_addr, gfp, SCTP_ACTIVE))
if (peer_addr) {
flip_to_n(&tmp, peer_addr);
if(!sctp_assoc_add_peer(asoc, &tmp, gfp, SCTP_ACTIVE))
goto nomem;
}

/* Process the initialization parameters. */

Expand Down Expand Up @@ -2016,6 +2019,7 @@ static int sctp_process_param(struct sctp_association *asoc,
sctp_scope_t scope;
time_t stale;
struct sctp_af *af;
union sctp_addr tmp;

/* We maintain all INIT parameters in network byte order all the
* time. This allows us to not worry about whether the parameters
Expand All @@ -2029,9 +2033,10 @@ static int sctp_process_param(struct sctp_association *asoc,
case SCTP_PARAM_IPV4_ADDRESS:
af = sctp_get_af_specific(param_type2af(param.p->type));
af->from_addr_param(&addr, param.addr, asoc->peer.port, 0);
flip_to_n(&tmp, &addr);
scope = sctp_scope(peer_addr);
if (sctp_in_scope(&addr, scope))
if (!sctp_assoc_add_peer(asoc, &addr, gfp, SCTP_UNCONFIRMED))
if (sctp_in_scope(&tmp, scope))
if (!sctp_assoc_add_peer(asoc, &tmp, gfp, SCTP_UNCONFIRMED))
return 0;
break;

Expand Down Expand Up @@ -2434,7 +2439,7 @@ static __be16 sctp_process_asconf_param(struct sctp_association *asoc,
* Due to Resource Shortage'.
*/

peer = sctp_assoc_add_peer(asoc, &addr, GFP_ATOMIC, SCTP_UNCONFIRMED);
peer = sctp_assoc_add_peer(asoc, &tmp_addr, GFP_ATOMIC, SCTP_UNCONFIRMED);
if (!peer)
return SCTP_ERROR_RSRC_LOW;

Expand Down
13 changes: 6 additions & 7 deletions net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ static int __sctp_connect(struct sock* sk,
int err = 0;
int addrcnt = 0;
int walk_size = 0;
struct sockaddr *sa_addr;
union sctp_addr *sa_addr;
void *addr_buf;

sp = sctp_sk(sk);
Expand All @@ -989,8 +989,8 @@ static int __sctp_connect(struct sock* sk,
/* Walk through the addrs buffer and count the number of addresses. */
addr_buf = kaddrs;
while (walk_size < addrs_size) {
sa_addr = (struct sockaddr *)addr_buf;
af = sctp_get_af_specific(sa_addr->sa_family);
sa_addr = (union sctp_addr *)addr_buf;
af = sctp_get_af_specific(sa_addr->sa.sa_family);

/* If the address family is not supported or if this address
* causes the address buffer to overflow return EINVAL.
Expand All @@ -1000,8 +1000,7 @@ static int __sctp_connect(struct sock* sk,
goto out_free;
}

err = sctp_verify_addr(sk, (union sctp_addr *)sa_addr,
af->sockaddr_len);
err = sctp_verify_addr(sk, sa_addr, af->sockaddr_len);
if (err)
goto out_free;

Expand Down Expand Up @@ -1064,7 +1063,7 @@ static int __sctp_connect(struct sock* sk,
}

/* Prime the peer's transport structures. */
transport = sctp_assoc_add_peer(asoc, &to, GFP_KERNEL,
transport = sctp_assoc_add_peer(asoc, sa_addr, GFP_KERNEL,
SCTP_UNKNOWN);
if (!transport) {
err = -ENOMEM;
Expand Down Expand Up @@ -1618,7 +1617,7 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
}

/* Prime the peer's transport structures. */
transport = sctp_assoc_add_peer(asoc, &to, GFP_KERNEL, SCTP_UNKNOWN);
transport = sctp_assoc_add_peer(asoc, &tmp, GFP_KERNEL, SCTP_UNKNOWN);
if (!transport) {
err = -ENOMEM;
goto out_free;
Expand Down

0 comments on commit 4bdf4b5

Please sign in to comment.