diff options
Diffstat (limited to 'net/sctp/sm_make_chunk.c')
-rw-r--r-- | net/sctp/sm_make_chunk.c | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index 507dff72c585..04954e5f6846 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c | |||
@@ -111,7 +111,7 @@ static const struct sctp_paramhdr prsctp_param = { | |||
111 | * provided chunk, as most cause codes will be embedded inside an | 111 | * provided chunk, as most cause codes will be embedded inside an |
112 | * abort chunk. | 112 | * abort chunk. |
113 | */ | 113 | */ |
114 | void sctp_init_cause(struct sctp_chunk *chunk, __u16 cause_code, | 114 | void sctp_init_cause(struct sctp_chunk *chunk, __be16 cause_code, |
115 | const void *payload, size_t paylen) | 115 | const void *payload, size_t paylen) |
116 | { | 116 | { |
117 | sctp_errhdr_t err; | 117 | sctp_errhdr_t err; |
@@ -183,7 +183,7 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc, | |||
183 | int num_types, addrs_len = 0; | 183 | int num_types, addrs_len = 0; |
184 | struct sctp_sock *sp; | 184 | struct sctp_sock *sp; |
185 | sctp_supported_addrs_param_t sat; | 185 | sctp_supported_addrs_param_t sat; |
186 | __u16 types[2]; | 186 | __be16 types[2]; |
187 | sctp_adaption_ind_param_t aiparam; | 187 | sctp_adaption_ind_param_t aiparam; |
188 | 188 | ||
189 | /* RFC 2960 3.3.2 Initiation (INIT) (1) | 189 | /* RFC 2960 3.3.2 Initiation (INIT) (1) |
@@ -775,7 +775,7 @@ struct sctp_chunk *sctp_make_abort_no_data( | |||
775 | const struct sctp_chunk *chunk, __u32 tsn) | 775 | const struct sctp_chunk *chunk, __u32 tsn) |
776 | { | 776 | { |
777 | struct sctp_chunk *retval; | 777 | struct sctp_chunk *retval; |
778 | __u32 payload; | 778 | __be32 payload; |
779 | 779 | ||
780 | retval = sctp_make_abort(asoc, chunk, sizeof(sctp_errhdr_t) | 780 | retval = sctp_make_abort(asoc, chunk, sizeof(sctp_errhdr_t) |
781 | + sizeof(tsn)); | 781 | + sizeof(tsn)); |
@@ -951,7 +951,7 @@ nodata: | |||
951 | /* Create an Operation Error chunk. */ | 951 | /* Create an Operation Error chunk. */ |
952 | struct sctp_chunk *sctp_make_op_error(const struct sctp_association *asoc, | 952 | struct sctp_chunk *sctp_make_op_error(const struct sctp_association *asoc, |
953 | const struct sctp_chunk *chunk, | 953 | const struct sctp_chunk *chunk, |
954 | __u16 cause_code, const void *payload, | 954 | __be16 cause_code, const void *payload, |
955 | size_t paylen) | 955 | size_t paylen) |
956 | { | 956 | { |
957 | struct sctp_chunk *retval; | 957 | struct sctp_chunk *retval; |
@@ -1190,15 +1190,14 @@ void sctp_chunk_assign_ssn(struct sctp_chunk *chunk) | |||
1190 | if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) { | 1190 | if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) { |
1191 | ssn = 0; | 1191 | ssn = 0; |
1192 | } else { | 1192 | } else { |
1193 | sid = htons(chunk->subh.data_hdr->stream); | 1193 | sid = ntohs(chunk->subh.data_hdr->stream); |
1194 | if (chunk->chunk_hdr->flags & SCTP_DATA_LAST_FRAG) | 1194 | if (chunk->chunk_hdr->flags & SCTP_DATA_LAST_FRAG) |
1195 | ssn = sctp_ssn_next(&chunk->asoc->ssnmap->out, sid); | 1195 | ssn = sctp_ssn_next(&chunk->asoc->ssnmap->out, sid); |
1196 | else | 1196 | else |
1197 | ssn = sctp_ssn_peek(&chunk->asoc->ssnmap->out, sid); | 1197 | ssn = sctp_ssn_peek(&chunk->asoc->ssnmap->out, sid); |
1198 | ssn = htons(ssn); | ||
1199 | } | 1198 | } |
1200 | 1199 | ||
1201 | chunk->subh.data_hdr->ssn = ssn; | 1200 | chunk->subh.data_hdr->ssn = htons(ssn); |
1202 | chunk->has_ssn = 1; | 1201 | chunk->has_ssn = 1; |
1203 | } | 1202 | } |
1204 | 1203 | ||
@@ -1280,15 +1279,13 @@ static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep, | |||
1280 | - (bodysize % SCTP_COOKIE_MULTIPLE); | 1279 | - (bodysize % SCTP_COOKIE_MULTIPLE); |
1281 | *cookie_len = headersize + bodysize; | 1280 | *cookie_len = headersize + bodysize; |
1282 | 1281 | ||
1283 | retval = kmalloc(*cookie_len, GFP_ATOMIC); | ||
1284 | |||
1285 | if (!retval) | ||
1286 | goto nodata; | ||
1287 | |||
1288 | /* Clear this memory since we are sending this data structure | 1282 | /* Clear this memory since we are sending this data structure |
1289 | * out on the network. | 1283 | * out on the network. |
1290 | */ | 1284 | */ |
1291 | memset(retval, 0x00, *cookie_len); | 1285 | retval = kzalloc(*cookie_len, GFP_ATOMIC); |
1286 | if (!retval) | ||
1287 | goto nodata; | ||
1288 | |||
1292 | cookie = (struct sctp_signed_cookie *) retval->body; | 1289 | cookie = (struct sctp_signed_cookie *) retval->body; |
1293 | 1290 | ||
1294 | /* Set up the parameter header. */ | 1291 | /* Set up the parameter header. */ |
@@ -1438,7 +1435,7 @@ no_hmac: | |||
1438 | goto fail; | 1435 | goto fail; |
1439 | } | 1436 | } |
1440 | 1437 | ||
1441 | if (ntohs(chunk->sctp_hdr->source) != bear_cookie->peer_addr.v4.sin_port || | 1438 | if (chunk->sctp_hdr->source != bear_cookie->peer_addr.v4.sin_port || |
1442 | ntohs(chunk->sctp_hdr->dest) != bear_cookie->my_port) { | 1439 | ntohs(chunk->sctp_hdr->dest) != bear_cookie->my_port) { |
1443 | *error = -SCTP_IERROR_BAD_PORTS; | 1440 | *error = -SCTP_IERROR_BAD_PORTS; |
1444 | goto fail; | 1441 | goto fail; |
@@ -1473,10 +1470,10 @@ no_hmac: | |||
1473 | suseconds_t usecs = (tv.tv_sec - | 1470 | suseconds_t usecs = (tv.tv_sec - |
1474 | bear_cookie->expiration.tv_sec) * 1000000L + | 1471 | bear_cookie->expiration.tv_sec) * 1000000L + |
1475 | tv.tv_usec - bear_cookie->expiration.tv_usec; | 1472 | tv.tv_usec - bear_cookie->expiration.tv_usec; |
1473 | __be32 n = htonl(usecs); | ||
1476 | 1474 | ||
1477 | usecs = htonl(usecs); | ||
1478 | sctp_init_cause(*errp, SCTP_ERROR_STALE_COOKIE, | 1475 | sctp_init_cause(*errp, SCTP_ERROR_STALE_COOKIE, |
1479 | &usecs, sizeof(usecs)); | 1476 | &n, sizeof(n)); |
1480 | *error = -SCTP_IERROR_STALE_COOKIE; | 1477 | *error = -SCTP_IERROR_STALE_COOKIE; |
1481 | } else | 1478 | } else |
1482 | *error = -SCTP_IERROR_NOMEM; | 1479 | *error = -SCTP_IERROR_NOMEM; |
@@ -1539,8 +1536,8 @@ malformed: | |||
1539 | ********************************************************************/ | 1536 | ********************************************************************/ |
1540 | 1537 | ||
1541 | struct __sctp_missing { | 1538 | struct __sctp_missing { |
1542 | __u32 num_missing; | 1539 | __be32 num_missing; |
1543 | __u16 type; | 1540 | __be16 type; |
1544 | } __attribute__((packed)); | 1541 | } __attribute__((packed)); |
1545 | 1542 | ||
1546 | /* | 1543 | /* |
@@ -1852,9 +1849,10 @@ int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid, | |||
1852 | * added as the primary transport. The source address seems to | 1849 | * added as the primary transport. The source address seems to |
1853 | * be a a better choice than any of the embedded addresses. | 1850 | * be a a better choice than any of the embedded addresses. |
1854 | */ | 1851 | */ |
1855 | if (peer_addr) | 1852 | if (peer_addr) { |
1856 | if(!sctp_assoc_add_peer(asoc, peer_addr, gfp, SCTP_ACTIVE)) | 1853 | if(!sctp_assoc_add_peer(asoc, peer_addr, gfp, SCTP_ACTIVE)) |
1857 | goto nomem; | 1854 | goto nomem; |
1855 | } | ||
1858 | 1856 | ||
1859 | /* Process the initialization parameters. */ | 1857 | /* Process the initialization parameters. */ |
1860 | 1858 | ||
@@ -1910,10 +1908,9 @@ int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid, | |||
1910 | /* Copy cookie in case we need to resend COOKIE-ECHO. */ | 1908 | /* Copy cookie in case we need to resend COOKIE-ECHO. */ |
1911 | cookie = asoc->peer.cookie; | 1909 | cookie = asoc->peer.cookie; |
1912 | if (cookie) { | 1910 | if (cookie) { |
1913 | asoc->peer.cookie = kmalloc(asoc->peer.cookie_len, gfp); | 1911 | asoc->peer.cookie = kmemdup(cookie, asoc->peer.cookie_len, gfp); |
1914 | if (!asoc->peer.cookie) | 1912 | if (!asoc->peer.cookie) |
1915 | goto clean_up; | 1913 | goto clean_up; |
1916 | memcpy(asoc->peer.cookie, cookie, asoc->peer.cookie_len); | ||
1917 | } | 1914 | } |
1918 | 1915 | ||
1919 | /* RFC 2960 7.2.1 The initial value of ssthresh MAY be arbitrarily | 1916 | /* RFC 2960 7.2.1 The initial value of ssthresh MAY be arbitrarily |
@@ -2027,7 +2024,7 @@ static int sctp_process_param(struct sctp_association *asoc, | |||
2027 | /* Fall through. */ | 2024 | /* Fall through. */ |
2028 | case SCTP_PARAM_IPV4_ADDRESS: | 2025 | case SCTP_PARAM_IPV4_ADDRESS: |
2029 | af = sctp_get_af_specific(param_type2af(param.p->type)); | 2026 | af = sctp_get_af_specific(param_type2af(param.p->type)); |
2030 | af->from_addr_param(&addr, param.addr, asoc->peer.port, 0); | 2027 | af->from_addr_param(&addr, param.addr, htons(asoc->peer.port), 0); |
2031 | scope = sctp_scope(peer_addr); | 2028 | scope = sctp_scope(peer_addr); |
2032 | if (sctp_in_scope(&addr, scope)) | 2029 | if (sctp_in_scope(&addr, scope)) |
2033 | if (!sctp_assoc_add_peer(asoc, &addr, gfp, SCTP_UNCONFIRMED)) | 2030 | if (!sctp_assoc_add_peer(asoc, &addr, gfp, SCTP_UNCONFIRMED)) |
@@ -2230,7 +2227,7 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc, | |||
2230 | union sctp_addr *laddr, | 2227 | union sctp_addr *laddr, |
2231 | struct sockaddr *addrs, | 2228 | struct sockaddr *addrs, |
2232 | int addrcnt, | 2229 | int addrcnt, |
2233 | __u16 flags) | 2230 | __be16 flags) |
2234 | { | 2231 | { |
2235 | sctp_addip_param_t param; | 2232 | sctp_addip_param_t param; |
2236 | struct sctp_chunk *retval; | 2233 | struct sctp_chunk *retval; |
@@ -2363,14 +2360,14 @@ static struct sctp_chunk *sctp_make_asconf_ack(const struct sctp_association *as | |||
2363 | } | 2360 | } |
2364 | 2361 | ||
2365 | /* Add response parameters to an ASCONF_ACK chunk. */ | 2362 | /* Add response parameters to an ASCONF_ACK chunk. */ |
2366 | static void sctp_add_asconf_response(struct sctp_chunk *chunk, __u32 crr_id, | 2363 | static void sctp_add_asconf_response(struct sctp_chunk *chunk, __be32 crr_id, |
2367 | __u16 err_code, sctp_addip_param_t *asconf_param) | 2364 | __be16 err_code, sctp_addip_param_t *asconf_param) |
2368 | { | 2365 | { |
2369 | sctp_addip_param_t ack_param; | 2366 | sctp_addip_param_t ack_param; |
2370 | sctp_errhdr_t err_param; | 2367 | sctp_errhdr_t err_param; |
2371 | int asconf_param_len = 0; | 2368 | int asconf_param_len = 0; |
2372 | int err_param_len = 0; | 2369 | int err_param_len = 0; |
2373 | __u16 response_type; | 2370 | __be16 response_type; |
2374 | 2371 | ||
2375 | if (SCTP_ERROR_NO_ERROR == err_code) { | 2372 | if (SCTP_ERROR_NO_ERROR == err_code) { |
2376 | response_type = SCTP_PARAM_SUCCESS_REPORT; | 2373 | response_type = SCTP_PARAM_SUCCESS_REPORT; |
@@ -2404,7 +2401,7 @@ static void sctp_add_asconf_response(struct sctp_chunk *chunk, __u32 crr_id, | |||
2404 | } | 2401 | } |
2405 | 2402 | ||
2406 | /* Process a asconf parameter. */ | 2403 | /* Process a asconf parameter. */ |
2407 | static __u16 sctp_process_asconf_param(struct sctp_association *asoc, | 2404 | static __be16 sctp_process_asconf_param(struct sctp_association *asoc, |
2408 | struct sctp_chunk *asconf, | 2405 | struct sctp_chunk *asconf, |
2409 | sctp_addip_param_t *asconf_param) | 2406 | sctp_addip_param_t *asconf_param) |
2410 | { | 2407 | { |
@@ -2413,7 +2410,7 @@ static __u16 sctp_process_asconf_param(struct sctp_association *asoc, | |||
2413 | union sctp_addr addr; | 2410 | union sctp_addr addr; |
2414 | struct list_head *pos; | 2411 | struct list_head *pos; |
2415 | union sctp_addr_param *addr_param; | 2412 | union sctp_addr_param *addr_param; |
2416 | 2413 | ||
2417 | addr_param = (union sctp_addr_param *) | 2414 | addr_param = (union sctp_addr_param *) |
2418 | ((void *)asconf_param + sizeof(sctp_addip_param_t)); | 2415 | ((void *)asconf_param + sizeof(sctp_addip_param_t)); |
2419 | 2416 | ||
@@ -2421,7 +2418,7 @@ static __u16 sctp_process_asconf_param(struct sctp_association *asoc, | |||
2421 | if (unlikely(!af)) | 2418 | if (unlikely(!af)) |
2422 | return SCTP_ERROR_INV_PARAM; | 2419 | return SCTP_ERROR_INV_PARAM; |
2423 | 2420 | ||
2424 | af->from_addr_param(&addr, addr_param, asoc->peer.port, 0); | 2421 | af->from_addr_param(&addr, addr_param, htons(asoc->peer.port), 0); |
2425 | switch (asconf_param->param_hdr.type) { | 2422 | switch (asconf_param->param_hdr.type) { |
2426 | case SCTP_PARAM_ADD_IP: | 2423 | case SCTP_PARAM_ADD_IP: |
2427 | /* ADDIP 4.3 D9) If an endpoint receives an ADD IP address | 2424 | /* ADDIP 4.3 D9) If an endpoint receives an ADD IP address |
@@ -2487,7 +2484,7 @@ struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc, | |||
2487 | sctp_addip_param_t *asconf_param; | 2484 | sctp_addip_param_t *asconf_param; |
2488 | struct sctp_chunk *asconf_ack; | 2485 | struct sctp_chunk *asconf_ack; |
2489 | 2486 | ||
2490 | __u16 err_code; | 2487 | __be16 err_code; |
2491 | int length = 0; | 2488 | int length = 0; |
2492 | int chunk_len = asconf->skb->len; | 2489 | int chunk_len = asconf->skb->len; |
2493 | __u32 serial; | 2490 | __u32 serial; |
@@ -2586,7 +2583,7 @@ static int sctp_asconf_param_success(struct sctp_association *asoc, | |||
2586 | 2583 | ||
2587 | /* We have checked the packet before, so we do not check again. */ | 2584 | /* We have checked the packet before, so we do not check again. */ |
2588 | af = sctp_get_af_specific(param_type2af(addr_param->v4.param_hdr.type)); | 2585 | af = sctp_get_af_specific(param_type2af(addr_param->v4.param_hdr.type)); |
2589 | af->from_addr_param(&addr, addr_param, bp->port, 0); | 2586 | af->from_addr_param(&addr, addr_param, htons(bp->port), 0); |
2590 | 2587 | ||
2591 | switch (asconf_param->param_hdr.type) { | 2588 | switch (asconf_param->param_hdr.type) { |
2592 | case SCTP_PARAM_ADD_IP: | 2589 | case SCTP_PARAM_ADD_IP: |
@@ -2630,7 +2627,7 @@ static int sctp_asconf_param_success(struct sctp_association *asoc, | |||
2630 | * All TLVs after the failed response are considered unsuccessful unless a | 2627 | * All TLVs after the failed response are considered unsuccessful unless a |
2631 | * specific success indication is present for the parameter. | 2628 | * specific success indication is present for the parameter. |
2632 | */ | 2629 | */ |
2633 | static __u16 sctp_get_asconf_response(struct sctp_chunk *asconf_ack, | 2630 | static __be16 sctp_get_asconf_response(struct sctp_chunk *asconf_ack, |
2634 | sctp_addip_param_t *asconf_param, | 2631 | sctp_addip_param_t *asconf_param, |
2635 | int no_err) | 2632 | int no_err) |
2636 | { | 2633 | { |
@@ -2638,7 +2635,7 @@ static __u16 sctp_get_asconf_response(struct sctp_chunk *asconf_ack, | |||
2638 | sctp_errhdr_t *err_param; | 2635 | sctp_errhdr_t *err_param; |
2639 | int length; | 2636 | int length; |
2640 | int asconf_ack_len = asconf_ack->skb->len; | 2637 | int asconf_ack_len = asconf_ack->skb->len; |
2641 | __u16 err_code; | 2638 | __be16 err_code; |
2642 | 2639 | ||
2643 | if (no_err) | 2640 | if (no_err) |
2644 | err_code = SCTP_ERROR_NO_ERROR; | 2641 | err_code = SCTP_ERROR_NO_ERROR; |
@@ -2694,7 +2691,7 @@ int sctp_process_asconf_ack(struct sctp_association *asoc, | |||
2694 | int all_param_pass = 0; | 2691 | int all_param_pass = 0; |
2695 | int no_err = 1; | 2692 | int no_err = 1; |
2696 | int retval = 0; | 2693 | int retval = 0; |
2697 | __u16 err_code = SCTP_ERROR_NO_ERROR; | 2694 | __be16 err_code = SCTP_ERROR_NO_ERROR; |
2698 | 2695 | ||
2699 | /* Skip the chunkhdr and addiphdr from the last asconf sent and store | 2696 | /* Skip the chunkhdr and addiphdr from the last asconf sent and store |
2700 | * a pointer to address parameter. | 2697 | * a pointer to address parameter. |