Skip to content

Commit 9ba62f9

Browse files
committed
Merge branch 'sctp-align'
Marcelo Ricardo Leitner says: ==================== Rename WORD_TRUNC/ROUND macros and use them This patchset aims to rename these macros to a non-confusing name, as reported by David Laight and David Miller, and to update all remaining places to make use of it, which was 1 last remaining spot. v3: - Name it SCTP_PAD4 instead of SCTP_ALIGN4, as suggested by David Laight v2: - fixed 2nd patch summary Details on the specific changelogs. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents b80b8d7 + 4a225ce commit 9ba62f9

File tree

11 files changed

+46
-45
lines changed

11 files changed

+46
-45
lines changed

include/net/sctp/sctp.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@
8383
#endif
8484

8585
/* Round an int up to the next multiple of 4. */
86-
#define WORD_ROUND(s) (((s)+3)&~3)
86+
#define SCTP_PAD4(s) (((s)+3)&~3)
8787
/* Truncate to the previous multiple of 4. */
88-
#define WORD_TRUNC(s) ((s)&~3)
88+
#define SCTP_TRUNC4(s) ((s)&~3)
8989

9090
/*
9191
* Function declarations.
@@ -433,7 +433,7 @@ static inline int sctp_frag_point(const struct sctp_association *asoc, int pmtu)
433433
if (asoc->user_frag)
434434
frag = min_t(int, frag, asoc->user_frag);
435435

436-
frag = WORD_TRUNC(min_t(int, frag, SCTP_MAX_CHUNK_LEN));
436+
frag = SCTP_TRUNC4(min_t(int, frag, SCTP_MAX_CHUNK_LEN));
437437

438438
return frag;
439439
}
@@ -462,7 +462,7 @@ _sctp_walk_params((pos), (chunk), ntohs((chunk)->chunk_hdr.length), member)
462462
for (pos.v = chunk->member;\
463463
pos.v <= (void *)chunk + end - ntohs(pos.p->length) &&\
464464
ntohs(pos.p->length) >= sizeof(sctp_paramhdr_t);\
465-
pos.v += WORD_ROUND(ntohs(pos.p->length)))
465+
pos.v += SCTP_PAD4(ntohs(pos.p->length)))
466466

467467
#define sctp_walk_errors(err, chunk_hdr)\
468468
_sctp_walk_errors((err), (chunk_hdr), ntohs((chunk_hdr)->length))
@@ -472,7 +472,7 @@ for (err = (sctp_errhdr_t *)((void *)chunk_hdr + \
472472
sizeof(sctp_chunkhdr_t));\
473473
(void *)err <= (void *)chunk_hdr + end - ntohs(err->length) &&\
474474
ntohs(err->length) >= sizeof(sctp_errhdr_t); \
475-
err = (sctp_errhdr_t *)((void *)err + WORD_ROUND(ntohs(err->length))))
475+
err = (sctp_errhdr_t *)((void *)err + SCTP_PAD4(ntohs(err->length))))
476476

477477
#define sctp_walk_fwdtsn(pos, chunk)\
478478
_sctp_walk_fwdtsn((pos), (chunk), ntohs((chunk)->chunk_hdr->length) - sizeof(struct sctp_fwdtsn_chunk))

net/netfilter/xt_sctp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ match_packet(const struct sk_buff *skb,
6868
++i, offset, sch->type, htons(sch->length),
6969
sch->flags);
7070
#endif
71-
offset += WORD_ROUND(ntohs(sch->length));
71+
offset += SCTP_PAD4(ntohs(sch->length));
7272

7373
pr_debug("skb->len: %d\toffset: %d\n", skb->len, offset);
7474

net/sctp/associola.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ void sctp_assoc_sync_pmtu(struct sock *sk, struct sctp_association *asoc)
14081408
transports) {
14091409
if (t->pmtu_pending && t->dst) {
14101410
sctp_transport_update_pmtu(sk, t,
1411-
WORD_TRUNC(dst_mtu(t->dst)));
1411+
SCTP_TRUNC4(dst_mtu(t->dst)));
14121412
t->pmtu_pending = 0;
14131413
}
14141414
if (!pmtu || (t->pathmtu < pmtu))

net/sctp/chunk.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,10 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
195195
/* This is the biggest possible DATA chunk that can fit into
196196
* the packet
197197
*/
198-
max_data = (asoc->pathmtu -
199-
sctp_sk(asoc->base.sk)->pf->af->net_header_len -
200-
sizeof(struct sctphdr) - sizeof(struct sctp_data_chunk)) & ~3;
198+
max_data = asoc->pathmtu -
199+
sctp_sk(asoc->base.sk)->pf->af->net_header_len -
200+
sizeof(struct sctphdr) - sizeof(struct sctp_data_chunk);
201+
max_data = SCTP_TRUNC4(max_data);
201202

202203
max = asoc->frag_point;
203204
/* If the the peer requested that we authenticate DATA chunks
@@ -208,8 +209,8 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
208209
struct sctp_hmac *hmac_desc = sctp_auth_asoc_get_hmac(asoc);
209210

210211
if (hmac_desc)
211-
max_data -= WORD_ROUND(sizeof(sctp_auth_chunk_t) +
212-
hmac_desc->hmac_len);
212+
max_data -= SCTP_PAD4(sizeof(sctp_auth_chunk_t) +
213+
hmac_desc->hmac_len);
213214
}
214215

215216
/* Now, check if we need to reduce our max */
@@ -229,7 +230,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
229230
asoc->outqueue.out_qlen == 0 &&
230231
list_empty(&asoc->outqueue.retransmit) &&
231232
msg_len > max)
232-
max_data -= WORD_ROUND(sizeof(sctp_sack_chunk_t));
233+
max_data -= SCTP_PAD4(sizeof(sctp_sack_chunk_t));
233234

234235
/* Encourage Cookie-ECHO bundling. */
235236
if (asoc->state < SCTP_STATE_COOKIE_ECHOED)

net/sctp/input.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ void sctp_v4_err(struct sk_buff *skb, __u32 info)
605605
/* PMTU discovery (RFC1191) */
606606
if (ICMP_FRAG_NEEDED == code) {
607607
sctp_icmp_frag_needed(sk, asoc, transport,
608-
WORD_TRUNC(info));
608+
SCTP_TRUNC4(info));
609609
goto out_unlock;
610610
} else {
611611
if (ICMP_PROT_UNREACH == code) {
@@ -673,7 +673,7 @@ static int sctp_rcv_ootb(struct sk_buff *skb)
673673
if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t))
674674
break;
675675

676-
ch_end = offset + WORD_ROUND(ntohs(ch->length));
676+
ch_end = offset + SCTP_PAD4(ntohs(ch->length));
677677
if (ch_end > skb->len)
678678
break;
679679

@@ -1121,7 +1121,7 @@ static struct sctp_association *__sctp_rcv_walk_lookup(struct net *net,
11211121
if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t))
11221122
break;
11231123

1124-
ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
1124+
ch_end = ((__u8 *)ch) + SCTP_PAD4(ntohs(ch->length));
11251125
if (ch_end > skb_tail_pointer(skb))
11261126
break;
11271127

@@ -1190,7 +1190,7 @@ static struct sctp_association *__sctp_rcv_lookup_harder(struct net *net,
11901190
* that the chunk length doesn't cause overflow. Otherwise, we'll
11911191
* walk off the end.
11921192
*/
1193-
if (WORD_ROUND(ntohs(ch->length)) > skb->len)
1193+
if (SCTP_PAD4(ntohs(ch->length)) > skb->len)
11941194
return NULL;
11951195

11961196
/* If this is INIT/INIT-ACK look inside the chunk too. */

net/sctp/inqueue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue)
213213
}
214214

215215
chunk->chunk_hdr = ch;
216-
chunk->chunk_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
216+
chunk->chunk_end = ((__u8 *)ch) + SCTP_PAD4(ntohs(ch->length));
217217
skb_pull(chunk->skb, sizeof(sctp_chunkhdr_t));
218218
chunk->subh.v = NULL; /* Subheader is no longer valid. */
219219

net/sctp/output.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static sctp_xmit_t __sctp_packet_append_chunk(struct sctp_packet *packet,
297297
struct sctp_chunk *chunk)
298298
{
299299
sctp_xmit_t retval = SCTP_XMIT_OK;
300-
__u16 chunk_len = WORD_ROUND(ntohs(chunk->chunk_hdr->length));
300+
__u16 chunk_len = SCTP_PAD4(ntohs(chunk->chunk_hdr->length));
301301

302302
/* Check to see if this chunk will fit into the packet */
303303
retval = sctp_packet_will_fit(packet, chunk, chunk_len);
@@ -508,7 +508,7 @@ int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp)
508508
if (gso) {
509509
pkt_size = packet->overhead;
510510
list_for_each_entry(chunk, &packet->chunk_list, list) {
511-
int padded = WORD_ROUND(chunk->skb->len);
511+
int padded = SCTP_PAD4(chunk->skb->len);
512512

513513
if (pkt_size + padded > tp->pathmtu)
514514
break;
@@ -538,7 +538,7 @@ int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp)
538538
* included in the chunk length field. The sender should
539539
* never pad with more than 3 bytes.
540540
*
541-
* [This whole comment explains WORD_ROUND() below.]
541+
* [This whole comment explains SCTP_PAD4() below.]
542542
*/
543543

544544
pkt_size -= packet->overhead;
@@ -560,7 +560,7 @@ int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp)
560560
has_data = 1;
561561
}
562562

563-
padding = WORD_ROUND(chunk->skb->len) - chunk->skb->len;
563+
padding = SCTP_PAD4(chunk->skb->len) - chunk->skb->len;
564564
if (padding)
565565
memset(skb_put(chunk->skb, padding), 0, padding);
566566

@@ -587,7 +587,7 @@ int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp)
587587
* acknowledged or have failed.
588588
* Re-queue auth chunks if needed.
589589
*/
590-
pkt_size -= WORD_ROUND(chunk->skb->len);
590+
pkt_size -= SCTP_PAD4(chunk->skb->len);
591591

592592
if (!sctp_chunk_is_data(chunk) && chunk != packet->auth)
593593
sctp_chunk_free(chunk);
@@ -911,7 +911,7 @@ static sctp_xmit_t sctp_packet_will_fit(struct sctp_packet *packet,
911911
*/
912912
maxsize = pmtu - packet->overhead;
913913
if (packet->auth)
914-
maxsize -= WORD_ROUND(packet->auth->skb->len);
914+
maxsize -= SCTP_PAD4(packet->auth->skb->len);
915915
if (chunk_len > maxsize)
916916
retval = SCTP_XMIT_PMTU_FULL;
917917

net/sctp/sm_make_chunk.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
253253
num_types = sp->pf->supported_addrs(sp, types);
254254

255255
chunksize = sizeof(init) + addrs_len;
256-
chunksize += WORD_ROUND(SCTP_SAT_LEN(num_types));
256+
chunksize += SCTP_PAD4(SCTP_SAT_LEN(num_types));
257257
chunksize += sizeof(ecap_param);
258258

259259
if (asoc->prsctp_enable)
@@ -283,14 +283,14 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
283283
/* Add HMACS parameter length if any were defined */
284284
auth_hmacs = (sctp_paramhdr_t *)asoc->c.auth_hmacs;
285285
if (auth_hmacs->length)
286-
chunksize += WORD_ROUND(ntohs(auth_hmacs->length));
286+
chunksize += SCTP_PAD4(ntohs(auth_hmacs->length));
287287
else
288288
auth_hmacs = NULL;
289289

290290
/* Add CHUNKS parameter length */
291291
auth_chunks = (sctp_paramhdr_t *)asoc->c.auth_chunks;
292292
if (auth_chunks->length)
293-
chunksize += WORD_ROUND(ntohs(auth_chunks->length));
293+
chunksize += SCTP_PAD4(ntohs(auth_chunks->length));
294294
else
295295
auth_chunks = NULL;
296296

@@ -300,8 +300,8 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
300300

301301
/* If we have any extensions to report, account for that */
302302
if (num_ext)
303-
chunksize += WORD_ROUND(sizeof(sctp_supported_ext_param_t) +
304-
num_ext);
303+
chunksize += SCTP_PAD4(sizeof(sctp_supported_ext_param_t) +
304+
num_ext);
305305

306306
/* RFC 2960 3.3.2 Initiation (INIT) (1)
307307
*
@@ -443,13 +443,13 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
443443

444444
auth_hmacs = (sctp_paramhdr_t *)asoc->c.auth_hmacs;
445445
if (auth_hmacs->length)
446-
chunksize += WORD_ROUND(ntohs(auth_hmacs->length));
446+
chunksize += SCTP_PAD4(ntohs(auth_hmacs->length));
447447
else
448448
auth_hmacs = NULL;
449449

450450
auth_chunks = (sctp_paramhdr_t *)asoc->c.auth_chunks;
451451
if (auth_chunks->length)
452-
chunksize += WORD_ROUND(ntohs(auth_chunks->length));
452+
chunksize += SCTP_PAD4(ntohs(auth_chunks->length));
453453
else
454454
auth_chunks = NULL;
455455

@@ -458,8 +458,8 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
458458
}
459459

460460
if (num_ext)
461-
chunksize += WORD_ROUND(sizeof(sctp_supported_ext_param_t) +
462-
num_ext);
461+
chunksize += SCTP_PAD4(sizeof(sctp_supported_ext_param_t) +
462+
num_ext);
463463

464464
/* Now allocate and fill out the chunk. */
465465
retval = sctp_make_control(asoc, SCTP_CID_INIT_ACK, 0, chunksize, gfp);
@@ -1390,7 +1390,7 @@ static struct sctp_chunk *_sctp_make_chunk(const struct sctp_association *asoc,
13901390
struct sock *sk;
13911391

13921392
/* No need to allocate LL here, as this is only a chunk. */
1393-
skb = alloc_skb(WORD_ROUND(sizeof(sctp_chunkhdr_t) + paylen), gfp);
1393+
skb = alloc_skb(SCTP_PAD4(sizeof(sctp_chunkhdr_t) + paylen), gfp);
13941394
if (!skb)
13951395
goto nodata;
13961396

@@ -1482,7 +1482,7 @@ void *sctp_addto_chunk(struct sctp_chunk *chunk, int len, const void *data)
14821482
void *target;
14831483
void *padding;
14841484
int chunklen = ntohs(chunk->chunk_hdr->length);
1485-
int padlen = WORD_ROUND(chunklen) - chunklen;
1485+
int padlen = SCTP_PAD4(chunklen) - chunklen;
14861486

14871487
padding = skb_put(chunk->skb, padlen);
14881488
target = skb_put(chunk->skb, len);
@@ -1900,7 +1900,7 @@ static int sctp_process_missing_param(const struct sctp_association *asoc,
19001900
struct __sctp_missing report;
19011901
__u16 len;
19021902

1903-
len = WORD_ROUND(sizeof(report));
1903+
len = SCTP_PAD4(sizeof(report));
19041904

19051905
/* Make an ERROR chunk, preparing enough room for
19061906
* returning multiple unknown parameters.
@@ -2098,9 +2098,9 @@ static sctp_ierror_t sctp_process_unk_param(const struct sctp_association *asoc,
20982098

20992099
if (*errp) {
21002100
if (!sctp_init_cause_fixed(*errp, SCTP_ERROR_UNKNOWN_PARAM,
2101-
WORD_ROUND(ntohs(param.p->length))))
2101+
SCTP_PAD4(ntohs(param.p->length))))
21022102
sctp_addto_chunk_fixed(*errp,
2103-
WORD_ROUND(ntohs(param.p->length)),
2103+
SCTP_PAD4(ntohs(param.p->length)),
21042104
param.v);
21052105
} else {
21062106
/* If there is no memory for generating the ERROR

net/sctp/sm_statefuns.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3454,7 +3454,7 @@ sctp_disposition_t sctp_sf_ootb(struct net *net,
34543454
}
34553455

34563456
/* Report violation if chunk len overflows */
3457-
ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
3457+
ch_end = ((__u8 *)ch) + SCTP_PAD4(ntohs(ch->length));
34583458
if (ch_end > skb_tail_pointer(skb))
34593459
return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
34603460
commands);
@@ -4185,7 +4185,7 @@ sctp_disposition_t sctp_sf_unk_chunk(struct net *net,
41854185
hdr = unk_chunk->chunk_hdr;
41864186
err_chunk = sctp_make_op_error(asoc, unk_chunk,
41874187
SCTP_ERROR_UNKNOWN_CHUNK, hdr,
4188-
WORD_ROUND(ntohs(hdr->length)),
4188+
SCTP_PAD4(ntohs(hdr->length)),
41894189
0);
41904190
if (err_chunk) {
41914191
sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
@@ -4203,7 +4203,7 @@ sctp_disposition_t sctp_sf_unk_chunk(struct net *net,
42034203
hdr = unk_chunk->chunk_hdr;
42044204
err_chunk = sctp_make_op_error(asoc, unk_chunk,
42054205
SCTP_ERROR_UNKNOWN_CHUNK, hdr,
4206-
WORD_ROUND(ntohs(hdr->length)),
4206+
SCTP_PAD4(ntohs(hdr->length)),
42074207
0);
42084208
if (err_chunk) {
42094209
sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,

net/sctp/transport.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void sctp_transport_pmtu(struct sctp_transport *transport, struct sock *sk)
233233
}
234234

235235
if (transport->dst) {
236-
transport->pathmtu = WORD_TRUNC(dst_mtu(transport->dst));
236+
transport->pathmtu = SCTP_TRUNC4(dst_mtu(transport->dst));
237237
} else
238238
transport->pathmtu = SCTP_DEFAULT_MAXSEGMENT;
239239
}
@@ -287,7 +287,7 @@ void sctp_transport_route(struct sctp_transport *transport,
287287
return;
288288
}
289289
if (transport->dst) {
290-
transport->pathmtu = WORD_TRUNC(dst_mtu(transport->dst));
290+
transport->pathmtu = SCTP_TRUNC4(dst_mtu(transport->dst));
291291

292292
/* Initialize sk->sk_rcv_saddr, if the transport is the
293293
* association's active path for getsockname().

net/sctp/ulpevent.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ sctp_ulpevent_make_remote_error(const struct sctp_association *asoc,
383383

384384
ch = (sctp_errhdr_t *)(chunk->skb->data);
385385
cause = ch->cause;
386-
elen = WORD_ROUND(ntohs(ch->length)) - sizeof(sctp_errhdr_t);
386+
elen = SCTP_PAD4(ntohs(ch->length)) - sizeof(sctp_errhdr_t);
387387

388388
/* Pull off the ERROR header. */
389389
skb_pull(chunk->skb, sizeof(sctp_errhdr_t));
@@ -688,7 +688,7 @@ struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
688688
* MUST ignore the padding bytes.
689689
*/
690690
len = ntohs(chunk->chunk_hdr->length);
691-
padding = WORD_ROUND(len) - len;
691+
padding = SCTP_PAD4(len) - len;
692692

693693
/* Fixup cloned skb with just this chunks data. */
694694
skb_trim(skb, chunk->chunk_end - padding - skb->data);

0 commit comments

Comments
 (0)