[SCTP]: Switch sctp_cookie ->peer_addr to net-endian.
[deliverable/linux.git] / net / sctp / sm_make_chunk.c
index 507dff72c5853508279847672c84dcab460436cf..59536368f79a680f749d69438944cc6bf9fb86d4 100644 (file)
@@ -111,7 +111,7 @@ static const struct sctp_paramhdr prsctp_param = {
  * provided chunk, as most cause codes will be embedded inside an
  * abort chunk.
  */
-void  sctp_init_cause(struct sctp_chunk *chunk, __u16 cause_code,
+void  sctp_init_cause(struct sctp_chunk *chunk, __be16 cause_code,
                      const void *payload, size_t paylen)
 {
        sctp_errhdr_t err;
@@ -951,7 +951,7 @@ nodata:
 /* Create an Operation Error chunk.  */
 struct sctp_chunk *sctp_make_op_error(const struct sctp_association *asoc,
                                 const struct sctp_chunk *chunk,
-                                __u16 cause_code, const void *payload,
+                                __be16 cause_code, const void *payload,
                                 size_t paylen)
 {
        struct sctp_chunk *retval;
@@ -1032,7 +1032,8 @@ void sctp_init_addrs(struct sctp_chunk *chunk, union sctp_addr *src,
                     union sctp_addr *dest)
 {
        memcpy(&chunk->source, src, sizeof(union sctp_addr));
-       memcpy(&chunk->dest, dest, sizeof(union sctp_addr));
+       flip_to_h(&chunk->source_h, &chunk->source);
+       flip_to_h(&chunk->dest, dest);
 }
 
 /* Extract the source address from a chunk.  */
@@ -1040,10 +1041,10 @@ const union sctp_addr *sctp_source(const struct sctp_chunk *chunk)
 {
        /* If we have a known transport, use that.  */
        if (chunk->transport) {
-               return &chunk->transport->ipaddr;
+               return &chunk->transport->ipaddr_h;
        } else {
                /* Otherwise, extract it from the IP header.  */
-               return &chunk->source;
+               return &chunk->source_h;
        }
 }
 
@@ -1190,7 +1191,7 @@ void sctp_chunk_assign_ssn(struct sctp_chunk *chunk)
        if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) {
                ssn = 0;
        } else {
-               sid = htons(chunk->subh.data_hdr->stream);
+               sid = ntohs(chunk->subh.data_hdr->stream);
                if (chunk->chunk_hdr->flags & SCTP_DATA_LAST_FRAG)
                        ssn = sctp_ssn_next(&chunk->asoc->ssnmap->out, sid);
                else
@@ -1226,6 +1227,7 @@ struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *ep,
        struct sk_buff *skb;
        sctp_scope_t scope;
        struct sctp_af *af;
+       union sctp_addr tmp;
 
        /* Create the bare association.  */
        scope = sctp_scope(sctp_source(chunk));
@@ -1238,7 +1240,8 @@ struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *ep,
        af = sctp_get_af_specific(ipver2af(skb->nh.iph->version));
        if (unlikely(!af))
                goto fail;
-       af->from_skb(&asoc->c.peer_addr, skb, 1);
+       af->from_skb(&tmp, skb, 1);
+       flip_to_n(&asoc->c.peer_addr, &tmp);
 nodata:
        return asoc;
 
@@ -1438,7 +1441,7 @@ no_hmac:
                goto fail;
        }
 
-       if (ntohs(chunk->sctp_hdr->source) != bear_cookie->peer_addr.v4.sin_port ||
+       if (chunk->sctp_hdr->source != bear_cookie->peer_addr.v4.sin_port ||
            ntohs(chunk->sctp_hdr->dest) != bear_cookie->my_port) {
                *error = -SCTP_IERROR_BAD_PORTS;
                goto fail;
@@ -2230,7 +2233,7 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
                                              union sctp_addr         *laddr,
                                              struct sockaddr         *addrs,
                                              int                     addrcnt,
-                                             __u16                   flags)
+                                             __be16                  flags)
 {
        sctp_addip_param_t      param;
        struct sctp_chunk       *retval;
@@ -2364,13 +2367,13 @@ static struct sctp_chunk *sctp_make_asconf_ack(const struct sctp_association *as
 
 /* Add response parameters to an ASCONF_ACK chunk. */
 static void sctp_add_asconf_response(struct sctp_chunk *chunk, __u32 crr_id,
-                             __u16 err_code, sctp_addip_param_t *asconf_param)
+                             __be16 err_code, sctp_addip_param_t *asconf_param)
 {
        sctp_addip_param_t      ack_param;
        sctp_errhdr_t           err_param;
        int                     asconf_param_len = 0;
        int                     err_param_len = 0;
-       __u16                   response_type;
+       __be16                  response_type;
 
        if (SCTP_ERROR_NO_ERROR == err_code) {
                response_type = SCTP_PARAM_SUCCESS_REPORT;
@@ -2404,7 +2407,7 @@ static void sctp_add_asconf_response(struct sctp_chunk *chunk, __u32 crr_id,
 }
 
 /* Process a asconf parameter. */
-static __u16 sctp_process_asconf_param(struct sctp_association *asoc,
+static __be16 sctp_process_asconf_param(struct sctp_association *asoc,
                                       struct sctp_chunk *asconf,
                                       sctp_addip_param_t *asconf_param)
 {
@@ -2413,7 +2416,8 @@ static __u16 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;
+
        addr_param = (union sctp_addr_param *)
                        ((void *)asconf_param + sizeof(sctp_addip_param_t));
 
@@ -2422,6 +2426,7 @@ static __u16 sctp_process_asconf_param(struct sctp_association *asoc,
                return SCTP_ERROR_INV_PARAM;
 
        af->from_addr_param(&addr, addr_param, asoc->peer.port, 0);
+       flip_to_n(&tmp_addr, &addr);
        switch (asconf_param->param_hdr.type) {
        case SCTP_PARAM_ADD_IP:
                /* ADDIP 4.3 D9) If an endpoint receives an ADD IP address
@@ -2456,13 +2461,14 @@ static __u16 sctp_process_asconf_param(struct sctp_association *asoc,
                 * an Error Cause TLV set to the new error code 'Request to
                 * Delete Source IP Address'
                 */
-               if (sctp_cmp_addr_exact(sctp_source(asconf), &addr))
+               flip_to_n(&tmp, sctp_source(asconf));
+               if (sctp_cmp_addr_exact(&tmp, &tmp_addr))
                        return SCTP_ERROR_DEL_SRC_IP;
 
-               sctp_assoc_del_peer(asoc, &addr);
+               sctp_assoc_del_peer(asoc, &tmp_addr);
                break;
        case SCTP_PARAM_SET_PRIMARY:
-               peer = sctp_assoc_lookup_paddr(asoc, &addr);
+               peer = sctp_assoc_lookup_paddr(asoc, &tmp_addr);
                if (!peer)
                        return SCTP_ERROR_INV_PARAM;
 
@@ -2487,7 +2493,7 @@ struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
        sctp_addip_param_t      *asconf_param;
        struct sctp_chunk       *asconf_ack;
 
-       __u16   err_code;
+       __be16  err_code;
        int     length = 0;
        int     chunk_len = asconf->skb->len;
        __u32   serial;
@@ -2580,6 +2586,7 @@ 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));
@@ -2587,6 +2594,7 @@ static int sctp_asconf_param_success(struct sctp_association *asoc,
        /* 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);
 
        switch (asconf_param->param_hdr.type) {
        case SCTP_PARAM_ADD_IP:
@@ -2594,7 +2602,7 @@ static int sctp_asconf_param_success(struct sctp_association *asoc,
                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, &addr))
+                       if (sctp_cmp_addr_exact(&saddr->a, &tmp))
                                saddr->use_as_src = 1;
                }
                sctp_write_unlock(&asoc->base.addr_lock);
@@ -2603,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, &addr);
+               retval = sctp_del_bind_addr(bp, &tmp);
                sctp_write_unlock(&asoc->base.addr_lock);
                sctp_local_bh_enable();
                list_for_each(pos, &asoc->peer.transport_addr_list) {
@@ -2630,7 +2638,7 @@ static int sctp_asconf_param_success(struct sctp_association *asoc,
  * All TLVs after the failed response are considered unsuccessful unless a
  * specific success indication is present for the parameter.
  */
-static __u16 sctp_get_asconf_response(struct sctp_chunk *asconf_ack,
+static __be16 sctp_get_asconf_response(struct sctp_chunk *asconf_ack,
                                      sctp_addip_param_t *asconf_param,
                                      int no_err)
 {
@@ -2638,7 +2646,7 @@ static __u16 sctp_get_asconf_response(struct sctp_chunk *asconf_ack,
        sctp_errhdr_t           *err_param;
        int                     length;
        int                     asconf_ack_len = asconf_ack->skb->len;
-       __u16                   err_code;
+       __be16                  err_code;
 
        if (no_err)
                err_code = SCTP_ERROR_NO_ERROR;
@@ -2694,7 +2702,7 @@ int sctp_process_asconf_ack(struct sctp_association *asoc,
        int     all_param_pass = 0;
        int     no_err = 1;
        int     retval = 0;
-       __u16   err_code = SCTP_ERROR_NO_ERROR;
+       __be16  err_code = SCTP_ERROR_NO_ERROR;
 
        /* Skip the chunkhdr and addiphdr from the last asconf sent and store
         * a pointer to address parameter.
This page took 0.031883 seconds and 5 git commands to generate.