stream_interleave.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* SCTP kernel implementation
  3. * (C) Copyright Red Hat Inc. 2017
  4. *
  5. * This file is part of the SCTP kernel implementation
  6. *
  7. * These functions implement sctp stream message interleaving, mostly
  8. * including I-DATA and I-FORWARD-TSN chunks process.
  9. *
  10. * Please send any bug reports or fixes you make to the
  11. * email addresched(es):
  12. * lksctp developers <linux-sctp@vger.kernel.org>
  13. *
  14. * Written or modified by:
  15. * Xin Long <lucien.xin@gmail.com>
  16. */
  17. #include <net/busy_poll.h>
  18. #include <net/sctp/sctp.h>
  19. #include <net/sctp/sm.h>
  20. #include <net/sctp/ulpevent.h>
  21. #include <linux/sctp.h>
  22. static struct sctp_chunk *sctp_make_idatafrag_empty(
  23. const struct sctp_association *asoc,
  24. const struct sctp_sndrcvinfo *sinfo,
  25. int len, __u8 flags, gfp_t gfp)
  26. {
  27. struct sctp_chunk *retval;
  28. struct sctp_idatahdr dp;
  29. memset(&dp, 0, sizeof(dp));
  30. dp.stream = htons(sinfo->sinfo_stream);
  31. if (sinfo->sinfo_flags & SCTP_UNORDERED)
  32. flags |= SCTP_DATA_UNORDERED;
  33. retval = sctp_make_idata(asoc, flags, sizeof(dp) + len, gfp);
  34. if (!retval)
  35. return NULL;
  36. retval->subh.idata_hdr = sctp_addto_chunk(retval, sizeof(dp), &dp);
  37. memcpy(&retval->sinfo, sinfo, sizeof(struct sctp_sndrcvinfo));
  38. return retval;
  39. }
  40. static void sctp_chunk_assign_mid(struct sctp_chunk *chunk)
  41. {
  42. struct sctp_stream *stream;
  43. struct sctp_chunk *lchunk;
  44. __u32 cfsn = 0;
  45. __u16 sid;
  46. if (chunk->has_mid)
  47. return;
  48. sid = sctp_chunk_stream_no(chunk);
  49. stream = &chunk->asoc->stream;
  50. list_for_each_entry(lchunk, &chunk->msg->chunks, frag_list) {
  51. struct sctp_idatahdr *hdr;
  52. __u32 mid;
  53. lchunk->has_mid = 1;
  54. hdr = lchunk->subh.idata_hdr;
  55. if (lchunk->chunk_hdr->flags & SCTP_DATA_FIRST_FRAG)
  56. hdr->ppid = lchunk->sinfo.sinfo_ppid;
  57. else
  58. hdr->fsn = htonl(cfsn++);
  59. if (lchunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) {
  60. mid = lchunk->chunk_hdr->flags & SCTP_DATA_LAST_FRAG ?
  61. sctp_mid_uo_next(stream, out, sid) :
  62. sctp_mid_uo_peek(stream, out, sid);
  63. } else {
  64. mid = lchunk->chunk_hdr->flags & SCTP_DATA_LAST_FRAG ?
  65. sctp_mid_next(stream, out, sid) :
  66. sctp_mid_peek(stream, out, sid);
  67. }
  68. hdr->mid = htonl(mid);
  69. }
  70. }
  71. static bool sctp_validate_data(struct sctp_chunk *chunk)
  72. {
  73. struct sctp_stream *stream;
  74. __u16 sid, ssn;
  75. if (chunk->chunk_hdr->type != SCTP_CID_DATA)
  76. return false;
  77. if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
  78. return true;
  79. stream = &chunk->asoc->stream;
  80. sid = sctp_chunk_stream_no(chunk);
  81. ssn = ntohs(chunk->subh.data_hdr->ssn);
  82. return !SSN_lt(ssn, sctp_ssn_peek(stream, in, sid));
  83. }
  84. static bool sctp_validate_idata(struct sctp_chunk *chunk)
  85. {
  86. struct sctp_stream *stream;
  87. __u32 mid;
  88. __u16 sid;
  89. if (chunk->chunk_hdr->type != SCTP_CID_I_DATA)
  90. return false;
  91. if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
  92. return true;
  93. stream = &chunk->asoc->stream;
  94. sid = sctp_chunk_stream_no(chunk);
  95. mid = ntohl(chunk->subh.idata_hdr->mid);
  96. return !MID_lt(mid, sctp_mid_peek(stream, in, sid));
  97. }
  98. static void sctp_intl_store_reasm(struct sctp_ulpq *ulpq,
  99. struct sctp_ulpevent *event)
  100. {
  101. struct sctp_ulpevent *cevent;
  102. struct sk_buff *pos, *loc;
  103. pos = skb_peek_tail(&ulpq->reasm);
  104. if (!pos) {
  105. __skb_queue_tail(&ulpq->reasm, sctp_event2skb(event));
  106. return;
  107. }
  108. cevent = sctp_skb2event(pos);
  109. if (event->stream == cevent->stream &&
  110. event->mid == cevent->mid &&
  111. (cevent->msg_flags & SCTP_DATA_FIRST_FRAG ||
  112. (!(event->msg_flags & SCTP_DATA_FIRST_FRAG) &&
  113. event->fsn > cevent->fsn))) {
  114. __skb_queue_tail(&ulpq->reasm, sctp_event2skb(event));
  115. return;
  116. }
  117. if ((event->stream == cevent->stream &&
  118. MID_lt(cevent->mid, event->mid)) ||
  119. event->stream > cevent->stream) {
  120. __skb_queue_tail(&ulpq->reasm, sctp_event2skb(event));
  121. return;
  122. }
  123. loc = NULL;
  124. skb_queue_walk(&ulpq->reasm, pos) {
  125. cevent = sctp_skb2event(pos);
  126. if (event->stream < cevent->stream ||
  127. (event->stream == cevent->stream &&
  128. MID_lt(event->mid, cevent->mid))) {
  129. loc = pos;
  130. break;
  131. }
  132. if (event->stream == cevent->stream &&
  133. event->mid == cevent->mid &&
  134. !(cevent->msg_flags & SCTP_DATA_FIRST_FRAG) &&
  135. (event->msg_flags & SCTP_DATA_FIRST_FRAG ||
  136. event->fsn < cevent->fsn)) {
  137. loc = pos;
  138. break;
  139. }
  140. }
  141. if (!loc)
  142. __skb_queue_tail(&ulpq->reasm, sctp_event2skb(event));
  143. else
  144. __skb_queue_before(&ulpq->reasm, loc, sctp_event2skb(event));
  145. }
  146. static struct sctp_ulpevent *sctp_intl_retrieve_partial(
  147. struct sctp_ulpq *ulpq,
  148. struct sctp_ulpevent *event)
  149. {
  150. struct sk_buff *first_frag = NULL;
  151. struct sk_buff *last_frag = NULL;
  152. struct sctp_ulpevent *retval;
  153. struct sctp_stream_in *sin;
  154. struct sk_buff *pos;
  155. __u32 next_fsn = 0;
  156. int is_last = 0;
  157. sin = sctp_stream_in(&ulpq->asoc->stream, event->stream);
  158. skb_queue_walk(&ulpq->reasm, pos) {
  159. struct sctp_ulpevent *cevent = sctp_skb2event(pos);
  160. if (cevent->stream < event->stream)
  161. continue;
  162. if (cevent->stream > event->stream ||
  163. cevent->mid != sin->mid)
  164. break;
  165. switch (cevent->msg_flags & SCTP_DATA_FRAG_MASK) {
  166. case SCTP_DATA_FIRST_FRAG:
  167. goto out;
  168. case SCTP_DATA_MIDDLE_FRAG:
  169. if (!first_frag) {
  170. if (cevent->fsn == sin->fsn) {
  171. first_frag = pos;
  172. last_frag = pos;
  173. next_fsn = cevent->fsn + 1;
  174. }
  175. } else if (cevent->fsn == next_fsn) {
  176. last_frag = pos;
  177. next_fsn++;
  178. } else {
  179. goto out;
  180. }
  181. break;
  182. case SCTP_DATA_LAST_FRAG:
  183. if (!first_frag) {
  184. if (cevent->fsn == sin->fsn) {
  185. first_frag = pos;
  186. last_frag = pos;
  187. next_fsn = 0;
  188. is_last = 1;
  189. }
  190. } else if (cevent->fsn == next_fsn) {
  191. last_frag = pos;
  192. next_fsn = 0;
  193. is_last = 1;
  194. }
  195. goto out;
  196. default:
  197. goto out;
  198. }
  199. }
  200. out:
  201. if (!first_frag)
  202. return NULL;
  203. retval = sctp_make_reassembled_event(ulpq->asoc->base.net, &ulpq->reasm,
  204. first_frag, last_frag);
  205. if (retval) {
  206. sin->fsn = next_fsn;
  207. if (is_last) {
  208. retval->msg_flags |= MSG_EOR;
  209. sin->pd_mode = 0;
  210. }
  211. }
  212. return retval;
  213. }
  214. static struct sctp_ulpevent *sctp_intl_retrieve_reassembled(
  215. struct sctp_ulpq *ulpq,
  216. struct sctp_ulpevent *event)
  217. {
  218. struct sctp_association *asoc = ulpq->asoc;
  219. struct sk_buff *pos, *first_frag = NULL;
  220. struct sctp_ulpevent *retval = NULL;
  221. struct sk_buff *pd_first = NULL;
  222. struct sk_buff *pd_last = NULL;
  223. struct sctp_stream_in *sin;
  224. __u32 next_fsn = 0;
  225. __u32 pd_point = 0;
  226. __u32 pd_len = 0;
  227. __u32 mid = 0;
  228. sin = sctp_stream_in(&ulpq->asoc->stream, event->stream);
  229. skb_queue_walk(&ulpq->reasm, pos) {
  230. struct sctp_ulpevent *cevent = sctp_skb2event(pos);
  231. if (cevent->stream < event->stream)
  232. continue;
  233. if (cevent->stream > event->stream)
  234. break;
  235. if (MID_lt(cevent->mid, event->mid))
  236. continue;
  237. if (MID_lt(event->mid, cevent->mid))
  238. break;
  239. switch (cevent->msg_flags & SCTP_DATA_FRAG_MASK) {
  240. case SCTP_DATA_FIRST_FRAG:
  241. if (cevent->mid == sin->mid) {
  242. pd_first = pos;
  243. pd_last = pos;
  244. pd_len = pos->len;
  245. }
  246. first_frag = pos;
  247. next_fsn = 0;
  248. mid = cevent->mid;
  249. break;
  250. case SCTP_DATA_MIDDLE_FRAG:
  251. if (first_frag && cevent->mid == mid &&
  252. cevent->fsn == next_fsn) {
  253. next_fsn++;
  254. if (pd_first) {
  255. pd_last = pos;
  256. pd_len += pos->len;
  257. }
  258. } else {
  259. first_frag = NULL;
  260. }
  261. break;
  262. case SCTP_DATA_LAST_FRAG:
  263. if (first_frag && cevent->mid == mid &&
  264. cevent->fsn == next_fsn)
  265. goto found;
  266. else
  267. first_frag = NULL;
  268. break;
  269. }
  270. }
  271. if (!pd_first)
  272. goto out;
  273. pd_point = sctp_sk(asoc->base.sk)->pd_point;
  274. if (pd_point && pd_point <= pd_len) {
  275. retval = sctp_make_reassembled_event(asoc->base.net,
  276. &ulpq->reasm,
  277. pd_first, pd_last);
  278. if (retval) {
  279. sin->fsn = next_fsn;
  280. sin->pd_mode = 1;
  281. }
  282. }
  283. goto out;
  284. found:
  285. retval = sctp_make_reassembled_event(asoc->base.net, &ulpq->reasm,
  286. first_frag, pos);
  287. if (retval)
  288. retval->msg_flags |= MSG_EOR;
  289. out:
  290. return retval;
  291. }
  292. static struct sctp_ulpevent *sctp_intl_reasm(struct sctp_ulpq *ulpq,
  293. struct sctp_ulpevent *event)
  294. {
  295. struct sctp_ulpevent *retval = NULL;
  296. struct sctp_stream_in *sin;
  297. if (SCTP_DATA_NOT_FRAG == (event->msg_flags & SCTP_DATA_FRAG_MASK)) {
  298. event->msg_flags |= MSG_EOR;
  299. return event;
  300. }
  301. sctp_intl_store_reasm(ulpq, event);
  302. sin = sctp_stream_in(&ulpq->asoc->stream, event->stream);
  303. if (sin->pd_mode && event->mid == sin->mid &&
  304. event->fsn == sin->fsn)
  305. retval = sctp_intl_retrieve_partial(ulpq, event);
  306. if (!retval)
  307. retval = sctp_intl_retrieve_reassembled(ulpq, event);
  308. return retval;
  309. }
  310. static void sctp_intl_store_ordered(struct sctp_ulpq *ulpq,
  311. struct sctp_ulpevent *event)
  312. {
  313. struct sctp_ulpevent *cevent;
  314. struct sk_buff *pos, *loc;
  315. pos = skb_peek_tail(&ulpq->lobby);
  316. if (!pos) {
  317. __skb_queue_tail(&ulpq->lobby, sctp_event2skb(event));
  318. return;
  319. }
  320. cevent = (struct sctp_ulpevent *)pos->cb;
  321. if (event->stream == cevent->stream &&
  322. MID_lt(cevent->mid, event->mid)) {
  323. __skb_queue_tail(&ulpq->lobby, sctp_event2skb(event));
  324. return;
  325. }
  326. if (event->stream > cevent->stream) {
  327. __skb_queue_tail(&ulpq->lobby, sctp_event2skb(event));
  328. return;
  329. }
  330. loc = NULL;
  331. skb_queue_walk(&ulpq->lobby, pos) {
  332. cevent = (struct sctp_ulpevent *)pos->cb;
  333. if (cevent->stream > event->stream) {
  334. loc = pos;
  335. break;
  336. }
  337. if (cevent->stream == event->stream &&
  338. MID_lt(event->mid, cevent->mid)) {
  339. loc = pos;
  340. break;
  341. }
  342. }
  343. if (!loc)
  344. __skb_queue_tail(&ulpq->lobby, sctp_event2skb(event));
  345. else
  346. __skb_queue_before(&ulpq->lobby, loc, sctp_event2skb(event));
  347. }
  348. static void sctp_intl_retrieve_ordered(struct sctp_ulpq *ulpq,
  349. struct sctp_ulpevent *event)
  350. {
  351. struct sk_buff_head *event_list;
  352. struct sctp_stream *stream;
  353. struct sk_buff *pos, *tmp;
  354. __u16 sid = event->stream;
  355. stream = &ulpq->asoc->stream;
  356. event_list = (struct sk_buff_head *)sctp_event2skb(event)->prev;
  357. sctp_skb_for_each(pos, &ulpq->lobby, tmp) {
  358. struct sctp_ulpevent *cevent = (struct sctp_ulpevent *)pos->cb;
  359. if (cevent->stream > sid)
  360. break;
  361. if (cevent->stream < sid)
  362. continue;
  363. if (cevent->mid != sctp_mid_peek(stream, in, sid))
  364. break;
  365. sctp_mid_next(stream, in, sid);
  366. __skb_unlink(pos, &ulpq->lobby);
  367. __skb_queue_tail(event_list, pos);
  368. }
  369. }
  370. static struct sctp_ulpevent *sctp_intl_order(struct sctp_ulpq *ulpq,
  371. struct sctp_ulpevent *event)
  372. {
  373. struct sctp_stream *stream;
  374. __u16 sid;
  375. stream = &ulpq->asoc->stream;
  376. sid = event->stream;
  377. if (event->mid != sctp_mid_peek(stream, in, sid)) {
  378. sctp_intl_store_ordered(ulpq, event);
  379. return NULL;
  380. }
  381. sctp_mid_next(stream, in, sid);
  382. sctp_intl_retrieve_ordered(ulpq, event);
  383. return event;
  384. }
  385. static int sctp_enqueue_event(struct sctp_ulpq *ulpq,
  386. struct sk_buff_head *skb_list)
  387. {
  388. struct sock *sk = ulpq->asoc->base.sk;
  389. struct sctp_sock *sp = sctp_sk(sk);
  390. struct sctp_ulpevent *event;
  391. struct sk_buff *skb;
  392. skb = __skb_peek(skb_list);
  393. event = sctp_skb2event(skb);
  394. if (sk->sk_shutdown & RCV_SHUTDOWN &&
  395. (sk->sk_shutdown & SEND_SHUTDOWN ||
  396. !sctp_ulpevent_is_notification(event)))
  397. goto out_free;
  398. if (!sctp_ulpevent_is_notification(event)) {
  399. sk_mark_napi_id(sk, skb);
  400. sk_incoming_cpu_update(sk);
  401. }
  402. if (!sctp_ulpevent_is_enabled(event, ulpq->asoc->subscribe))
  403. goto out_free;
  404. skb_queue_splice_tail_init(skb_list,
  405. &sk->sk_receive_queue);
  406. if (!sp->data_ready_signalled) {
  407. sp->data_ready_signalled = 1;
  408. sk->sk_data_ready(sk);
  409. }
  410. return 1;
  411. out_free:
  412. sctp_queue_purge_ulpevents(skb_list);
  413. return 0;
  414. }
  415. static void sctp_intl_store_reasm_uo(struct sctp_ulpq *ulpq,
  416. struct sctp_ulpevent *event)
  417. {
  418. struct sctp_ulpevent *cevent;
  419. struct sk_buff *pos;
  420. pos = skb_peek_tail(&ulpq->reasm_uo);
  421. if (!pos) {
  422. __skb_queue_tail(&ulpq->reasm_uo, sctp_event2skb(event));
  423. return;
  424. }
  425. cevent = sctp_skb2event(pos);
  426. if (event->stream == cevent->stream &&
  427. event->mid == cevent->mid &&
  428. (cevent->msg_flags & SCTP_DATA_FIRST_FRAG ||
  429. (!(event->msg_flags & SCTP_DATA_FIRST_FRAG) &&
  430. event->fsn > cevent->fsn))) {
  431. __skb_queue_tail(&ulpq->reasm_uo, sctp_event2skb(event));
  432. return;
  433. }
  434. if ((event->stream == cevent->stream &&
  435. MID_lt(cevent->mid, event->mid)) ||
  436. event->stream > cevent->stream) {
  437. __skb_queue_tail(&ulpq->reasm_uo, sctp_event2skb(event));
  438. return;
  439. }
  440. skb_queue_walk(&ulpq->reasm_uo, pos) {
  441. cevent = sctp_skb2event(pos);
  442. if (event->stream < cevent->stream ||
  443. (event->stream == cevent->stream &&
  444. MID_lt(event->mid, cevent->mid)))
  445. break;
  446. if (event->stream == cevent->stream &&
  447. event->mid == cevent->mid &&
  448. !(cevent->msg_flags & SCTP_DATA_FIRST_FRAG) &&
  449. (event->msg_flags & SCTP_DATA_FIRST_FRAG ||
  450. event->fsn < cevent->fsn))
  451. break;
  452. }
  453. __skb_queue_before(&ulpq->reasm_uo, pos, sctp_event2skb(event));
  454. }
  455. static struct sctp_ulpevent *sctp_intl_retrieve_partial_uo(
  456. struct sctp_ulpq *ulpq,
  457. struct sctp_ulpevent *event)
  458. {
  459. struct sk_buff *first_frag = NULL;
  460. struct sk_buff *last_frag = NULL;
  461. struct sctp_ulpevent *retval;
  462. struct sctp_stream_in *sin;
  463. struct sk_buff *pos;
  464. __u32 next_fsn = 0;
  465. int is_last = 0;
  466. sin = sctp_stream_in(&ulpq->asoc->stream, event->stream);
  467. skb_queue_walk(&ulpq->reasm_uo, pos) {
  468. struct sctp_ulpevent *cevent = sctp_skb2event(pos);
  469. if (cevent->stream < event->stream)
  470. continue;
  471. if (cevent->stream > event->stream)
  472. break;
  473. if (MID_lt(cevent->mid, sin->mid_uo))
  474. continue;
  475. if (MID_lt(sin->mid_uo, cevent->mid))
  476. break;
  477. switch (cevent->msg_flags & SCTP_DATA_FRAG_MASK) {
  478. case SCTP_DATA_FIRST_FRAG:
  479. goto out;
  480. case SCTP_DATA_MIDDLE_FRAG:
  481. if (!first_frag) {
  482. if (cevent->fsn == sin->fsn_uo) {
  483. first_frag = pos;
  484. last_frag = pos;
  485. next_fsn = cevent->fsn + 1;
  486. }
  487. } else if (cevent->fsn == next_fsn) {
  488. last_frag = pos;
  489. next_fsn++;
  490. } else {
  491. goto out;
  492. }
  493. break;
  494. case SCTP_DATA_LAST_FRAG:
  495. if (!first_frag) {
  496. if (cevent->fsn == sin->fsn_uo) {
  497. first_frag = pos;
  498. last_frag = pos;
  499. next_fsn = 0;
  500. is_last = 1;
  501. }
  502. } else if (cevent->fsn == next_fsn) {
  503. last_frag = pos;
  504. next_fsn = 0;
  505. is_last = 1;
  506. }
  507. goto out;
  508. default:
  509. goto out;
  510. }
  511. }
  512. out:
  513. if (!first_frag)
  514. return NULL;
  515. retval = sctp_make_reassembled_event(ulpq->asoc->base.net,
  516. &ulpq->reasm_uo, first_frag,
  517. last_frag);
  518. if (retval) {
  519. sin->fsn_uo = next_fsn;
  520. if (is_last) {
  521. retval->msg_flags |= MSG_EOR;
  522. sin->pd_mode_uo = 0;
  523. }
  524. }
  525. return retval;
  526. }
  527. static struct sctp_ulpevent *sctp_intl_retrieve_reassembled_uo(
  528. struct sctp_ulpq *ulpq,
  529. struct sctp_ulpevent *event)
  530. {
  531. struct sctp_association *asoc = ulpq->asoc;
  532. struct sk_buff *pos, *first_frag = NULL;
  533. struct sctp_ulpevent *retval = NULL;
  534. struct sk_buff *pd_first = NULL;
  535. struct sk_buff *pd_last = NULL;
  536. struct sctp_stream_in *sin;
  537. __u32 next_fsn = 0;
  538. __u32 pd_point = 0;
  539. __u32 pd_len = 0;
  540. __u32 mid = 0;
  541. sin = sctp_stream_in(&ulpq->asoc->stream, event->stream);
  542. skb_queue_walk(&ulpq->reasm_uo, pos) {
  543. struct sctp_ulpevent *cevent = sctp_skb2event(pos);
  544. if (cevent->stream < event->stream)
  545. continue;
  546. if (cevent->stream > event->stream)
  547. break;
  548. if (MID_lt(cevent->mid, event->mid))
  549. continue;
  550. if (MID_lt(event->mid, cevent->mid))
  551. break;
  552. switch (cevent->msg_flags & SCTP_DATA_FRAG_MASK) {
  553. case SCTP_DATA_FIRST_FRAG:
  554. if (!sin->pd_mode_uo) {
  555. sin->mid_uo = cevent->mid;
  556. pd_first = pos;
  557. pd_last = pos;
  558. pd_len = pos->len;
  559. }
  560. first_frag = pos;
  561. next_fsn = 0;
  562. mid = cevent->mid;
  563. break;
  564. case SCTP_DATA_MIDDLE_FRAG:
  565. if (first_frag && cevent->mid == mid &&
  566. cevent->fsn == next_fsn) {
  567. next_fsn++;
  568. if (pd_first) {
  569. pd_last = pos;
  570. pd_len += pos->len;
  571. }
  572. } else {
  573. first_frag = NULL;
  574. }
  575. break;
  576. case SCTP_DATA_LAST_FRAG:
  577. if (first_frag && cevent->mid == mid &&
  578. cevent->fsn == next_fsn)
  579. goto found;
  580. else
  581. first_frag = NULL;
  582. break;
  583. }
  584. }
  585. if (!pd_first)
  586. goto out;
  587. pd_point = sctp_sk(asoc->base.sk)->pd_point;
  588. if (pd_point && pd_point <= pd_len) {
  589. retval = sctp_make_reassembled_event(asoc->base.net,
  590. &ulpq->reasm_uo,
  591. pd_first, pd_last);
  592. if (retval) {
  593. sin->fsn_uo = next_fsn;
  594. sin->pd_mode_uo = 1;
  595. }
  596. }
  597. goto out;
  598. found:
  599. retval = sctp_make_reassembled_event(asoc->base.net, &ulpq->reasm_uo,
  600. first_frag, pos);
  601. if (retval)
  602. retval->msg_flags |= MSG_EOR;
  603. out:
  604. return retval;
  605. }
  606. static struct sctp_ulpevent *sctp_intl_reasm_uo(struct sctp_ulpq *ulpq,
  607. struct sctp_ulpevent *event)
  608. {
  609. struct sctp_ulpevent *retval = NULL;
  610. struct sctp_stream_in *sin;
  611. if (SCTP_DATA_NOT_FRAG == (event->msg_flags & SCTP_DATA_FRAG_MASK)) {
  612. event->msg_flags |= MSG_EOR;
  613. return event;
  614. }
  615. sctp_intl_store_reasm_uo(ulpq, event);
  616. sin = sctp_stream_in(&ulpq->asoc->stream, event->stream);
  617. if (sin->pd_mode_uo && event->mid == sin->mid_uo &&
  618. event->fsn == sin->fsn_uo)
  619. retval = sctp_intl_retrieve_partial_uo(ulpq, event);
  620. if (!retval)
  621. retval = sctp_intl_retrieve_reassembled_uo(ulpq, event);
  622. return retval;
  623. }
  624. static struct sctp_ulpevent *sctp_intl_retrieve_first_uo(struct sctp_ulpq *ulpq)
  625. {
  626. struct sctp_stream_in *csin, *sin = NULL;
  627. struct sk_buff *first_frag = NULL;
  628. struct sk_buff *last_frag = NULL;
  629. struct sctp_ulpevent *retval;
  630. struct sk_buff *pos;
  631. __u32 next_fsn = 0;
  632. __u16 sid = 0;
  633. skb_queue_walk(&ulpq->reasm_uo, pos) {
  634. struct sctp_ulpevent *cevent = sctp_skb2event(pos);
  635. csin = sctp_stream_in(&ulpq->asoc->stream, cevent->stream);
  636. if (csin->pd_mode_uo)
  637. continue;
  638. switch (cevent->msg_flags & SCTP_DATA_FRAG_MASK) {
  639. case SCTP_DATA_FIRST_FRAG:
  640. if (first_frag)
  641. goto out;
  642. first_frag = pos;
  643. last_frag = pos;
  644. next_fsn = 0;
  645. sin = csin;
  646. sid = cevent->stream;
  647. sin->mid_uo = cevent->mid;
  648. break;
  649. case SCTP_DATA_MIDDLE_FRAG:
  650. if (!first_frag)
  651. break;
  652. if (cevent->stream == sid &&
  653. cevent->mid == sin->mid_uo &&
  654. cevent->fsn == next_fsn) {
  655. next_fsn++;
  656. last_frag = pos;
  657. } else {
  658. goto out;
  659. }
  660. break;
  661. case SCTP_DATA_LAST_FRAG:
  662. if (first_frag)
  663. goto out;
  664. break;
  665. default:
  666. break;
  667. }
  668. }
  669. if (!first_frag)
  670. return NULL;
  671. out:
  672. retval = sctp_make_reassembled_event(ulpq->asoc->base.net,
  673. &ulpq->reasm_uo, first_frag,
  674. last_frag);
  675. if (retval) {
  676. sin->fsn_uo = next_fsn;
  677. sin->pd_mode_uo = 1;
  678. }
  679. return retval;
  680. }
  681. static int sctp_ulpevent_idata(struct sctp_ulpq *ulpq,
  682. struct sctp_chunk *chunk, gfp_t gfp)
  683. {
  684. struct sctp_ulpevent *event;
  685. struct sk_buff_head temp;
  686. int event_eor = 0;
  687. event = sctp_ulpevent_make_rcvmsg(chunk->asoc, chunk, gfp);
  688. if (!event)
  689. return -ENOMEM;
  690. event->mid = ntohl(chunk->subh.idata_hdr->mid);
  691. if (event->msg_flags & SCTP_DATA_FIRST_FRAG)
  692. event->ppid = chunk->subh.idata_hdr->ppid;
  693. else
  694. event->fsn = ntohl(chunk->subh.idata_hdr->fsn);
  695. if (!(event->msg_flags & SCTP_DATA_UNORDERED)) {
  696. event = sctp_intl_reasm(ulpq, event);
  697. if (event) {
  698. skb_queue_head_init(&temp);
  699. __skb_queue_tail(&temp, sctp_event2skb(event));
  700. if (event->msg_flags & MSG_EOR)
  701. event = sctp_intl_order(ulpq, event);
  702. }
  703. } else {
  704. event = sctp_intl_reasm_uo(ulpq, event);
  705. if (event) {
  706. skb_queue_head_init(&temp);
  707. __skb_queue_tail(&temp, sctp_event2skb(event));
  708. }
  709. }
  710. if (event) {
  711. event_eor = (event->msg_flags & MSG_EOR) ? 1 : 0;
  712. sctp_enqueue_event(ulpq, &temp);
  713. }
  714. return event_eor;
  715. }
  716. static struct sctp_ulpevent *sctp_intl_retrieve_first(struct sctp_ulpq *ulpq)
  717. {
  718. struct sctp_stream_in *csin, *sin = NULL;
  719. struct sk_buff *first_frag = NULL;
  720. struct sk_buff *last_frag = NULL;
  721. struct sctp_ulpevent *retval;
  722. struct sk_buff *pos;
  723. __u32 next_fsn = 0;
  724. __u16 sid = 0;
  725. skb_queue_walk(&ulpq->reasm, pos) {
  726. struct sctp_ulpevent *cevent = sctp_skb2event(pos);
  727. csin = sctp_stream_in(&ulpq->asoc->stream, cevent->stream);
  728. if (csin->pd_mode)
  729. continue;
  730. switch (cevent->msg_flags & SCTP_DATA_FRAG_MASK) {
  731. case SCTP_DATA_FIRST_FRAG:
  732. if (first_frag)
  733. goto out;
  734. if (cevent->mid == csin->mid) {
  735. first_frag = pos;
  736. last_frag = pos;
  737. next_fsn = 0;
  738. sin = csin;
  739. sid = cevent->stream;
  740. }
  741. break;
  742. case SCTP_DATA_MIDDLE_FRAG:
  743. if (!first_frag)
  744. break;
  745. if (cevent->stream == sid &&
  746. cevent->mid == sin->mid &&
  747. cevent->fsn == next_fsn) {
  748. next_fsn++;
  749. last_frag = pos;
  750. } else {
  751. goto out;
  752. }
  753. break;
  754. case SCTP_DATA_LAST_FRAG:
  755. if (first_frag)
  756. goto out;
  757. break;
  758. default:
  759. break;
  760. }
  761. }
  762. if (!first_frag)
  763. return NULL;
  764. out:
  765. retval = sctp_make_reassembled_event(ulpq->asoc->base.net,
  766. &ulpq->reasm, first_frag,
  767. last_frag);
  768. if (retval) {
  769. sin->fsn = next_fsn;
  770. sin->pd_mode = 1;
  771. }
  772. return retval;
  773. }
  774. static void sctp_intl_start_pd(struct sctp_ulpq *ulpq, gfp_t gfp)
  775. {
  776. struct sctp_ulpevent *event;
  777. struct sk_buff_head temp;
  778. if (!skb_queue_empty(&ulpq->reasm)) {
  779. do {
  780. event = sctp_intl_retrieve_first(ulpq);
  781. if (event) {
  782. skb_queue_head_init(&temp);
  783. __skb_queue_tail(&temp, sctp_event2skb(event));
  784. sctp_enqueue_event(ulpq, &temp);
  785. }
  786. } while (event);
  787. }
  788. if (!skb_queue_empty(&ulpq->reasm_uo)) {
  789. do {
  790. event = sctp_intl_retrieve_first_uo(ulpq);
  791. if (event) {
  792. skb_queue_head_init(&temp);
  793. __skb_queue_tail(&temp, sctp_event2skb(event));
  794. sctp_enqueue_event(ulpq, &temp);
  795. }
  796. } while (event);
  797. }
  798. }
  799. static void sctp_renege_events(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk,
  800. gfp_t gfp)
  801. {
  802. struct sctp_association *asoc = ulpq->asoc;
  803. __u32 freed = 0;
  804. __u16 needed;
  805. needed = ntohs(chunk->chunk_hdr->length) -
  806. sizeof(struct sctp_idata_chunk);
  807. if (skb_queue_empty(&asoc->base.sk->sk_receive_queue)) {
  808. freed = sctp_ulpq_renege_list(ulpq, &ulpq->lobby, needed);
  809. if (freed < needed)
  810. freed += sctp_ulpq_renege_list(ulpq, &ulpq->reasm,
  811. needed);
  812. if (freed < needed)
  813. freed += sctp_ulpq_renege_list(ulpq, &ulpq->reasm_uo,
  814. needed);
  815. }
  816. if (freed >= needed && sctp_ulpevent_idata(ulpq, chunk, gfp) <= 0)
  817. sctp_intl_start_pd(ulpq, gfp);
  818. }
  819. static void sctp_intl_stream_abort_pd(struct sctp_ulpq *ulpq, __u16 sid,
  820. __u32 mid, __u16 flags, gfp_t gfp)
  821. {
  822. struct sock *sk = ulpq->asoc->base.sk;
  823. struct sctp_ulpevent *ev = NULL;
  824. if (!sctp_ulpevent_type_enabled(ulpq->asoc->subscribe,
  825. SCTP_PARTIAL_DELIVERY_EVENT))
  826. return;
  827. ev = sctp_ulpevent_make_pdapi(ulpq->asoc, SCTP_PARTIAL_DELIVERY_ABORTED,
  828. sid, mid, flags, gfp);
  829. if (ev) {
  830. struct sctp_sock *sp = sctp_sk(sk);
  831. __skb_queue_tail(&sk->sk_receive_queue, sctp_event2skb(ev));
  832. if (!sp->data_ready_signalled) {
  833. sp->data_ready_signalled = 1;
  834. sk->sk_data_ready(sk);
  835. }
  836. }
  837. }
  838. static void sctp_intl_reap_ordered(struct sctp_ulpq *ulpq, __u16 sid)
  839. {
  840. struct sctp_stream *stream = &ulpq->asoc->stream;
  841. struct sctp_ulpevent *cevent, *event = NULL;
  842. struct sk_buff_head *lobby = &ulpq->lobby;
  843. struct sk_buff *pos, *tmp;
  844. struct sk_buff_head temp;
  845. __u16 csid;
  846. __u32 cmid;
  847. skb_queue_head_init(&temp);
  848. sctp_skb_for_each(pos, lobby, tmp) {
  849. cevent = (struct sctp_ulpevent *)pos->cb;
  850. csid = cevent->stream;
  851. cmid = cevent->mid;
  852. if (csid > sid)
  853. break;
  854. if (csid < sid)
  855. continue;
  856. if (!MID_lt(cmid, sctp_mid_peek(stream, in, csid)))
  857. break;
  858. __skb_unlink(pos, lobby);
  859. if (!event)
  860. event = sctp_skb2event(pos);
  861. __skb_queue_tail(&temp, pos);
  862. }
  863. if (!event && pos != (struct sk_buff *)lobby) {
  864. cevent = (struct sctp_ulpevent *)pos->cb;
  865. csid = cevent->stream;
  866. cmid = cevent->mid;
  867. if (csid == sid && cmid == sctp_mid_peek(stream, in, csid)) {
  868. sctp_mid_next(stream, in, csid);
  869. __skb_unlink(pos, lobby);
  870. __skb_queue_tail(&temp, pos);
  871. event = sctp_skb2event(pos);
  872. }
  873. }
  874. if (event) {
  875. sctp_intl_retrieve_ordered(ulpq, event);
  876. sctp_enqueue_event(ulpq, &temp);
  877. }
  878. }
  879. static void sctp_intl_abort_pd(struct sctp_ulpq *ulpq, gfp_t gfp)
  880. {
  881. struct sctp_stream *stream = &ulpq->asoc->stream;
  882. __u16 sid;
  883. for (sid = 0; sid < stream->incnt; sid++) {
  884. struct sctp_stream_in *sin = SCTP_SI(stream, sid);
  885. __u32 mid;
  886. if (sin->pd_mode_uo) {
  887. sin->pd_mode_uo = 0;
  888. mid = sin->mid_uo;
  889. sctp_intl_stream_abort_pd(ulpq, sid, mid, 0x1, gfp);
  890. }
  891. if (sin->pd_mode) {
  892. sin->pd_mode = 0;
  893. mid = sin->mid;
  894. sctp_intl_stream_abort_pd(ulpq, sid, mid, 0, gfp);
  895. sctp_mid_skip(stream, in, sid, mid);
  896. sctp_intl_reap_ordered(ulpq, sid);
  897. }
  898. }
  899. /* intl abort pd happens only when all data needs to be cleaned */
  900. sctp_ulpq_flush(ulpq);
  901. }
  902. static inline int sctp_get_skip_pos(struct sctp_ifwdtsn_skip *skiplist,
  903. int nskips, __be16 stream, __u8 flags)
  904. {
  905. int i;
  906. for (i = 0; i < nskips; i++)
  907. if (skiplist[i].stream == stream &&
  908. skiplist[i].flags == flags)
  909. return i;
  910. return i;
  911. }
  912. #define SCTP_FTSN_U_BIT 0x1
  913. static void sctp_generate_iftsn(struct sctp_outq *q, __u32 ctsn)
  914. {
  915. struct sctp_ifwdtsn_skip ftsn_skip_arr[10];
  916. struct sctp_association *asoc = q->asoc;
  917. struct sctp_chunk *ftsn_chunk = NULL;
  918. struct list_head *lchunk, *temp;
  919. int nskips = 0, skip_pos;
  920. struct sctp_chunk *chunk;
  921. __u32 tsn;
  922. if (!asoc->peer.prsctp_capable)
  923. return;
  924. if (TSN_lt(asoc->adv_peer_ack_point, ctsn))
  925. asoc->adv_peer_ack_point = ctsn;
  926. list_for_each_safe(lchunk, temp, &q->abandoned) {
  927. chunk = list_entry(lchunk, struct sctp_chunk, transmitted_list);
  928. tsn = ntohl(chunk->subh.data_hdr->tsn);
  929. if (TSN_lte(tsn, ctsn)) {
  930. list_del_init(lchunk);
  931. sctp_chunk_free(chunk);
  932. } else if (TSN_lte(tsn, asoc->adv_peer_ack_point + 1)) {
  933. __be16 sid = chunk->subh.idata_hdr->stream;
  934. __be32 mid = chunk->subh.idata_hdr->mid;
  935. __u8 flags = 0;
  936. if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
  937. flags |= SCTP_FTSN_U_BIT;
  938. asoc->adv_peer_ack_point = tsn;
  939. skip_pos = sctp_get_skip_pos(&ftsn_skip_arr[0], nskips,
  940. sid, flags);
  941. ftsn_skip_arr[skip_pos].stream = sid;
  942. ftsn_skip_arr[skip_pos].reserved = 0;
  943. ftsn_skip_arr[skip_pos].flags = flags;
  944. ftsn_skip_arr[skip_pos].mid = mid;
  945. if (skip_pos == nskips)
  946. nskips++;
  947. if (nskips == 10)
  948. break;
  949. } else {
  950. break;
  951. }
  952. }
  953. if (asoc->adv_peer_ack_point > ctsn)
  954. ftsn_chunk = sctp_make_ifwdtsn(asoc, asoc->adv_peer_ack_point,
  955. nskips, &ftsn_skip_arr[0]);
  956. if (ftsn_chunk) {
  957. list_add_tail(&ftsn_chunk->list, &q->control_chunk_list);
  958. SCTP_INC_STATS(asoc->base.net, SCTP_MIB_OUTCTRLCHUNKS);
  959. }
  960. }
  961. #define _sctp_walk_ifwdtsn(pos, chunk, end) \
  962. for (pos = (void *)(chunk->subh.ifwdtsn_hdr + 1); \
  963. (void *)pos <= (void *)(chunk->subh.ifwdtsn_hdr + 1) + (end) - \
  964. sizeof(struct sctp_ifwdtsn_skip); pos++)
  965. #define sctp_walk_ifwdtsn(pos, ch) \
  966. _sctp_walk_ifwdtsn((pos), (ch), ntohs((ch)->chunk_hdr->length) - \
  967. sizeof(struct sctp_ifwdtsn_chunk))
  968. static bool sctp_validate_fwdtsn(struct sctp_chunk *chunk)
  969. {
  970. struct sctp_fwdtsn_skip *skip;
  971. __u16 incnt;
  972. if (chunk->chunk_hdr->type != SCTP_CID_FWD_TSN)
  973. return false;
  974. incnt = chunk->asoc->stream.incnt;
  975. sctp_walk_fwdtsn(skip, chunk)
  976. if (ntohs(skip->stream) >= incnt)
  977. return false;
  978. return true;
  979. }
  980. static bool sctp_validate_iftsn(struct sctp_chunk *chunk)
  981. {
  982. struct sctp_ifwdtsn_skip *skip;
  983. __u16 incnt;
  984. if (chunk->chunk_hdr->type != SCTP_CID_I_FWD_TSN)
  985. return false;
  986. incnt = chunk->asoc->stream.incnt;
  987. sctp_walk_ifwdtsn(skip, chunk)
  988. if (ntohs(skip->stream) >= incnt)
  989. return false;
  990. return true;
  991. }
  992. static void sctp_report_fwdtsn(struct sctp_ulpq *ulpq, __u32 ftsn)
  993. {
  994. /* Move the Cumulattive TSN Ack ahead. */
  995. sctp_tsnmap_skip(&ulpq->asoc->peer.tsn_map, ftsn);
  996. /* purge the fragmentation queue */
  997. sctp_ulpq_reasm_flushtsn(ulpq, ftsn);
  998. /* Abort any in progress partial delivery. */
  999. sctp_ulpq_abort_pd(ulpq, GFP_ATOMIC);
  1000. }
  1001. static void sctp_intl_reasm_flushtsn(struct sctp_ulpq *ulpq, __u32 ftsn)
  1002. {
  1003. struct sk_buff *pos, *tmp;
  1004. skb_queue_walk_safe(&ulpq->reasm, pos, tmp) {
  1005. struct sctp_ulpevent *event = sctp_skb2event(pos);
  1006. __u32 tsn = event->tsn;
  1007. if (TSN_lte(tsn, ftsn)) {
  1008. __skb_unlink(pos, &ulpq->reasm);
  1009. sctp_ulpevent_free(event);
  1010. }
  1011. }
  1012. skb_queue_walk_safe(&ulpq->reasm_uo, pos, tmp) {
  1013. struct sctp_ulpevent *event = sctp_skb2event(pos);
  1014. __u32 tsn = event->tsn;
  1015. if (TSN_lte(tsn, ftsn)) {
  1016. __skb_unlink(pos, &ulpq->reasm_uo);
  1017. sctp_ulpevent_free(event);
  1018. }
  1019. }
  1020. }
  1021. static void sctp_report_iftsn(struct sctp_ulpq *ulpq, __u32 ftsn)
  1022. {
  1023. /* Move the Cumulattive TSN Ack ahead. */
  1024. sctp_tsnmap_skip(&ulpq->asoc->peer.tsn_map, ftsn);
  1025. /* purge the fragmentation queue */
  1026. sctp_intl_reasm_flushtsn(ulpq, ftsn);
  1027. /* abort only when it's for all data */
  1028. if (ftsn == sctp_tsnmap_get_max_tsn_seen(&ulpq->asoc->peer.tsn_map))
  1029. sctp_intl_abort_pd(ulpq, GFP_ATOMIC);
  1030. }
  1031. static void sctp_handle_fwdtsn(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk)
  1032. {
  1033. struct sctp_fwdtsn_skip *skip;
  1034. /* Walk through all the skipped SSNs */
  1035. sctp_walk_fwdtsn(skip, chunk)
  1036. sctp_ulpq_skip(ulpq, ntohs(skip->stream), ntohs(skip->ssn));
  1037. }
  1038. static void sctp_intl_skip(struct sctp_ulpq *ulpq, __u16 sid, __u32 mid,
  1039. __u8 flags)
  1040. {
  1041. struct sctp_stream_in *sin = sctp_stream_in(&ulpq->asoc->stream, sid);
  1042. struct sctp_stream *stream = &ulpq->asoc->stream;
  1043. if (flags & SCTP_FTSN_U_BIT) {
  1044. if (sin->pd_mode_uo && MID_lt(sin->mid_uo, mid)) {
  1045. sin->pd_mode_uo = 0;
  1046. sctp_intl_stream_abort_pd(ulpq, sid, mid, 0x1,
  1047. GFP_ATOMIC);
  1048. }
  1049. return;
  1050. }
  1051. if (MID_lt(mid, sctp_mid_peek(stream, in, sid)))
  1052. return;
  1053. if (sin->pd_mode) {
  1054. sin->pd_mode = 0;
  1055. sctp_intl_stream_abort_pd(ulpq, sid, mid, 0x0, GFP_ATOMIC);
  1056. }
  1057. sctp_mid_skip(stream, in, sid, mid);
  1058. sctp_intl_reap_ordered(ulpq, sid);
  1059. }
  1060. static void sctp_handle_iftsn(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk)
  1061. {
  1062. struct sctp_ifwdtsn_skip *skip;
  1063. /* Walk through all the skipped MIDs and abort stream pd if possible */
  1064. sctp_walk_ifwdtsn(skip, chunk)
  1065. sctp_intl_skip(ulpq, ntohs(skip->stream),
  1066. ntohl(skip->mid), skip->flags);
  1067. }
  1068. static int do_ulpq_tail_event(struct sctp_ulpq *ulpq, struct sctp_ulpevent *event)
  1069. {
  1070. struct sk_buff_head temp;
  1071. skb_queue_head_init(&temp);
  1072. __skb_queue_tail(&temp, sctp_event2skb(event));
  1073. return sctp_ulpq_tail_event(ulpq, &temp);
  1074. }
  1075. static struct sctp_stream_interleave sctp_stream_interleave_0 = {
  1076. .data_chunk_len = sizeof(struct sctp_data_chunk),
  1077. .ftsn_chunk_len = sizeof(struct sctp_fwdtsn_chunk),
  1078. /* DATA process functions */
  1079. .make_datafrag = sctp_make_datafrag_empty,
  1080. .assign_number = sctp_chunk_assign_ssn,
  1081. .validate_data = sctp_validate_data,
  1082. .ulpevent_data = sctp_ulpq_tail_data,
  1083. .enqueue_event = do_ulpq_tail_event,
  1084. .renege_events = sctp_ulpq_renege,
  1085. .start_pd = sctp_ulpq_partial_delivery,
  1086. .abort_pd = sctp_ulpq_abort_pd,
  1087. /* FORWARD-TSN process functions */
  1088. .generate_ftsn = sctp_generate_fwdtsn,
  1089. .validate_ftsn = sctp_validate_fwdtsn,
  1090. .report_ftsn = sctp_report_fwdtsn,
  1091. .handle_ftsn = sctp_handle_fwdtsn,
  1092. };
  1093. static int do_sctp_enqueue_event(struct sctp_ulpq *ulpq,
  1094. struct sctp_ulpevent *event)
  1095. {
  1096. struct sk_buff_head temp;
  1097. skb_queue_head_init(&temp);
  1098. __skb_queue_tail(&temp, sctp_event2skb(event));
  1099. return sctp_enqueue_event(ulpq, &temp);
  1100. }
  1101. static struct sctp_stream_interleave sctp_stream_interleave_1 = {
  1102. .data_chunk_len = sizeof(struct sctp_idata_chunk),
  1103. .ftsn_chunk_len = sizeof(struct sctp_ifwdtsn_chunk),
  1104. /* I-DATA process functions */
  1105. .make_datafrag = sctp_make_idatafrag_empty,
  1106. .assign_number = sctp_chunk_assign_mid,
  1107. .validate_data = sctp_validate_idata,
  1108. .ulpevent_data = sctp_ulpevent_idata,
  1109. .enqueue_event = do_sctp_enqueue_event,
  1110. .renege_events = sctp_renege_events,
  1111. .start_pd = sctp_intl_start_pd,
  1112. .abort_pd = sctp_intl_abort_pd,
  1113. /* I-FORWARD-TSN process functions */
  1114. .generate_ftsn = sctp_generate_iftsn,
  1115. .validate_ftsn = sctp_validate_iftsn,
  1116. .report_ftsn = sctp_report_iftsn,
  1117. .handle_ftsn = sctp_handle_iftsn,
  1118. };
  1119. void sctp_stream_interleave_init(struct sctp_stream *stream)
  1120. {
  1121. struct sctp_association *asoc;
  1122. asoc = container_of(stream, struct sctp_association, stream);
  1123. stream->si = asoc->peer.intl_capable ? &sctp_stream_interleave_1
  1124. : &sctp_stream_interleave_0;
  1125. }