stream_interleave.c 31 KB

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