Skip to content

Commit 05364ca

Browse files
finist0davem330
authored andcommitted
net/sctp: Make wrappers for accessing in/out streams
This patch introduces wrappers for accessing in/out streams indirectly. This will enable to replace physically contiguous memory arrays of streams with flexible arrays (or maybe any other appropriate mechanism) which do memory allocation on a per-page basis. Signed-off-by: Oleg Babin <obabin@virtuozzo.com> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b70f1f3 commit 05364ca

9 files changed

Lines changed: 103 additions & 81 deletions

File tree

‎include/net/sctp/structs.h‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -398,37 +398,35 @@ void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new);
398398

399399
/* What is the current SSN number for this stream? */
400400
#define sctp_ssn_peek(stream, type, sid) \
401-
((stream)->type[sid].ssn)
401+
(sctp_stream_##type((stream), (sid))->ssn)
402402

403403
/* Return the next SSN number for this stream. */
404404
#define sctp_ssn_next(stream, type, sid) \
405-
((stream)->type[sid].ssn++)
405+
(sctp_stream_##type((stream), (sid))->ssn++)
406406

407407
/* Skip over this ssn and all below. */
408408
#define sctp_ssn_skip(stream, type, sid, ssn) \
409-
((stream)->type[sid].ssn = ssn + 1)
409+
(sctp_stream_##type((stream), (sid))->ssn = ssn + 1)
410410

411411
/* What is the current MID number for this stream? */
412412
#define sctp_mid_peek(stream, type, sid) \
413-
((stream)->type[sid].mid)
413+
(sctp_stream_##type((stream), (sid))->mid)
414414

415415
/* Return the next MID number for this stream. */
416416
#define sctp_mid_next(stream, type, sid) \
417-
((stream)->type[sid].mid++)
417+
(sctp_stream_##type((stream), (sid))->mid++)
418418

419419
/* Skip over this mid and all below. */
420420
#define sctp_mid_skip(stream, type, sid, mid) \
421-
((stream)->type[sid].mid = mid + 1)
422-
423-
#define sctp_stream_in(asoc, sid) (&(asoc)->stream.in[sid])
421+
(sctp_stream_##type((stream), (sid))->mid = mid + 1)
424422

425423
/* What is the current MID_uo number for this stream? */
426424
#define sctp_mid_uo_peek(stream, type, sid) \
427-
((stream)->type[sid].mid_uo)
425+
(sctp_stream_##type((stream), (sid))->mid_uo)
428426

429427
/* Return the next MID_uo number for this stream. */
430428
#define sctp_mid_uo_next(stream, type, sid) \
431-
((stream)->type[sid].mid_uo++)
429+
(sctp_stream_##type((stream), (sid))->mid_uo++)
432430

433431
/*
434432
* Pointers to address related SCTP functions.
@@ -1463,6 +1461,23 @@ struct sctp_stream {
14631461
struct sctp_stream_interleave *si;
14641462
};
14651463

1464+
static inline struct sctp_stream_out *sctp_stream_out(
1465+
const struct sctp_stream *stream,
1466+
__u16 sid)
1467+
{
1468+
return ((struct sctp_stream_out *)(stream->out)) + sid;
1469+
}
1470+
1471+
static inline struct sctp_stream_in *sctp_stream_in(
1472+
const struct sctp_stream *stream,
1473+
__u16 sid)
1474+
{
1475+
return ((struct sctp_stream_in *)(stream->in)) + sid;
1476+
}
1477+
1478+
#define SCTP_SO(s, i) sctp_stream_out((s), (i))
1479+
#define SCTP_SI(s, i) sctp_stream_in((s), (i))
1480+
14661481
#define SCTP_STREAM_CLOSED 0x00
14671482
#define SCTP_STREAM_OPEN 0x01
14681483

‎net/sctp/chunk.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ int sctp_chunk_abandoned(struct sctp_chunk *chunk)
325325
if (SCTP_PR_TTL_ENABLED(chunk->sinfo.sinfo_flags) &&
326326
time_after(jiffies, chunk->msg->expires_at)) {
327327
struct sctp_stream_out *streamout =
328-
&chunk->asoc->stream.out[chunk->sinfo.sinfo_stream];
328+
SCTP_SO(&chunk->asoc->stream,
329+
chunk->sinfo.sinfo_stream);
329330

330331
if (chunk->sent_count) {
331332
chunk->asoc->abandoned_sent[SCTP_PR_INDEX(TTL)]++;
@@ -339,7 +340,8 @@ int sctp_chunk_abandoned(struct sctp_chunk *chunk)
339340
} else if (SCTP_PR_RTX_ENABLED(chunk->sinfo.sinfo_flags) &&
340341
chunk->sent_count > chunk->sinfo.sinfo_timetolive) {
341342
struct sctp_stream_out *streamout =
342-
&chunk->asoc->stream.out[chunk->sinfo.sinfo_stream];
343+
SCTP_SO(&chunk->asoc->stream,
344+
chunk->sinfo.sinfo_stream);
343345

344346
chunk->asoc->abandoned_sent[SCTP_PR_INDEX(RTX)]++;
345347
streamout->ext->abandoned_sent[SCTP_PR_INDEX(RTX)]++;

‎net/sctp/outqueue.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static inline void sctp_outq_head_data(struct sctp_outq *q,
8080
q->out_qlen += ch->skb->len;
8181

8282
stream = sctp_chunk_stream_no(ch);
83-
oute = q->asoc->stream.out[stream].ext;
83+
oute = SCTP_SO(&q->asoc->stream, stream)->ext;
8484
list_add(&ch->stream_list, &oute->outq);
8585
}
8686

@@ -101,7 +101,7 @@ static inline void sctp_outq_tail_data(struct sctp_outq *q,
101101
q->out_qlen += ch->skb->len;
102102

103103
stream = sctp_chunk_stream_no(ch);
104-
oute = q->asoc->stream.out[stream].ext;
104+
oute = SCTP_SO(&q->asoc->stream, stream)->ext;
105105
list_add_tail(&ch->stream_list, &oute->outq);
106106
}
107107

@@ -372,7 +372,7 @@ static int sctp_prsctp_prune_sent(struct sctp_association *asoc,
372372
sctp_insert_list(&asoc->outqueue.abandoned,
373373
&chk->transmitted_list);
374374

375-
streamout = &asoc->stream.out[chk->sinfo.sinfo_stream];
375+
streamout = SCTP_SO(&asoc->stream, chk->sinfo.sinfo_stream);
376376
asoc->sent_cnt_removable--;
377377
asoc->abandoned_sent[SCTP_PR_INDEX(PRIO)]++;
378378
streamout->ext->abandoned_sent[SCTP_PR_INDEX(PRIO)]++;
@@ -416,7 +416,7 @@ static int sctp_prsctp_prune_unsent(struct sctp_association *asoc,
416416
asoc->abandoned_unsent[SCTP_PR_INDEX(PRIO)]++;
417417
if (chk->sinfo.sinfo_stream < asoc->stream.outcnt) {
418418
struct sctp_stream_out *streamout =
419-
&asoc->stream.out[chk->sinfo.sinfo_stream];
419+
SCTP_SO(&asoc->stream, chk->sinfo.sinfo_stream);
420420

421421
streamout->ext->abandoned_unsent[SCTP_PR_INDEX(PRIO)]++;
422422
}
@@ -1082,6 +1082,7 @@ static void sctp_outq_flush_data(struct sctp_flush_ctx *ctx,
10821082
/* Finally, transmit new packets. */
10831083
while ((chunk = sctp_outq_dequeue_data(ctx->q)) != NULL) {
10841084
__u32 sid = ntohs(chunk->subh.data_hdr->stream);
1085+
__u8 stream_state = SCTP_SO(&ctx->asoc->stream, sid)->state;
10851086

10861087
/* Has this chunk expired? */
10871088
if (sctp_chunk_abandoned(chunk)) {
@@ -1091,7 +1092,7 @@ static void sctp_outq_flush_data(struct sctp_flush_ctx *ctx,
10911092
continue;
10921093
}
10931094

1094-
if (ctx->asoc->stream.out[sid].state == SCTP_STREAM_CLOSED) {
1095+
if (stream_state == SCTP_STREAM_CLOSED) {
10951096
sctp_outq_head_data(ctx->q, chunk);
10961097
break;
10971098
}

‎net/sctp/socket.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,7 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,
19111911
goto err;
19121912
}
19131913

1914-
if (unlikely(!asoc->stream.out[sinfo->sinfo_stream].ext)) {
1914+
if (unlikely(!SCTP_SO(&asoc->stream, sinfo->sinfo_stream)->ext)) {
19151915
err = sctp_stream_init_ext(&asoc->stream, sinfo->sinfo_stream);
19161916
if (err)
19171917
goto err;
@@ -7154,7 +7154,7 @@ static int sctp_getsockopt_pr_streamstatus(struct sock *sk, int len,
71547154
if (!asoc || params.sprstat_sid >= asoc->stream.outcnt)
71557155
goto out;
71567156

7157-
streamoute = asoc->stream.out[params.sprstat_sid].ext;
7157+
streamoute = SCTP_SO(&asoc->stream, params.sprstat_sid)->ext;
71587158
if (!streamoute) {
71597159
/* Not allocated yet, means all stats are 0 */
71607160
params.sprstat_abandoned_unsent = 0;

‎net/sctp/stream.c‎

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
162162

163163
stream->outcnt = outcnt;
164164
for (i = 0; i < stream->outcnt; i++)
165-
stream->out[i].state = SCTP_STREAM_OPEN;
165+
SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN;
166166

167167
sched->init(stream);
168168

@@ -193,7 +193,7 @@ int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid)
193193
soute = kzalloc(sizeof(*soute), GFP_KERNEL);
194194
if (!soute)
195195
return -ENOMEM;
196-
stream->out[sid].ext = soute;
196+
SCTP_SO(stream, sid)->ext = soute;
197197

198198
return sctp_sched_init_sid(stream, sid, GFP_KERNEL);
199199
}
@@ -205,7 +205,7 @@ void sctp_stream_free(struct sctp_stream *stream)
205205

206206
sched->free(stream);
207207
for (i = 0; i < stream->outcnt; i++)
208-
kfree(stream->out[i].ext);
208+
kfree(SCTP_SO(stream, i)->ext);
209209
kfree(stream->out);
210210
kfree(stream->in);
211211
}
@@ -215,12 +215,12 @@ void sctp_stream_clear(struct sctp_stream *stream)
215215
int i;
216216

217217
for (i = 0; i < stream->outcnt; i++) {
218-
stream->out[i].mid = 0;
219-
stream->out[i].mid_uo = 0;
218+
SCTP_SO(stream, i)->mid = 0;
219+
SCTP_SO(stream, i)->mid_uo = 0;
220220
}
221221

222222
for (i = 0; i < stream->incnt; i++)
223-
stream->in[i].mid = 0;
223+
SCTP_SI(stream, i)->mid = 0;
224224
}
225225

226226
void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new)
@@ -273,8 +273,8 @@ static bool sctp_stream_outq_is_empty(struct sctp_stream *stream,
273273
for (i = 0; i < str_nums; i++) {
274274
__u16 sid = ntohs(str_list[i]);
275275

276-
if (stream->out[sid].ext &&
277-
!list_empty(&stream->out[sid].ext->outq))
276+
if (SCTP_SO(stream, sid)->ext &&
277+
!list_empty(&SCTP_SO(stream, sid)->ext->outq))
278278
return false;
279279
}
280280

@@ -361,11 +361,11 @@ int sctp_send_reset_streams(struct sctp_association *asoc,
361361
if (out) {
362362
if (str_nums)
363363
for (i = 0; i < str_nums; i++)
364-
stream->out[str_list[i]].state =
364+
SCTP_SO(stream, str_list[i])->state =
365365
SCTP_STREAM_CLOSED;
366366
else
367367
for (i = 0; i < stream->outcnt; i++)
368-
stream->out[i].state = SCTP_STREAM_CLOSED;
368+
SCTP_SO(stream, i)->state = SCTP_STREAM_CLOSED;
369369
}
370370

371371
asoc->strreset_chunk = chunk;
@@ -380,11 +380,11 @@ int sctp_send_reset_streams(struct sctp_association *asoc,
380380

381381
if (str_nums)
382382
for (i = 0; i < str_nums; i++)
383-
stream->out[str_list[i]].state =
383+
SCTP_SO(stream, str_list[i])->state =
384384
SCTP_STREAM_OPEN;
385385
else
386386
for (i = 0; i < stream->outcnt; i++)
387-
stream->out[i].state = SCTP_STREAM_OPEN;
387+
SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN;
388388

389389
goto out;
390390
}
@@ -418,7 +418,7 @@ int sctp_send_reset_assoc(struct sctp_association *asoc)
418418

419419
/* Block further xmit of data until this request is completed */
420420
for (i = 0; i < stream->outcnt; i++)
421-
stream->out[i].state = SCTP_STREAM_CLOSED;
421+
SCTP_SO(stream, i)->state = SCTP_STREAM_CLOSED;
422422

423423
asoc->strreset_chunk = chunk;
424424
sctp_chunk_hold(asoc->strreset_chunk);
@@ -429,7 +429,7 @@ int sctp_send_reset_assoc(struct sctp_association *asoc)
429429
asoc->strreset_chunk = NULL;
430430

431431
for (i = 0; i < stream->outcnt; i++)
432-
stream->out[i].state = SCTP_STREAM_OPEN;
432+
SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN;
433433

434434
return retval;
435435
}
@@ -609,10 +609,10 @@ struct sctp_chunk *sctp_process_strreset_outreq(
609609
}
610610

611611
for (i = 0; i < nums; i++)
612-
stream->in[ntohs(str_p[i])].mid = 0;
612+
SCTP_SI(stream, ntohs(str_p[i]))->mid = 0;
613613
} else {
614614
for (i = 0; i < stream->incnt; i++)
615-
stream->in[i].mid = 0;
615+
SCTP_SI(stream, i)->mid = 0;
616616
}
617617

618618
result = SCTP_STRRESET_PERFORMED;
@@ -683,11 +683,11 @@ struct sctp_chunk *sctp_process_strreset_inreq(
683683

684684
if (nums)
685685
for (i = 0; i < nums; i++)
686-
stream->out[ntohs(str_p[i])].state =
686+
SCTP_SO(stream, ntohs(str_p[i]))->state =
687687
SCTP_STREAM_CLOSED;
688688
else
689689
for (i = 0; i < stream->outcnt; i++)
690-
stream->out[i].state = SCTP_STREAM_CLOSED;
690+
SCTP_SO(stream, i)->state = SCTP_STREAM_CLOSED;
691691

692692
asoc->strreset_chunk = chunk;
693693
asoc->strreset_outstanding = 1;
@@ -786,11 +786,11 @@ struct sctp_chunk *sctp_process_strreset_tsnreq(
786786
* incoming and outgoing streams.
787787
*/
788788
for (i = 0; i < stream->outcnt; i++) {
789-
stream->out[i].mid = 0;
790-
stream->out[i].mid_uo = 0;
789+
SCTP_SO(stream, i)->mid = 0;
790+
SCTP_SO(stream, i)->mid_uo = 0;
791791
}
792792
for (i = 0; i < stream->incnt; i++)
793-
stream->in[i].mid = 0;
793+
SCTP_SI(stream, i)->mid = 0;
794794

795795
result = SCTP_STRRESET_PERFORMED;
796796

@@ -979,23 +979,26 @@ struct sctp_chunk *sctp_process_strreset_resp(
979979
sizeof(__u16);
980980

981981
if (result == SCTP_STRRESET_PERFORMED) {
982+
struct sctp_stream_out *sout;
982983
if (nums) {
983984
for (i = 0; i < nums; i++) {
984-
stream->out[ntohs(str_p[i])].mid = 0;
985-
stream->out[ntohs(str_p[i])].mid_uo = 0;
985+
sout = SCTP_SO(stream, ntohs(str_p[i]));
986+
sout->mid = 0;
987+
sout->mid_uo = 0;
986988
}
987989
} else {
988990
for (i = 0; i < stream->outcnt; i++) {
989-
stream->out[i].mid = 0;
990-
stream->out[i].mid_uo = 0;
991+
sout = SCTP_SO(stream, i);
992+
sout->mid = 0;
993+
sout->mid_uo = 0;
991994
}
992995
}
993996

994997
flags = SCTP_STREAM_RESET_OUTGOING_SSN;
995998
}
996999

9971000
for (i = 0; i < stream->outcnt; i++)
998-
stream->out[i].state = SCTP_STREAM_OPEN;
1001+
SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN;
9991002

10001003
*evp = sctp_ulpevent_make_stream_reset_event(asoc, flags,
10011004
nums, str_p, GFP_ATOMIC);
@@ -1050,15 +1053,15 @@ struct sctp_chunk *sctp_process_strreset_resp(
10501053
asoc->adv_peer_ack_point = asoc->ctsn_ack_point;
10511054

10521055
for (i = 0; i < stream->outcnt; i++) {
1053-
stream->out[i].mid = 0;
1054-
stream->out[i].mid_uo = 0;
1056+
SCTP_SO(stream, i)->mid = 0;
1057+
SCTP_SO(stream, i)->mid_uo = 0;
10551058
}
10561059
for (i = 0; i < stream->incnt; i++)
1057-
stream->in[i].mid = 0;
1060+
SCTP_SI(stream, i)->mid = 0;
10581061
}
10591062

10601063
for (i = 0; i < stream->outcnt; i++)
1061-
stream->out[i].state = SCTP_STREAM_OPEN;
1064+
SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN;
10621065

10631066
*evp = sctp_ulpevent_make_assoc_reset_event(asoc, flags,
10641067
stsn, rtsn, GFP_ATOMIC);
@@ -1072,7 +1075,7 @@ struct sctp_chunk *sctp_process_strreset_resp(
10721075

10731076
if (result == SCTP_STRRESET_PERFORMED)
10741077
for (i = number; i < stream->outcnt; i++)
1075-
stream->out[i].state = SCTP_STREAM_OPEN;
1078+
SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN;
10761079
else
10771080
stream->outcnt = number;
10781081

0 commit comments

Comments
 (0)