msg.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /*
  2. * net/tipc/msg.c: TIPC message header routines
  3. *
  4. * Copyright (c) 2000-2006, 2014-2015, Ericsson AB
  5. * Copyright (c) 2005, 2010-2011, Wind River Systems
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the names of the copyright holders nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed under the terms of the
  21. * GNU General Public License ("GPL") version 2 as published by the Free
  22. * Software Foundation.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include <net/sock.h>
  37. #include "core.h"
  38. #include "msg.h"
  39. #include "addr.h"
  40. #include "name_table.h"
  41. #define MAX_FORWARD_SIZE 1024
  42. static unsigned int align(unsigned int i)
  43. {
  44. return (i + 3) & ~3u;
  45. }
  46. /**
  47. * tipc_buf_acquire - creates a TIPC message buffer
  48. * @size: message size (including TIPC header)
  49. *
  50. * Returns a new buffer with data pointers set to the specified size.
  51. *
  52. * NOTE: Headroom is reserved to allow prepending of a data link header.
  53. * There may also be unrequested tailroom present at the buffer's end.
  54. */
  55. struct sk_buff *tipc_buf_acquire(u32 size)
  56. {
  57. struct sk_buff *skb;
  58. unsigned int buf_size = (BUF_HEADROOM + size + 3) & ~3u;
  59. skb = alloc_skb_fclone(buf_size, GFP_ATOMIC);
  60. if (skb) {
  61. skb_reserve(skb, BUF_HEADROOM);
  62. skb_put(skb, size);
  63. skb->next = NULL;
  64. }
  65. return skb;
  66. }
  67. void tipc_msg_init(u32 own_node, struct tipc_msg *m, u32 user, u32 type,
  68. u32 hsize, u32 dnode)
  69. {
  70. memset(m, 0, hsize);
  71. msg_set_version(m);
  72. msg_set_user(m, user);
  73. msg_set_hdr_sz(m, hsize);
  74. msg_set_size(m, hsize);
  75. msg_set_prevnode(m, own_node);
  76. msg_set_type(m, type);
  77. if (hsize > SHORT_H_SIZE) {
  78. msg_set_orignode(m, own_node);
  79. msg_set_destnode(m, dnode);
  80. }
  81. }
  82. struct sk_buff *tipc_msg_create(uint user, uint type,
  83. uint hdr_sz, uint data_sz, u32 dnode,
  84. u32 onode, u32 dport, u32 oport, int errcode)
  85. {
  86. struct tipc_msg *msg;
  87. struct sk_buff *buf;
  88. buf = tipc_buf_acquire(hdr_sz + data_sz);
  89. if (unlikely(!buf))
  90. return NULL;
  91. msg = buf_msg(buf);
  92. tipc_msg_init(onode, msg, user, type, hdr_sz, dnode);
  93. msg_set_size(msg, hdr_sz + data_sz);
  94. msg_set_origport(msg, oport);
  95. msg_set_destport(msg, dport);
  96. msg_set_errcode(msg, errcode);
  97. if (hdr_sz > SHORT_H_SIZE) {
  98. msg_set_orignode(msg, onode);
  99. msg_set_destnode(msg, dnode);
  100. }
  101. return buf;
  102. }
  103. /* tipc_buf_append(): Append a buffer to the fragment list of another buffer
  104. * @*headbuf: in: NULL for first frag, otherwise value returned from prev call
  105. * out: set when successful non-complete reassembly, otherwise NULL
  106. * @*buf: in: the buffer to append. Always defined
  107. * out: head buf after successful complete reassembly, otherwise NULL
  108. * Returns 1 when reassembly complete, otherwise 0
  109. */
  110. int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)
  111. {
  112. struct sk_buff *head = *headbuf;
  113. struct sk_buff *frag = *buf;
  114. struct sk_buff *tail;
  115. struct tipc_msg *msg;
  116. u32 fragid;
  117. int delta;
  118. bool headstolen;
  119. if (!frag)
  120. goto err;
  121. msg = buf_msg(frag);
  122. fragid = msg_type(msg);
  123. frag->next = NULL;
  124. skb_pull(frag, msg_hdr_sz(msg));
  125. if (fragid == FIRST_FRAGMENT) {
  126. if (unlikely(head))
  127. goto err;
  128. if (unlikely(skb_unclone(frag, GFP_ATOMIC)))
  129. goto err;
  130. head = *headbuf = frag;
  131. skb_frag_list_init(head);
  132. TIPC_SKB_CB(head)->tail = NULL;
  133. *buf = NULL;
  134. return 0;
  135. }
  136. if (!head)
  137. goto err;
  138. if (skb_try_coalesce(head, frag, &headstolen, &delta)) {
  139. kfree_skb_partial(frag, headstolen);
  140. } else {
  141. tail = TIPC_SKB_CB(head)->tail;
  142. if (!skb_has_frag_list(head))
  143. skb_shinfo(head)->frag_list = frag;
  144. else
  145. tail->next = frag;
  146. head->truesize += frag->truesize;
  147. head->data_len += frag->len;
  148. head->len += frag->len;
  149. TIPC_SKB_CB(head)->tail = frag;
  150. }
  151. if (fragid == LAST_FRAGMENT) {
  152. TIPC_SKB_CB(head)->validated = false;
  153. if (unlikely(!tipc_msg_validate(head)))
  154. goto err;
  155. *buf = head;
  156. TIPC_SKB_CB(head)->tail = NULL;
  157. *headbuf = NULL;
  158. return 1;
  159. }
  160. *buf = NULL;
  161. return 0;
  162. err:
  163. pr_warn_ratelimited("Unable to build fragment list\n");
  164. kfree_skb(*buf);
  165. kfree_skb(*headbuf);
  166. *buf = *headbuf = NULL;
  167. return 0;
  168. }
  169. /* tipc_msg_validate - validate basic format of received message
  170. *
  171. * This routine ensures a TIPC message has an acceptable header, and at least
  172. * as much data as the header indicates it should. The routine also ensures
  173. * that the entire message header is stored in the main fragment of the message
  174. * buffer, to simplify future access to message header fields.
  175. *
  176. * Note: Having extra info present in the message header or data areas is OK.
  177. * TIPC will ignore the excess, under the assumption that it is optional info
  178. * introduced by a later release of the protocol.
  179. */
  180. bool tipc_msg_validate(struct sk_buff *skb)
  181. {
  182. struct tipc_msg *msg;
  183. int msz, hsz;
  184. if (unlikely(TIPC_SKB_CB(skb)->validated))
  185. return true;
  186. if (unlikely(!pskb_may_pull(skb, MIN_H_SIZE)))
  187. return false;
  188. hsz = msg_hdr_sz(buf_msg(skb));
  189. if (unlikely(hsz < MIN_H_SIZE) || (hsz > MAX_H_SIZE))
  190. return false;
  191. if (unlikely(!pskb_may_pull(skb, hsz)))
  192. return false;
  193. msg = buf_msg(skb);
  194. if (unlikely(msg_version(msg) != TIPC_VERSION))
  195. return false;
  196. msz = msg_size(msg);
  197. if (unlikely(msz < hsz))
  198. return false;
  199. if (unlikely((msz - hsz) > TIPC_MAX_USER_MSG_SIZE))
  200. return false;
  201. if (unlikely(skb->len < msz))
  202. return false;
  203. TIPC_SKB_CB(skb)->validated = true;
  204. return true;
  205. }
  206. /**
  207. * tipc_msg_build - create buffer chain containing specified header and data
  208. * @mhdr: Message header, to be prepended to data
  209. * @m: User message
  210. * @dsz: Total length of user data
  211. * @pktmax: Max packet size that can be used
  212. * @list: Buffer or chain of buffers to be returned to caller
  213. *
  214. * Returns message data size or errno: -ENOMEM, -EFAULT
  215. */
  216. int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m,
  217. int offset, int dsz, int pktmax, struct sk_buff_head *list)
  218. {
  219. int mhsz = msg_hdr_sz(mhdr);
  220. int msz = mhsz + dsz;
  221. int pktno = 1;
  222. int pktsz;
  223. int pktrem = pktmax;
  224. int drem = dsz;
  225. struct tipc_msg pkthdr;
  226. struct sk_buff *skb;
  227. char *pktpos;
  228. int rc;
  229. msg_set_size(mhdr, msz);
  230. /* No fragmentation needed? */
  231. if (likely(msz <= pktmax)) {
  232. skb = tipc_buf_acquire(msz);
  233. if (unlikely(!skb))
  234. return -ENOMEM;
  235. skb_orphan(skb);
  236. __skb_queue_tail(list, skb);
  237. skb_copy_to_linear_data(skb, mhdr, mhsz);
  238. pktpos = skb->data + mhsz;
  239. if (copy_from_iter(pktpos, dsz, &m->msg_iter) == dsz)
  240. return dsz;
  241. rc = -EFAULT;
  242. goto error;
  243. }
  244. /* Prepare reusable fragment header */
  245. tipc_msg_init(msg_prevnode(mhdr), &pkthdr, MSG_FRAGMENTER,
  246. FIRST_FRAGMENT, INT_H_SIZE, msg_destnode(mhdr));
  247. msg_set_size(&pkthdr, pktmax);
  248. msg_set_fragm_no(&pkthdr, pktno);
  249. msg_set_importance(&pkthdr, msg_importance(mhdr));
  250. /* Prepare first fragment */
  251. skb = tipc_buf_acquire(pktmax);
  252. if (!skb)
  253. return -ENOMEM;
  254. skb_orphan(skb);
  255. __skb_queue_tail(list, skb);
  256. pktpos = skb->data;
  257. skb_copy_to_linear_data(skb, &pkthdr, INT_H_SIZE);
  258. pktpos += INT_H_SIZE;
  259. pktrem -= INT_H_SIZE;
  260. skb_copy_to_linear_data_offset(skb, INT_H_SIZE, mhdr, mhsz);
  261. pktpos += mhsz;
  262. pktrem -= mhsz;
  263. do {
  264. if (drem < pktrem)
  265. pktrem = drem;
  266. if (copy_from_iter(pktpos, pktrem, &m->msg_iter) != pktrem) {
  267. rc = -EFAULT;
  268. goto error;
  269. }
  270. drem -= pktrem;
  271. if (!drem)
  272. break;
  273. /* Prepare new fragment: */
  274. if (drem < (pktmax - INT_H_SIZE))
  275. pktsz = drem + INT_H_SIZE;
  276. else
  277. pktsz = pktmax;
  278. skb = tipc_buf_acquire(pktsz);
  279. if (!skb) {
  280. rc = -ENOMEM;
  281. goto error;
  282. }
  283. skb_orphan(skb);
  284. __skb_queue_tail(list, skb);
  285. msg_set_type(&pkthdr, FRAGMENT);
  286. msg_set_size(&pkthdr, pktsz);
  287. msg_set_fragm_no(&pkthdr, ++pktno);
  288. skb_copy_to_linear_data(skb, &pkthdr, INT_H_SIZE);
  289. pktpos = skb->data + INT_H_SIZE;
  290. pktrem = pktsz - INT_H_SIZE;
  291. } while (1);
  292. msg_set_type(buf_msg(skb), LAST_FRAGMENT);
  293. return dsz;
  294. error:
  295. __skb_queue_purge(list);
  296. __skb_queue_head_init(list);
  297. return rc;
  298. }
  299. /**
  300. * tipc_msg_bundle(): Append contents of a buffer to tail of an existing one
  301. * @skb: the buffer to append to ("bundle")
  302. * @msg: message to be appended
  303. * @mtu: max allowable size for the bundle buffer
  304. * Consumes buffer if successful
  305. * Returns true if bundling could be performed, otherwise false
  306. */
  307. bool tipc_msg_bundle(struct sk_buff *skb, struct tipc_msg *msg, u32 mtu)
  308. {
  309. struct tipc_msg *bmsg;
  310. unsigned int bsz;
  311. unsigned int msz = msg_size(msg);
  312. u32 start, pad;
  313. u32 max = mtu - INT_H_SIZE;
  314. if (likely(msg_user(msg) == MSG_FRAGMENTER))
  315. return false;
  316. if (!skb)
  317. return false;
  318. bmsg = buf_msg(skb);
  319. bsz = msg_size(bmsg);
  320. start = align(bsz);
  321. pad = start - bsz;
  322. if (unlikely(msg_user(msg) == TUNNEL_PROTOCOL))
  323. return false;
  324. if (unlikely(msg_user(msg) == BCAST_PROTOCOL))
  325. return false;
  326. if (unlikely(msg_user(bmsg) != MSG_BUNDLER))
  327. return false;
  328. if (unlikely(skb_tailroom(skb) < (pad + msz)))
  329. return false;
  330. if (unlikely(max < (start + msz)))
  331. return false;
  332. if ((msg_importance(msg) < TIPC_SYSTEM_IMPORTANCE) &&
  333. (msg_importance(bmsg) == TIPC_SYSTEM_IMPORTANCE))
  334. return false;
  335. skb_put(skb, pad + msz);
  336. skb_copy_to_linear_data_offset(skb, start, msg, msz);
  337. msg_set_size(bmsg, start + msz);
  338. msg_set_msgcnt(bmsg, msg_msgcnt(bmsg) + 1);
  339. return true;
  340. }
  341. /**
  342. * tipc_msg_extract(): extract bundled inner packet from buffer
  343. * @skb: buffer to be extracted from.
  344. * @iskb: extracted inner buffer, to be returned
  345. * @pos: position in outer message of msg to be extracted.
  346. * Returns position of next msg
  347. * Consumes outer buffer when last packet extracted
  348. * Returns true when when there is an extracted buffer, otherwise false
  349. */
  350. bool tipc_msg_extract(struct sk_buff *skb, struct sk_buff **iskb, int *pos)
  351. {
  352. struct tipc_msg *msg;
  353. int imsz, offset;
  354. *iskb = NULL;
  355. if (unlikely(skb_linearize(skb)))
  356. goto none;
  357. msg = buf_msg(skb);
  358. offset = msg_hdr_sz(msg) + *pos;
  359. if (unlikely(offset > (msg_size(msg) - MIN_H_SIZE)))
  360. goto none;
  361. *iskb = skb_clone(skb, GFP_ATOMIC);
  362. if (unlikely(!*iskb))
  363. goto none;
  364. skb_pull(*iskb, offset);
  365. imsz = msg_size(buf_msg(*iskb));
  366. skb_trim(*iskb, imsz);
  367. if (unlikely(!tipc_msg_validate(*iskb)))
  368. goto none;
  369. *pos += align(imsz);
  370. return true;
  371. none:
  372. kfree_skb(skb);
  373. kfree_skb(*iskb);
  374. *iskb = NULL;
  375. return false;
  376. }
  377. /**
  378. * tipc_msg_make_bundle(): Create bundle buf and append message to its tail
  379. * @list: the buffer chain, where head is the buffer to replace/append
  380. * @skb: buffer to be created, appended to and returned in case of success
  381. * @msg: message to be appended
  382. * @mtu: max allowable size for the bundle buffer, inclusive header
  383. * @dnode: destination node for message. (Not always present in header)
  384. * Returns true if success, otherwise false
  385. */
  386. bool tipc_msg_make_bundle(struct sk_buff **skb, struct tipc_msg *msg,
  387. u32 mtu, u32 dnode)
  388. {
  389. struct sk_buff *_skb;
  390. struct tipc_msg *bmsg;
  391. u32 msz = msg_size(msg);
  392. u32 max = mtu - INT_H_SIZE;
  393. if (msg_user(msg) == MSG_FRAGMENTER)
  394. return false;
  395. if (msg_user(msg) == TUNNEL_PROTOCOL)
  396. return false;
  397. if (msg_user(msg) == BCAST_PROTOCOL)
  398. return false;
  399. if (msz > (max / 2))
  400. return false;
  401. _skb = tipc_buf_acquire(max);
  402. if (!_skb)
  403. return false;
  404. skb_trim(_skb, INT_H_SIZE);
  405. bmsg = buf_msg(_skb);
  406. tipc_msg_init(msg_prevnode(msg), bmsg, MSG_BUNDLER, 0,
  407. INT_H_SIZE, dnode);
  408. if (msg_isdata(msg))
  409. msg_set_importance(bmsg, TIPC_CRITICAL_IMPORTANCE);
  410. else
  411. msg_set_importance(bmsg, TIPC_SYSTEM_IMPORTANCE);
  412. msg_set_seqno(bmsg, msg_seqno(msg));
  413. msg_set_ack(bmsg, msg_ack(msg));
  414. msg_set_bcast_ack(bmsg, msg_bcast_ack(msg));
  415. tipc_msg_bundle(_skb, msg, mtu);
  416. *skb = _skb;
  417. return true;
  418. }
  419. /**
  420. * tipc_msg_reverse(): swap source and destination addresses and add error code
  421. * @own_node: originating node id for reversed message
  422. * @skb: buffer containing message to be reversed; may be replaced.
  423. * @err: error code to be set in message, if any
  424. * Consumes buffer at failure
  425. * Returns true if success, otherwise false
  426. */
  427. bool tipc_msg_reverse(u32 own_node, struct sk_buff **skb, int err)
  428. {
  429. struct sk_buff *_skb = *skb;
  430. struct tipc_msg *hdr = buf_msg(_skb);
  431. struct tipc_msg ohdr;
  432. int dlen = min_t(uint, msg_data_sz(hdr), MAX_FORWARD_SIZE);
  433. if (skb_linearize(_skb))
  434. goto exit;
  435. hdr = buf_msg(_skb);
  436. if (msg_dest_droppable(hdr))
  437. goto exit;
  438. if (msg_errcode(hdr))
  439. goto exit;
  440. /* Take a copy of original header before altering message */
  441. memcpy(&ohdr, hdr, msg_hdr_sz(hdr));
  442. /* Never return SHORT header; expand by replacing buffer if necessary */
  443. if (msg_short(hdr)) {
  444. *skb = tipc_buf_acquire(BASIC_H_SIZE + dlen);
  445. if (!*skb)
  446. goto exit;
  447. memcpy((*skb)->data + BASIC_H_SIZE, msg_data(hdr), dlen);
  448. kfree_skb(_skb);
  449. _skb = *skb;
  450. hdr = buf_msg(_skb);
  451. memcpy(hdr, &ohdr, BASIC_H_SIZE);
  452. msg_set_hdr_sz(hdr, BASIC_H_SIZE);
  453. }
  454. /* Now reverse the concerned fields */
  455. msg_set_errcode(hdr, err);
  456. msg_set_origport(hdr, msg_destport(&ohdr));
  457. msg_set_destport(hdr, msg_origport(&ohdr));
  458. msg_set_destnode(hdr, msg_prevnode(&ohdr));
  459. msg_set_prevnode(hdr, own_node);
  460. msg_set_orignode(hdr, own_node);
  461. msg_set_size(hdr, msg_hdr_sz(hdr) + dlen);
  462. skb_trim(_skb, msg_size(hdr));
  463. skb_orphan(_skb);
  464. return true;
  465. exit:
  466. kfree_skb(_skb);
  467. *skb = NULL;
  468. return false;
  469. }
  470. /**
  471. * tipc_msg_lookup_dest(): try to find new destination for named message
  472. * @skb: the buffer containing the message.
  473. * @err: error code to be used by caller if lookup fails
  474. * Does not consume buffer
  475. * Returns true if a destination is found, false otherwise
  476. */
  477. bool tipc_msg_lookup_dest(struct net *net, struct sk_buff *skb, int *err)
  478. {
  479. struct tipc_msg *msg = buf_msg(skb);
  480. u32 dport, dnode;
  481. u32 onode = tipc_own_addr(net);
  482. if (!msg_isdata(msg))
  483. return false;
  484. if (!msg_named(msg))
  485. return false;
  486. if (msg_errcode(msg))
  487. return false;
  488. *err = -TIPC_ERR_NO_NAME;
  489. if (skb_linearize(skb))
  490. return false;
  491. msg = buf_msg(skb);
  492. if (msg_reroute_cnt(msg))
  493. return false;
  494. dnode = addr_domain(net, msg_lookup_scope(msg));
  495. dport = tipc_nametbl_translate(net, msg_nametype(msg),
  496. msg_nameinst(msg), &dnode);
  497. if (!dport)
  498. return false;
  499. msg_incr_reroute_cnt(msg);
  500. if (dnode != onode)
  501. msg_set_prevnode(msg, onode);
  502. msg_set_destnode(msg, dnode);
  503. msg_set_destport(msg, dport);
  504. *err = TIPC_OK;
  505. return true;
  506. }
  507. /* tipc_msg_reassemble() - clone a buffer chain of fragments and
  508. * reassemble the clones into one message
  509. */
  510. struct sk_buff *tipc_msg_reassemble(struct sk_buff_head *list)
  511. {
  512. struct sk_buff *skb;
  513. struct sk_buff *frag = NULL;
  514. struct sk_buff *head = NULL;
  515. int hdr_sz;
  516. /* Copy header if single buffer */
  517. if (skb_queue_len(list) == 1) {
  518. skb = skb_peek(list);
  519. hdr_sz = skb_headroom(skb) + msg_hdr_sz(buf_msg(skb));
  520. return __pskb_copy(skb, hdr_sz, GFP_ATOMIC);
  521. }
  522. /* Clone all fragments and reassemble */
  523. skb_queue_walk(list, skb) {
  524. frag = skb_clone(skb, GFP_ATOMIC);
  525. if (!frag)
  526. goto error;
  527. frag->next = NULL;
  528. if (tipc_buf_append(&head, &frag))
  529. break;
  530. if (!head)
  531. goto error;
  532. }
  533. return frag;
  534. error:
  535. pr_warn("Failed do clone local mcast rcv buffer\n");
  536. kfree_skb(head);
  537. return NULL;
  538. }