Blame view
net/sctp/inqueue.c
7 KB
60c778b25 [SCTP]: Stop clai... |
1 |
/* SCTP kernel implementation |
1da177e4c Linux-2.6.12-rc2 |
2 3 4 |
* Copyright (c) 1999-2000 Cisco, Inc. * Copyright (c) 1999-2001 Motorola, Inc. * Copyright (c) 2002 International Business Machines, Corp. |
d808ad9ab [NET] SCTP: Fix w... |
5 |
* |
60c778b25 [SCTP]: Stop clai... |
6 |
* This file is part of the SCTP kernel implementation |
d808ad9ab [NET] SCTP: Fix w... |
7 |
* |
1da177e4c Linux-2.6.12-rc2 |
8 9 10 11 12 |
* These functions are the methods for accessing the SCTP inqueue. * * An SCTP inqueue is a queue into which you push SCTP packets * (which might be bundles or fragments of chunks) and out of which you * pop SCTP whole chunks. |
d808ad9ab [NET] SCTP: Fix w... |
13 |
* |
60c778b25 [SCTP]: Stop clai... |
14 |
* This SCTP implementation is free software; |
d808ad9ab [NET] SCTP: Fix w... |
15 |
* you can redistribute it and/or modify it under the terms of |
1da177e4c Linux-2.6.12-rc2 |
16 17 18 |
* the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. |
d808ad9ab [NET] SCTP: Fix w... |
19 |
* |
60c778b25 [SCTP]: Stop clai... |
20 |
* This SCTP implementation is distributed in the hope that it |
1da177e4c Linux-2.6.12-rc2 |
21 22 23 24 |
* will be useful, but WITHOUT ANY WARRANTY; without even the implied * ************************ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. |
d808ad9ab [NET] SCTP: Fix w... |
25 |
* |
1da177e4c Linux-2.6.12-rc2 |
26 27 28 |
* You should have received a copy of the GNU General Public License * along with GNU CC; see the file COPYING. If not, write to * the Free Software Foundation, 59 Temple Place - Suite 330, |
d808ad9ab [NET] SCTP: Fix w... |
29 30 |
* Boston, MA 02111-1307, USA. * |
1da177e4c Linux-2.6.12-rc2 |
31 32 33 |
* Please send any bug reports or fixes you make to the * email address(es): * lksctp developers <lksctp-developers@lists.sourceforge.net> |
d808ad9ab [NET] SCTP: Fix w... |
34 |
* |
1da177e4c Linux-2.6.12-rc2 |
35 36 37 |
* Or submit a bug report through the following website: * http://www.sf.net/projects/lksctp * |
d808ad9ab [NET] SCTP: Fix w... |
38 |
* Written or modified by: |
1da177e4c Linux-2.6.12-rc2 |
39 40 |
* La Monte H.P. Yarroll <piggy@acm.org> * Karl Knutson <karl@athena.chicago.il.us> |
d808ad9ab [NET] SCTP: Fix w... |
41 |
* |
1da177e4c Linux-2.6.12-rc2 |
42 43 44 |
* Any bugs reported given to us we will try to fix... any fixes shared will * be incorporated into the next SCTP release. */ |
145ce502e net/sctp: Use pr_... |
45 |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
1da177e4c Linux-2.6.12-rc2 |
46 47 48 |
#include <net/sctp/sctp.h> #include <net/sctp/sm.h> #include <linux/interrupt.h> |
5a0e3ad6a include cleanup: ... |
49 |
#include <linux/slab.h> |
1da177e4c Linux-2.6.12-rc2 |
50 51 52 53 |
/* Initialize an SCTP inqueue. */ void sctp_inq_init(struct sctp_inq *queue) { |
79af02c25 [SCTP]: Use struc... |
54 |
INIT_LIST_HEAD(&queue->in_chunk_list); |
1da177e4c Linux-2.6.12-rc2 |
55 56 57 |
queue->in_progress = NULL; /* Create a task for delivering data. */ |
c4028958b WorkStruct: make ... |
58 |
INIT_WORK(&queue->immediate, NULL); |
1da177e4c Linux-2.6.12-rc2 |
59 60 61 62 63 64 65 |
queue->malloced = 0; } /* Release the memory associated with an SCTP inqueue. */ void sctp_inq_free(struct sctp_inq *queue) { |
79af02c25 [SCTP]: Use struc... |
66 |
struct sctp_chunk *chunk, *tmp; |
1da177e4c Linux-2.6.12-rc2 |
67 68 |
/* Empty the queue. */ |
79af02c25 [SCTP]: Use struc... |
69 70 |
list_for_each_entry_safe(chunk, tmp, &queue->in_chunk_list, list) { list_del_init(&chunk->list); |
1da177e4c Linux-2.6.12-rc2 |
71 |
sctp_chunk_free(chunk); |
79af02c25 [SCTP]: Use struc... |
72 |
} |
1da177e4c Linux-2.6.12-rc2 |
73 74 75 76 |
/* If there is a packet which is currently being worked on, * free it as well. */ |
7a48f923b [SCTP]: Fix poten... |
77 |
if (queue->in_progress) { |
1da177e4c Linux-2.6.12-rc2 |
78 |
sctp_chunk_free(queue->in_progress); |
7a48f923b [SCTP]: Fix poten... |
79 80 |
queue->in_progress = NULL; } |
1da177e4c Linux-2.6.12-rc2 |
81 82 83 84 85 86 87 88 89 90 |
if (queue->malloced) { /* Dump the master memory segment. */ kfree(queue); } } /* Put a new packet in an SCTP inqueue. * We assume that packet->sctp_hdr is set and in host byte order. */ |
ac0b04627 [SCTP]: Extend /p... |
91 |
void sctp_inq_push(struct sctp_inq *q, struct sctp_chunk *chunk) |
1da177e4c Linux-2.6.12-rc2 |
92 93 |
{ /* Directly call the packet handling routine. */ |
027f6e1ad SCTP: Fix a poten... |
94 95 96 97 |
if (chunk->rcvr->dead) { sctp_chunk_free(chunk); return; } |
1da177e4c Linux-2.6.12-rc2 |
98 99 100 101 102 103 |
/* We are now calling this either from the soft interrupt * or from the backlog processing. * Eventually, we should clean up inqueue to not rely * on the BH related data structures. */ |
ac0b04627 [SCTP]: Extend /p... |
104 |
list_add_tail(&chunk->list, &q->in_chunk_list); |
c4028958b WorkStruct: make ... |
105 |
q->immediate.func(&q->immediate); |
1da177e4c Linux-2.6.12-rc2 |
106 |
} |
bbd0d5980 [SCTP]: Implement... |
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
/* Peek at the next chunk on the inqeue. */ struct sctp_chunkhdr *sctp_inq_peek(struct sctp_inq *queue) { struct sctp_chunk *chunk; sctp_chunkhdr_t *ch = NULL; chunk = queue->in_progress; /* If there is no more chunks in this packet, say so */ if (chunk->singleton || chunk->end_of_packet || chunk->pdiscard) return NULL; ch = (sctp_chunkhdr_t *)chunk->chunk_end; return ch; } |
1da177e4c Linux-2.6.12-rc2 |
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
/* Extract a chunk from an SCTP inqueue. * * WARNING: If you need to put the chunk on another queue, you need to * make a shallow copy (clone) of it. */ struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue) { struct sctp_chunk *chunk; sctp_chunkhdr_t *ch = NULL; /* The assumption is that we are safe to process the chunks * at this time. */ if ((chunk = queue->in_progress)) { /* There is a packet that we have been working on. * Any post processing work to do before we move on? */ if (chunk->singleton || chunk->end_of_packet || chunk->pdiscard) { sctp_chunk_free(chunk); chunk = queue->in_progress = NULL; } else { /* Nothing to do. Next chunk in the packet, please. */ ch = (sctp_chunkhdr_t *) chunk->chunk_end; /* Force chunk->skb->data to chunk->chunk_end. */ skb_pull(chunk->skb, chunk->chunk_end - chunk->skb->data); |
a09c83847 SCTP: Validate bu... |
154 155 156 157 158 159 160 161 |
/* Verify that we have at least chunk headers * worth of buffer left. */ if (skb_headlen(chunk->skb) < sizeof(sctp_chunkhdr_t)) { sctp_chunk_free(chunk); chunk = queue->in_progress = NULL; } |
1da177e4c Linux-2.6.12-rc2 |
162 163 164 165 166 |
} } /* Do we need to take the next packet out of the queue to process? */ if (!chunk) { |
79af02c25 [SCTP]: Use struc... |
167 |
struct list_head *entry; |
1da177e4c Linux-2.6.12-rc2 |
168 |
/* Is the queue empty? */ |
79af02c25 [SCTP]: Use struc... |
169 |
if (list_empty(&queue->in_chunk_list)) |
1da177e4c Linux-2.6.12-rc2 |
170 |
return NULL; |
79af02c25 [SCTP]: Use struc... |
171 |
entry = queue->in_chunk_list.next; |
1da177e4c Linux-2.6.12-rc2 |
172 |
chunk = queue->in_progress = |
79af02c25 [SCTP]: Use struc... |
173 174 |
list_entry(entry, struct sctp_chunk, list); list_del_init(entry); |
1da177e4c Linux-2.6.12-rc2 |
175 176 177 178 |
/* This is the first chunk in the packet. */ chunk->singleton = 1; ch = (sctp_chunkhdr_t *) chunk->skb->data; |
7c3ceb4fb [SCTP]: Allow spi... |
179 |
chunk->data_accepted = 0; |
1da177e4c Linux-2.6.12-rc2 |
180 |
} |
d808ad9ab [NET] SCTP: Fix w... |
181 182 |
chunk->chunk_hdr = ch; chunk->chunk_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length)); |
1da177e4c Linux-2.6.12-rc2 |
183 184 185 186 187 |
/* In the unlikely case of an IP reassembly, the skb could be * non-linear. If so, update chunk_end so that it doesn't go past * the skb->tail. */ if (unlikely(skb_is_nonlinear(chunk->skb))) { |
27a884dc3 [SK_BUFF]: Conver... |
188 189 |
if (chunk->chunk_end > skb_tail_pointer(chunk->skb)) chunk->chunk_end = skb_tail_pointer(chunk->skb); |
1da177e4c Linux-2.6.12-rc2 |
190 191 192 |
} skb_pull(chunk->skb, sizeof(sctp_chunkhdr_t)); chunk->subh.v = NULL; /* Subheader is no longer valid. */ |
27a884dc3 [SK_BUFF]: Conver... |
193 |
if (chunk->chunk_end < skb_tail_pointer(chunk->skb)) { |
1da177e4c Linux-2.6.12-rc2 |
194 195 |
/* This is not a singleton */ chunk->singleton = 0; |
27a884dc3 [SK_BUFF]: Conver... |
196 |
} else if (chunk->chunk_end > skb_tail_pointer(chunk->skb)) { |
d808ad9ab [NET] SCTP: Fix w... |
197 |
/* RFC 2960, Section 6.10 Bundling |
1da177e4c Linux-2.6.12-rc2 |
198 199 200 |
* * Partial chunks MUST NOT be placed in an SCTP packet. * If the receiver detects a partial chunk, it MUST drop |
d808ad9ab [NET] SCTP: Fix w... |
201 |
* the chunk. |
1da177e4c Linux-2.6.12-rc2 |
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
* * Since the end of the chunk is past the end of our buffer * (which contains the whole packet, we can freely discard * the whole packet. */ sctp_chunk_free(chunk); chunk = queue->in_progress = NULL; return NULL; } else { /* We are at the end of the packet, so mark the chunk * in case we need to send a SACK. */ chunk->end_of_packet = 1; } SCTP_DEBUG_PRINTK("+++sctp_inq_pop+++ chunk %p[%s]," " length %d, skb->len %d ",chunk, sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)), ntohs(chunk->chunk_hdr->length), chunk->skb->len); return chunk; } /* Set a top-half handler. * * Originally, we the top-half handler was scheduled as a BH. We now * call the handler directly in sctp_inq_push() at a time that * we know we are lock safe. * The intent is that this routine will pull stuff out of the * inqueue and process it. */ |
c4028958b WorkStruct: make ... |
234 |
void sctp_inq_set_th_handler(struct sctp_inq *q, work_func_t callback) |
1da177e4c Linux-2.6.12-rc2 |
235 |
{ |
c4028958b WorkStruct: make ... |
236 |
INIT_WORK(&q->immediate, callback); |
1da177e4c Linux-2.6.12-rc2 |
237 |
} |