options.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Multipath TCP
  3. *
  4. * Copyright (c) 2017 - 2019, Intel Corporation.
  5. */
  6. #define pr_fmt(fmt) "MPTCP: " fmt
  7. #include <linux/kernel.h>
  8. #include <crypto/sha2.h>
  9. #include <net/tcp.h>
  10. #include <net/mptcp.h>
  11. #include "protocol.h"
  12. #include "mib.h"
  13. #include <trace/events/mptcp.h>
  14. static bool mptcp_cap_flag_sha256(u8 flags)
  15. {
  16. return (flags & MPTCP_CAP_FLAG_MASK) == MPTCP_CAP_HMAC_SHA256;
  17. }
  18. static void mptcp_parse_option(const struct sk_buff *skb,
  19. const unsigned char *ptr, int opsize,
  20. struct mptcp_options_received *mp_opt)
  21. {
  22. u8 subtype = *ptr >> 4;
  23. int expected_opsize;
  24. u8 version;
  25. u8 flags;
  26. u8 i;
  27. switch (subtype) {
  28. case MPTCPOPT_MP_CAPABLE:
  29. /* strict size checking */
  30. if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) {
  31. if (skb->len > tcp_hdr(skb)->doff << 2)
  32. expected_opsize = TCPOLEN_MPTCP_MPC_ACK_DATA;
  33. else
  34. expected_opsize = TCPOLEN_MPTCP_MPC_ACK;
  35. } else {
  36. if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_ACK)
  37. expected_opsize = TCPOLEN_MPTCP_MPC_SYNACK;
  38. else
  39. expected_opsize = TCPOLEN_MPTCP_MPC_SYN;
  40. }
  41. /* Cfr RFC 8684 Section 3.3.0:
  42. * If a checksum is present but its use had
  43. * not been negotiated in the MP_CAPABLE handshake, the receiver MUST
  44. * close the subflow with a RST, as it is not behaving as negotiated.
  45. * If a checksum is not present when its use has been negotiated, the
  46. * receiver MUST close the subflow with a RST, as it is considered
  47. * broken
  48. * We parse even option with mismatching csum presence, so that
  49. * later in subflow_data_ready we can trigger the reset.
  50. */
  51. if (opsize != expected_opsize &&
  52. (expected_opsize != TCPOLEN_MPTCP_MPC_ACK_DATA ||
  53. opsize != TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM))
  54. break;
  55. /* try to be gentle vs future versions on the initial syn */
  56. version = *ptr++ & MPTCP_VERSION_MASK;
  57. if (opsize != TCPOLEN_MPTCP_MPC_SYN) {
  58. if (version != MPTCP_SUPPORTED_VERSION)
  59. break;
  60. } else if (version < MPTCP_SUPPORTED_VERSION) {
  61. break;
  62. }
  63. flags = *ptr++;
  64. if (!mptcp_cap_flag_sha256(flags) ||
  65. (flags & MPTCP_CAP_EXTENSIBILITY))
  66. break;
  67. /* RFC 6824, Section 3.1:
  68. * "For the Checksum Required bit (labeled "A"), if either
  69. * host requires the use of checksums, checksums MUST be used.
  70. * In other words, the only way for checksums not to be used
  71. * is if both hosts in their SYNs set A=0."
  72. */
  73. if (flags & MPTCP_CAP_CHECKSUM_REQD)
  74. mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
  75. mp_opt->deny_join_id0 = !!(flags & MPTCP_CAP_DENY_JOIN_ID0);
  76. mp_opt->suboptions |= OPTIONS_MPTCP_MPC;
  77. if (opsize >= TCPOLEN_MPTCP_MPC_SYNACK) {
  78. mp_opt->sndr_key = get_unaligned_be64(ptr);
  79. ptr += 8;
  80. }
  81. if (opsize >= TCPOLEN_MPTCP_MPC_ACK) {
  82. mp_opt->rcvr_key = get_unaligned_be64(ptr);
  83. ptr += 8;
  84. }
  85. if (opsize >= TCPOLEN_MPTCP_MPC_ACK_DATA) {
  86. /* Section 3.1.:
  87. * "the data parameters in a MP_CAPABLE are semantically
  88. * equivalent to those in a DSS option and can be used
  89. * interchangeably."
  90. */
  91. mp_opt->suboptions |= OPTION_MPTCP_DSS;
  92. mp_opt->use_map = 1;
  93. mp_opt->mpc_map = 1;
  94. mp_opt->data_len = get_unaligned_be16(ptr);
  95. ptr += 2;
  96. }
  97. if (opsize == TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM) {
  98. mp_opt->csum = get_unaligned((__force __sum16 *)ptr);
  99. mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
  100. ptr += 2;
  101. }
  102. pr_debug("MP_CAPABLE version=%x, flags=%x, optlen=%d sndr=%llu, rcvr=%llu len=%d csum=%u",
  103. version, flags, opsize, mp_opt->sndr_key,
  104. mp_opt->rcvr_key, mp_opt->data_len, mp_opt->csum);
  105. break;
  106. case MPTCPOPT_MP_JOIN:
  107. mp_opt->suboptions |= OPTIONS_MPTCP_MPJ;
  108. if (opsize == TCPOLEN_MPTCP_MPJ_SYN) {
  109. mp_opt->backup = *ptr++ & MPTCPOPT_BACKUP;
  110. mp_opt->join_id = *ptr++;
  111. mp_opt->token = get_unaligned_be32(ptr);
  112. ptr += 4;
  113. mp_opt->nonce = get_unaligned_be32(ptr);
  114. ptr += 4;
  115. pr_debug("MP_JOIN bkup=%u, id=%u, token=%u, nonce=%u",
  116. mp_opt->backup, mp_opt->join_id,
  117. mp_opt->token, mp_opt->nonce);
  118. } else if (opsize == TCPOLEN_MPTCP_MPJ_SYNACK) {
  119. mp_opt->backup = *ptr++ & MPTCPOPT_BACKUP;
  120. mp_opt->join_id = *ptr++;
  121. mp_opt->thmac = get_unaligned_be64(ptr);
  122. ptr += 8;
  123. mp_opt->nonce = get_unaligned_be32(ptr);
  124. ptr += 4;
  125. pr_debug("MP_JOIN bkup=%u, id=%u, thmac=%llu, nonce=%u",
  126. mp_opt->backup, mp_opt->join_id,
  127. mp_opt->thmac, mp_opt->nonce);
  128. } else if (opsize == TCPOLEN_MPTCP_MPJ_ACK) {
  129. ptr += 2;
  130. memcpy(mp_opt->hmac, ptr, MPTCPOPT_HMAC_LEN);
  131. pr_debug("MP_JOIN hmac");
  132. } else {
  133. mp_opt->suboptions &= ~OPTIONS_MPTCP_MPJ;
  134. }
  135. break;
  136. case MPTCPOPT_DSS:
  137. pr_debug("DSS");
  138. ptr++;
  139. /* we must clear 'mpc_map' be able to detect MP_CAPABLE
  140. * map vs DSS map in mptcp_incoming_options(), and reconstruct
  141. * map info accordingly
  142. */
  143. mp_opt->mpc_map = 0;
  144. flags = (*ptr++) & MPTCP_DSS_FLAG_MASK;
  145. mp_opt->data_fin = (flags & MPTCP_DSS_DATA_FIN) != 0;
  146. mp_opt->dsn64 = (flags & MPTCP_DSS_DSN64) != 0;
  147. mp_opt->use_map = (flags & MPTCP_DSS_HAS_MAP) != 0;
  148. mp_opt->ack64 = (flags & MPTCP_DSS_ACK64) != 0;
  149. mp_opt->use_ack = (flags & MPTCP_DSS_HAS_ACK);
  150. pr_debug("data_fin=%d dsn64=%d use_map=%d ack64=%d use_ack=%d",
  151. mp_opt->data_fin, mp_opt->dsn64,
  152. mp_opt->use_map, mp_opt->ack64,
  153. mp_opt->use_ack);
  154. expected_opsize = TCPOLEN_MPTCP_DSS_BASE;
  155. if (mp_opt->use_ack) {
  156. if (mp_opt->ack64)
  157. expected_opsize += TCPOLEN_MPTCP_DSS_ACK64;
  158. else
  159. expected_opsize += TCPOLEN_MPTCP_DSS_ACK32;
  160. }
  161. if (mp_opt->use_map) {
  162. if (mp_opt->dsn64)
  163. expected_opsize += TCPOLEN_MPTCP_DSS_MAP64;
  164. else
  165. expected_opsize += TCPOLEN_MPTCP_DSS_MAP32;
  166. }
  167. /* Always parse any csum presence combination, we will enforce
  168. * RFC 8684 Section 3.3.0 checks later in subflow_data_ready
  169. */
  170. if (opsize != expected_opsize &&
  171. opsize != expected_opsize + TCPOLEN_MPTCP_DSS_CHECKSUM)
  172. break;
  173. mp_opt->suboptions |= OPTION_MPTCP_DSS;
  174. if (mp_opt->use_ack) {
  175. if (mp_opt->ack64) {
  176. mp_opt->data_ack = get_unaligned_be64(ptr);
  177. ptr += 8;
  178. } else {
  179. mp_opt->data_ack = get_unaligned_be32(ptr);
  180. ptr += 4;
  181. }
  182. pr_debug("data_ack=%llu", mp_opt->data_ack);
  183. }
  184. if (mp_opt->use_map) {
  185. if (mp_opt->dsn64) {
  186. mp_opt->data_seq = get_unaligned_be64(ptr);
  187. ptr += 8;
  188. } else {
  189. mp_opt->data_seq = get_unaligned_be32(ptr);
  190. ptr += 4;
  191. }
  192. mp_opt->subflow_seq = get_unaligned_be32(ptr);
  193. ptr += 4;
  194. mp_opt->data_len = get_unaligned_be16(ptr);
  195. ptr += 2;
  196. if (opsize == expected_opsize + TCPOLEN_MPTCP_DSS_CHECKSUM) {
  197. mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
  198. mp_opt->csum = get_unaligned((__force __sum16 *)ptr);
  199. ptr += 2;
  200. }
  201. pr_debug("data_seq=%llu subflow_seq=%u data_len=%u csum=%d:%u",
  202. mp_opt->data_seq, mp_opt->subflow_seq,
  203. mp_opt->data_len, !!(mp_opt->suboptions & OPTION_MPTCP_CSUMREQD),
  204. mp_opt->csum);
  205. }
  206. break;
  207. case MPTCPOPT_ADD_ADDR:
  208. mp_opt->echo = (*ptr++) & MPTCP_ADDR_ECHO;
  209. if (!mp_opt->echo) {
  210. if (opsize == TCPOLEN_MPTCP_ADD_ADDR ||
  211. opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT)
  212. mp_opt->addr.family = AF_INET;
  213. #if IS_ENABLED(CONFIG_MPTCP_IPV6)
  214. else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6 ||
  215. opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT)
  216. mp_opt->addr.family = AF_INET6;
  217. #endif
  218. else
  219. break;
  220. } else {
  221. if (opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE ||
  222. opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT)
  223. mp_opt->addr.family = AF_INET;
  224. #if IS_ENABLED(CONFIG_MPTCP_IPV6)
  225. else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE ||
  226. opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT)
  227. mp_opt->addr.family = AF_INET6;
  228. #endif
  229. else
  230. break;
  231. }
  232. mp_opt->suboptions |= OPTION_MPTCP_ADD_ADDR;
  233. mp_opt->addr.id = *ptr++;
  234. mp_opt->addr.port = 0;
  235. mp_opt->ahmac = 0;
  236. if (mp_opt->addr.family == AF_INET) {
  237. memcpy((u8 *)&mp_opt->addr.addr.s_addr, (u8 *)ptr, 4);
  238. ptr += 4;
  239. if (opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT ||
  240. opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT) {
  241. mp_opt->addr.port = htons(get_unaligned_be16(ptr));
  242. ptr += 2;
  243. }
  244. }
  245. #if IS_ENABLED(CONFIG_MPTCP_IPV6)
  246. else {
  247. memcpy(mp_opt->addr.addr6.s6_addr, (u8 *)ptr, 16);
  248. ptr += 16;
  249. if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT ||
  250. opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT) {
  251. mp_opt->addr.port = htons(get_unaligned_be16(ptr));
  252. ptr += 2;
  253. }
  254. }
  255. #endif
  256. if (!mp_opt->echo) {
  257. mp_opt->ahmac = get_unaligned_be64(ptr);
  258. ptr += 8;
  259. }
  260. pr_debug("ADD_ADDR%s: id=%d, ahmac=%llu, echo=%d, port=%d",
  261. (mp_opt->addr.family == AF_INET6) ? "6" : "",
  262. mp_opt->addr.id, mp_opt->ahmac, mp_opt->echo, ntohs(mp_opt->addr.port));
  263. break;
  264. case MPTCPOPT_RM_ADDR:
  265. if (opsize < TCPOLEN_MPTCP_RM_ADDR_BASE + 1 ||
  266. opsize > TCPOLEN_MPTCP_RM_ADDR_BASE + MPTCP_RM_IDS_MAX)
  267. break;
  268. ptr++;
  269. mp_opt->suboptions |= OPTION_MPTCP_RM_ADDR;
  270. mp_opt->rm_list.nr = opsize - TCPOLEN_MPTCP_RM_ADDR_BASE;
  271. for (i = 0; i < mp_opt->rm_list.nr; i++)
  272. mp_opt->rm_list.ids[i] = *ptr++;
  273. pr_debug("RM_ADDR: rm_list_nr=%d", mp_opt->rm_list.nr);
  274. break;
  275. case MPTCPOPT_MP_PRIO:
  276. if (opsize != TCPOLEN_MPTCP_PRIO)
  277. break;
  278. mp_opt->suboptions |= OPTION_MPTCP_PRIO;
  279. mp_opt->backup = *ptr++ & MPTCP_PRIO_BKUP;
  280. pr_debug("MP_PRIO: prio=%d", mp_opt->backup);
  281. break;
  282. case MPTCPOPT_MP_FASTCLOSE:
  283. if (opsize != TCPOLEN_MPTCP_FASTCLOSE)
  284. break;
  285. ptr += 2;
  286. mp_opt->rcvr_key = get_unaligned_be64(ptr);
  287. ptr += 8;
  288. mp_opt->suboptions |= OPTION_MPTCP_FASTCLOSE;
  289. pr_debug("MP_FASTCLOSE: recv_key=%llu", mp_opt->rcvr_key);
  290. break;
  291. case MPTCPOPT_RST:
  292. if (opsize != TCPOLEN_MPTCP_RST)
  293. break;
  294. if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_RST))
  295. break;
  296. mp_opt->suboptions |= OPTION_MPTCP_RST;
  297. flags = *ptr++;
  298. mp_opt->reset_transient = flags & MPTCP_RST_TRANSIENT;
  299. mp_opt->reset_reason = *ptr;
  300. pr_debug("MP_RST: transient=%u reason=%u",
  301. mp_opt->reset_transient, mp_opt->reset_reason);
  302. break;
  303. case MPTCPOPT_MP_FAIL:
  304. if (opsize != TCPOLEN_MPTCP_FAIL)
  305. break;
  306. ptr += 2;
  307. mp_opt->suboptions |= OPTION_MPTCP_FAIL;
  308. mp_opt->fail_seq = get_unaligned_be64(ptr);
  309. pr_debug("MP_FAIL: data_seq=%llu", mp_opt->fail_seq);
  310. break;
  311. default:
  312. break;
  313. }
  314. }
  315. void mptcp_get_options(const struct sk_buff *skb,
  316. struct mptcp_options_received *mp_opt)
  317. {
  318. const struct tcphdr *th = tcp_hdr(skb);
  319. const unsigned char *ptr;
  320. int length;
  321. /* initialize option status */
  322. mp_opt->suboptions = 0;
  323. length = (th->doff * 4) - sizeof(struct tcphdr);
  324. ptr = (const unsigned char *)(th + 1);
  325. while (length > 0) {
  326. int opcode = *ptr++;
  327. int opsize;
  328. switch (opcode) {
  329. case TCPOPT_EOL:
  330. return;
  331. case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
  332. length--;
  333. continue;
  334. default:
  335. if (length < 2)
  336. return;
  337. opsize = *ptr++;
  338. if (opsize < 2) /* "silly options" */
  339. return;
  340. if (opsize > length)
  341. return; /* don't parse partial options */
  342. if (opcode == TCPOPT_MPTCP)
  343. mptcp_parse_option(skb, ptr, opsize, mp_opt);
  344. ptr += opsize - 2;
  345. length -= opsize;
  346. }
  347. }
  348. }
  349. bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
  350. unsigned int *size, struct mptcp_out_options *opts)
  351. {
  352. struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
  353. /* we will use snd_isn to detect first pkt [re]transmission
  354. * in mptcp_established_options_mp()
  355. */
  356. subflow->snd_isn = TCP_SKB_CB(skb)->end_seq;
  357. if (subflow->request_mptcp) {
  358. opts->suboptions = OPTION_MPTCP_MPC_SYN;
  359. opts->csum_reqd = mptcp_is_checksum_enabled(sock_net(sk));
  360. opts->allow_join_id0 = mptcp_allow_join_id0(sock_net(sk));
  361. *size = TCPOLEN_MPTCP_MPC_SYN;
  362. return true;
  363. } else if (subflow->request_join) {
  364. pr_debug("remote_token=%u, nonce=%u", subflow->remote_token,
  365. subflow->local_nonce);
  366. opts->suboptions = OPTION_MPTCP_MPJ_SYN;
  367. opts->join_id = subflow->local_id;
  368. opts->token = subflow->remote_token;
  369. opts->nonce = subflow->local_nonce;
  370. opts->backup = subflow->request_bkup;
  371. *size = TCPOLEN_MPTCP_MPJ_SYN;
  372. return true;
  373. }
  374. return false;
  375. }
  376. static void clear_3rdack_retransmission(struct sock *sk)
  377. {
  378. struct inet_connection_sock *icsk = inet_csk(sk);
  379. sk_stop_timer(sk, &icsk->icsk_delack_timer);
  380. icsk->icsk_ack.timeout = 0;
  381. icsk->icsk_ack.ato = 0;
  382. icsk->icsk_ack.pending &= ~(ICSK_ACK_SCHED | ICSK_ACK_TIMER);
  383. }
  384. static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
  385. bool snd_data_fin_enable,
  386. unsigned int *size,
  387. unsigned int remaining,
  388. struct mptcp_out_options *opts)
  389. {
  390. struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
  391. struct mptcp_sock *msk = mptcp_sk(subflow->conn);
  392. struct mptcp_ext *mpext;
  393. unsigned int data_len;
  394. u8 len;
  395. /* When skb is not available, we better over-estimate the emitted
  396. * options len. A full DSS option (28 bytes) is longer than
  397. * TCPOLEN_MPTCP_MPC_ACK_DATA(22) or TCPOLEN_MPTCP_MPJ_ACK(24), so
  398. * tell the caller to defer the estimate to
  399. * mptcp_established_options_dss(), which will reserve enough space.
  400. */
  401. if (!skb)
  402. return false;
  403. /* MPC/MPJ needed only on 3rd ack packet, DATA_FIN and TCP shutdown take precedence */
  404. if (subflow->fully_established || snd_data_fin_enable ||
  405. subflow->snd_isn != TCP_SKB_CB(skb)->seq ||
  406. sk->sk_state != TCP_ESTABLISHED)
  407. return false;
  408. if (subflow->mp_capable) {
  409. mpext = mptcp_get_ext(skb);
  410. data_len = mpext ? mpext->data_len : 0;
  411. /* we will check ops->data_len in mptcp_write_options() to
  412. * discriminate between TCPOLEN_MPTCP_MPC_ACK_DATA and
  413. * TCPOLEN_MPTCP_MPC_ACK
  414. */
  415. opts->data_len = data_len;
  416. opts->suboptions = OPTION_MPTCP_MPC_ACK;
  417. opts->sndr_key = subflow->local_key;
  418. opts->rcvr_key = subflow->remote_key;
  419. opts->csum_reqd = READ_ONCE(msk->csum_enabled);
  420. opts->allow_join_id0 = mptcp_allow_join_id0(sock_net(sk));
  421. /* Section 3.1.
  422. * The MP_CAPABLE option is carried on the SYN, SYN/ACK, and ACK
  423. * packets that start the first subflow of an MPTCP connection,
  424. * as well as the first packet that carries data
  425. */
  426. if (data_len > 0) {
  427. len = TCPOLEN_MPTCP_MPC_ACK_DATA;
  428. if (opts->csum_reqd) {
  429. /* we need to propagate more info to csum the pseudo hdr */
  430. opts->data_seq = mpext->data_seq;
  431. opts->subflow_seq = mpext->subflow_seq;
  432. opts->csum = mpext->csum;
  433. len += TCPOLEN_MPTCP_DSS_CHECKSUM;
  434. }
  435. *size = ALIGN(len, 4);
  436. } else {
  437. *size = TCPOLEN_MPTCP_MPC_ACK;
  438. }
  439. pr_debug("subflow=%p, local_key=%llu, remote_key=%llu map_len=%d",
  440. subflow, subflow->local_key, subflow->remote_key,
  441. data_len);
  442. return true;
  443. } else if (subflow->mp_join) {
  444. opts->suboptions = OPTION_MPTCP_MPJ_ACK;
  445. memcpy(opts->hmac, subflow->hmac, MPTCPOPT_HMAC_LEN);
  446. *size = TCPOLEN_MPTCP_MPJ_ACK;
  447. pr_debug("subflow=%p", subflow);
  448. /* we can use the full delegate action helper only from BH context
  449. * If we are in process context - sk is flushing the backlog at
  450. * socket lock release time - just set the appropriate flag, will
  451. * be handled by the release callback
  452. */
  453. if (sock_owned_by_user(sk))
  454. set_bit(MPTCP_DELEGATE_ACK, &subflow->delegated_status);
  455. else
  456. mptcp_subflow_delegate(subflow, MPTCP_DELEGATE_ACK);
  457. return true;
  458. }
  459. return false;
  460. }
  461. static void mptcp_write_data_fin(struct mptcp_subflow_context *subflow,
  462. struct sk_buff *skb, struct mptcp_ext *ext)
  463. {
  464. /* The write_seq value has already been incremented, so the actual
  465. * sequence number for the DATA_FIN is one less.
  466. */
  467. u64 data_fin_tx_seq = READ_ONCE(mptcp_sk(subflow->conn)->write_seq) - 1;
  468. if (!ext->use_map || !skb->len) {
  469. /* RFC6824 requires a DSS mapping with specific values
  470. * if DATA_FIN is set but no data payload is mapped
  471. */
  472. ext->data_fin = 1;
  473. ext->use_map = 1;
  474. ext->dsn64 = 1;
  475. ext->data_seq = data_fin_tx_seq;
  476. ext->subflow_seq = 0;
  477. ext->data_len = 1;
  478. } else if (ext->data_seq + ext->data_len == data_fin_tx_seq) {
  479. /* If there's an existing DSS mapping and it is the
  480. * final mapping, DATA_FIN consumes 1 additional byte of
  481. * mapping space.
  482. */
  483. ext->data_fin = 1;
  484. ext->data_len++;
  485. }
  486. }
  487. static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
  488. bool snd_data_fin_enable,
  489. unsigned int *size,
  490. unsigned int remaining,
  491. struct mptcp_out_options *opts)
  492. {
  493. struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
  494. struct mptcp_sock *msk = mptcp_sk(subflow->conn);
  495. unsigned int dss_size = 0;
  496. struct mptcp_ext *mpext;
  497. unsigned int ack_size;
  498. bool ret = false;
  499. u64 ack_seq;
  500. opts->csum_reqd = READ_ONCE(msk->csum_enabled);
  501. mpext = skb ? mptcp_get_ext(skb) : NULL;
  502. if (!skb || (mpext && mpext->use_map) || snd_data_fin_enable) {
  503. unsigned int map_size = TCPOLEN_MPTCP_DSS_BASE + TCPOLEN_MPTCP_DSS_MAP64;
  504. if (mpext) {
  505. if (opts->csum_reqd)
  506. map_size += TCPOLEN_MPTCP_DSS_CHECKSUM;
  507. opts->ext_copy = *mpext;
  508. }
  509. remaining -= map_size;
  510. dss_size = map_size;
  511. if (skb && snd_data_fin_enable)
  512. mptcp_write_data_fin(subflow, skb, &opts->ext_copy);
  513. opts->suboptions = OPTION_MPTCP_DSS;
  514. ret = true;
  515. }
  516. /* passive sockets msk will set the 'can_ack' after accept(), even
  517. * if the first subflow may have the already the remote key handy
  518. */
  519. opts->ext_copy.use_ack = 0;
  520. if (!READ_ONCE(msk->can_ack)) {
  521. *size = ALIGN(dss_size, 4);
  522. return ret;
  523. }
  524. ack_seq = READ_ONCE(msk->ack_seq);
  525. if (READ_ONCE(msk->use_64bit_ack)) {
  526. ack_size = TCPOLEN_MPTCP_DSS_ACK64;
  527. opts->ext_copy.data_ack = ack_seq;
  528. opts->ext_copy.ack64 = 1;
  529. } else {
  530. ack_size = TCPOLEN_MPTCP_DSS_ACK32;
  531. opts->ext_copy.data_ack32 = (uint32_t)ack_seq;
  532. opts->ext_copy.ack64 = 0;
  533. }
  534. opts->ext_copy.use_ack = 1;
  535. opts->suboptions = OPTION_MPTCP_DSS;
  536. WRITE_ONCE(msk->old_wspace, __mptcp_space((struct sock *)msk));
  537. /* Add kind/length/subtype/flag overhead if mapping is not populated */
  538. if (dss_size == 0)
  539. ack_size += TCPOLEN_MPTCP_DSS_BASE;
  540. dss_size += ack_size;
  541. *size = ALIGN(dss_size, 4);
  542. return true;
  543. }
  544. static u64 add_addr_generate_hmac(u64 key1, u64 key2,
  545. struct mptcp_addr_info *addr)
  546. {
  547. u16 port = ntohs(addr->port);
  548. u8 hmac[SHA256_DIGEST_SIZE];
  549. u8 msg[19];
  550. int i = 0;
  551. msg[i++] = addr->id;
  552. if (addr->family == AF_INET) {
  553. memcpy(&msg[i], &addr->addr.s_addr, 4);
  554. i += 4;
  555. }
  556. #if IS_ENABLED(CONFIG_MPTCP_IPV6)
  557. else if (addr->family == AF_INET6) {
  558. memcpy(&msg[i], &addr->addr6.s6_addr, 16);
  559. i += 16;
  560. }
  561. #endif
  562. msg[i++] = port >> 8;
  563. msg[i++] = port & 0xFF;
  564. mptcp_crypto_hmac_sha(key1, key2, msg, i, hmac);
  565. return get_unaligned_be64(&hmac[SHA256_DIGEST_SIZE - sizeof(u64)]);
  566. }
  567. static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *skb,
  568. unsigned int *size,
  569. unsigned int remaining,
  570. struct mptcp_out_options *opts)
  571. {
  572. struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
  573. struct mptcp_sock *msk = mptcp_sk(subflow->conn);
  574. bool drop_other_suboptions = false;
  575. unsigned int opt_size = *size;
  576. bool echo;
  577. int len;
  578. /* add addr will strip the existing options, be sure to avoid breaking
  579. * MPC/MPJ handshakes
  580. */
  581. if (!mptcp_pm_should_add_signal(msk) ||
  582. (opts->suboptions & (OPTION_MPTCP_MPJ_ACK | OPTION_MPTCP_MPC_ACK)) ||
  583. !mptcp_pm_add_addr_signal(msk, skb, opt_size, remaining, &opts->addr,
  584. &echo, &drop_other_suboptions))
  585. return false;
  586. if (drop_other_suboptions)
  587. remaining += opt_size;
  588. len = mptcp_add_addr_len(opts->addr.family, echo, !!opts->addr.port);
  589. if (remaining < len)
  590. return false;
  591. *size = len;
  592. if (drop_other_suboptions) {
  593. pr_debug("drop other suboptions");
  594. opts->suboptions = 0;
  595. /* note that e.g. DSS could have written into the memory
  596. * aliased by ahmac, we must reset the field here
  597. * to avoid appending the hmac even for ADD_ADDR echo
  598. * options
  599. */
  600. opts->ahmac = 0;
  601. *size -= opt_size;
  602. }
  603. opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
  604. if (!echo) {
  605. opts->ahmac = add_addr_generate_hmac(msk->local_key,
  606. msk->remote_key,
  607. &opts->addr);
  608. }
  609. pr_debug("addr_id=%d, ahmac=%llu, echo=%d, port=%d",
  610. opts->addr.id, opts->ahmac, echo, ntohs(opts->addr.port));
  611. return true;
  612. }
  613. static bool mptcp_established_options_rm_addr(struct sock *sk,
  614. unsigned int *size,
  615. unsigned int remaining,
  616. struct mptcp_out_options *opts)
  617. {
  618. struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
  619. struct mptcp_sock *msk = mptcp_sk(subflow->conn);
  620. struct mptcp_rm_list rm_list;
  621. int i, len;
  622. if (!mptcp_pm_should_rm_signal(msk) ||
  623. !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list)))
  624. return false;
  625. len = mptcp_rm_addr_len(&rm_list);
  626. if (len < 0)
  627. return false;
  628. if (remaining < len)
  629. return false;
  630. *size = len;
  631. opts->suboptions |= OPTION_MPTCP_RM_ADDR;
  632. opts->rm_list = rm_list;
  633. for (i = 0; i < opts->rm_list.nr; i++)
  634. pr_debug("rm_list_ids[%d]=%d", i, opts->rm_list.ids[i]);
  635. return true;
  636. }
  637. static bool mptcp_established_options_mp_prio(struct sock *sk,
  638. unsigned int *size,
  639. unsigned int remaining,
  640. struct mptcp_out_options *opts)
  641. {
  642. struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
  643. /* can't send MP_PRIO with MPC, as they share the same option space:
  644. * 'backup'. Also it makes no sense at all
  645. */
  646. if (!subflow->send_mp_prio || (opts->suboptions & OPTIONS_MPTCP_MPC))
  647. return false;
  648. /* account for the trailing 'nop' option */
  649. if (remaining < TCPOLEN_MPTCP_PRIO_ALIGN)
  650. return false;
  651. *size = TCPOLEN_MPTCP_PRIO_ALIGN;
  652. opts->suboptions |= OPTION_MPTCP_PRIO;
  653. opts->backup = subflow->request_bkup;
  654. pr_debug("prio=%d", opts->backup);
  655. return true;
  656. }
  657. static noinline bool mptcp_established_options_rst(struct sock *sk, struct sk_buff *skb,
  658. unsigned int *size,
  659. unsigned int remaining,
  660. struct mptcp_out_options *opts)
  661. {
  662. const struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
  663. if (remaining < TCPOLEN_MPTCP_RST)
  664. return false;
  665. *size = TCPOLEN_MPTCP_RST;
  666. opts->suboptions |= OPTION_MPTCP_RST;
  667. opts->reset_transient = subflow->reset_transient;
  668. opts->reset_reason = subflow->reset_reason;
  669. MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPRSTTX);
  670. return true;
  671. }
  672. static bool mptcp_established_options_fastclose(struct sock *sk,
  673. unsigned int *size,
  674. unsigned int remaining,
  675. struct mptcp_out_options *opts)
  676. {
  677. struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
  678. struct mptcp_sock *msk = mptcp_sk(subflow->conn);
  679. if (likely(!subflow->send_fastclose))
  680. return false;
  681. if (remaining < TCPOLEN_MPTCP_FASTCLOSE)
  682. return false;
  683. *size = TCPOLEN_MPTCP_FASTCLOSE;
  684. opts->suboptions |= OPTION_MPTCP_FASTCLOSE;
  685. opts->rcvr_key = msk->remote_key;
  686. pr_debug("FASTCLOSE key=%llu", opts->rcvr_key);
  687. MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSETX);
  688. return true;
  689. }
  690. static bool mptcp_established_options_mp_fail(struct sock *sk,
  691. unsigned int *size,
  692. unsigned int remaining,
  693. struct mptcp_out_options *opts)
  694. {
  695. struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
  696. if (likely(!subflow->send_mp_fail))
  697. return false;
  698. if (remaining < TCPOLEN_MPTCP_FAIL)
  699. return false;
  700. *size = TCPOLEN_MPTCP_FAIL;
  701. opts->suboptions |= OPTION_MPTCP_FAIL;
  702. opts->fail_seq = subflow->map_seq;
  703. pr_debug("MP_FAIL fail_seq=%llu", opts->fail_seq);
  704. MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFAILTX);
  705. return true;
  706. }
  707. bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
  708. unsigned int *size, unsigned int remaining,
  709. struct mptcp_out_options *opts)
  710. {
  711. struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
  712. struct mptcp_sock *msk = mptcp_sk(subflow->conn);
  713. unsigned int opt_size = 0;
  714. bool snd_data_fin;
  715. bool ret = false;
  716. opts->suboptions = 0;
  717. if (unlikely(__mptcp_check_fallback(msk) && !mptcp_check_infinite_map(skb)))
  718. return false;
  719. if (unlikely(skb && TCP_SKB_CB(skb)->tcp_flags & TCPHDR_RST)) {
  720. if (mptcp_established_options_fastclose(sk, &opt_size, remaining, opts) ||
  721. mptcp_established_options_mp_fail(sk, &opt_size, remaining, opts)) {
  722. *size += opt_size;
  723. remaining -= opt_size;
  724. }
  725. /* MP_RST can be used with MP_FASTCLOSE and MP_FAIL if there is room */
  726. if (mptcp_established_options_rst(sk, skb, &opt_size, remaining, opts)) {
  727. *size += opt_size;
  728. remaining -= opt_size;
  729. }
  730. return true;
  731. }
  732. snd_data_fin = mptcp_data_fin_enabled(msk);
  733. if (mptcp_established_options_mp(sk, skb, snd_data_fin, &opt_size, remaining, opts))
  734. ret = true;
  735. else if (mptcp_established_options_dss(sk, skb, snd_data_fin, &opt_size, remaining, opts)) {
  736. unsigned int mp_fail_size;
  737. ret = true;
  738. if (mptcp_established_options_mp_fail(sk, &mp_fail_size,
  739. remaining - opt_size, opts)) {
  740. *size += opt_size + mp_fail_size;
  741. remaining -= opt_size - mp_fail_size;
  742. return true;
  743. }
  744. }
  745. /* we reserved enough space for the above options, and exceeding the
  746. * TCP option space would be fatal
  747. */
  748. if (WARN_ON_ONCE(opt_size > remaining))
  749. return false;
  750. *size += opt_size;
  751. remaining -= opt_size;
  752. if (mptcp_established_options_add_addr(sk, skb, &opt_size, remaining, opts)) {
  753. *size += opt_size;
  754. remaining -= opt_size;
  755. ret = true;
  756. } else if (mptcp_established_options_rm_addr(sk, &opt_size, remaining, opts)) {
  757. *size += opt_size;
  758. remaining -= opt_size;
  759. ret = true;
  760. }
  761. if (mptcp_established_options_mp_prio(sk, &opt_size, remaining, opts)) {
  762. *size += opt_size;
  763. remaining -= opt_size;
  764. ret = true;
  765. }
  766. return ret;
  767. }
  768. bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
  769. struct mptcp_out_options *opts)
  770. {
  771. struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
  772. if (subflow_req->mp_capable) {
  773. opts->suboptions = OPTION_MPTCP_MPC_SYNACK;
  774. opts->sndr_key = subflow_req->local_key;
  775. opts->csum_reqd = subflow_req->csum_reqd;
  776. opts->allow_join_id0 = subflow_req->allow_join_id0;
  777. *size = TCPOLEN_MPTCP_MPC_SYNACK;
  778. pr_debug("subflow_req=%p, local_key=%llu",
  779. subflow_req, subflow_req->local_key);
  780. return true;
  781. } else if (subflow_req->mp_join) {
  782. opts->suboptions = OPTION_MPTCP_MPJ_SYNACK;
  783. opts->backup = subflow_req->backup;
  784. opts->join_id = subflow_req->local_id;
  785. opts->thmac = subflow_req->thmac;
  786. opts->nonce = subflow_req->local_nonce;
  787. pr_debug("req=%p, bkup=%u, id=%u, thmac=%llu, nonce=%u",
  788. subflow_req, opts->backup, opts->join_id,
  789. opts->thmac, opts->nonce);
  790. *size = TCPOLEN_MPTCP_MPJ_SYNACK;
  791. return true;
  792. }
  793. return false;
  794. }
  795. static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
  796. struct mptcp_subflow_context *subflow,
  797. struct sk_buff *skb,
  798. struct mptcp_options_received *mp_opt)
  799. {
  800. /* here we can process OoO, in-window pkts, only in-sequence 4th ack
  801. * will make the subflow fully established
  802. */
  803. if (likely(subflow->fully_established)) {
  804. /* on passive sockets, check for 3rd ack retransmission
  805. * note that msk is always set by subflow_syn_recv_sock()
  806. * for mp_join subflows
  807. */
  808. if (TCP_SKB_CB(skb)->seq == subflow->ssn_offset + 1 &&
  809. TCP_SKB_CB(skb)->end_seq == TCP_SKB_CB(skb)->seq &&
  810. subflow->mp_join && (mp_opt->suboptions & OPTIONS_MPTCP_MPJ) &&
  811. !subflow->request_join)
  812. tcp_send_ack(ssk);
  813. goto fully_established;
  814. }
  815. /* we must process OoO packets before the first subflow is fully
  816. * established. OoO packets are instead a protocol violation
  817. * for MP_JOIN subflows as the peer must not send any data
  818. * before receiving the forth ack - cfr. RFC 8684 section 3.2.
  819. */
  820. if (TCP_SKB_CB(skb)->seq != subflow->ssn_offset + 1) {
  821. if (subflow->mp_join)
  822. goto reset;
  823. return subflow->mp_capable;
  824. }
  825. if (((mp_opt->suboptions & OPTION_MPTCP_DSS) && mp_opt->use_ack) ||
  826. ((mp_opt->suboptions & OPTION_MPTCP_ADD_ADDR) && !mp_opt->echo)) {
  827. /* subflows are fully established as soon as we get any
  828. * additional ack, including ADD_ADDR.
  829. */
  830. subflow->fully_established = 1;
  831. WRITE_ONCE(msk->fully_established, true);
  832. goto fully_established;
  833. }
  834. /* If the first established packet does not contain MP_CAPABLE + data
  835. * then fallback to TCP. Fallback scenarios requires a reset for
  836. * MP_JOIN subflows.
  837. */
  838. if (!(mp_opt->suboptions & OPTIONS_MPTCP_MPC)) {
  839. if (subflow->mp_join)
  840. goto reset;
  841. subflow->mp_capable = 0;
  842. pr_fallback(msk);
  843. mptcp_do_fallback(ssk);
  844. return false;
  845. }
  846. if (mp_opt->deny_join_id0)
  847. WRITE_ONCE(msk->pm.remote_deny_join_id0, true);
  848. if (unlikely(!READ_ONCE(msk->pm.server_side)))
  849. pr_warn_once("bogus mpc option on established client sk");
  850. mptcp_subflow_fully_established(subflow, mp_opt);
  851. fully_established:
  852. /* if the subflow is not already linked into the conn_list, we can't
  853. * notify the PM: this subflow is still on the listener queue
  854. * and the PM possibly acquiring the subflow lock could race with
  855. * the listener close
  856. */
  857. if (likely(subflow->pm_notified) || list_empty(&subflow->node))
  858. return true;
  859. subflow->pm_notified = 1;
  860. if (subflow->mp_join) {
  861. clear_3rdack_retransmission(ssk);
  862. mptcp_pm_subflow_established(msk);
  863. } else {
  864. mptcp_pm_fully_established(msk, ssk, GFP_ATOMIC);
  865. }
  866. return true;
  867. reset:
  868. mptcp_subflow_reset(ssk);
  869. return false;
  870. }
  871. u64 __mptcp_expand_seq(u64 old_seq, u64 cur_seq)
  872. {
  873. u32 old_seq32, cur_seq32;
  874. old_seq32 = (u32)old_seq;
  875. cur_seq32 = (u32)cur_seq;
  876. cur_seq = (old_seq & GENMASK_ULL(63, 32)) + cur_seq32;
  877. if (unlikely(cur_seq32 < old_seq32 && before(old_seq32, cur_seq32)))
  878. return cur_seq + (1LL << 32);
  879. /* reverse wrap could happen, too */
  880. if (unlikely(cur_seq32 > old_seq32 && after(old_seq32, cur_seq32)))
  881. return cur_seq - (1LL << 32);
  882. return cur_seq;
  883. }
  884. static void ack_update_msk(struct mptcp_sock *msk,
  885. struct sock *ssk,
  886. struct mptcp_options_received *mp_opt)
  887. {
  888. u64 new_wnd_end, new_snd_una, snd_nxt = READ_ONCE(msk->snd_nxt);
  889. struct sock *sk = (struct sock *)msk;
  890. u64 old_snd_una;
  891. mptcp_data_lock(sk);
  892. /* avoid ack expansion on update conflict, to reduce the risk of
  893. * wrongly expanding to a future ack sequence number, which is way
  894. * more dangerous than missing an ack
  895. */
  896. old_snd_una = msk->snd_una;
  897. new_snd_una = mptcp_expand_seq(old_snd_una, mp_opt->data_ack, mp_opt->ack64);
  898. /* ACK for data not even sent yet? Ignore.*/
  899. if (unlikely(after64(new_snd_una, snd_nxt)))
  900. new_snd_una = old_snd_una;
  901. new_wnd_end = new_snd_una + tcp_sk(ssk)->snd_wnd;
  902. if (after64(new_wnd_end, msk->wnd_end))
  903. msk->wnd_end = new_wnd_end;
  904. /* this assumes mptcp_incoming_options() is invoked after tcp_ack() */
  905. if (after64(msk->wnd_end, READ_ONCE(msk->snd_nxt)))
  906. __mptcp_check_push(sk, ssk);
  907. if (after64(new_snd_una, old_snd_una)) {
  908. msk->snd_una = new_snd_una;
  909. __mptcp_data_acked(sk);
  910. }
  911. mptcp_data_unlock(sk);
  912. trace_ack_update_msk(mp_opt->data_ack,
  913. old_snd_una, new_snd_una,
  914. new_wnd_end, msk->wnd_end);
  915. }
  916. bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit)
  917. {
  918. /* Skip if DATA_FIN was already received.
  919. * If updating simultaneously with the recvmsg loop, values
  920. * should match. If they mismatch, the peer is misbehaving and
  921. * we will prefer the most recent information.
  922. */
  923. if (READ_ONCE(msk->rcv_data_fin))
  924. return false;
  925. WRITE_ONCE(msk->rcv_data_fin_seq,
  926. mptcp_expand_seq(READ_ONCE(msk->ack_seq), data_fin_seq, use_64bit));
  927. WRITE_ONCE(msk->rcv_data_fin, 1);
  928. return true;
  929. }
  930. static bool add_addr_hmac_valid(struct mptcp_sock *msk,
  931. struct mptcp_options_received *mp_opt)
  932. {
  933. u64 hmac = 0;
  934. if (mp_opt->echo)
  935. return true;
  936. hmac = add_addr_generate_hmac(msk->remote_key,
  937. msk->local_key,
  938. &mp_opt->addr);
  939. pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n",
  940. msk, hmac, mp_opt->ahmac);
  941. return hmac == mp_opt->ahmac;
  942. }
  943. /* Return false if a subflow has been reset, else return true */
  944. bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
  945. {
  946. struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
  947. struct mptcp_sock *msk = mptcp_sk(subflow->conn);
  948. struct mptcp_options_received mp_opt;
  949. struct mptcp_ext *mpext;
  950. if (__mptcp_check_fallback(msk)) {
  951. /* Keep it simple and unconditionally trigger send data cleanup and
  952. * pending queue spooling. We will need to acquire the data lock
  953. * for more accurate checks, and once the lock is acquired, such
  954. * helpers are cheap.
  955. */
  956. mptcp_data_lock(subflow->conn);
  957. if (sk_stream_memory_free(sk))
  958. __mptcp_check_push(subflow->conn, sk);
  959. __mptcp_data_acked(subflow->conn);
  960. mptcp_data_unlock(subflow->conn);
  961. return true;
  962. }
  963. mptcp_get_options(skb, &mp_opt);
  964. /* The subflow can be in close state only if check_fully_established()
  965. * just sent a reset. If so, tell the caller to ignore the current packet.
  966. */
  967. if (!check_fully_established(msk, sk, subflow, skb, &mp_opt))
  968. return sk->sk_state != TCP_CLOSE;
  969. if (unlikely(mp_opt.suboptions != OPTION_MPTCP_DSS)) {
  970. if ((mp_opt.suboptions & OPTION_MPTCP_FASTCLOSE) &&
  971. msk->local_key == mp_opt.rcvr_key) {
  972. WRITE_ONCE(msk->rcv_fastclose, true);
  973. mptcp_schedule_work((struct sock *)msk);
  974. MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSERX);
  975. }
  976. if ((mp_opt.suboptions & OPTION_MPTCP_ADD_ADDR) &&
  977. add_addr_hmac_valid(msk, &mp_opt)) {
  978. if (!mp_opt.echo) {
  979. mptcp_pm_add_addr_received(sk, &mp_opt.addr);
  980. MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDR);
  981. } else {
  982. mptcp_pm_add_addr_echoed(msk, &mp_opt.addr);
  983. mptcp_pm_del_add_timer(msk, &mp_opt.addr, true);
  984. MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADD);
  985. }
  986. if (mp_opt.addr.port)
  987. MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_PORTADD);
  988. }
  989. if (mp_opt.suboptions & OPTION_MPTCP_RM_ADDR)
  990. mptcp_pm_rm_addr_received(msk, &mp_opt.rm_list);
  991. if (mp_opt.suboptions & OPTION_MPTCP_PRIO) {
  992. mptcp_pm_mp_prio_received(sk, mp_opt.backup);
  993. MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPPRIORX);
  994. }
  995. if (mp_opt.suboptions & OPTION_MPTCP_FAIL) {
  996. mptcp_pm_mp_fail_received(sk, mp_opt.fail_seq);
  997. MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFAILRX);
  998. }
  999. if (mp_opt.suboptions & OPTION_MPTCP_RST) {
  1000. subflow->reset_seen = 1;
  1001. subflow->reset_reason = mp_opt.reset_reason;
  1002. subflow->reset_transient = mp_opt.reset_transient;
  1003. MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPRSTRX);
  1004. }
  1005. if (!(mp_opt.suboptions & OPTION_MPTCP_DSS))
  1006. return true;
  1007. }
  1008. /* we can't wait for recvmsg() to update the ack_seq, otherwise
  1009. * monodirectional flows will stuck
  1010. */
  1011. if (mp_opt.use_ack)
  1012. ack_update_msk(msk, sk, &mp_opt);
  1013. /* Zero-data-length packets are dropped by the caller and not
  1014. * propagated to the MPTCP layer, so the skb extension does not
  1015. * need to be allocated or populated. DATA_FIN information, if
  1016. * present, needs to be updated here before the skb is freed.
  1017. */
  1018. if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) {
  1019. if (mp_opt.data_fin && mp_opt.data_len == 1 &&
  1020. mptcp_update_rcv_data_fin(msk, mp_opt.data_seq, mp_opt.dsn64))
  1021. mptcp_schedule_work((struct sock *)msk);
  1022. return true;
  1023. }
  1024. mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
  1025. if (!mpext)
  1026. return true;
  1027. memset(mpext, 0, sizeof(*mpext));
  1028. if (likely(mp_opt.use_map)) {
  1029. if (mp_opt.mpc_map) {
  1030. /* this is an MP_CAPABLE carrying MPTCP data
  1031. * we know this map the first chunk of data
  1032. */
  1033. mptcp_crypto_key_sha(subflow->remote_key, NULL,
  1034. &mpext->data_seq);
  1035. mpext->data_seq++;
  1036. mpext->subflow_seq = 1;
  1037. mpext->dsn64 = 1;
  1038. mpext->mpc_map = 1;
  1039. mpext->data_fin = 0;
  1040. } else {
  1041. mpext->data_seq = mp_opt.data_seq;
  1042. mpext->subflow_seq = mp_opt.subflow_seq;
  1043. mpext->dsn64 = mp_opt.dsn64;
  1044. mpext->data_fin = mp_opt.data_fin;
  1045. }
  1046. mpext->data_len = mp_opt.data_len;
  1047. mpext->use_map = 1;
  1048. mpext->csum_reqd = !!(mp_opt.suboptions & OPTION_MPTCP_CSUMREQD);
  1049. if (mpext->csum_reqd)
  1050. mpext->csum = mp_opt.csum;
  1051. }
  1052. return true;
  1053. }
  1054. static void mptcp_set_rwin(struct tcp_sock *tp, struct tcphdr *th)
  1055. {
  1056. const struct sock *ssk = (const struct sock *)tp;
  1057. struct mptcp_subflow_context *subflow;
  1058. u64 ack_seq, rcv_wnd_old, rcv_wnd_new;
  1059. struct mptcp_sock *msk;
  1060. u32 new_win;
  1061. u64 win;
  1062. subflow = mptcp_subflow_ctx(ssk);
  1063. msk = mptcp_sk(subflow->conn);
  1064. ack_seq = READ_ONCE(msk->ack_seq);
  1065. rcv_wnd_new = ack_seq + tp->rcv_wnd;
  1066. rcv_wnd_old = atomic64_read(&msk->rcv_wnd_sent);
  1067. if (after64(rcv_wnd_new, rcv_wnd_old)) {
  1068. u64 rcv_wnd;
  1069. for (;;) {
  1070. rcv_wnd = atomic64_cmpxchg(&msk->rcv_wnd_sent, rcv_wnd_old, rcv_wnd_new);
  1071. if (rcv_wnd == rcv_wnd_old)
  1072. break;
  1073. rcv_wnd_old = rcv_wnd;
  1074. if (before64(rcv_wnd_new, rcv_wnd_old)) {
  1075. MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_RCVWNDCONFLICTUPDATE);
  1076. goto raise_win;
  1077. }
  1078. MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_RCVWNDCONFLICT);
  1079. }
  1080. return;
  1081. }
  1082. if (rcv_wnd_new != rcv_wnd_old) {
  1083. raise_win:
  1084. win = rcv_wnd_old - ack_seq;
  1085. tp->rcv_wnd = min_t(u64, win, U32_MAX);
  1086. new_win = tp->rcv_wnd;
  1087. /* Make sure we do not exceed the maximum possible
  1088. * scaled window.
  1089. */
  1090. if (unlikely(th->syn))
  1091. new_win = min(new_win, 65535U) << tp->rx_opt.rcv_wscale;
  1092. if (!tp->rx_opt.rcv_wscale &&
  1093. READ_ONCE(sock_net(ssk)->ipv4.sysctl_tcp_workaround_signed_windows))
  1094. new_win = min(new_win, MAX_TCP_WINDOW);
  1095. else
  1096. new_win = min(new_win, (65535U << tp->rx_opt.rcv_wscale));
  1097. /* RFC1323 scaling applied */
  1098. new_win >>= tp->rx_opt.rcv_wscale;
  1099. th->window = htons(new_win);
  1100. MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_RCVWNDSHARED);
  1101. }
  1102. }
  1103. __sum16 __mptcp_make_csum(u64 data_seq, u32 subflow_seq, u16 data_len, __wsum sum)
  1104. {
  1105. struct csum_pseudo_header header;
  1106. __wsum csum;
  1107. /* cfr RFC 8684 3.3.1.:
  1108. * the data sequence number used in the pseudo-header is
  1109. * always the 64-bit value, irrespective of what length is used in the
  1110. * DSS option itself.
  1111. */
  1112. header.data_seq = cpu_to_be64(data_seq);
  1113. header.subflow_seq = htonl(subflow_seq);
  1114. header.data_len = htons(data_len);
  1115. header.csum = 0;
  1116. csum = csum_partial(&header, sizeof(header), sum);
  1117. return csum_fold(csum);
  1118. }
  1119. static __sum16 mptcp_make_csum(const struct mptcp_ext *mpext)
  1120. {
  1121. return __mptcp_make_csum(mpext->data_seq, mpext->subflow_seq, mpext->data_len,
  1122. ~csum_unfold(mpext->csum));
  1123. }
  1124. static void put_len_csum(u16 len, __sum16 csum, void *data)
  1125. {
  1126. __sum16 *sumptr = data + 2;
  1127. __be16 *ptr = data;
  1128. put_unaligned_be16(len, ptr);
  1129. put_unaligned(csum, sumptr);
  1130. }
  1131. void mptcp_write_options(struct tcphdr *th, __be32 *ptr, struct tcp_sock *tp,
  1132. struct mptcp_out_options *opts)
  1133. {
  1134. const struct sock *ssk = (const struct sock *)tp;
  1135. struct mptcp_subflow_context *subflow;
  1136. /* Which options can be used together?
  1137. *
  1138. * X: mutually exclusive
  1139. * O: often used together
  1140. * C: can be used together in some cases
  1141. * P: could be used together but we prefer not to (optimisations)
  1142. *
  1143. * Opt: | MPC | MPJ | DSS | ADD | RM | PRIO | FAIL | FC |
  1144. * ------|------|------|------|------|------|------|------|------|
  1145. * MPC |------|------|------|------|------|------|------|------|
  1146. * MPJ | X |------|------|------|------|------|------|------|
  1147. * DSS | X | X |------|------|------|------|------|------|
  1148. * ADD | X | X | P |------|------|------|------|------|
  1149. * RM | C | C | C | P |------|------|------|------|
  1150. * PRIO | X | C | C | C | C |------|------|------|
  1151. * FAIL | X | X | C | X | X | X |------|------|
  1152. * FC | X | X | X | X | X | X | X |------|
  1153. * RST | X | X | X | X | X | X | O | O |
  1154. * ------|------|------|------|------|------|------|------|------|
  1155. *
  1156. * The same applies in mptcp_established_options() function.
  1157. */
  1158. if (likely(OPTION_MPTCP_DSS & opts->suboptions)) {
  1159. struct mptcp_ext *mpext = &opts->ext_copy;
  1160. u8 len = TCPOLEN_MPTCP_DSS_BASE;
  1161. u8 flags = 0;
  1162. if (mpext->use_ack) {
  1163. flags = MPTCP_DSS_HAS_ACK;
  1164. if (mpext->ack64) {
  1165. len += TCPOLEN_MPTCP_DSS_ACK64;
  1166. flags |= MPTCP_DSS_ACK64;
  1167. } else {
  1168. len += TCPOLEN_MPTCP_DSS_ACK32;
  1169. }
  1170. }
  1171. if (mpext->use_map) {
  1172. len += TCPOLEN_MPTCP_DSS_MAP64;
  1173. /* Use only 64-bit mapping flags for now, add
  1174. * support for optional 32-bit mappings later.
  1175. */
  1176. flags |= MPTCP_DSS_HAS_MAP | MPTCP_DSS_DSN64;
  1177. if (mpext->data_fin)
  1178. flags |= MPTCP_DSS_DATA_FIN;
  1179. if (opts->csum_reqd)
  1180. len += TCPOLEN_MPTCP_DSS_CHECKSUM;
  1181. }
  1182. *ptr++ = mptcp_option(MPTCPOPT_DSS, len, 0, flags);
  1183. if (mpext->use_ack) {
  1184. if (mpext->ack64) {
  1185. put_unaligned_be64(mpext->data_ack, ptr);
  1186. ptr += 2;
  1187. } else {
  1188. put_unaligned_be32(mpext->data_ack32, ptr);
  1189. ptr += 1;
  1190. }
  1191. }
  1192. if (mpext->use_map) {
  1193. put_unaligned_be64(mpext->data_seq, ptr);
  1194. ptr += 2;
  1195. put_unaligned_be32(mpext->subflow_seq, ptr);
  1196. ptr += 1;
  1197. if (opts->csum_reqd) {
  1198. /* data_len == 0 is reserved for the infinite mapping,
  1199. * the checksum will also be set to 0.
  1200. */
  1201. put_len_csum(mpext->data_len,
  1202. (mpext->data_len ? mptcp_make_csum(mpext) : 0),
  1203. ptr);
  1204. } else {
  1205. put_unaligned_be32(mpext->data_len << 16 |
  1206. TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
  1207. }
  1208. ptr += 1;
  1209. }
  1210. /* We might need to add MP_FAIL options in rare cases */
  1211. if (unlikely(OPTION_MPTCP_FAIL & opts->suboptions))
  1212. goto mp_fail;
  1213. } else if (OPTIONS_MPTCP_MPC & opts->suboptions) {
  1214. u8 len, flag = MPTCP_CAP_HMAC_SHA256;
  1215. if (OPTION_MPTCP_MPC_SYN & opts->suboptions) {
  1216. len = TCPOLEN_MPTCP_MPC_SYN;
  1217. } else if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions) {
  1218. len = TCPOLEN_MPTCP_MPC_SYNACK;
  1219. } else if (opts->data_len) {
  1220. len = TCPOLEN_MPTCP_MPC_ACK_DATA;
  1221. if (opts->csum_reqd)
  1222. len += TCPOLEN_MPTCP_DSS_CHECKSUM;
  1223. } else {
  1224. len = TCPOLEN_MPTCP_MPC_ACK;
  1225. }
  1226. if (opts->csum_reqd)
  1227. flag |= MPTCP_CAP_CHECKSUM_REQD;
  1228. if (!opts->allow_join_id0)
  1229. flag |= MPTCP_CAP_DENY_JOIN_ID0;
  1230. *ptr++ = mptcp_option(MPTCPOPT_MP_CAPABLE, len,
  1231. MPTCP_SUPPORTED_VERSION,
  1232. flag);
  1233. if (!((OPTION_MPTCP_MPC_SYNACK | OPTION_MPTCP_MPC_ACK) &
  1234. opts->suboptions))
  1235. goto mp_capable_done;
  1236. put_unaligned_be64(opts->sndr_key, ptr);
  1237. ptr += 2;
  1238. if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))
  1239. goto mp_capable_done;
  1240. put_unaligned_be64(opts->rcvr_key, ptr);
  1241. ptr += 2;
  1242. if (!opts->data_len)
  1243. goto mp_capable_done;
  1244. if (opts->csum_reqd) {
  1245. put_len_csum(opts->data_len,
  1246. __mptcp_make_csum(opts->data_seq,
  1247. opts->subflow_seq,
  1248. opts->data_len,
  1249. ~csum_unfold(opts->csum)),
  1250. ptr);
  1251. } else {
  1252. put_unaligned_be32(opts->data_len << 16 |
  1253. TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
  1254. }
  1255. ptr += 1;
  1256. /* MPC is additionally mutually exclusive with MP_PRIO */
  1257. goto mp_capable_done;
  1258. } else if (OPTIONS_MPTCP_MPJ & opts->suboptions) {
  1259. if (OPTION_MPTCP_MPJ_SYN & opts->suboptions) {
  1260. *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
  1261. TCPOLEN_MPTCP_MPJ_SYN,
  1262. opts->backup, opts->join_id);
  1263. put_unaligned_be32(opts->token, ptr);
  1264. ptr += 1;
  1265. put_unaligned_be32(opts->nonce, ptr);
  1266. ptr += 1;
  1267. } else if (OPTION_MPTCP_MPJ_SYNACK & opts->suboptions) {
  1268. *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
  1269. TCPOLEN_MPTCP_MPJ_SYNACK,
  1270. opts->backup, opts->join_id);
  1271. put_unaligned_be64(opts->thmac, ptr);
  1272. ptr += 2;
  1273. put_unaligned_be32(opts->nonce, ptr);
  1274. ptr += 1;
  1275. } else {
  1276. *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
  1277. TCPOLEN_MPTCP_MPJ_ACK, 0, 0);
  1278. memcpy(ptr, opts->hmac, MPTCPOPT_HMAC_LEN);
  1279. ptr += 5;
  1280. }
  1281. } else if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
  1282. u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
  1283. u8 echo = MPTCP_ADDR_ECHO;
  1284. #if IS_ENABLED(CONFIG_MPTCP_IPV6)
  1285. if (opts->addr.family == AF_INET6)
  1286. len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
  1287. #endif
  1288. if (opts->addr.port)
  1289. len += TCPOLEN_MPTCP_PORT_LEN;
  1290. if (opts->ahmac) {
  1291. len += sizeof(opts->ahmac);
  1292. echo = 0;
  1293. }
  1294. *ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
  1295. len, echo, opts->addr.id);
  1296. if (opts->addr.family == AF_INET) {
  1297. memcpy((u8 *)ptr, (u8 *)&opts->addr.addr.s_addr, 4);
  1298. ptr += 1;
  1299. }
  1300. #if IS_ENABLED(CONFIG_MPTCP_IPV6)
  1301. else if (opts->addr.family == AF_INET6) {
  1302. memcpy((u8 *)ptr, opts->addr.addr6.s6_addr, 16);
  1303. ptr += 4;
  1304. }
  1305. #endif
  1306. if (!opts->addr.port) {
  1307. if (opts->ahmac) {
  1308. put_unaligned_be64(opts->ahmac, ptr);
  1309. ptr += 2;
  1310. }
  1311. } else {
  1312. u16 port = ntohs(opts->addr.port);
  1313. if (opts->ahmac) {
  1314. u8 *bptr = (u8 *)ptr;
  1315. put_unaligned_be16(port, bptr);
  1316. bptr += 2;
  1317. put_unaligned_be64(opts->ahmac, bptr);
  1318. bptr += 8;
  1319. put_unaligned_be16(TCPOPT_NOP << 8 |
  1320. TCPOPT_NOP, bptr);
  1321. ptr += 3;
  1322. } else {
  1323. put_unaligned_be32(port << 16 |
  1324. TCPOPT_NOP << 8 |
  1325. TCPOPT_NOP, ptr);
  1326. ptr += 1;
  1327. }
  1328. }
  1329. } else if (unlikely(OPTION_MPTCP_FASTCLOSE & opts->suboptions)) {
  1330. /* FASTCLOSE is mutually exclusive with others except RST */
  1331. *ptr++ = mptcp_option(MPTCPOPT_MP_FASTCLOSE,
  1332. TCPOLEN_MPTCP_FASTCLOSE,
  1333. 0, 0);
  1334. put_unaligned_be64(opts->rcvr_key, ptr);
  1335. ptr += 2;
  1336. if (OPTION_MPTCP_RST & opts->suboptions)
  1337. goto mp_rst;
  1338. return;
  1339. } else if (unlikely(OPTION_MPTCP_FAIL & opts->suboptions)) {
  1340. mp_fail:
  1341. /* MP_FAIL is mutually exclusive with others except RST */
  1342. subflow = mptcp_subflow_ctx(ssk);
  1343. subflow->send_mp_fail = 0;
  1344. *ptr++ = mptcp_option(MPTCPOPT_MP_FAIL,
  1345. TCPOLEN_MPTCP_FAIL,
  1346. 0, 0);
  1347. put_unaligned_be64(opts->fail_seq, ptr);
  1348. ptr += 2;
  1349. if (OPTION_MPTCP_RST & opts->suboptions)
  1350. goto mp_rst;
  1351. return;
  1352. } else if (unlikely(OPTION_MPTCP_RST & opts->suboptions)) {
  1353. mp_rst:
  1354. *ptr++ = mptcp_option(MPTCPOPT_RST,
  1355. TCPOLEN_MPTCP_RST,
  1356. opts->reset_transient,
  1357. opts->reset_reason);
  1358. return;
  1359. }
  1360. if (OPTION_MPTCP_PRIO & opts->suboptions) {
  1361. subflow = mptcp_subflow_ctx(ssk);
  1362. subflow->send_mp_prio = 0;
  1363. *ptr++ = mptcp_option(MPTCPOPT_MP_PRIO,
  1364. TCPOLEN_MPTCP_PRIO,
  1365. opts->backup, TCPOPT_NOP);
  1366. MPTCP_INC_STATS(sock_net((const struct sock *)tp),
  1367. MPTCP_MIB_MPPRIOTX);
  1368. }
  1369. mp_capable_done:
  1370. if (OPTION_MPTCP_RM_ADDR & opts->suboptions) {
  1371. u8 i = 1;
  1372. *ptr++ = mptcp_option(MPTCPOPT_RM_ADDR,
  1373. TCPOLEN_MPTCP_RM_ADDR_BASE + opts->rm_list.nr,
  1374. 0, opts->rm_list.ids[0]);
  1375. while (i < opts->rm_list.nr) {
  1376. u8 id1, id2, id3, id4;
  1377. id1 = opts->rm_list.ids[i];
  1378. id2 = i + 1 < opts->rm_list.nr ? opts->rm_list.ids[i + 1] : TCPOPT_NOP;
  1379. id3 = i + 2 < opts->rm_list.nr ? opts->rm_list.ids[i + 2] : TCPOPT_NOP;
  1380. id4 = i + 3 < opts->rm_list.nr ? opts->rm_list.ids[i + 3] : TCPOPT_NOP;
  1381. put_unaligned_be32(id1 << 24 | id2 << 16 | id3 << 8 | id4, ptr);
  1382. ptr += 1;
  1383. i += 4;
  1384. }
  1385. }
  1386. if (tp)
  1387. mptcp_set_rwin(tp, th);
  1388. }
  1389. __be32 mptcp_get_reset_option(const struct sk_buff *skb)
  1390. {
  1391. const struct mptcp_ext *ext = mptcp_get_ext(skb);
  1392. u8 flags, reason;
  1393. if (ext) {
  1394. flags = ext->reset_transient;
  1395. reason = ext->reset_reason;
  1396. return mptcp_option(MPTCPOPT_RST, TCPOLEN_MPTCP_RST,
  1397. flags, reason);
  1398. }
  1399. return htonl(0u);
  1400. }
  1401. EXPORT_SYMBOL_GPL(mptcp_get_reset_option);