Skip to content

Commit

Permalink
[SCTP]: Switch ->from_addr_param() 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 5ab7b85 commit dd86d13
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion include/net/sctp/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ struct sctp_af {
struct sock *sk);
void (*from_addr_param) (union sctp_addr *,
union sctp_addr_param *,
__u16 port, int iif);
__be16 port, int iif);
int (*to_addr_param) (const union sctp_addr *,
union sctp_addr_param *);
int (*addr_valid) (union sctp_addr *,
Expand Down
6 changes: 2 additions & 4 deletions net/sctp/bind_addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ 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,9 +277,8 @@ int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw_addr_list,
break;
}

af->from_addr_param(&addr, rawaddr, port, 0);
flip_to_n(&tmp, &addr);
retval = sctp_add_bind_addr(bp, &tmp, 1, gfp);
af->from_addr_param(&addr, rawaddr, htons(port), 0);
retval = sctp_add_bind_addr(bp, &addr, 1, gfp);
if (retval) {
/* Can't finish building the list, clean up. */
sctp_bind_addr_clean(bp);
Expand Down
6 changes: 2 additions & 4 deletions net/sctp/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,6 @@ static struct sctp_association *__sctp_rcv_init_lookup(struct sk_buff *skb,
sctp_init_chunk_t *init;
struct sctp_transport *transport;
struct sctp_af *af;
union sctp_addr tmp2;

ch = (sctp_chunkhdr_t *) skb->data;

Expand Down Expand Up @@ -961,10 +960,9 @@ static struct sctp_association *__sctp_rcv_init_lookup(struct sk_buff *skb,
if (!af)
continue;

af->from_addr_param(paddr, params.addr, ntohs(sh->source), 0);
flip_to_n(&tmp2, paddr);
af->from_addr_param(paddr, params.addr, sh->source, 0);

asoc = __sctp_lookup_association(laddr, &tmp2, &transport);
asoc = __sctp_lookup_association(laddr, paddr, &transport);
if (asoc)
return asoc;
}
Expand Down
2 changes: 1 addition & 1 deletion net/sctp/ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ static void sctp_v6_to_sk_daddr(union sctp_addr *addr, struct sock *sk)
/* Initialize a sctp_addr from an address parameter. */
static void sctp_v6_from_addr_param(union sctp_addr *addr,
union sctp_addr_param *param,
__u16 port, int iif)
__be16 port, int iif)
{
addr->v6.sin6_family = AF_INET6;
addr->v6.sin6_port = port;
Expand Down
2 changes: 1 addition & 1 deletion net/sctp/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ static void sctp_v4_to_sk_daddr(union sctp_addr *addr, struct sock *sk)
/* Initialize a sctp_addr from an address parameter. */
static void sctp_v4_from_addr_param(union sctp_addr *addr,
union sctp_addr_param *param,
__u16 port, int iif)
__be16 port, int iif)
{
addr->v4.sin_family = AF_INET;
addr->v4.sin_port = port;
Expand Down
29 changes: 12 additions & 17 deletions net/sctp/sm_make_chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,6 @@ 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 @@ -2034,11 +2033,10 @@ static int sctp_process_param(struct sctp_association *asoc,
/* Fall through. */
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);
af->from_addr_param(&addr, param.addr, htons(asoc->peer.port), 0);
scope = sctp_scope(peer_addr);
if (sctp_in_scope(&tmp, scope))
if (!sctp_assoc_add_peer(asoc, &tmp, gfp, SCTP_UNCONFIRMED))
if (sctp_in_scope(&addr, scope))
if (!sctp_assoc_add_peer(asoc, &addr, gfp, SCTP_UNCONFIRMED))
return 0;
break;

Expand Down Expand Up @@ -2421,7 +2419,7 @@ static __be16 sctp_process_asconf_param(struct sctp_association *asoc,
union sctp_addr addr;
struct list_head *pos;
union sctp_addr_param *addr_param;
union sctp_addr tmp, tmp_addr;
union sctp_addr tmp;

addr_param = (union sctp_addr_param *)
((void *)asconf_param + sizeof(sctp_addip_param_t));
Expand All @@ -2430,8 +2428,7 @@ static __be16 sctp_process_asconf_param(struct sctp_association *asoc,
if (unlikely(!af))
return SCTP_ERROR_INV_PARAM;

af->from_addr_param(&addr, addr_param, asoc->peer.port, 0);
flip_to_n(&tmp_addr, &addr);
af->from_addr_param(&addr, addr_param, htons(asoc->peer.port), 0);
switch (asconf_param->param_hdr.type) {
case SCTP_PARAM_ADD_IP:
/* ADDIP 4.3 D9) If an endpoint receives an ADD IP address
Expand All @@ -2441,7 +2438,7 @@ static __be16 sctp_process_asconf_param(struct sctp_association *asoc,
* Due to Resource Shortage'.
*/

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

Expand All @@ -2467,13 +2464,13 @@ static __be16 sctp_process_asconf_param(struct sctp_association *asoc,
* Delete Source IP Address'
*/
flip_to_n(&tmp, sctp_source(asconf));
if (sctp_cmp_addr_exact(&tmp, &tmp_addr))
if (sctp_cmp_addr_exact(&tmp, &addr))
return SCTP_ERROR_DEL_SRC_IP;

sctp_assoc_del_peer(asoc, &tmp_addr);
sctp_assoc_del_peer(asoc, &addr);
break;
case SCTP_PARAM_SET_PRIMARY:
peer = sctp_assoc_lookup_paddr(asoc, &tmp_addr);
peer = sctp_assoc_lookup_paddr(asoc, &addr);
if (!peer)
return SCTP_ERROR_INV_PARAM;

Expand Down Expand Up @@ -2591,23 +2588,21 @@ static int sctp_asconf_param_success(struct sctp_association *asoc,
struct sctp_transport *transport;
struct sctp_sockaddr_entry *saddr;
int retval = 0;
union sctp_addr tmp;

addr_param = (union sctp_addr_param *)
((void *)asconf_param + sizeof(sctp_addip_param_t));

/* We have checked the packet before, so we do not check again. */
af = sctp_get_af_specific(param_type2af(addr_param->v4.param_hdr.type));
af->from_addr_param(&addr, addr_param, bp->port, 0);
flip_to_n(&tmp, &addr);
af->from_addr_param(&addr, addr_param, htons(bp->port), 0);

switch (asconf_param->param_hdr.type) {
case SCTP_PARAM_ADD_IP:
sctp_local_bh_disable();
sctp_write_lock(&asoc->base.addr_lock);
list_for_each(pos, &bp->address_list) {
saddr = list_entry(pos, struct sctp_sockaddr_entry, list);
if (sctp_cmp_addr_exact(&saddr->a, &tmp))
if (sctp_cmp_addr_exact(&saddr->a, &addr))
saddr->use_as_src = 1;
}
sctp_write_unlock(&asoc->base.addr_lock);
Expand All @@ -2616,7 +2611,7 @@ static int sctp_asconf_param_success(struct sctp_association *asoc,
case SCTP_PARAM_DEL_IP:
sctp_local_bh_disable();
sctp_write_lock(&asoc->base.addr_lock);
retval = sctp_del_bind_addr(bp, &tmp);
retval = sctp_del_bind_addr(bp, &addr);
sctp_write_unlock(&asoc->base.addr_lock);
sctp_local_bh_enable();
list_for_each(pos, &asoc->peer.transport_addr_list) {
Expand Down

0 comments on commit dd86d13

Please sign in to comment.