Skip to content

Commit 79af02c

Browse files
committed
[SCTP]: Use struct list_head for chunk lists, not sk_buff_head.
Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9c05989 commit 79af02c

8 files changed

Lines changed: 86 additions & 66 deletions

File tree

‎include/net/sctp/structs.h‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ void sctp_datamsg_track(struct sctp_chunk *);
582582
void sctp_chunk_fail(struct sctp_chunk *, int error);
583583
int sctp_chunk_abandoned(struct sctp_chunk *);
584584

585-
586585
/* RFC2960 1.4 Key Terms
587586
*
588587
* o Chunk: A unit of information within an SCTP packet, consisting of
@@ -592,13 +591,8 @@ int sctp_chunk_abandoned(struct sctp_chunk *);
592591
* each chunk as well as a few other header pointers...
593592
*/
594593
struct sctp_chunk {
595-
/* These first three elements MUST PRECISELY match the first
596-
* three elements of struct sk_buff. This allows us to reuse
597-
* all the skb_* queue management functions.
598-
*/
599-
struct sctp_chunk *next;
600-
struct sctp_chunk *prev;
601-
struct sk_buff_head *list;
594+
struct list_head list;
595+
602596
atomic_t refcnt;
603597

604598
/* This is our link to the per-transport transmitted list. */
@@ -717,7 +711,7 @@ struct sctp_packet {
717711
__u32 vtag;
718712

719713
/* This contains the payload chunks. */
720-
struct sk_buff_head chunks;
714+
struct list_head chunk_list;
721715

722716
/* This is the overhead of the sctp and ip headers. */
723717
size_t overhead;
@@ -974,7 +968,7 @@ struct sctp_inq {
974968
/* This is actually a queue of sctp_chunk each
975969
* containing a partially decoded packet.
976970
*/
977-
struct sk_buff_head in;
971+
struct list_head in_chunk_list;
978972
/* This is the packet which is currently off the in queue and is
979973
* being worked on through the inbound chunk processing.
980974
*/
@@ -1017,15 +1011,15 @@ struct sctp_outq {
10171011
struct sctp_association *asoc;
10181012

10191013
/* Data pending that has never been transmitted. */
1020-
struct sk_buff_head out;
1014+
struct list_head out_chunk_list;
10211015

10221016
unsigned out_qlen; /* Total length of queued data chunks. */
10231017

10241018
/* Error of send failed, may used in SCTP_SEND_FAILED event. */
10251019
unsigned error;
10261020

10271021
/* These are control chunks we want to send. */
1028-
struct sk_buff_head control;
1022+
struct list_head control_chunk_list;
10291023

10301024
/* These are chunks that have been sacked but are above the
10311025
* CTSN, or cumulative tsn ack point.
@@ -1672,7 +1666,7 @@ struct sctp_association {
16721666
* which already resides in sctp_outq. Please move this
16731667
* queue and its supporting logic down there. --piggy]
16741668
*/
1675-
struct sk_buff_head addip_chunks;
1669+
struct list_head addip_chunk_list;
16761670

16771671
/* ADDIP Section 4.1 ASCONF Chunk Procedures
16781672
*

‎net/sctp/associola.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
203203
*/
204204
asoc->addip_serial = asoc->c.initial_tsn;
205205

206-
skb_queue_head_init(&asoc->addip_chunks);
206+
INIT_LIST_HEAD(&asoc->addip_chunk_list);
207207

208208
/* Make an empty list of remote transport addresses. */
209209
INIT_LIST_HEAD(&asoc->peer.transport_addr_list);

‎net/sctp/input.c‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ static void sctp_rcv_set_owner_r(struct sk_buff *skb, struct sock *sk)
115115
atomic_add(sizeof(struct sctp_chunk),&sk->sk_rmem_alloc);
116116
}
117117

118+
struct sctp_input_cb {
119+
union {
120+
struct inet_skb_parm h4;
121+
#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
122+
struct inet6_skb_parm h6;
123+
#endif
124+
} header;
125+
struct sctp_chunk *chunk;
126+
};
127+
#define SCTP_INPUT_CB(__skb) ((struct sctp_input_cb *)&((__skb)->cb[0]))
128+
118129
/*
119130
* This is the routine which IP calls when receiving an SCTP packet.
120131
*/
@@ -243,6 +254,7 @@ int sctp_rcv(struct sk_buff *skb)
243254
ret = -ENOMEM;
244255
goto discard_release;
245256
}
257+
SCTP_INPUT_CB(skb)->chunk = chunk;
246258

247259
sctp_rcv_set_owner_r(skb,sk);
248260

@@ -265,9 +277,9 @@ int sctp_rcv(struct sk_buff *skb)
265277
sctp_bh_lock_sock(sk);
266278

267279
if (sock_owned_by_user(sk))
268-
sk_add_backlog(sk, (struct sk_buff *) chunk);
280+
sk_add_backlog(sk, skb);
269281
else
270-
sctp_backlog_rcv(sk, (struct sk_buff *) chunk);
282+
sctp_backlog_rcv(sk, skb);
271283

272284
/* Release the sock and any reference counts we took in the
273285
* lookup calls.
@@ -302,14 +314,8 @@ int sctp_rcv(struct sk_buff *skb)
302314
*/
303315
int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb)
304316
{
305-
struct sctp_chunk *chunk;
306-
struct sctp_inq *inqueue;
307-
308-
/* One day chunk will live inside the skb, but for
309-
* now this works.
310-
*/
311-
chunk = (struct sctp_chunk *) skb;
312-
inqueue = &chunk->rcvr->inqueue;
317+
struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk;
318+
struct sctp_inq *inqueue = &chunk->rcvr->inqueue;
313319

314320
sctp_inq_push(inqueue, chunk);
315321
return 0;

‎net/sctp/inqueue.c‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
/* Initialize an SCTP inqueue. */
5151
void sctp_inq_init(struct sctp_inq *queue)
5252
{
53-
skb_queue_head_init(&queue->in);
53+
INIT_LIST_HEAD(&queue->in_chunk_list);
5454
queue->in_progress = NULL;
5555

5656
/* Create a task for delivering data. */
@@ -62,11 +62,13 @@ void sctp_inq_init(struct sctp_inq *queue)
6262
/* Release the memory associated with an SCTP inqueue. */
6363
void sctp_inq_free(struct sctp_inq *queue)
6464
{
65-
struct sctp_chunk *chunk;
65+
struct sctp_chunk *chunk, *tmp;
6666

6767
/* Empty the queue. */
68-
while ((chunk = (struct sctp_chunk *) skb_dequeue(&queue->in)) != NULL)
68+
list_for_each_entry_safe(chunk, tmp, &queue->in_chunk_list, list) {
69+
list_del_init(&chunk->list);
6970
sctp_chunk_free(chunk);
71+
}
7072

7173
/* If there is a packet which is currently being worked on,
7274
* free it as well.
@@ -92,7 +94,7 @@ void sctp_inq_push(struct sctp_inq *q, struct sctp_chunk *packet)
9294
* Eventually, we should clean up inqueue to not rely
9395
* on the BH related data structures.
9496
*/
95-
skb_queue_tail(&(q->in), (struct sk_buff *) packet);
97+
list_add_tail(&packet->list, &q->in_chunk_list);
9698
q->immediate.func(q->immediate.data);
9799
}
98100

@@ -131,12 +133,16 @@ struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue)
131133

132134
/* Do we need to take the next packet out of the queue to process? */
133135
if (!chunk) {
136+
struct list_head *entry;
137+
134138
/* Is the queue empty? */
135-
if (skb_queue_empty(&queue->in))
139+
if (list_empty(&queue->in_chunk_list))
136140
return NULL;
137141

142+
entry = queue->in_chunk_list.next;
138143
chunk = queue->in_progress =
139-
(struct sctp_chunk *) skb_dequeue(&queue->in);
144+
list_entry(entry, struct sctp_chunk, list);
145+
list_del_init(entry);
140146

141147
/* This is the first chunk in the packet. */
142148
chunk->singleton = 1;

‎net/sctp/output.c‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct sctp_packet *sctp_packet_init(struct sctp_packet *packet,
108108
packet->transport = transport;
109109
packet->source_port = sport;
110110
packet->destination_port = dport;
111-
skb_queue_head_init(&packet->chunks);
111+
INIT_LIST_HEAD(&packet->chunk_list);
112112
if (asoc) {
113113
struct sctp_sock *sp = sctp_sk(asoc->base.sk);
114114
overhead = sp->pf->af->net_header_len;
@@ -129,12 +129,14 @@ struct sctp_packet *sctp_packet_init(struct sctp_packet *packet,
129129
/* Free a packet. */
130130
void sctp_packet_free(struct sctp_packet *packet)
131131
{
132-
struct sctp_chunk *chunk;
132+
struct sctp_chunk *chunk, *tmp;
133133

134134
SCTP_DEBUG_PRINTK("%s: packet:%p\n", __FUNCTION__, packet);
135135

136-
while ((chunk = (struct sctp_chunk *)__skb_dequeue(&packet->chunks)) != NULL)
136+
list_for_each_entry_safe(chunk, tmp, &packet->chunk_list, list) {
137+
list_del_init(&chunk->list);
137138
sctp_chunk_free(chunk);
139+
}
138140

139141
if (packet->malloced)
140142
kfree(packet);
@@ -276,7 +278,7 @@ sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *packet,
276278
packet->has_sack = 1;
277279

278280
/* It is OK to send this chunk. */
279-
__skb_queue_tail(&packet->chunks, (struct sk_buff *)chunk);
281+
list_add_tail(&chunk->list, &packet->chunk_list);
280282
packet->size += chunk_len;
281283
chunk->transport = packet->transport;
282284
finish:
@@ -295,7 +297,7 @@ int sctp_packet_transmit(struct sctp_packet *packet)
295297
struct sctphdr *sh;
296298
__u32 crc32;
297299
struct sk_buff *nskb;
298-
struct sctp_chunk *chunk;
300+
struct sctp_chunk *chunk, *tmp;
299301
struct sock *sk;
300302
int err = 0;
301303
int padding; /* How much padding do we need? */
@@ -305,11 +307,11 @@ int sctp_packet_transmit(struct sctp_packet *packet)
305307
SCTP_DEBUG_PRINTK("%s: packet:%p\n", __FUNCTION__, packet);
306308

307309
/* Do NOT generate a chunkless packet. */
308-
chunk = (struct sctp_chunk *)skb_peek(&packet->chunks);
309-
if (unlikely(!chunk))
310+
if (list_empty(&packet->chunk_list))
310311
return err;
311312

312313
/* Set up convenience variables... */
314+
chunk = list_entry(packet->chunk_list.next, struct sctp_chunk, list);
313315
sk = chunk->skb->sk;
314316

315317
/* Allocate the new skb. */
@@ -370,7 +372,8 @@ int sctp_packet_transmit(struct sctp_packet *packet)
370372
* [This whole comment explains WORD_ROUND() below.]
371373
*/
372374
SCTP_DEBUG_PRINTK("***sctp_transmit_packet***\n");
373-
while ((chunk = (struct sctp_chunk *)__skb_dequeue(&packet->chunks)) != NULL) {
375+
list_for_each_entry_safe(chunk, tmp, &packet->chunk_list, list) {
376+
list_del_init(&chunk->list);
374377
if (sctp_chunk_is_data(chunk)) {
375378

376379
if (!chunk->has_tsn) {
@@ -511,7 +514,8 @@ int sctp_packet_transmit(struct sctp_packet *packet)
511514
* will get resent or dropped later.
512515
*/
513516

514-
while ((chunk = (struct sctp_chunk *)__skb_dequeue(&packet->chunks)) != NULL) {
517+
list_for_each_entry_safe(chunk, tmp, &packet->chunk_list, list) {
518+
list_del_init(&chunk->list);
515519
if (!sctp_chunk_is_data(chunk))
516520
sctp_chunk_free(chunk);
517521
}

0 commit comments

Comments
 (0)