diff options
Diffstat (limited to 'net/tipc/msg.c')
-rw-r--r-- | net/tipc/msg.c | 133 |
1 files changed, 66 insertions, 67 deletions
diff --git a/net/tipc/msg.c b/net/tipc/msg.c index 74745a47d72a..a687b30a699c 100644 --- a/net/tipc/msg.c +++ b/net/tipc/msg.c | |||
@@ -91,7 +91,7 @@ struct sk_buff *tipc_msg_create(uint user, uint type, uint hdr_sz, | |||
91 | * @*headbuf: in: NULL for first frag, otherwise value returned from prev call | 91 | * @*headbuf: in: NULL for first frag, otherwise value returned from prev call |
92 | * out: set when successful non-complete reassembly, otherwise NULL | 92 | * out: set when successful non-complete reassembly, otherwise NULL |
93 | * @*buf: in: the buffer to append. Always defined | 93 | * @*buf: in: the buffer to append. Always defined |
94 | * out: head buf after sucessful complete reassembly, otherwise NULL | 94 | * out: head buf after successful complete reassembly, otherwise NULL |
95 | * Returns 1 when reassembly complete, otherwise 0 | 95 | * Returns 1 when reassembly complete, otherwise 0 |
96 | */ | 96 | */ |
97 | int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf) | 97 | int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf) |
@@ -162,15 +162,16 @@ err: | |||
162 | /** | 162 | /** |
163 | * tipc_msg_build - create buffer chain containing specified header and data | 163 | * tipc_msg_build - create buffer chain containing specified header and data |
164 | * @mhdr: Message header, to be prepended to data | 164 | * @mhdr: Message header, to be prepended to data |
165 | * @iov: User data | 165 | * @m: User message |
166 | * @offset: Posision in iov to start copying from | 166 | * @offset: Posision in iov to start copying from |
167 | * @dsz: Total length of user data | 167 | * @dsz: Total length of user data |
168 | * @pktmax: Max packet size that can be used | 168 | * @pktmax: Max packet size that can be used |
169 | * @chain: Buffer or chain of buffers to be returned to caller | 169 | * @list: Buffer or chain of buffers to be returned to caller |
170 | * | ||
170 | * Returns message data size or errno: -ENOMEM, -EFAULT | 171 | * Returns message data size or errno: -ENOMEM, -EFAULT |
171 | */ | 172 | */ |
172 | int tipc_msg_build(struct tipc_msg *mhdr, struct iovec const *iov, | 173 | int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, int offset, |
173 | int offset, int dsz, int pktmax , struct sk_buff **chain) | 174 | int dsz, int pktmax, struct sk_buff_head *list) |
174 | { | 175 | { |
175 | int mhsz = msg_hdr_sz(mhdr); | 176 | int mhsz = msg_hdr_sz(mhdr); |
176 | int msz = mhsz + dsz; | 177 | int msz = mhsz + dsz; |
@@ -179,22 +180,22 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct iovec const *iov, | |||
179 | int pktrem = pktmax; | 180 | int pktrem = pktmax; |
180 | int drem = dsz; | 181 | int drem = dsz; |
181 | struct tipc_msg pkthdr; | 182 | struct tipc_msg pkthdr; |
182 | struct sk_buff *buf, *prev; | 183 | struct sk_buff *skb; |
183 | char *pktpos; | 184 | char *pktpos; |
184 | int rc; | 185 | int rc; |
185 | uint chain_sz = 0; | 186 | |
186 | msg_set_size(mhdr, msz); | 187 | msg_set_size(mhdr, msz); |
187 | 188 | ||
188 | /* No fragmentation needed? */ | 189 | /* No fragmentation needed? */ |
189 | if (likely(msz <= pktmax)) { | 190 | if (likely(msz <= pktmax)) { |
190 | buf = tipc_buf_acquire(msz); | 191 | skb = tipc_buf_acquire(msz); |
191 | *chain = buf; | 192 | if (unlikely(!skb)) |
192 | if (unlikely(!buf)) | ||
193 | return -ENOMEM; | 193 | return -ENOMEM; |
194 | skb_copy_to_linear_data(buf, mhdr, mhsz); | 194 | __skb_queue_tail(list, skb); |
195 | pktpos = buf->data + mhsz; | 195 | skb_copy_to_linear_data(skb, mhdr, mhsz); |
196 | TIPC_SKB_CB(buf)->chain_sz = 1; | 196 | pktpos = skb->data + mhsz; |
197 | if (!dsz || !memcpy_fromiovecend(pktpos, iov, offset, dsz)) | 197 | if (!dsz || !memcpy_fromiovecend(pktpos, m->msg_iter.iov, offset, |
198 | dsz)) | ||
198 | return dsz; | 199 | return dsz; |
199 | rc = -EFAULT; | 200 | rc = -EFAULT; |
200 | goto error; | 201 | goto error; |
@@ -207,15 +208,15 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct iovec const *iov, | |||
207 | msg_set_fragm_no(&pkthdr, pktno); | 208 | msg_set_fragm_no(&pkthdr, pktno); |
208 | 209 | ||
209 | /* Prepare first fragment */ | 210 | /* Prepare first fragment */ |
210 | *chain = buf = tipc_buf_acquire(pktmax); | 211 | skb = tipc_buf_acquire(pktmax); |
211 | if (!buf) | 212 | if (!skb) |
212 | return -ENOMEM; | 213 | return -ENOMEM; |
213 | chain_sz = 1; | 214 | __skb_queue_tail(list, skb); |
214 | pktpos = buf->data; | 215 | pktpos = skb->data; |
215 | skb_copy_to_linear_data(buf, &pkthdr, INT_H_SIZE); | 216 | skb_copy_to_linear_data(skb, &pkthdr, INT_H_SIZE); |
216 | pktpos += INT_H_SIZE; | 217 | pktpos += INT_H_SIZE; |
217 | pktrem -= INT_H_SIZE; | 218 | pktrem -= INT_H_SIZE; |
218 | skb_copy_to_linear_data_offset(buf, INT_H_SIZE, mhdr, mhsz); | 219 | skb_copy_to_linear_data_offset(skb, INT_H_SIZE, mhdr, mhsz); |
219 | pktpos += mhsz; | 220 | pktpos += mhsz; |
220 | pktrem -= mhsz; | 221 | pktrem -= mhsz; |
221 | 222 | ||
@@ -223,7 +224,7 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct iovec const *iov, | |||
223 | if (drem < pktrem) | 224 | if (drem < pktrem) |
224 | pktrem = drem; | 225 | pktrem = drem; |
225 | 226 | ||
226 | if (memcpy_fromiovecend(pktpos, iov, offset, pktrem)) { | 227 | if (memcpy_fromiovecend(pktpos, m->msg_iter.iov, offset, pktrem)) { |
227 | rc = -EFAULT; | 228 | rc = -EFAULT; |
228 | goto error; | 229 | goto error; |
229 | } | 230 | } |
@@ -238,43 +239,41 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct iovec const *iov, | |||
238 | pktsz = drem + INT_H_SIZE; | 239 | pktsz = drem + INT_H_SIZE; |
239 | else | 240 | else |
240 | pktsz = pktmax; | 241 | pktsz = pktmax; |
241 | prev = buf; | 242 | skb = tipc_buf_acquire(pktsz); |
242 | buf = tipc_buf_acquire(pktsz); | 243 | if (!skb) { |
243 | if (!buf) { | ||
244 | rc = -ENOMEM; | 244 | rc = -ENOMEM; |
245 | goto error; | 245 | goto error; |
246 | } | 246 | } |
247 | chain_sz++; | 247 | __skb_queue_tail(list, skb); |
248 | prev->next = buf; | ||
249 | msg_set_type(&pkthdr, FRAGMENT); | 248 | msg_set_type(&pkthdr, FRAGMENT); |
250 | msg_set_size(&pkthdr, pktsz); | 249 | msg_set_size(&pkthdr, pktsz); |
251 | msg_set_fragm_no(&pkthdr, ++pktno); | 250 | msg_set_fragm_no(&pkthdr, ++pktno); |
252 | skb_copy_to_linear_data(buf, &pkthdr, INT_H_SIZE); | 251 | skb_copy_to_linear_data(skb, &pkthdr, INT_H_SIZE); |
253 | pktpos = buf->data + INT_H_SIZE; | 252 | pktpos = skb->data + INT_H_SIZE; |
254 | pktrem = pktsz - INT_H_SIZE; | 253 | pktrem = pktsz - INT_H_SIZE; |
255 | 254 | ||
256 | } while (1); | 255 | } while (1); |
257 | TIPC_SKB_CB(*chain)->chain_sz = chain_sz; | 256 | msg_set_type(buf_msg(skb), LAST_FRAGMENT); |
258 | msg_set_type(buf_msg(buf), LAST_FRAGMENT); | ||
259 | return dsz; | 257 | return dsz; |
260 | error: | 258 | error: |
261 | kfree_skb_list(*chain); | 259 | __skb_queue_purge(list); |
262 | *chain = NULL; | 260 | __skb_queue_head_init(list); |
263 | return rc; | 261 | return rc; |
264 | } | 262 | } |
265 | 263 | ||
266 | /** | 264 | /** |
267 | * tipc_msg_bundle(): Append contents of a buffer to tail of an existing one | 265 | * tipc_msg_bundle(): Append contents of a buffer to tail of an existing one |
268 | * @bbuf: the existing buffer ("bundle") | 266 | * @list: the buffer chain of the existing buffer ("bundle") |
269 | * @buf: buffer to be appended | 267 | * @skb: buffer to be appended |
270 | * @mtu: max allowable size for the bundle buffer | 268 | * @mtu: max allowable size for the bundle buffer |
271 | * Consumes buffer if successful | 269 | * Consumes buffer if successful |
272 | * Returns true if bundling could be performed, otherwise false | 270 | * Returns true if bundling could be performed, otherwise false |
273 | */ | 271 | */ |
274 | bool tipc_msg_bundle(struct sk_buff *bbuf, struct sk_buff *buf, u32 mtu) | 272 | bool tipc_msg_bundle(struct sk_buff_head *list, struct sk_buff *skb, u32 mtu) |
275 | { | 273 | { |
276 | struct tipc_msg *bmsg = buf_msg(bbuf); | 274 | struct sk_buff *bskb = skb_peek_tail(list); |
277 | struct tipc_msg *msg = buf_msg(buf); | 275 | struct tipc_msg *bmsg = buf_msg(bskb); |
276 | struct tipc_msg *msg = buf_msg(skb); | ||
278 | unsigned int bsz = msg_size(bmsg); | 277 | unsigned int bsz = msg_size(bmsg); |
279 | unsigned int msz = msg_size(msg); | 278 | unsigned int msz = msg_size(msg); |
280 | u32 start = align(bsz); | 279 | u32 start = align(bsz); |
@@ -289,35 +288,36 @@ bool tipc_msg_bundle(struct sk_buff *bbuf, struct sk_buff *buf, u32 mtu) | |||
289 | return false; | 288 | return false; |
290 | if (likely(msg_user(bmsg) != MSG_BUNDLER)) | 289 | if (likely(msg_user(bmsg) != MSG_BUNDLER)) |
291 | return false; | 290 | return false; |
292 | if (likely(msg_type(bmsg) != BUNDLE_OPEN)) | 291 | if (likely(!TIPC_SKB_CB(bskb)->bundling)) |
293 | return false; | 292 | return false; |
294 | if (unlikely(skb_tailroom(bbuf) < (pad + msz))) | 293 | if (unlikely(skb_tailroom(bskb) < (pad + msz))) |
295 | return false; | 294 | return false; |
296 | if (unlikely(max < (start + msz))) | 295 | if (unlikely(max < (start + msz))) |
297 | return false; | 296 | return false; |
298 | 297 | ||
299 | skb_put(bbuf, pad + msz); | 298 | skb_put(bskb, pad + msz); |
300 | skb_copy_to_linear_data_offset(bbuf, start, buf->data, msz); | 299 | skb_copy_to_linear_data_offset(bskb, start, skb->data, msz); |
301 | msg_set_size(bmsg, start + msz); | 300 | msg_set_size(bmsg, start + msz); |
302 | msg_set_msgcnt(bmsg, msg_msgcnt(bmsg) + 1); | 301 | msg_set_msgcnt(bmsg, msg_msgcnt(bmsg) + 1); |
303 | bbuf->next = buf->next; | 302 | kfree_skb(skb); |
304 | kfree_skb(buf); | ||
305 | return true; | 303 | return true; |
306 | } | 304 | } |
307 | 305 | ||
308 | /** | 306 | /** |
309 | * tipc_msg_make_bundle(): Create bundle buf and append message to its tail | 307 | * tipc_msg_make_bundle(): Create bundle buf and append message to its tail |
310 | * @buf: buffer to be appended and replaced | 308 | * @list: the buffer chain |
311 | * @mtu: max allowable size for the bundle buffer, inclusive header | 309 | * @skb: buffer to be appended and replaced |
310 | * @mtu: max allowable size for the bundle buffer, inclusive header | ||
312 | * @dnode: destination node for message. (Not always present in header) | 311 | * @dnode: destination node for message. (Not always present in header) |
313 | * Replaces buffer if successful | 312 | * Replaces buffer if successful |
314 | * Returns true if sucess, otherwise false | 313 | * Returns true if success, otherwise false |
315 | */ | 314 | */ |
316 | bool tipc_msg_make_bundle(struct sk_buff **buf, u32 mtu, u32 dnode) | 315 | bool tipc_msg_make_bundle(struct sk_buff_head *list, struct sk_buff *skb, |
316 | u32 mtu, u32 dnode) | ||
317 | { | 317 | { |
318 | struct sk_buff *bbuf; | 318 | struct sk_buff *bskb; |
319 | struct tipc_msg *bmsg; | 319 | struct tipc_msg *bmsg; |
320 | struct tipc_msg *msg = buf_msg(*buf); | 320 | struct tipc_msg *msg = buf_msg(skb); |
321 | u32 msz = msg_size(msg); | 321 | u32 msz = msg_size(msg); |
322 | u32 max = mtu - INT_H_SIZE; | 322 | u32 max = mtu - INT_H_SIZE; |
323 | 323 | ||
@@ -330,20 +330,19 @@ bool tipc_msg_make_bundle(struct sk_buff **buf, u32 mtu, u32 dnode) | |||
330 | if (msz > (max / 2)) | 330 | if (msz > (max / 2)) |
331 | return false; | 331 | return false; |
332 | 332 | ||
333 | bbuf = tipc_buf_acquire(max); | 333 | bskb = tipc_buf_acquire(max); |
334 | if (!bbuf) | 334 | if (!bskb) |
335 | return false; | 335 | return false; |
336 | 336 | ||
337 | skb_trim(bbuf, INT_H_SIZE); | 337 | skb_trim(bskb, INT_H_SIZE); |
338 | bmsg = buf_msg(bbuf); | 338 | bmsg = buf_msg(bskb); |
339 | tipc_msg_init(bmsg, MSG_BUNDLER, BUNDLE_OPEN, INT_H_SIZE, dnode); | 339 | tipc_msg_init(bmsg, MSG_BUNDLER, 0, INT_H_SIZE, dnode); |
340 | msg_set_seqno(bmsg, msg_seqno(msg)); | 340 | msg_set_seqno(bmsg, msg_seqno(msg)); |
341 | msg_set_ack(bmsg, msg_ack(msg)); | 341 | msg_set_ack(bmsg, msg_ack(msg)); |
342 | msg_set_bcast_ack(bmsg, msg_bcast_ack(msg)); | 342 | msg_set_bcast_ack(bmsg, msg_bcast_ack(msg)); |
343 | bbuf->next = (*buf)->next; | 343 | TIPC_SKB_CB(bskb)->bundling = true; |
344 | tipc_msg_bundle(bbuf, *buf, mtu); | 344 | __skb_queue_tail(list, bskb); |
345 | *buf = bbuf; | 345 | return tipc_msg_bundle(list, skb, mtu); |
346 | return true; | ||
347 | } | 346 | } |
348 | 347 | ||
349 | /** | 348 | /** |
@@ -429,22 +428,23 @@ int tipc_msg_eval(struct sk_buff *buf, u32 *dnode) | |||
429 | /* tipc_msg_reassemble() - clone a buffer chain of fragments and | 428 | /* tipc_msg_reassemble() - clone a buffer chain of fragments and |
430 | * reassemble the clones into one message | 429 | * reassemble the clones into one message |
431 | */ | 430 | */ |
432 | struct sk_buff *tipc_msg_reassemble(struct sk_buff *chain) | 431 | struct sk_buff *tipc_msg_reassemble(struct sk_buff_head *list) |
433 | { | 432 | { |
434 | struct sk_buff *buf = chain; | 433 | struct sk_buff *skb; |
435 | struct sk_buff *frag = buf; | 434 | struct sk_buff *frag = NULL; |
436 | struct sk_buff *head = NULL; | 435 | struct sk_buff *head = NULL; |
437 | int hdr_sz; | 436 | int hdr_sz; |
438 | 437 | ||
439 | /* Copy header if single buffer */ | 438 | /* Copy header if single buffer */ |
440 | if (!buf->next) { | 439 | if (skb_queue_len(list) == 1) { |
441 | hdr_sz = skb_headroom(buf) + msg_hdr_sz(buf_msg(buf)); | 440 | skb = skb_peek(list); |
442 | return __pskb_copy(buf, hdr_sz, GFP_ATOMIC); | 441 | hdr_sz = skb_headroom(skb) + msg_hdr_sz(buf_msg(skb)); |
442 | return __pskb_copy(skb, hdr_sz, GFP_ATOMIC); | ||
443 | } | 443 | } |
444 | 444 | ||
445 | /* Clone all fragments and reassemble */ | 445 | /* Clone all fragments and reassemble */ |
446 | while (buf) { | 446 | skb_queue_walk(list, skb) { |
447 | frag = skb_clone(buf, GFP_ATOMIC); | 447 | frag = skb_clone(skb, GFP_ATOMIC); |
448 | if (!frag) | 448 | if (!frag) |
449 | goto error; | 449 | goto error; |
450 | frag->next = NULL; | 450 | frag->next = NULL; |
@@ -452,7 +452,6 @@ struct sk_buff *tipc_msg_reassemble(struct sk_buff *chain) | |||
452 | break; | 452 | break; |
453 | if (!head) | 453 | if (!head) |
454 | goto error; | 454 | goto error; |
455 | buf = buf->next; | ||
456 | } | 455 | } |
457 | return frag; | 456 | return frag; |
458 | error: | 457 | error: |