2 * Copyright (c) 2012-2014 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <netinet/in_systm.h>
31 #include <sys/socket.h>
32 #include <sys/socketvar.h>
34 #include <net/route.h>
35 #include <netinet/in.h>
38 #include <netinet/ip.h>
39 #include <netinet/ip_var.h>
40 #include <netinet/in_var.h>
41 #include <netinet/tcp.h>
42 #include <netinet/tcp_var.h>
43 #include <netinet/tcp_seq.h>
44 #include <netinet/tcpip.h>
45 #include <netinet/tcp_fsm.h>
46 #include <netinet/mptcp_var.h>
47 #include <netinet/mptcp.h>
48 #include <netinet/mptcp_opt.h>
49 #include <netinet/mptcp_seq.h>
51 #include <libkern/crypto/sha1.h>
52 #include <netinet/mptcp_timer.h>
57 * SYSCTL for enforcing 64 bit dsn
59 int32_t force_64bit_dsn
= 0;
60 SYSCTL_INT(_net_inet_mptcp
, OID_AUTO
, force_64bit_dsn
,
61 CTLFLAG_RW
|CTLFLAG_LOCKED
, &force_64bit_dsn
, 0,
62 "Force MPTCP 64bit dsn");
65 static int mptcp_validate_join_hmac(struct tcpcb
*, u_char
*, int);
66 static int mptcp_snd_mpprio(struct tcpcb
*tp
, u_char
*cp
, int optlen
);
69 * MPTCP Options Output Processing
73 mptcp_setup_first_subflow_syn_opts(struct socket
*so
, int flags
, u_char
*opt
,
76 struct tcpcb
*tp
= sototcpcb(so
);
77 struct mptcb
*mp_tp
= NULL
;
80 if (!(so
->so_flags
& SOF_MP_SUBFLOW
))
84 * Avoid retransmitting the MP_CAPABLE option.
86 if (tp
->t_rxtshift
> mptcp_mpcap_retries
)
89 if ((flags
& (TH_SYN
| TH_ACK
)) == (TH_SYN
| TH_ACK
)) {
90 struct mptcp_mpcapable_opt_rsp mptcp_opt
;
91 mptcp_key_t mp_localkey
= 0;
93 mp_localkey
= mptcp_get_localkey(mp_tp
);
94 if (mp_localkey
== 0) {
95 /* an embryonic connection was closed from above */
99 sizeof (struct mptcp_mpcapable_opt_rsp
));
100 mptcp_opt
.mmc_common
.mmco_kind
= TCPOPT_MULTIPATH
;
101 mptcp_opt
.mmc_common
.mmco_len
=
102 sizeof (struct mptcp_mpcapable_opt_rsp
);
103 mptcp_opt
.mmc_common
.mmco_subtype
= MPO_CAPABLE
;
104 MPT_LOCK_SPIN(mp_tp
);
105 mptcp_opt
.mmc_common
.mmco_version
= mp_tp
->mpt_version
;
106 mptcp_opt
.mmc_common
.mmco_flags
|= MPCAP_PROPOSAL_SBIT
;
107 if (mp_tp
->mpt_flags
& MPTCPF_CHECKSUM
)
108 mptcp_opt
.mmc_common
.mmco_flags
|=
111 mptcp_opt
.mmc_localkey
= mp_localkey
;
112 memcpy(opt
+ optlen
, &mptcp_opt
,
113 mptcp_opt
.mmc_common
.mmco_len
);
114 optlen
+= mptcp_opt
.mmc_common
.mmco_len
;
115 if (mptcp_dbg
>= MP_VERBOSE_DEBUG_2
) {
116 printf("%s: SYN_ACK localkey = %llx \n",
117 __func__
, mp_localkey
);
120 /* Only the SYN flag is set */
121 struct mptcp_mpcapable_opt_common mptcp_opt
;
122 mptcp_key_t mp_localkey
= 0;
123 mp_localkey
= mptcp_get_localkey(mp_tp
);
124 so
->so_flags
|= SOF_MPTCP_CLIENT
;
125 if (mp_localkey
== 0) {
126 /* an embryonic connection was closed */
130 sizeof (struct mptcp_mpcapable_opt_common
));
131 mptcp_opt
.mmco_kind
= TCPOPT_MULTIPATH
;
133 sizeof (struct mptcp_mpcapable_opt_common
) +
134 sizeof (mptcp_key_t
);
135 mptcp_opt
.mmco_subtype
= MPO_CAPABLE
;
136 MPT_LOCK_SPIN(mp_tp
);
137 mptcp_opt
.mmco_version
= mp_tp
->mpt_version
;
138 mptcp_opt
.mmco_flags
|= MPCAP_PROPOSAL_SBIT
;
139 if (mp_tp
->mpt_flags
& MPTCPF_CHECKSUM
)
140 mptcp_opt
.mmco_flags
|= MPCAP_CHECKSUM_CBIT
;
142 (void) memcpy(opt
+ optlen
, &mptcp_opt
,
143 sizeof (struct mptcp_mpcapable_opt_common
));
144 optlen
+= sizeof (struct mptcp_mpcapable_opt_common
);
145 (void) memcpy(opt
+ optlen
, &mp_localkey
,
146 sizeof (mptcp_key_t
));
147 optlen
+= sizeof (mptcp_key_t
);
154 mptcp_setup_join_subflow_syn_opts(struct socket
*so
, int flags
, u_char
*opt
,
157 struct inpcb
*inp
= sotoinpcb(so
);
158 struct tcpcb
*tp
= NULL
;
170 if ((flags
& (TH_SYN
| TH_ACK
)) == (TH_SYN
| TH_ACK
)) {
171 struct mptcp_mpjoin_opt_rsp mpjoin_rsp
;
172 struct mptcb
*mp_tp
= tptomptp(tp
);
178 if (mptcp_get_localkey(mp_tp
) == 0) {
183 bzero(&mpjoin_rsp
, sizeof (mpjoin_rsp
));
184 mpjoin_rsp
.mmjo_kind
= TCPOPT_MULTIPATH
;
185 mpjoin_rsp
.mmjo_len
= sizeof (mpjoin_rsp
);
186 mpjoin_rsp
.mmjo_subtype_bkp
= MPO_JOIN
<< 4;
187 if (tp
->t_mpflags
& TMPF_BACKUP_PATH
)
188 mpjoin_rsp
.mmjo_subtype_bkp
|= MPTCP_BACKUP
;
189 mpjoin_rsp
.mmjo_addr_id
= tp
->t_local_aid
;
190 mptcp_get_rands(tp
->t_local_aid
, tptomptp(tp
),
191 &mpjoin_rsp
.mmjo_rand
, NULL
);
192 mpjoin_rsp
.mmjo_mac
= mptcp_get_trunced_hmac(tp
->t_local_aid
,
194 memcpy(opt
+ optlen
, &mpjoin_rsp
, mpjoin_rsp
.mmjo_len
);
195 optlen
+= mpjoin_rsp
.mmjo_len
;
197 struct mptcp_mpjoin_opt_req mpjoin_req
;
198 bzero(&mpjoin_req
, sizeof (mpjoin_req
));
199 mpjoin_req
.mmjo_kind
= TCPOPT_MULTIPATH
;
200 mpjoin_req
.mmjo_len
= sizeof (mpjoin_req
);
201 mpjoin_req
.mmjo_subtype_bkp
= MPO_JOIN
<< 4;
202 /* A secondary subflow is started off as backup */
203 mpjoin_req
.mmjo_subtype_bkp
|= MPTCP_BACKUP
;
204 tp
->t_mpflags
|= TMPF_BACKUP_PATH
;
205 mpjoin_req
.mmjo_addr_id
= tp
->t_local_aid
;
206 mpjoin_req
.mmjo_peer_token
= mptcp_get_remotetoken(tp
->t_mptcb
);
207 if (mpjoin_req
.mmjo_peer_token
== 0) {
208 if (mptcp_dbg
>= MP_ERR_DEBUG
)
209 printf("%s: zero peer token \n", __func__
);
211 mptcp_get_rands(tp
->t_local_aid
, tptomptp(tp
),
212 &mpjoin_req
.mmjo_rand
, NULL
);
213 memcpy(opt
+ optlen
, &mpjoin_req
, mpjoin_req
.mmjo_len
);
214 optlen
+= mpjoin_req
.mmjo_len
;
215 /* send an event up, if Fast Join is requested */
216 if (mptcp_zerortt_fastjoin
&&
217 (so
->so_flags
& SOF_MPTCP_FASTJOIN
)) {
219 (SO_FILT_HINT_LOCKED
| SO_FILT_HINT_MPFASTJ
));
220 if (mptcp_dbg
>= MP_ERR_DEBUG
)
221 printf("%s: fast join request\n", __func__
);
228 mptcp_setup_join_ack_opts(struct tcpcb
*tp
, u_char
*opt
, unsigned optlen
)
231 struct mptcp_mpjoin_opt_rsp2 join_rsp2
;
233 if ((MAX_TCPOPTLEN
- optlen
) < sizeof (struct mptcp_mpjoin_opt_rsp2
)) {
234 printf("%s: no space left %d \n", __func__
, optlen
);
238 bzero(&join_rsp2
, sizeof (struct mptcp_mpjoin_opt_rsp2
));
239 join_rsp2
.mmjo_kind
= TCPOPT_MULTIPATH
;
240 join_rsp2
.mmjo_len
= sizeof (struct mptcp_mpjoin_opt_rsp2
);
241 join_rsp2
.mmjo_subtype
= MPO_JOIN
;
242 mptcp_get_hmac(tp
->t_local_aid
, tptomptp(tp
),
243 (u_char
*)&join_rsp2
.mmjo_mac
,
244 sizeof (join_rsp2
.mmjo_mac
));
245 memcpy(opt
+ optlen
, &join_rsp2
, join_rsp2
.mmjo_len
);
246 new_optlen
= optlen
+ join_rsp2
.mmjo_len
;
247 tp
->t_mpflags
|= TMPF_FASTJOINBY2_SEND
;
252 mptcp_setup_syn_opts(struct socket
*so
, int flags
, u_char
*opt
, unsigned optlen
)
256 if (mptcp_enable
== 0) {
261 if (!(so
->so_flags
& SOF_MP_SEC_SUBFLOW
)) {
262 new_optlen
= mptcp_setup_first_subflow_syn_opts(so
, flags
, opt
,
266 * To simulate SYN_ACK with no join opt, comment this line on
267 * OS X server side. This serves as a testing hook.
269 new_optlen
= mptcp_setup_join_subflow_syn_opts(so
, flags
, opt
,
276 mptcp_send_mpfail(struct tcpcb
*tp
, u_char
*opt
, unsigned int optlen
)
278 #pragma unused(tp, opt, optlen)
280 struct mptcb
*mp_tp
= NULL
;
281 struct mptcp_mpfail_opt fail_opt
;
283 int len
= sizeof (struct mptcp_mpfail_opt
);
285 mp_tp
= tptomptp(tp
);
287 tp
->t_mpflags
&= ~TMPF_SND_MPFAIL
;
291 /* if option space low give up */
292 if ((MAX_TCPOPTLEN
- optlen
) < sizeof (struct mptcp_mpfail_opt
)) {
293 tp
->t_mpflags
&= ~TMPF_SND_MPFAIL
;
298 dsn
= mp_tp
->mpt_rcvnxt
;
301 bzero(&fail_opt
, sizeof (fail_opt
));
302 fail_opt
.mfail_kind
= TCPOPT_MULTIPATH
;
303 fail_opt
.mfail_len
= len
;
304 fail_opt
.mfail_subtype
= MPO_FAIL
;
305 fail_opt
.mfail_dsn
= mptcp_hton64(dsn
);
306 memcpy(opt
+ optlen
, &fail_opt
, len
);
308 tp
->t_mpflags
&= ~TMPF_SND_MPFAIL
;
309 if (mptcp_dbg
>= MP_ERR_DEBUG
)
310 printf("%s: %d \n", __func__
, tp
->t_local_aid
);
315 mptcp_send_infinite_mapping(struct tcpcb
*tp
, u_char
*opt
, unsigned int optlen
)
317 struct mptcp_dsn_opt infin_opt
;
318 struct mptcb
*mp_tp
= NULL
;
319 size_t len
= sizeof (struct mptcp_dsn_opt
);
320 struct socket
*so
= tp
->t_inpcb
->inp_socket
;
327 mp_tp
= tptomptp(tp
);
332 if (mp_tp
->mpt_flags
& MPTCPF_CHECKSUM
)
336 if ((MAX_TCPOPTLEN
- optlen
) < (len
+ csum_len
)) {
340 bzero(&infin_opt
, sizeof (infin_opt
));
341 infin_opt
.mdss_copt
.mdss_kind
= TCPOPT_MULTIPATH
;
342 infin_opt
.mdss_copt
.mdss_len
= len
+ csum_len
;
343 infin_opt
.mdss_copt
.mdss_subtype
= MPO_DSS
;
344 infin_opt
.mdss_copt
.mdss_flags
|= MDSS_M
;
345 if (mp_tp
->mpt_flags
& MPTCPF_RECVD_MPFAIL
) {
346 infin_opt
.mdss_dsn
= (u_int32_t
)
347 MPTCP_DATASEQ_LOW32(mp_tp
->mpt_dsn_at_csum_fail
);
348 infin_opt
.mdss_subflow_seqn
= mp_tp
->mpt_ssn_at_csum_fail
;
350 infin_opt
.mdss_dsn
= (u_int32_t
)
351 MPTCP_DATASEQ_LOW32(mp_tp
->mpt_snduna
);
352 infin_opt
.mdss_subflow_seqn
= tp
->snd_una
- tp
->iss
;
357 if ((infin_opt
.mdss_dsn
== 0) || (infin_opt
.mdss_subflow_seqn
== 0)) {
360 infin_opt
.mdss_dsn
= htonl(infin_opt
.mdss_dsn
);
361 infin_opt
.mdss_subflow_seqn
= htonl(infin_opt
.mdss_subflow_seqn
);
362 infin_opt
.mdss_data_len
= 0;
364 memcpy(opt
+ optlen
, &infin_opt
, len
);
367 /* The checksum field is set to 0 for infinite mapping */
369 memcpy(opt
+ optlen
, &csum
, csum_len
);
373 if (mptcp_dbg
== MP_VERBOSE_DEBUG_1
) {
374 printf("%s: dsn = %x, seq = %x len = %x\n", __func__
,
375 ntohl(infin_opt
.mdss_dsn
),
376 ntohl(infin_opt
.mdss_subflow_seqn
),
377 ntohs(infin_opt
.mdss_data_len
));
380 /* so->so_flags &= ~SOF_MPTCP_CLIENT; */
381 tp
->t_mpflags
|= TMPF_INFIN_SENT
;
382 tcpstat
.tcps_estab_fallback
++;
388 mptcp_ok_to_fin(struct tcpcb
*tp
, u_int64_t dsn
, u_int32_t datalen
)
390 struct mptcb
*mp_tp
= NULL
;
391 mp_tp
= tptomptp(tp
);
394 dsn
= (mp_tp
->mpt_sndmax
& MPTCP_DATASEQ_LOW32_MASK
) | dsn
;
395 if ((dsn
+ datalen
) == mp_tp
->mpt_sndmax
) {
404 /* Must be called from tcp_output to fill in the fast close option */
406 mptcp_send_fastclose(struct tcpcb
*tp
, u_char
*opt
, unsigned int optlen
,
409 struct mptcp_fastclose_opt fastclose_opt
;
410 struct mptcb
*mp_tp
= tptomptp(tp
);
412 /* Only ACK flag should be set */
416 if ((MAX_TCPOPTLEN
- optlen
) <
417 sizeof (struct mptcp_fastclose_opt
)) {
421 bzero(&fastclose_opt
, sizeof (struct mptcp_fastclose_opt
));
422 fastclose_opt
.mfast_kind
= TCPOPT_MULTIPATH
;
423 fastclose_opt
.mfast_len
= sizeof (struct mptcp_fastclose_opt
);
424 fastclose_opt
.mfast_subtype
= MPO_FASTCLOSE
;
425 MPT_LOCK_SPIN(mp_tp
);
426 fastclose_opt
.mfast_key
= mptcp_get_remotekey(mp_tp
);
428 memcpy(opt
+ optlen
, &fastclose_opt
, fastclose_opt
.mfast_len
);
429 optlen
+= fastclose_opt
.mfast_len
;
435 mptcp_setup_opts(struct tcpcb
*tp
, int32_t off
, u_char
*opt
,
436 unsigned int optlen
, int flags
, int datalen
,
437 unsigned int **dss_lenp
, u_int8_t
**finp
, u_int64_t
*dss_valp
,
438 u_int32_t
**sseqp
, boolean_t
*p_mptcp_acknow
)
440 struct inpcb
*inp
= (struct inpcb
*)tp
->t_inpcb
;
441 struct socket
*so
= inp
->inp_socket
;
442 struct mptcb
*mp_tp
= tptomptp(tp
);
443 boolean_t do_csum
= FALSE
;
444 boolean_t send_64bit_dsn
= FALSE
;
445 boolean_t send_64bit_ack
= FALSE
;
446 u_int32_t old_mpt_flags
= tp
->t_mpflags
&
447 (TMPF_SND_MPPRIO
| TMPF_SND_REM_ADDR
| TMPF_SND_MPFAIL
);
449 if ((mptcp_enable
== 0) ||
451 (mp_tp
->mpt_flags
& MPTCPF_PEEL_OFF
) ||
452 (tp
->t_state
== TCPS_CLOSED
)) {
457 if (mp_tp
->mpt_flags
& MPTCPF_CHECKSUM
) {
461 /* tcp_output handles the SYN path separately */
462 if (flags
& TH_SYN
) {
466 if ((MAX_TCPOPTLEN
- optlen
) <
467 sizeof (struct mptcp_mpcapable_opt_common
)) {
468 if (mptcp_dbg
>= MP_ERR_DEBUG
) {
469 printf("MPTCP ERROR %s: no space left %d flags %x "
471 "len %d\n", __func__
, optlen
, flags
, tp
->t_mpflags
,
477 if (tp
->t_mpflags
& TMPF_FASTCLOSE
) {
478 optlen
= mptcp_send_fastclose(tp
, opt
, optlen
, flags
);
479 VERIFY(datalen
== 0);
483 if (tp
->t_mpflags
& TMPF_TCP_FALLBACK
) {
484 if (tp
->t_mpflags
& TMPF_SND_MPFAIL
)
485 optlen
= mptcp_send_mpfail(tp
, opt
, optlen
);
486 else if (!(tp
->t_mpflags
& TMPF_INFIN_SENT
))
487 optlen
= mptcp_send_infinite_mapping(tp
, opt
, optlen
);
491 if (tp
->t_mpflags
& TMPF_SND_MPPRIO
) {
492 optlen
= mptcp_snd_mpprio(tp
, opt
, optlen
);
496 if (((tp
->t_mpflags
& TMPF_FASTJOINBY2_SEND
) ||
497 (tp
->t_mpflags
& TMPF_FASTJOIN_SEND
)) &&
499 tp
->t_mpflags
&= ~TMPF_FASTJOINBY2_SEND
;
500 tp
->t_mpflags
&= ~TMPF_FASTJOIN_SEND
;
504 if ((tp
->t_mpflags
& TMPF_PREESTABLISHED
) &&
505 (!(tp
->t_mpflags
& TMPF_SENT_KEYS
)) &&
506 (!(tp
->t_mpflags
& TMPF_JOINED_FLOW
))) {
507 struct mptcp_mpcapable_opt_rsp1 mptcp_opt
;
508 if ((MAX_TCPOPTLEN
- optlen
) <
509 sizeof (struct mptcp_mpcapable_opt_rsp1
))
511 bzero(&mptcp_opt
, sizeof (struct mptcp_mpcapable_opt_rsp1
));
512 mptcp_opt
.mmc_common
.mmco_kind
= TCPOPT_MULTIPATH
;
513 mptcp_opt
.mmc_common
.mmco_len
=
514 sizeof (struct mptcp_mpcapable_opt_rsp1
);
515 mptcp_opt
.mmc_common
.mmco_subtype
= MPO_CAPABLE
;
516 mptcp_opt
.mmc_common
.mmco_version
= MP_DRAFT_VERSION_12
;
517 /* HMAC-SHA1 is the proposal */
518 mptcp_opt
.mmc_common
.mmco_flags
|= MPCAP_PROPOSAL_SBIT
;
520 if (mp_tp
->mpt_flags
& MPTCPF_CHECKSUM
)
521 mptcp_opt
.mmc_common
.mmco_flags
|= MPCAP_CHECKSUM_CBIT
;
522 mptcp_opt
.mmc_localkey
= mptcp_get_localkey(mp_tp
);
523 mptcp_opt
.mmc_remotekey
= mptcp_get_remotekey(mp_tp
);
525 memcpy(opt
+ optlen
, &mptcp_opt
, mptcp_opt
.mmc_common
.mmco_len
);
526 optlen
+= mptcp_opt
.mmc_common
.mmco_len
;
527 tp
->t_mpflags
|= TMPF_SENT_KEYS
;
528 so
->so_flags
|= SOF_MPTCP_TRUE
;
529 tp
->t_mpflags
&= ~TMPF_PREESTABLISHED
;
530 tp
->t_mpflags
|= TMPF_MPTCP_TRUE
;
533 tp
->t_mpuna
= tp
->snd_una
;
535 /* its a retransmission of the MP_CAPABLE ACK */
537 if (mptcp_dbg
>= MP_ERR_DEBUG
) {
538 printf("MPTCP SUCCESS %s: established.\n", __func__
);
541 } else if (tp
->t_mpflags
& TMPF_MPTCP_TRUE
) {
542 if (tp
->t_mpflags
& TMPF_SND_REM_ADDR
) {
543 int rem_opt_len
= sizeof (struct mptcp_remaddr_opt
);
544 if ((optlen
+ rem_opt_len
) <= MAX_TCPOPTLEN
) {
545 mptcp_send_remaddr_opt(tp
,
546 (struct mptcp_remaddr_opt
*)(opt
+ optlen
));
547 optlen
+= rem_opt_len
;
550 tp
->t_mpflags
&= ~TMPF_SND_REM_ADDR
;
555 if ((tp
->t_mpflags
& TMPF_JOINED_FLOW
) &&
556 (tp
->t_mpflags
& TMPF_PREESTABLISHED
) &&
557 (!(tp
->t_mpflags
& TMPF_RECVD_JOIN
)) &&
558 (tp
->t_mpflags
& TMPF_SENT_JOIN
) &&
559 (!(tp
->t_mpflags
& TMPF_MPTCP_TRUE
))) {
561 if (mptcp_get_localkey(mp_tp
) == 0) {
566 /* Do the ACK part */
567 optlen
= mptcp_setup_join_ack_opts(tp
, opt
, optlen
);
569 tp
->t_mpuna
= tp
->snd_una
;
571 /* Start a timer to retransmit the ACK */
572 tp
->t_timer
[TCPT_JACK_RXMT
] =
573 OFFSET_FROM_START(tp
, tcp_jack_rxmt
);
577 if (!(tp
->t_mpflags
& TMPF_MPTCP_TRUE
))
581 * From here on, all options are sent only if MPTCP_TRUE
582 * or when data is sent early on as in Fast Join
586 if ((mp_tp
->mpt_flags
& MPTCPF_SND_64BITDSN
) || force_64bit_dsn
) {
587 send_64bit_dsn
= TRUE
;
589 if (mp_tp
->mpt_flags
& MPTCPF_SND_64BITACK
) {
590 send_64bit_ack
= TRUE
;
594 #define CHECK_OPTLEN { \
595 if ((MAX_TCPOPTLEN - optlen) < len) { \
596 if (mptcp_dbg >= MP_ERR_DEBUG) { \
597 printf("MPTCP ERROR %s: len %d optlen %d \n", \
605 #define DO_FIN(dsn_opt) { \
607 sndfin = mptcp_ok_to_fin(tp, dsn_opt.mdss_dsn, datalen); \
609 dsn_opt.mdss_copt.mdss_flags |= MDSS_F; \
610 *finp = opt + optlen + offsetof(struct mptcp_dss_copt, \
612 dsn_opt.mdss_data_len += 1; \
616 #define CHECK_DATALEN { \
617 /* MPTCP socket does not support IP options */ \
618 if ((datalen + optlen + len) > tp->t_maxopd) { \
619 if (mptcp_dbg >= MP_VERBOSE_DEBUG_2) \
620 printf("%s: nosp %d len %d opt %d %d %d\n", \
621 __func__, datalen, len, optlen, \
622 tp->t_maxseg, tp->t_maxopd); \
623 /* remove option length from payload len */ \
624 datalen = tp->t_maxopd - optlen - len; \
628 if ((tp
->t_mpflags
& TMPF_SEND_DSN
) &&
631 * If there was the need to send 64-bit Data ACK along
632 * with 64-bit DSN, then 26 or 28 bytes would be used.
633 * With timestamps and NOOP padding that will cause
634 * overflow. Hence, in the rare event that both 64-bit
635 * DSN and 64-bit ACK have to be sent, delay the send of
636 * 64-bit ACK until our 64-bit DSN is acked with a 64-bit ack.
637 * XXX If this delay causes issue, remove the 2-byte padding.
639 struct mptcp_dss64_ack32_opt dsn_ack_opt
;
640 unsigned int len
= sizeof (dsn_ack_opt
);
648 bzero(&dsn_ack_opt
, sizeof (dsn_ack_opt
));
649 dsn_ack_opt
.mdss_copt
.mdss_kind
= TCPOPT_MULTIPATH
;
650 dsn_ack_opt
.mdss_copt
.mdss_subtype
= MPO_DSS
;
651 dsn_ack_opt
.mdss_copt
.mdss_len
= len
;
652 dsn_ack_opt
.mdss_copt
.mdss_flags
|=
653 MDSS_M
| MDSS_m
| MDSS_A
;
657 mptcp_output_getm_dsnmap64(so
, off
, (u_int32_t
)datalen
,
658 &dsn_ack_opt
.mdss_dsn
,
659 &dsn_ack_opt
.mdss_subflow_seqn
,
660 &dsn_ack_opt
.mdss_data_len
);
662 *dss_valp
= dsn_ack_opt
.mdss_dsn
;
664 if ((dsn_ack_opt
.mdss_data_len
== 0) ||
665 (dsn_ack_opt
.mdss_dsn
== 0)) {
669 if (tp
->t_mpflags
& TMPF_SEND_DFIN
) {
674 dsn_ack_opt
.mdss_ack
=
675 htonl(MPTCP_DATAACK_LOW32(mp_tp
->mpt_rcvnxt
));
678 dsn_ack_opt
.mdss_dsn
= mptcp_hton64(dsn_ack_opt
.mdss_dsn
);
679 dsn_ack_opt
.mdss_subflow_seqn
= htonl(
680 dsn_ack_opt
.mdss_subflow_seqn
);
681 dsn_ack_opt
.mdss_data_len
= htons(
682 dsn_ack_opt
.mdss_data_len
);
683 *dss_lenp
= (unsigned int *)(void *)(opt
+ optlen
+
684 offsetof(struct mptcp_dss64_ack32_opt
, mdss_data_len
));
686 memcpy(opt
+ optlen
, &dsn_ack_opt
, sizeof (dsn_ack_opt
));
689 *sseqp
= (u_int32_t
*)(void *)(opt
+ optlen
+
690 offsetof(struct mptcp_dss64_ack32_opt
,
694 if (mptcp_dbg
== MP_VERBOSE_DEBUG_2
) {
695 printf("%s: long DSS = %llx ACK = %llx \n",
697 mptcp_ntoh64(dsn_ack_opt
.mdss_dsn
),
698 mptcp_ntoh64(dsn_ack_opt
.mdss_ack
));
700 tp
->t_mpflags
&= ~TMPF_MPTCP_ACKNOW
;
704 if ((tp
->t_mpflags
& TMPF_SEND_DSN
) &&
706 !(tp
->t_mpflags
& TMPF_MPTCP_ACKNOW
)) {
707 struct mptcp_dsn_opt dsn_opt
;
708 unsigned int len
= sizeof (struct mptcp_dsn_opt
);
716 bzero(&dsn_opt
, sizeof (dsn_opt
));
717 dsn_opt
.mdss_copt
.mdss_kind
= TCPOPT_MULTIPATH
;
718 dsn_opt
.mdss_copt
.mdss_subtype
= MPO_DSS
;
719 dsn_opt
.mdss_copt
.mdss_len
= len
;
720 dsn_opt
.mdss_copt
.mdss_flags
|= MDSS_M
;
724 mptcp_output_getm_dsnmap32(so
, off
, (u_int32_t
)datalen
,
726 &dsn_opt
.mdss_subflow_seqn
, &dsn_opt
.mdss_data_len
,
729 if ((dsn_opt
.mdss_data_len
== 0) ||
730 (dsn_opt
.mdss_dsn
== 0)) {
734 if (tp
->t_mpflags
& TMPF_SEND_DFIN
) {
738 dsn_opt
.mdss_dsn
= htonl(dsn_opt
.mdss_dsn
);
739 dsn_opt
.mdss_subflow_seqn
= htonl(dsn_opt
.mdss_subflow_seqn
);
740 dsn_opt
.mdss_data_len
= htons(dsn_opt
.mdss_data_len
);
741 *dss_lenp
= (unsigned int *)(void *)(opt
+ optlen
+
742 offsetof(struct mptcp_dsn_opt
, mdss_data_len
));
743 memcpy(opt
+ optlen
, &dsn_opt
, sizeof (dsn_opt
));
745 *sseqp
= (u_int32_t
*)(void *)(opt
+ optlen
+
746 offsetof(struct mptcp_dsn_opt
, mdss_subflow_seqn
));
749 if (mptcp_dbg
== MP_VERBOSE_DEBUG_2
) {
750 printf("%s: DSS option. dsn = %x, seq = %x len = %x\n",
752 ntohl(dsn_opt
.mdss_dsn
),
753 ntohl(dsn_opt
.mdss_subflow_seqn
),
754 ntohs(dsn_opt
.mdss_data_len
));
756 tp
->t_mpflags
&= ~TMPF_MPTCP_ACKNOW
;
760 /* 32-bit Data ACK option */
761 if ((tp
->t_mpflags
& TMPF_MPTCP_ACKNOW
) &&
763 !(tp
->t_mpflags
& TMPF_SEND_DSN
) &&
764 !(tp
->t_mpflags
& TMPF_SEND_DFIN
)) {
766 struct mptcp_data_ack_opt dack_opt
;
767 unsigned int len
= 0;
769 len
= sizeof (dack_opt
);
773 bzero(&dack_opt
, len
);
774 dack_opt
.mdss_copt
.mdss_kind
= TCPOPT_MULTIPATH
;
775 dack_opt
.mdss_copt
.mdss_len
= len
;
776 dack_opt
.mdss_copt
.mdss_subtype
= MPO_DSS
;
777 dack_opt
.mdss_copt
.mdss_flags
|= MDSS_A
;
778 MPT_LOCK_SPIN(mp_tp
);
780 htonl(MPTCP_DATAACK_LOW32(mp_tp
->mpt_rcvnxt
));
782 memcpy(opt
+ optlen
, &dack_opt
, len
);
784 VERIFY(optlen
<= MAX_TCPOPTLEN
);
785 tp
->t_mpflags
&= ~TMPF_MPTCP_ACKNOW
;
789 /* 64-bit Data ACK option */
790 if ((tp
->t_mpflags
& TMPF_MPTCP_ACKNOW
) &&
792 !(tp
->t_mpflags
& TMPF_SEND_DSN
) &&
793 !(tp
->t_mpflags
& TMPF_SEND_DFIN
)) {
794 struct mptcp_data_ack64_opt dack_opt
;
795 unsigned int len
= 0;
797 len
= sizeof (dack_opt
);
801 bzero(&dack_opt
, len
);
802 dack_opt
.mdss_copt
.mdss_kind
= TCPOPT_MULTIPATH
;
803 dack_opt
.mdss_copt
.mdss_len
= len
;
804 dack_opt
.mdss_copt
.mdss_subtype
= MPO_DSS
;
805 dack_opt
.mdss_copt
.mdss_flags
|= (MDSS_A
| MDSS_a
);
806 MPT_LOCK_SPIN(mp_tp
);
807 dack_opt
.mdss_ack
= mptcp_hton64(mp_tp
->mpt_rcvnxt
);
809 * The other end should retransmit 64-bit DSN until it
810 * receives a 64-bit ACK.
812 mp_tp
->mpt_flags
&= ~MPTCPF_SND_64BITACK
;
814 memcpy(opt
+ optlen
, &dack_opt
, len
);
816 VERIFY(optlen
<= MAX_TCPOPTLEN
);
817 tp
->t_mpflags
&= ~TMPF_MPTCP_ACKNOW
;
821 /* 32-bit DSS+Data ACK option */
822 if ((tp
->t_mpflags
& TMPF_SEND_DSN
) &&
825 (tp
->t_mpflags
& TMPF_MPTCP_ACKNOW
)) {
826 struct mptcp_dss_ack_opt dss_ack_opt
;
827 unsigned int len
= sizeof (dss_ack_opt
);
834 bzero(&dss_ack_opt
, sizeof (dss_ack_opt
));
835 dss_ack_opt
.mdss_copt
.mdss_kind
= TCPOPT_MULTIPATH
;
836 dss_ack_opt
.mdss_copt
.mdss_len
= len
;
837 dss_ack_opt
.mdss_copt
.mdss_subtype
= MPO_DSS
;
838 dss_ack_opt
.mdss_copt
.mdss_flags
|= MDSS_A
| MDSS_M
;
839 MPT_LOCK_SPIN(mp_tp
);
840 dss_ack_opt
.mdss_ack
=
841 htonl(MPTCP_DATAACK_LOW32(mp_tp
->mpt_rcvnxt
));
846 mptcp_output_getm_dsnmap32(so
, off
, (u_int32_t
)datalen
,
847 &dss_ack_opt
.mdss_dsn
,
848 &dss_ack_opt
.mdss_subflow_seqn
,
849 &dss_ack_opt
.mdss_data_len
,
852 if ((dss_ack_opt
.mdss_data_len
== 0) ||
853 (dss_ack_opt
.mdss_dsn
== 0)) {
857 if (tp
->t_mpflags
& TMPF_SEND_DFIN
) {
861 dss_ack_opt
.mdss_dsn
= htonl(dss_ack_opt
.mdss_dsn
);
862 dss_ack_opt
.mdss_subflow_seqn
=
863 htonl(dss_ack_opt
.mdss_subflow_seqn
);
864 dss_ack_opt
.mdss_data_len
= htons(dss_ack_opt
.mdss_data_len
);
865 *dss_lenp
= (unsigned int *)(void *)(opt
+ optlen
+
866 offsetof(struct mptcp_dss_ack_opt
, mdss_data_len
));
867 memcpy(opt
+ optlen
, &dss_ack_opt
, sizeof (dss_ack_opt
));
869 *sseqp
= (u_int32_t
*)(void *)(opt
+ optlen
+
870 offsetof(struct mptcp_dss_ack_opt
,
876 if (optlen
> MAX_TCPOPTLEN
)
877 panic("optlen too large");
878 tp
->t_mpflags
&= ~TMPF_MPTCP_ACKNOW
;
882 /* 32-bit DSS + 64-bit DACK option */
883 if ((tp
->t_mpflags
& TMPF_SEND_DSN
) &&
886 (tp
->t_mpflags
& TMPF_MPTCP_ACKNOW
)) {
887 struct mptcp_dss32_ack64_opt dss_ack_opt
;
888 unsigned int len
= sizeof (dss_ack_opt
);
895 bzero(&dss_ack_opt
, sizeof (dss_ack_opt
));
896 dss_ack_opt
.mdss_copt
.mdss_kind
= TCPOPT_MULTIPATH
;
897 dss_ack_opt
.mdss_copt
.mdss_len
= len
;
898 dss_ack_opt
.mdss_copt
.mdss_subtype
= MPO_DSS
;
899 dss_ack_opt
.mdss_copt
.mdss_flags
|= MDSS_M
| MDSS_A
| MDSS_a
;
900 MPT_LOCK_SPIN(mp_tp
);
901 dss_ack_opt
.mdss_ack
=
902 mptcp_hton64(mp_tp
->mpt_rcvnxt
);
907 mptcp_output_getm_dsnmap32(so
, off
, (u_int32_t
)datalen
,
908 &dss_ack_opt
.mdss_dsn
, &dss_ack_opt
.mdss_subflow_seqn
,
909 &dss_ack_opt
.mdss_data_len
, dss_valp
);
911 if ((dss_ack_opt
.mdss_data_len
== 0) ||
912 (dss_ack_opt
.mdss_dsn
== 0)) {
916 if (tp
->t_mpflags
& TMPF_SEND_DFIN
) {
920 dss_ack_opt
.mdss_dsn
= htonl(dss_ack_opt
.mdss_dsn
);
921 dss_ack_opt
.mdss_subflow_seqn
=
922 htonl(dss_ack_opt
.mdss_subflow_seqn
);
923 dss_ack_opt
.mdss_data_len
= htons(dss_ack_opt
.mdss_data_len
);
924 *dss_lenp
= (unsigned int *)(void *)(opt
+ optlen
+
925 offsetof(struct mptcp_dss32_ack64_opt
, mdss_data_len
));
926 memcpy(opt
+ optlen
, &dss_ack_opt
, sizeof (dss_ack_opt
));
928 *sseqp
= (u_int32_t
*)(void *)(opt
+ optlen
+
929 offsetof(struct mptcp_dss32_ack64_opt
,
935 if (optlen
> MAX_TCPOPTLEN
)
936 panic("optlen too large");
937 tp
->t_mpflags
&= ~TMPF_MPTCP_ACKNOW
;
941 if (tp
->t_mpflags
& TMPF_SEND_DFIN
) {
942 struct mptcp_dss_ack_opt dss_ack_opt
;
943 unsigned int len
= sizeof (struct mptcp_dss_ack_opt
);
950 bzero(&dss_ack_opt
, sizeof (dss_ack_opt
));
954 * Data FIN occupies one sequence space.
955 * Don't send it if it has been Acked.
957 if (((mp_tp
->mpt_sndnxt
+ 1) != mp_tp
->mpt_sndmax
) ||
958 (mp_tp
->mpt_snduna
== mp_tp
->mpt_sndmax
)) {
960 if (mptcp_dbg
== MP_VERBOSE_DEBUG_2
)
961 printf("%s: Fin state %d %llu %llu\n", __func__
,
962 mp_tp
->mpt_state
, mp_tp
->mpt_sndnxt
,
967 dss_ack_opt
.mdss_copt
.mdss_kind
= TCPOPT_MULTIPATH
;
968 dss_ack_opt
.mdss_copt
.mdss_len
= len
;
969 dss_ack_opt
.mdss_copt
.mdss_subtype
= MPO_DSS
;
970 dss_ack_opt
.mdss_copt
.mdss_flags
|= MDSS_A
| MDSS_M
| MDSS_F
;
971 dss_ack_opt
.mdss_ack
=
972 htonl(MPTCP_DATAACK_LOW32(mp_tp
->mpt_rcvnxt
));
973 dss_ack_opt
.mdss_dsn
=
974 htonl(MPTCP_DATASEQ_LOW32(mp_tp
->mpt_sndnxt
));
976 dss_ack_opt
.mdss_subflow_seqn
= 0;
977 dss_ack_opt
.mdss_data_len
= 1;
978 dss_ack_opt
.mdss_data_len
= htons(dss_ack_opt
.mdss_data_len
);
979 memcpy(opt
+ optlen
, &dss_ack_opt
, sizeof (dss_ack_opt
));
981 *dss_valp
= mp_tp
->mpt_sndnxt
;
982 *sseqp
= (u_int32_t
*)(void *)(opt
+ optlen
+
983 offsetof(struct mptcp_dss_ack_opt
,
990 if (TRUE
== *p_mptcp_acknow
) {
991 VERIFY(old_mpt_flags
!= 0);
992 u_int32_t new_mpt_flags
= tp
->t_mpflags
&
993 (TMPF_SND_MPPRIO
| TMPF_SND_REM_ADDR
| TMPF_SND_MPFAIL
);
996 * If none of the above mpflags were acted on by
997 * this routine, reset these flags and set p_mptcp_acknow
999 * XXX The reset value of p_mptcp_acknow can be used
1000 * to communicate tcp_output to NOT send a pure ack without any
1001 * MPTCP options as it will be treated as a dup ack.
1002 * Since the instances of mptcp_setup_opts not acting on
1003 * these options are mostly corner cases and sending a dup
1004 * ack here would only have an impact if the system
1005 * has sent consecutive dup acks before this false one,
1006 * we haven't modified the logic in tcp_output to avoid
1009 if (old_mpt_flags
== new_mpt_flags
) {
1010 tp
->t_mpflags
&= ~(TMPF_SND_MPPRIO
1011 | TMPF_SND_REM_ADDR
| TMPF_SND_MPFAIL
);
1012 *p_mptcp_acknow
= FALSE
;
1020 * MPTCP Options Input Processing
1025 mptcp_valid_mpcapable_common_opt(u_char
*cp
, u_int32_t mptcp_version
)
1027 struct mptcp_mpcapable_opt_common
*rsp
=
1028 (struct mptcp_mpcapable_opt_common
*)cp
;
1030 /* mmco_kind, mmco_len and mmco_subtype are validated before */
1032 /* In future, there can be more than one version supported */
1033 if (rsp
->mmco_version
!= mptcp_version
)
1036 if (!(rsp
->mmco_flags
& MPCAP_PROPOSAL_SBIT
))
1039 if (rsp
->mmco_flags
& (MPCAP_BBIT
| MPCAP_CBIT
| MPCAP_DBIT
|
1040 MPCAP_EBIT
| MPCAP_FBIT
| MPCAP_GBIT
))
1048 mptcp_do_mpcapable_opt(struct tcpcb
*tp
, u_char
*cp
, struct tcphdr
*th
,
1051 struct mptcp_mpcapable_opt_rsp1
*rsp1
= NULL
;
1052 struct mptcp_mpcapable_opt_rsp
*rsp
= NULL
;
1053 struct mptcb
*mp_tp
= tptomptp(tp
);
1055 #define MPTCP_OPT_ERROR_PATH(tp) { \
1056 tp->t_mpflags |= TMPF_RESET; \
1057 tcpstat.tcps_invalid_mpcap++; \
1058 if (tp->t_inpcb->inp_socket != NULL) { \
1059 soevent(tp->t_inpcb->inp_socket, \
1060 SO_FILT_HINT_LOCKED | SO_FILT_HINT_MUSTRST); \
1064 if (mp_tp
== NULL
) {
1065 if (mptcp_dbg
== MP_ERR_DEBUG
)
1066 printf("MPTCP ERROR %s: NULL mpsocket \n", __func__
);
1067 tcpstat
.tcps_invalid_mpcap
++;
1071 /* Validate the kind, len, flags */
1072 if (mptcp_valid_mpcapable_common_opt(cp
, mp_tp
->mpt_version
) != 1) {
1073 tcpstat
.tcps_invalid_mpcap
++;
1077 /* A SYN contains only the MP_CAPABLE option */
1078 if ((th
->th_flags
& (TH_SYN
| TH_ACK
)) == TH_SYN
) {
1079 /* XXX passive side not supported yet */
1081 } else if ((th
->th_flags
& (TH_SYN
| TH_ACK
)) == (TH_SYN
| TH_ACK
)) {
1083 /* A SYN/ACK contains peer's key and flags */
1084 if (optlen
!= sizeof (struct mptcp_mpcapable_opt_rsp
)) {
1086 if (mptcp_dbg
== MP_ERR_DEBUG
) {
1087 printf("%s: SYN_ACK optlen = %d, sizeof mp opt \
1088 = %lu \n", __func__
, optlen
,
1089 sizeof (struct mptcp_mpcapable_opt_rsp
));
1091 tcpstat
.tcps_invalid_mpcap
++;
1096 * If checksum flag is set, enable MPTCP checksum, even if
1097 * it was not negotiated on the first SYN.
1099 if (((struct mptcp_mpcapable_opt_common
*)cp
)->mmco_flags
&
1100 MPCAP_CHECKSUM_CBIT
)
1101 mp_tp
->mpt_flags
|= MPTCPF_CHECKSUM
;
1103 rsp
= (struct mptcp_mpcapable_opt_rsp
*)cp
;
1104 MPT_LOCK_SPIN(mp_tp
);
1105 mp_tp
->mpt_remotekey
= rsp
->mmc_localkey
;
1107 tp
->t_mpflags
|= TMPF_PREESTABLISHED
;
1109 if (mptcp_dbg
> MP_VERBOSE_DEBUG_1
) {
1110 printf("SYN_ACK pre established, optlen = %d, tp \
1111 state = %d sport = %x dport = %x key = %llx \n",
1112 optlen
, tp
->t_state
, th
->th_sport
, th
->th_dport
,
1113 mp_tp
->mpt_remotekey
);
1116 } else if ((th
->th_flags
& TH_ACK
) &&
1117 (tp
->t_mpflags
& TMPF_PREESTABLISHED
)) {
1120 * Verify checksum flag is set, if we initially negotiated
1123 if ((mp_tp
->mpt_flags
& MPTCPF_CHECKSUM
) &&
1124 !(((struct mptcp_mpcapable_opt_common
*)cp
)->mmco_flags
&
1125 MPCAP_CHECKSUM_CBIT
)) {
1126 if (mptcp_dbg
== MP_ERR_DEBUG
) {
1127 printf("%s: checksum negotiation failure \n",
1130 MPTCP_OPT_ERROR_PATH(tp
);
1134 if (!(mp_tp
->mpt_flags
& MPTCPF_CHECKSUM
) &&
1135 (((struct mptcp_mpcapable_opt_common
*)cp
)->mmco_flags
&
1136 MPCAP_CHECKSUM_CBIT
)) {
1137 if (mptcp_dbg
== MP_ERR_DEBUG
) {
1138 printf("%s: checksum negotiation failure 2.\n",
1141 MPTCP_OPT_ERROR_PATH(tp
);
1146 * The ACK of a three way handshake contains peer's key and
1149 if (optlen
!= sizeof (struct mptcp_mpcapable_opt_rsp1
)) {
1151 if (mptcp_dbg
== MP_ERR_DEBUG
) {
1152 printf("%s: ACK optlen = %d , sizeof mp option \
1153 = %lu, state = %d \n",
1156 sizeof (struct mptcp_mpcapable_opt_rsp1
),
1159 MPTCP_OPT_ERROR_PATH(tp
);
1163 rsp1
= (struct mptcp_mpcapable_opt_rsp1
*)cp
;
1164 /* Skipping MPT_LOCK for invariant key */
1165 if (rsp1
->mmc_remotekey
!= *mp_tp
->mpt_localkey
) {
1166 if (mptcp_dbg
== MP_ERR_DEBUG
) {
1167 printf("MPTCP ERROR %s: key mismatch locally "
1168 "stored key. rsp = %llx local = %llx \n",
1169 __func__
, rsp1
->mmc_remotekey
,
1170 *mp_tp
->mpt_localkey
);
1172 tp
->t_mpflags
&= ~TMPF_PREESTABLISHED
;
1173 MPTCP_OPT_ERROR_PATH(tp
);
1176 /* We received both keys. Almost an MPTCP connection */
1177 /* Skipping MPT_LOCK for invariant key */
1178 if (mp_tp
->mpt_remotekey
!= rsp1
->mmc_localkey
) {
1179 if (mptcp_dbg
== MP_ERR_DEBUG
) {
1180 printf("MPTCP ERROR %s: keys don't"
1181 " match\n", __func__
);
1183 tp
->t_mpflags
&= ~TMPF_PREESTABLISHED
;
1184 MPTCP_OPT_ERROR_PATH(tp
);
1187 tp
->t_mpflags
&= ~TMPF_PREESTABLISHED
;
1188 tp
->t_mpflags
|= TMPF_MPTCP_RCVD_KEY
;
1189 tp
->t_mpflags
|= TMPF_MPTCP_TRUE
;
1190 tp
->t_inpcb
->inp_socket
->so_flags
|= SOF_MPTCP_TRUE
;
1192 DTRACE_MPTCP2(state__change
, struct mptcb
*, mp_tp
,
1193 uint32_t, 0 /* event */);
1194 mp_tp
->mpt_state
= MPTCPS_ESTABLISHED
;
1196 if (mptcp_dbg
>= MP_VERBOSE_DEBUG_2
) {
1197 printf("MPTCP SUCCESS %s: rem key = %llx local \
1199 __func__
, mp_tp
->mpt_remotekey
,
1200 *mp_tp
->mpt_localkey
);
1211 mptcp_do_mpjoin_opt(struct tcpcb
*tp
, u_char
*cp
, struct tcphdr
*th
, int optlen
)
1213 #define MPTCP_JOPT_ERROR_PATH(tp) { \
1214 tp->t_mpflags |= TMPF_RESET; \
1215 tcpstat.tcps_invalid_joins++; \
1216 if (tp->t_inpcb->inp_socket != NULL) { \
1217 soevent(tp->t_inpcb->inp_socket, \
1218 SO_FILT_HINT_LOCKED | SO_FILT_HINT_MUSTRST); \
1222 struct mptcb
*mp_tp
= tptomptp(tp
);
1224 if ((th
->th_flags
& (TH_SYN
| TH_ACK
)) == TH_SYN
) {
1225 /* We won't accept join requests as an active opener */
1226 if (tp
->t_inpcb
->inp_socket
->so_flags
& SOF_MPTCP_CLIENT
) {
1227 MPTCP_JOPT_ERROR_PATH(tp
);
1231 if (optlen
!= sizeof (struct mptcp_mpjoin_opt_req
)) {
1232 if (mptcp_dbg
== MP_ERR_DEBUG
) {
1233 printf("SYN: unexpected optlen = %d, mp option"
1236 sizeof (struct mptcp_mpjoin_opt_req
));
1238 /* send RST and close */
1239 MPTCP_JOPT_ERROR_PATH(tp
);
1242 /* not supported yet */
1245 struct mptcp_mpjoin_opt_req
*join_req
=
1246 (struct mptcp_mpjoin_opt_req
*)cp
;
1247 mp_so
= mptcp_find_mpso(join_req
->mmjo_peer_token
);
1249 if (mptcp_dbg
>= MP_ERR_DEBUG
)
1250 printf("%s: cannot find mp_so token = %x\n",
1251 __func__
, join_req
->mmjo_peer_token
);
1253 MPTCP_JOPT_ERROR_PATH(tp
);
1256 if (tp
->t_mpflags
& TMPF_PREESTABLISHED
) {
1259 mp_so
->ms_remote_addr_id
= join_req
->mmjo_addr_id
;
1260 mp_so
->ms_remote_rand
= join_req
->mmjo_rand
;
1261 tp
->t_mpflags
|= TMPF_PREESTABLISHED
| TMPF_JOINED_FLOW
;
1262 tp
->t_mpflags
|= TMPF_RECVD_JOIN
;
1263 tp
->t_inpcb
->inp_socket
->so_flags
|= SOF_MP_SEC_SUBFLOW
;
1264 if (join_req
->mmjo_subtype
& MPTCP_BACKUP
) {
1265 tp
->t_mpflags
|= TMPF_BACKUP_PATH
;
1268 } else if ((th
->th_flags
& (TH_SYN
| TH_ACK
)) == (TH_SYN
| TH_ACK
)) {
1269 struct mptcp_mpjoin_opt_rsp
*join_rsp
=
1270 (struct mptcp_mpjoin_opt_rsp
*)cp
;
1272 if (optlen
!= sizeof (struct mptcp_mpjoin_opt_rsp
)) {
1273 if (mptcp_dbg
>= MP_ERR_DEBUG
) {
1274 printf("SYN_ACK: unexpected optlen = %d mp "
1275 "option = %lu\n", optlen
,
1276 sizeof (struct mptcp_mpjoin_opt_rsp
));
1278 tp
->t_mpflags
&= ~TMPF_PREESTABLISHED
;
1279 /* send RST and close */
1280 MPTCP_JOPT_ERROR_PATH(tp
);
1284 if (mp_tp
== NULL
) {
1285 if (mptcp_dbg
>= MP_ERR_DEBUG
)
1286 printf("%s: cannot find mp_tp in SYN_ACK\n",
1288 tp
->t_mpflags
&= ~TMPF_PREESTABLISHED
;
1289 /* send RST and close */
1290 MPTCP_JOPT_ERROR_PATH(tp
);
1294 mptcp_set_raddr_rand(tp
->t_local_aid
,
1296 join_rsp
->mmjo_addr_id
, join_rsp
->mmjo_rand
);
1297 error
= mptcp_validate_join_hmac(tp
,
1298 (u_char
*)&join_rsp
->mmjo_mac
, SHA1_TRUNCATED
);
1300 if (mptcp_dbg
>= MP_ERR_DEBUG
) {
1301 printf("%s: SYN_ACK error = %d \n", __func__
,
1304 tp
->t_mpflags
&= ~TMPF_PREESTABLISHED
;
1305 /* send RST and close */
1306 MPTCP_JOPT_ERROR_PATH(tp
);
1309 tp
->t_mpflags
|= TMPF_SENT_JOIN
;
1310 } else if ((th
->th_flags
& TH_ACK
) &&
1311 (tp
->t_mpflags
& TMPF_PREESTABLISHED
)) {
1312 struct mptcp_mpjoin_opt_rsp2
*join_rsp2
=
1313 (struct mptcp_mpjoin_opt_rsp2
*)cp
;
1315 if (optlen
!= sizeof (struct mptcp_mpjoin_opt_rsp2
)) {
1316 if (mptcp_dbg
>= MP_ERR_DEBUG
) {
1317 printf("ACK: unexpected optlen = %d mp option "
1319 sizeof (struct mptcp_mpjoin_opt_rsp2
));
1321 tp
->t_mpflags
&= ~TMPF_PREESTABLISHED
;
1322 /* send RST and close */
1323 MPTCP_JOPT_ERROR_PATH(tp
);
1327 if (mp_tp
== NULL
) {
1328 tp
->t_mpflags
&= ~TMPF_PREESTABLISHED
;
1329 MPTCP_JOPT_ERROR_PATH(tp
);
1333 error
= mptcp_validate_join_hmac(tp
, join_rsp2
->mmjo_mac
,
1336 if (mptcp_dbg
>= MP_ERR_DEBUG
) {
1337 printf("%s: ACK error = %d\n", __func__
,
1340 tp
->t_mpflags
&= ~TMPF_PREESTABLISHED
;
1341 MPTCP_JOPT_ERROR_PATH(tp
);
1344 tp
->t_mpflags
|= TMPF_MPTCP_TRUE
;
1345 tp
->t_mpflags
&= ~TMPF_PREESTABLISHED
;
1346 tp
->t_flags
|= TF_ACKNOW
;
1347 tp
->t_mpflags
|= TMPF_MPTCP_ACKNOW
;
1348 tp
->t_inpcb
->inp_socket
->so_flags
|= SOF_MPTCP_TRUE
;
1349 if (mptcp_dbg
>= MP_ERR_DEBUG
) {
1350 printf("MPTCP SUCCESS %s: join \n", __func__
);
1356 mptcp_validate_join_hmac(struct tcpcb
*tp
, u_char
* hmac
, int mac_len
)
1358 u_char digest
[SHA1_RESULTLEN
] = {0};
1359 struct mptcb
*mp_tp
= NULL
;
1360 mptcp_key_t rem_key
, loc_key
;
1361 u_int32_t rem_rand
, loc_rand
;
1363 mp_tp
= tp
->t_mptcb
;
1367 rem_rand
= loc_rand
= 0;
1370 rem_key
= mp_tp
->mpt_remotekey
;
1371 loc_key
= *mp_tp
->mpt_localkey
;
1374 mptcp_get_rands(tp
->t_local_aid
, mp_tp
, &loc_rand
, &rem_rand
);
1375 if ((rem_rand
== 0) || (loc_rand
== 0))
1378 mptcp_hmac_sha1(rem_key
, loc_key
, rem_rand
, loc_rand
,
1379 digest
, sizeof (digest
));
1381 if (bcmp(digest
, hmac
, mac_len
) == 0)
1382 return (0); /* matches */
1384 printf("%s: remote key %llx local key %llx remote rand %x "
1385 "local rand %x \n", __func__
, rem_key
, loc_key
,
1386 rem_rand
, loc_rand
);
1392 mptcp_do_dss_opt_ack_meat(u_int64_t full_dack
, struct tcpcb
*tp
)
1394 struct mptcb
*mp_tp
= tptomptp(tp
);
1395 int close_notify
= 0;
1401 if (MPTCP_SEQ_LEQ(full_dack
, mp_tp
->mpt_sndmax
) &&
1402 MPTCP_SEQ_GEQ(full_dack
, mp_tp
->mpt_snduna
)) {
1403 mptcp_data_ack_rcvd(mp_tp
, tp
, full_dack
);
1404 if (mp_tp
->mpt_state
> MPTCPS_FIN_WAIT_2
)
1407 mptcp_notify_mpready(tp
->t_inpcb
->inp_socket
);
1409 mptcp_notify_close(tp
->t_inpcb
->inp_socket
);
1410 if (mp_tp
->mpt_flags
& MPTCPF_RCVD_64BITACK
) {
1411 mp_tp
->mpt_flags
&= ~MPTCPF_RCVD_64BITACK
;
1412 mp_tp
->mpt_flags
&= ~MPTCPF_SND_64BITDSN
;
1416 if (mptcp_dbg
== MP_VERBOSE_DEBUG_2
) {
1417 printf("%s: unexpected dack %llx snduna %llx "
1418 "sndmax %llx\n", __func__
, full_dack
,
1419 mp_tp
->mpt_snduna
, mp_tp
->mpt_sndmax
);
1423 if (mptcp_dbg
== MP_VERBOSE_DEBUG_2
) {
1424 printf("%s: full_dack = %llu \n", __func__
, full_dack
);
1429 mptcp_do_dss_opt_meat(u_char
*cp
, struct tcpcb
*tp
)
1431 struct mptcp_dss_copt
*dss_rsp
= (struct mptcp_dss_copt
*)cp
;
1432 u_int64_t full_dack
= 0;
1433 struct mptcb
*mp_tp
= tptomptp(tp
);
1436 #define MPTCP_DSS_OPT_SZ_CHK(len, expected_len) { \
1437 if (len != expected_len) { \
1438 if (mptcp_dbg >= MP_ERR_DEBUG) { \
1439 printf("MPTCP ERROR %s: bad len = %d" \
1440 "dss: %x \n", __func__, \
1442 dss_rsp->mdss_flags); \
1450 if (mp_tp
->mpt_flags
& MPTCPF_CHECKSUM
)
1453 dss_rsp
->mdss_flags
&= (MDSS_A
|MDSS_a
|MDSS_M
|MDSS_m
);
1454 switch (dss_rsp
->mdss_flags
) {
1457 /* 32-bit DSS, No Data ACK */
1458 struct mptcp_dsn_opt
*dss_rsp1
;
1459 dss_rsp1
= (struct mptcp_dsn_opt
*)cp
;
1461 MPTCP_DSS_OPT_SZ_CHK(dss_rsp1
->mdss_copt
.mdss_len
,
1462 sizeof (struct mptcp_dsn_opt
) + csum_len
);
1464 mptcp_update_dss_rcv_state(dss_rsp1
, tp
, 0);
1466 mptcp_update_dss_rcv_state(dss_rsp1
, tp
,
1467 *(uint16_t *)(void *)(cp
+
1468 (dss_rsp1
->mdss_copt
.mdss_len
- csum_len
)));
1473 /* 32-bit Data ACK, no DSS */
1474 struct mptcp_data_ack_opt
*dack_opt
;
1475 dack_opt
= (struct mptcp_data_ack_opt
*)cp
;
1477 MPTCP_DSS_OPT_SZ_CHK(dack_opt
->mdss_copt
.mdss_len
,
1478 sizeof (struct mptcp_data_ack_opt
));
1480 u_int32_t dack
= dack_opt
->mdss_ack
;
1482 MPT_LOCK_SPIN(mp_tp
);
1483 MPTCP_EXTEND_DSN(mp_tp
->mpt_snduna
, dack
, full_dack
);
1485 mptcp_do_dss_opt_ack_meat(full_dack
, tp
);
1488 case (MDSS_M
| MDSS_A
):
1490 /* 32-bit Data ACK + 32-bit DSS */
1491 struct mptcp_dss_ack_opt
*dss_ack_rsp
;
1492 dss_ack_rsp
= (struct mptcp_dss_ack_opt
*)cp
;
1494 MPTCP_DSS_OPT_SZ_CHK(dss_ack_rsp
->mdss_copt
.mdss_len
,
1495 sizeof (struct mptcp_dss_ack_opt
) + csum_len
);
1497 u_int32_t dack
= dss_ack_rsp
->mdss_ack
;
1499 MPT_LOCK_SPIN(mp_tp
);
1500 MPTCP_EXTEND_DSN(mp_tp
->mpt_snduna
, dack
, full_dack
);
1502 mptcp_do_dss_opt_ack_meat(full_dack
, tp
);
1504 mptcp_update_rcv_state_f(dss_ack_rsp
, tp
, 0);
1506 mptcp_update_rcv_state_f(dss_ack_rsp
, tp
,
1507 *(uint16_t *)(void *)(cp
+
1508 (dss_ack_rsp
->mdss_copt
.mdss_len
-
1512 case (MDSS_M
| MDSS_m
):
1514 /* 64-bit DSS , No Data ACK */
1515 struct mptcp_dsn64_opt
*dsn64
;
1516 dsn64
= (struct mptcp_dsn64_opt
*)cp
;
1519 MPTCP_DSS_OPT_SZ_CHK(dsn64
->mdss_copt
.mdss_len
,
1520 sizeof (struct mptcp_dsn64_opt
) + csum_len
);
1522 if (mptcp_dbg
== MP_VERBOSE_DEBUG_4
) {
1523 printf("%s: 64-bit M present.\n", __func__
);
1526 MPT_LOCK_SPIN(mp_tp
);
1527 mp_tp
->mpt_flags
|= MPTCPF_SND_64BITACK
;
1530 full_dsn
= mptcp_ntoh64(dsn64
->mdss_dsn
);
1531 NTOHL(dsn64
->mdss_subflow_seqn
);
1532 NTOHS(dsn64
->mdss_data_len
);
1534 mptcp_update_rcv_state_meat(mp_tp
, tp
, full_dsn
,
1535 dsn64
->mdss_subflow_seqn
,
1536 dsn64
->mdss_data_len
,
1539 mptcp_update_rcv_state_meat(mp_tp
, tp
, full_dsn
,
1540 dsn64
->mdss_subflow_seqn
,
1541 dsn64
->mdss_data_len
,
1542 *(uint16_t *)(void *)(cp
+
1543 dsn64
->mdss_copt
.mdss_len
- csum_len
));
1546 case (MDSS_A
| MDSS_a
):
1548 /* 64-bit Data ACK, no DSS */
1549 struct mptcp_data_ack64_opt
*dack64
;
1550 dack64
= (struct mptcp_data_ack64_opt
*)cp
;
1552 MPTCP_DSS_OPT_SZ_CHK(dack64
->mdss_copt
.mdss_len
,
1553 sizeof (struct mptcp_data_ack64_opt
));
1556 if (mptcp_dbg
== MP_VERBOSE_DEBUG_4
) {
1557 printf("%s: 64-bit A present. \n", __func__
);
1560 MPT_LOCK_SPIN(mp_tp
);
1561 mp_tp
->mpt_flags
|= MPTCPF_RCVD_64BITACK
;
1564 full_dack
= mptcp_ntoh64(dack64
->mdss_ack
);
1565 mptcp_do_dss_opt_ack_meat(full_dack
, tp
);
1568 case (MDSS_M
| MDSS_m
| MDSS_A
):
1570 /* 64-bit DSS + 32-bit Data ACK */
1571 struct mptcp_dss64_ack32_opt
*dss_ack_rsp
;
1572 dss_ack_rsp
= (struct mptcp_dss64_ack32_opt
*)cp
;
1574 MPTCP_DSS_OPT_SZ_CHK(dss_ack_rsp
->mdss_copt
.mdss_len
,
1575 sizeof (struct mptcp_dss64_ack32_opt
) + csum_len
);
1577 if (mptcp_dbg
== MP_VERBOSE_DEBUG_4
) {
1578 printf("%s: 64-bit M and 32-bit A present.\n",
1582 u_int32_t dack
= dss_ack_rsp
->mdss_ack
;
1584 MPT_LOCK_SPIN(mp_tp
);
1585 mp_tp
->mpt_flags
|= MPTCPF_SND_64BITACK
;
1586 MPTCP_EXTEND_DSN(mp_tp
->mpt_snduna
, dack
, full_dack
);
1588 mptcp_do_dss_opt_ack_meat(full_dack
, tp
);
1590 mptcp_update_rcv_state_g(dss_ack_rsp
, tp
, 0);
1592 mptcp_update_rcv_state_g(dss_ack_rsp
, tp
,
1593 *(uint16_t *)(void *)(cp
+
1594 dss_ack_rsp
->mdss_copt
.mdss_len
-
1598 case (MDSS_M
| MDSS_A
| MDSS_a
):
1600 /* 32-bit DSS + 64-bit Data ACK */
1601 struct mptcp_dss32_ack64_opt
*dss32_ack64_opt
;
1602 dss32_ack64_opt
= (struct mptcp_dss32_ack64_opt
*)cp
;
1605 MPTCP_DSS_OPT_SZ_CHK(
1606 dss32_ack64_opt
->mdss_copt
.mdss_len
,
1607 sizeof (struct mptcp_dss32_ack64_opt
) + csum_len
);
1609 if (mptcp_dbg
== MP_VERBOSE_DEBUG_4
) {
1610 printf("%s: 32-bit M and 64-bit A present.\n",
1613 full_dack
= mptcp_ntoh64(dss32_ack64_opt
->mdss_ack
);
1614 mptcp_do_dss_opt_ack_meat(full_dack
, tp
);
1615 NTOHL(dss32_ack64_opt
->mdss_dsn
);
1616 MPT_LOCK_SPIN(mp_tp
);
1617 mp_tp
->mpt_flags
|= MPTCPF_RCVD_64BITACK
;
1618 MPTCP_EXTEND_DSN(mp_tp
->mpt_rcvnxt
,
1619 dss32_ack64_opt
->mdss_dsn
, full_dsn
);
1621 NTOHL(dss32_ack64_opt
->mdss_subflow_seqn
);
1622 NTOHS(dss32_ack64_opt
->mdss_data_len
);
1624 mptcp_update_rcv_state_meat(mp_tp
, tp
, full_dsn
,
1625 dss32_ack64_opt
->mdss_subflow_seqn
,
1626 dss32_ack64_opt
->mdss_data_len
, 0);
1628 mptcp_update_rcv_state_meat(mp_tp
, tp
, full_dsn
,
1629 dss32_ack64_opt
->mdss_subflow_seqn
,
1630 dss32_ack64_opt
->mdss_data_len
,
1631 *(uint16_t *)(void *)(cp
+
1632 dss32_ack64_opt
->mdss_copt
.mdss_len
-
1636 case (MDSS_M
| MDSS_m
| MDSS_A
| MDSS_a
):
1638 /* 64-bit DSS + 64-bit Data ACK */
1639 struct mptcp_dss64_ack64_opt
*dss64_ack64
;
1640 dss64_ack64
= (struct mptcp_dss64_ack64_opt
*)cp
;
1643 MPTCP_DSS_OPT_SZ_CHK(dss64_ack64
->mdss_copt
.mdss_len
,
1644 sizeof (struct mptcp_dss64_ack64_opt
) + csum_len
);
1646 if (mptcp_dbg
== MP_VERBOSE_DEBUG_4
) {
1647 printf("%s: 64-bit M and 64-bit A present.\n",
1650 MPT_LOCK_SPIN(mp_tp
);
1651 mp_tp
->mpt_flags
|= MPTCPF_RCVD_64BITACK
;
1652 mp_tp
->mpt_flags
|= MPTCPF_SND_64BITACK
;
1654 full_dsn
= mptcp_ntoh64(dss64_ack64
->mdss_dsn
);
1655 full_dack
= mptcp_ntoh64(dss64_ack64
->mdss_dsn
);
1656 mptcp_do_dss_opt_ack_meat(full_dack
, tp
);
1657 NTOHL(dss64_ack64
->mdss_subflow_seqn
);
1658 NTOHS(dss64_ack64
->mdss_data_len
);
1660 mptcp_update_rcv_state_meat(mp_tp
, tp
, full_dsn
,
1661 dss64_ack64
->mdss_subflow_seqn
,
1662 dss64_ack64
->mdss_data_len
, 0);
1664 mptcp_update_rcv_state_meat(mp_tp
, tp
, full_dsn
,
1665 dss64_ack64
->mdss_subflow_seqn
,
1666 dss64_ack64
->mdss_data_len
,
1667 *(uint16_t *)(void *)(cp
+
1668 dss64_ack64
->mdss_copt
.mdss_len
-
1673 if (mptcp_dbg
>= MP_ERR_DEBUG
) {
1674 printf("MPTCP ERROR %s: File bug, DSS flags = %x\n",
1675 __func__
, dss_rsp
->mdss_flags
);
1683 mptcp_do_fin_opt(struct tcpcb
*tp
)
1685 struct mptcb
*mp_tp
= (struct mptcb
*)tp
->t_mptcb
;
1687 if (!(tp
->t_mpflags
& TMPF_RECV_DFIN
)) {
1688 if (mp_tp
!= NULL
) {
1690 mptcp_close_fsm(mp_tp
, MPCE_RECV_DATA_FIN
);
1693 if (tp
->t_inpcb
->inp_socket
!= NULL
) {
1694 soevent(tp
->t_inpcb
->inp_socket
,
1695 SO_FILT_HINT_LOCKED
|
1696 SO_FILT_HINT_MPCANTRCVMORE
);
1700 tp
->t_mpflags
|= TMPF_RECV_DFIN
;
1703 tp
->t_mpflags
|= TMPF_MPTCP_ACKNOW
;
1705 * Since this is a data level FIN, TCP needs to be explicitly told
1706 * to send back an ACK on which the Data ACK is piggybacked.
1708 tp
->t_flags
|= TF_ACKNOW
;
1712 mptcp_do_dss_opt(struct tcpcb
*tp
, u_char
*cp
, struct tcphdr
*th
, int optlen
)
1714 #pragma unused(th, optlen)
1715 struct mptcb
*mp_tp
= (struct mptcb
*)tp
->t_mptcb
;
1720 /* We may get Data ACKs just during fallback, so don't ignore those */
1721 if ((tp
->t_mpflags
& TMPF_MPTCP_TRUE
) ||
1722 (tp
->t_mpflags
& TMPF_TCP_FALLBACK
)) {
1723 struct mptcp_dss_copt
*dss_rsp
= (struct mptcp_dss_copt
*)cp
;
1725 if (dss_rsp
->mdss_subtype
== MPO_DSS
) {
1726 if (mptcp_dbg
> MP_VERBOSE_DEBUG_4
) {
1727 printf("%s: DSS option received: %d ",
1728 __func__
, dss_rsp
->mdss_flags
);
1730 if (dss_rsp
->mdss_flags
& MDSS_F
) {
1731 if (mptcp_dbg
>= MP_VERBOSE_DEBUG_1
)
1732 printf("%s: received FIN\n", __func__
);
1733 mptcp_do_fin_opt(tp
);
1736 mptcp_do_dss_opt_meat(cp
, tp
);
1742 mptcp_do_fastclose_opt(struct tcpcb
*tp
, u_char
*cp
, struct tcphdr
*th
)
1744 struct mptcb
*mp_tp
= NULL
;
1745 struct mptcp_fastclose_opt
*fc_opt
= (struct mptcp_fastclose_opt
*)cp
;
1747 if (th
->th_flags
!= TH_ACK
)
1750 if (mptcp_dbg
> MP_VERBOSE_DEBUG_2
)
1751 printf("%s: received \n", __func__
);
1753 if (fc_opt
->mfast_len
!= sizeof (struct mptcp_fastclose_opt
)) {
1754 tcpstat
.tcps_invalid_opt
++;
1758 mp_tp
= (struct mptcb
*)tp
->t_mptcb
;
1762 if (fc_opt
->mfast_key
!= mptcp_get_localkey(mp_tp
)) {
1763 tcpstat
.tcps_invalid_opt
++;
1768 * fastclose could make us more vulnerable to attacks, hence
1769 * accept only those that are at the next expected sequence number.
1771 if (th
->th_seq
!= tp
->rcv_nxt
) {
1772 tcpstat
.tcps_invalid_opt
++;
1777 if (mp_tp
->mpt_state
!= MPTCPS_FASTCLOSE_WAIT
) {
1778 mp_tp
->mpt_state
= MPTCPS_FASTCLOSE_WAIT
;
1779 DTRACE_MPTCP2(state__change
, struct mptcb
*, mp_tp
,
1780 uint32_t, 0 /* event */);
1781 mptcp_start_timer(mp_tp
, MPTT_FASTCLOSE
);
1785 /* Reset this flow */
1786 tp
->t_mpflags
|= TMPF_RESET
;
1788 if (tp
->t_inpcb
->inp_socket
!= NULL
) {
1789 soevent(tp
->t_inpcb
->inp_socket
,
1790 SO_FILT_HINT_LOCKED
| SO_FILT_HINT_MUSTRST
);
1796 mptcp_do_mpfail_opt(struct tcpcb
*tp
, u_char
*cp
, struct tcphdr
*th
)
1798 struct mptcb
*mp_tp
= NULL
;
1799 struct mptcp_mpfail_opt
*fail_opt
= (struct mptcp_mpfail_opt
*)cp
;
1800 u_int32_t mdss_subflow_seqn
= 0;
1804 * mpfail could make us more vulnerable to attacks. Hence accept
1805 * only those that are the next expected sequence number.
1807 if (th
->th_seq
!= tp
->rcv_nxt
) {
1808 tcpstat
.tcps_invalid_opt
++;
1812 /* A packet without RST, must atleast have the ACK bit set */
1813 if ((th
->th_flags
!= TH_ACK
) && (th
->th_flags
!= TH_RST
))
1816 if (fail_opt
->mfail_len
!= sizeof (struct mptcp_mpfail_opt
))
1819 mp_tp
= (struct mptcb
*)tp
->t_mptcb
;
1823 mp_tp
->mpt_flags
|= MPTCPF_RECVD_MPFAIL
;
1824 mp_tp
->mpt_dsn_at_csum_fail
= mptcp_hton64(fail_opt
->mfail_dsn
);
1826 error
= mptcp_get_map_for_dsn(tp
->t_inpcb
->inp_socket
,
1827 mp_tp
->mpt_dsn_at_csum_fail
, &mdss_subflow_seqn
);
1829 mp_tp
->mpt_ssn_at_csum_fail
= mdss_subflow_seqn
;
1832 mptcp_notify_mpfail(tp
->t_inpcb
->inp_socket
);
1836 tcp_do_mptcp_options(struct tcpcb
*tp
, u_char
*cp
, struct tcphdr
*th
,
1837 struct tcpopt
*to
, int optlen
)
1841 /* All MPTCP options have atleast 4 bytes */
1845 mptcp_subtype
= (cp
[2] >> 4);
1847 switch (mptcp_subtype
) {
1849 mptcp_do_mpcapable_opt(tp
, cp
, th
, optlen
);
1852 mptcp_do_mpjoin_opt(tp
, cp
, th
, optlen
);
1855 mptcp_do_dss_opt(tp
, cp
, th
, optlen
);
1858 mptcp_do_fastclose_opt(tp
, cp
, th
);
1861 mptcp_do_mpfail_opt(tp
, cp
, th
);
1863 case MPO_ADD_ADDR
: /* fall through */
1864 case MPO_REMOVE_ADDR
: /* fall through */
1866 to
->to_flags
|= TOF_MPTCP
;
1869 printf("%s: type = %d\n", __func__
, mptcp_subtype
);
1876 * MPTCP ADD_ADDR and REMOVE_ADDR options
1880 * ADD_ADDR is only placeholder code - not sent on wire
1881 * The ADD_ADDR option is not sent on wire because of security issues
1882 * around connection hijacking.
1885 mptcp_send_addaddr_opt(struct tcpcb
*tp
, struct mptcp_addaddr_opt
*opt
)
1888 opt
->ma_kind
= TCPOPT_MULTIPATH
;
1889 opt
->ma_len
= sizeof (struct mptcp_addaddr_opt
);
1890 opt
->ma_subtype
= MPO_ADD_ADDR
;
1891 opt
->ma_addr_id
= tp
->t_local_aid
;
1893 struct inpcb
*inp
= tp
->t_inpcb
;
1894 if (inp
->inp_vflag
== AF_INET
) {
1895 opt
->ma_ipver
= MA_IPVer_V4
;
1896 bcopy((char *)&sin
->sin_addr
.s_addr
, (char *)opt
+ opt
->ma_len
,
1897 sizeof (in_addr_t
));
1898 opt
->ma_len
+= sizeof (in_addr_t
);
1899 } else if (inp
->inp_vflag
== AF_INET6
) {
1900 opt
->ma_ipver
= MA_IPVer_V6
;
1901 bcopy((char *)&sin6
->sin6_addr
, (char *)opt
+ opt
->ma_len
,
1902 sizeof (struct in6_addr
));
1903 opt
->ma_len
+= sizeof (struct in6_addr
);
1906 if (tp
->t_mp_port
) {
1913 /* REMOVE_ADDR option is sent when a source address goes away */
1915 mptcp_send_remaddr_opt(struct tcpcb
*tp
, struct mptcp_remaddr_opt
*opt
)
1917 if (mptcp_dbg
>= MP_ERR_DEBUG
)
1918 printf("%s: local id %d remove id %d \n", __func__
,
1919 tp
->t_local_aid
, tp
->t_rem_aid
);
1921 bzero(opt
, sizeof (*opt
));
1922 opt
->mr_kind
= TCPOPT_MULTIPATH
;
1923 opt
->mr_len
= sizeof (*opt
);
1924 opt
->mr_subtype
= MPO_REMOVE_ADDR
;
1925 opt
->mr_addr_id
= tp
->t_rem_aid
;
1926 tp
->t_mpflags
&= ~TMPF_SND_REM_ADDR
;
1930 * MPTCP MP_PRIO option
1935 * Current implementation drops incoming MP_PRIO option and this code is
1936 * just a placeholder. The option is dropped because only the mobile client can
1937 * decide which of the subflows is preferred (usually wifi is preferred
1941 mptcp_do_mpprio_opt(struct tcpcb
*tp
, u_char
*cp
, struct tcphdr
*th
,
1945 struct mptcp_mpprio_opt
*mpprio
= (struct mptcp_mpprio_opt
*)cp
;
1947 if ((tp
== NULL
) || !(tp
->t_mpflags
& TMPF_MPTCP_TRUE
))
1950 if ((mpprio
->mpprio_len
!= sizeof (struct mptcp_mpprio_addr_opt
)) &&
1951 (mpprio
->mpprio_len
!= sizeof (struct mptcp_mpprio_opt
)))
1956 /* We send MP_PRIO option based on the values set by the SIOCSCONNORDER ioctl */
1958 mptcp_snd_mpprio(struct tcpcb
*tp
, u_char
*cp
, int optlen
)
1960 struct mptcp_mpprio_addr_opt mpprio
;
1962 if (tp
->t_state
!= TCPS_ESTABLISHED
) {
1963 tp
->t_mpflags
&= ~TMPF_SND_MPPRIO
;
1967 if (mptcp_mpprio_enable
!= 1) {
1968 tp
->t_mpflags
&= ~TMPF_SND_MPPRIO
;
1972 if ((MAX_TCPOPTLEN
- optlen
) <
1973 (int)sizeof (mpprio
))
1976 bzero(&mpprio
, sizeof (mpprio
));
1977 mpprio
.mpprio_kind
= TCPOPT_MULTIPATH
;
1978 mpprio
.mpprio_len
= sizeof (mpprio
);
1979 mpprio
.mpprio_subtype
= MPO_PRIO
;
1980 if (tp
->t_mpflags
& TMPF_BACKUP_PATH
)
1981 mpprio
.mpprio_flags
|= MPTCP_MPPRIO_BKP
;
1982 mpprio
.mpprio_addrid
= tp
->t_local_aid
;
1983 memcpy(cp
+ optlen
, &mpprio
, sizeof (mpprio
));
1984 optlen
+= sizeof (mpprio
);
1985 tp
->t_mpflags
&= ~TMPF_SND_MPPRIO
;
1986 if (mptcp_dbg
>= MP_ERR_DEBUG
)
1987 printf("%s: aid = %d \n", __func__
, tp
->t_local_aid
);