X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/94ff46dc2849db4d43eaaf144872decc522aafb4..HEAD:/bsd/netinet/mptcp.c diff --git a/bsd/netinet/mptcp.c b/bsd/netinet/mptcp.c index 25a51db92..85a8cebc1 100644 --- a/bsd/netinet/mptcp.c +++ b/bsd/netinet/mptcp.c @@ -137,7 +137,6 @@ int mptcp_fail_thresh = 1; SYSCTL_INT(_net_inet_mptcp, OID_AUTO, fail, CTLFLAG_RW | CTLFLAG_LOCKED, &mptcp_fail_thresh, 0, "Failover threshold"); - /* * MPTCP subflows have TCP keepalives set to ON. Set a conservative keeptime * as carrier networks mostly have a 30 minute to 60 minute NAT Timeout. @@ -151,13 +150,6 @@ int mptcp_rtthist_rtthresh = 600; SYSCTL_INT(_net_inet_mptcp, OID_AUTO, rtthist_thresh, CTLFLAG_RW | CTLFLAG_LOCKED, &mptcp_rtthist_rtthresh, 0, "Rtt threshold"); -/* - * Use RTO history for sending new data - */ -int mptcp_use_rto = 1; -SYSCTL_INT(_net_inet_mptcp, OID_AUTO, userto, CTLFLAG_RW | CTLFLAG_LOCKED, - &mptcp_use_rto, 0, "Disable RTO for subflow selection"); - int mptcp_rtothresh = 1500; SYSCTL_INT(_net_inet_mptcp, OID_AUTO, rto_thresh, CTLFLAG_RW | CTLFLAG_LOCKED, &mptcp_rtothresh, 0, "RTO threshold"); @@ -173,12 +165,6 @@ uint32_t mptcp_probecnt = 5; SYSCTL_UINT(_net_inet_mptcp, OID_AUTO, probecnt, CTLFLAG_RW | CTLFLAG_LOCKED, &mptcp_probecnt, 0, "Number of probe writes"); -/* - * Static declarations - */ -static uint16_t mptcp_input_csum(struct tcpcb *, struct mbuf *, uint64_t, - uint32_t, uint16_t, uint16_t, uint16_t); - static int mptcp_reass_present(struct socket *mp_so) { @@ -218,7 +204,7 @@ mptcp_reass_present(struct socket *mp_so) m_freem(q->tqe_m); } else { flags = !!(q->tqe_m->m_pkthdr.pkt_flags & PKTF_MPTCP_DFIN); - if (sbappendstream_rcvdemux(mp_so, q->tqe_m, 0, 0)) { + if (sbappendstream_rcvdemux(mp_so, q->tqe_m)) { dowakeup = 1; } } @@ -243,7 +229,7 @@ mptcp_reass(struct socket *mp_so, struct pkthdr *phdr, int *tlenp, struct mbuf * struct tseg_qent *p = NULL; struct tseg_qent *nq; struct tseg_qent *te = NULL; - u_int16_t qlimit; + uint32_t qlimit; /* * Limit the number of segments in the reassembly queue to prevent @@ -252,7 +238,7 @@ mptcp_reass(struct socket *mp_so, struct pkthdr *phdr, int *tlenp, struct mbuf * * queue. Always keep one global queue entry spare to be able to * process the missing segment. */ - qlimit = min(max(100, mp_so->so_rcv.sb_hiwat >> 10), + qlimit = MIN(MAX(100, mp_so->so_rcv.sb_hiwat >> 10), (tcp_autorcvbuf_max >> 10)); if (mb_dsn != mp_tp->mpt_rcvnxt && (mp_tp->mpt_reassqlen + 1) >= qlimit) { @@ -306,7 +292,8 @@ mptcp_reass(struct socket *mp_so, struct pkthdr *phdr, int *tlenp, struct mbuf * */ goto out; } - m_adj(m, i); + VERIFY(i <= INT_MAX); + m_adj(m, (int)i); *tlenp -= i; phdr->mp_dsn += i; } @@ -327,7 +314,9 @@ mptcp_reass(struct socket *mp_so, struct pkthdr *phdr, int *tlenp, struct mbuf * if (i < q->tqe_len) { q->tqe_m->m_pkthdr.mp_dsn += i; q->tqe_len -= i; - m_adj(q->tqe_m, i); + + VERIFY(i <= INT_MAX); + m_adj(q->tqe_m, (int)i); break; } @@ -425,7 +414,7 @@ fallback: * assume degraded flow as this may be the first packet * without DSS, and the subflow state is not updated yet. */ - if (sbappendstream_rcvdemux(mp_so, m, 0, 0)) { + if (sbappendstream_rcvdemux(mp_so, m)) { sorwakeup(mp_so); } @@ -508,7 +497,8 @@ fallback: prev = save = NULL; continue; } else { - m_adj(m, -todrop); + VERIFY(todrop <= INT_MAX); + m_adj(m, (int)-todrop); mb_datalen -= todrop; m->m_pkthdr.mp_rlen -= todrop; } @@ -539,10 +529,12 @@ fallback: prev = save = NULL; continue; } else { - m_adj(m, (mp_tp->mpt_rcvnxt - mb_dsn)); + VERIFY((mp_tp->mpt_rcvnxt - mb_dsn) <= INT_MAX); + m_adj(m, (int)(mp_tp->mpt_rcvnxt - mb_dsn)); mb_datalen -= (mp_tp->mpt_rcvnxt - mb_dsn); mb_dsn = mp_tp->mpt_rcvnxt; - m->m_pkthdr.mp_rlen = mb_datalen; + VERIFY(mb_datalen >= 0 && mb_datalen <= USHRT_MAX); + m->m_pkthdr.mp_rlen = (uint16_t)mb_datalen; m->m_pkthdr.mp_dsn = mb_dsn; } } @@ -557,7 +549,7 @@ fallback: mptcp_sbrcv_grow(mp_tp); - if (sbappendstream_rcvdemux(mp_so, m, 0, 0)) { + if (sbappendstream_rcvdemux(mp_so, m)) { wakeup = 1; } @@ -646,9 +638,14 @@ mptcp_output(struct mptses *mpte) int error = 0; mp_so = mptetoso(mpte); - socket_lock_assert_owned(mp_so); mp_tp = mpte->mpte_mptcb; + socket_lock_assert_owned(mp_so); + + if (mp_so->so_flags & SOF_DEFUNCT) { + return 0; + } + VERIFY(!(mpte->mpte_mppcb->mpp_flags & MPP_WUPCALL)); mpte->mpte_mppcb->mpp_flags |= MPP_WUPCALL; @@ -678,8 +675,7 @@ mptcp_output(struct mptses *mpte) * 2. send buffer is filled to 7/8th with data (so we actually * have data to make use of it); */ - if (tcp_do_autosendbuf == 1 && - (mp_so->so_snd.sb_flags & (SB_AUTOSIZE | SB_TRIM)) == SB_AUTOSIZE && + if ((mp_so->so_snd.sb_flags & (SB_AUTOSIZE | SB_TRIM)) == SB_AUTOSIZE && tcp_cansbgrow(&mp_so->so_snd)) { if ((mp_tp->mpt_sndwnd / 4 * 5) >= mp_so->so_snd.sb_hiwat && mp_so->so_snd.sb_cc >= (mp_so->so_snd.sb_hiwat / 8 * 7)) { @@ -796,7 +792,7 @@ mptcp_subflow_is_slow(struct mptses *mpte, struct mptsub *mpts) struct tcpcb *tp = sototcpcb(mpts->mpts_socket); int fail_thresh = mptcp_fail_thresh; - if (mpte->mpte_svctype == MPTCP_SVCTYPE_HANDOVER) { + if (mpte->mpte_svctype == MPTCP_SVCTYPE_HANDOVER || mpte->mpte_svctype == MPTCP_SVCTYPE_PURE_HANDOVER) { fail_thresh *= 2; } @@ -912,7 +908,9 @@ mptcp_get_subflow(struct mptses *mpte, struct mptsub **preferred) * Second Step: Among best and second_best. Choose the one that is * most appropriate for this particular service-type. */ - if (mpte->mpte_svctype == MPTCP_SVCTYPE_HANDOVER) { + if (mpte->mpte_svctype == MPTCP_SVCTYPE_PURE_HANDOVER) { + return mptcp_return_subflow(best); + } else if (mpte->mpte_svctype == MPTCP_SVCTYPE_HANDOVER) { /* * Only handover if Symptoms tells us to do so. */ @@ -1219,39 +1217,16 @@ mptcp_input_preproc(struct tcpcb *tp, struct mbuf *m, struct tcphdr *th, return 0; } -/* - * MPTCP Checksum support - * The checksum is calculated whenever the MPTCP DSS option is included - * in the TCP packet. The checksum includes the sum of the MPTCP psuedo - * header and the actual data indicated by the length specified in the - * DSS option. - */ - -int -mptcp_validate_csum(struct tcpcb *tp, struct mbuf *m, uint64_t dsn, - uint32_t sseq, uint16_t dlen, uint16_t csum, uint16_t dfin) -{ - uint16_t mptcp_csum; - - mptcp_csum = mptcp_input_csum(tp, m, dsn, sseq, dlen, csum, dfin); - if (mptcp_csum) { - tp->t_mpflags |= TMPF_SND_MPFAIL; - mptcp_notify_mpfail(tp->t_inpcb->inp_socket); - m_freem(m); - tcpstat.tcps_mp_badcsum++; - return -1; - } - return 0; -} - static uint16_t mptcp_input_csum(struct tcpcb *tp, struct mbuf *m, uint64_t dsn, uint32_t sseq, - uint16_t dlen, uint16_t csum, uint16_t dfin) + uint16_t dlen, uint16_t csum, int dfin) { struct mptcb *mp_tp = tptomptp(tp); - uint16_t real_len = dlen - dfin; + int real_len = dlen - dfin; uint32_t sum = 0; + VERIFY(real_len >= 0); + if (mp_tp == NULL) { return 0; } @@ -1278,15 +1253,39 @@ mptcp_input_csum(struct tcpcb *tp, struct mbuf *m, uint64_t dsn, uint32_t sseq, sum += in_pseudo64(htonll(dsn), htonl(sseq), htons(dlen) + csum); ADDCARRY(sum); + DTRACE_MPTCP3(checksum__result, struct tcpcb *, tp, struct mbuf *, m, uint32_t, sum); - mptcplog((LOG_DEBUG, "%s: sum = %x \n", __func__, sum), - MPTCP_RECEIVER_DBG, MPTCP_LOGLVL_VERBOSE); return ~sum & 0xffff; } -uint32_t +/* + * MPTCP Checksum support + * The checksum is calculated whenever the MPTCP DSS option is included + * in the TCP packet. The checksum includes the sum of the MPTCP psuedo + * header and the actual data indicated by the length specified in the + * DSS option. + */ + +int +mptcp_validate_csum(struct tcpcb *tp, struct mbuf *m, uint64_t dsn, + uint32_t sseq, uint16_t dlen, uint16_t csum, int dfin) +{ + uint16_t mptcp_csum; + + mptcp_csum = mptcp_input_csum(tp, m, dsn, sseq, dlen, csum, dfin); + if (mptcp_csum) { + tp->t_mpflags |= TMPF_SND_MPFAIL; + mptcp_notify_mpfail(tp->t_inpcb->inp_socket); + m_freem(m); + tcpstat.tcps_mp_badcsum++; + return -1; + } + return 0; +} + +uint16_t mptcp_output_csum(struct mbuf *m, uint64_t dss_val, uint32_t sseq, uint16_t dlen) { uint32_t sum = 0; @@ -1306,7 +1305,7 @@ mptcp_output_csum(struct mbuf *m, uint64_t dss_val, uint32_t sseq, uint16_t dlen mptcplog((LOG_DEBUG, "%s: sum = %x \n", __func__, sum), MPTCP_SENDER_DBG, MPTCP_LOGLVL_VERBOSE); - return sum; + return (uint16_t)sum; } /* @@ -1366,16 +1365,6 @@ mptcp_handle_deferred_upcalls(struct mppcb *mpp, uint32_t flag) } } -void -mptcp_ask_for_nat64(struct ifnet *ifp) -{ - in6_post_msg(ifp, KEV_INET6_REQUEST_NAT64_PREFIX, NULL, NULL); - - os_log_info(mptcp_log_handle, - "%s: asked for NAT64-prefix on %s\n", __func__, - ifp->if_name); -} - static void mptcp_reset_itfinfo(struct mpt_itf_info *info) { @@ -1394,8 +1383,9 @@ mptcp_session_necp_cb(void *handle, int action, uint32_t interface_index, struct mptses *mpte = mptompte(mp); struct socket *mp_so; struct mptcb *mp_tp; - int locked = 0; uint32_t i, ifindex; + struct ifnet *ifp; + int locked = 0; ifindex = interface_index; VERIFY(ifindex != IFSCOPE_NONE); @@ -1421,8 +1411,13 @@ mptcp_session_necp_cb(void *handle, int action, uint32_t interface_index, mp_tp = mpte->mpte_mptcb; - os_log_info(mptcp_log_handle, "%s - %lx: action: %u ifindex %u usecount %u mpt_flags %#x state %u v4 %u v6 %u nat64 %u power %u\n", + ifnet_head_lock_shared(); + ifp = ifindex2ifnet[ifindex]; + ifnet_head_done(); + + os_log(mptcp_log_handle, "%s - %lx: action: %u ifindex %u delegated to %u usecount %u mpt_flags %#x state %u v4 %u v6 %u nat64 %u power %u\n", __func__, (unsigned long)VM_KERNEL_ADDRPERM(mpte), action, ifindex, + ifp && ifp->if_delegated.ifp ? ifp->if_delegated.ifp->if_index : IFSCOPE_NONE, mp->mpp_socket->so_usecount, mp_tp->mpt_flags, mp_tp->mpt_state, has_v4, has_v6, has_nat64, low_power); @@ -1455,11 +1450,6 @@ mptcp_session_necp_cb(void *handle, int action, uint32_t interface_index, action == NECP_CLIENT_CBACTION_INITIAL) { int found_slot = 0, slot_index = -1; struct sockaddr *dst; - struct ifnet *ifp; - - ifnet_head_lock_shared(); - ifp = ifindex2ifnet[ifindex]; - ifnet_head_done(); if (ifp == NULL) { goto out; @@ -1519,14 +1509,14 @@ mptcp_session_necp_cb(void *handle, int action, uint32_t interface_index, } dst = mptcp_get_session_dst(mpte, has_v6, has_v4); - if (dst && (dst->sa_family == AF_INET || dst->sa_family == 0) && + if (dst && dst->sa_family == AF_INET && has_v6 && !has_nat64 && !has_v4) { if (found_slot) { + mpte->mpte_itfinfo[slot_index].ifindex = ifindex; mpte->mpte_itfinfo[slot_index].has_v4_conn = has_v4; mpte->mpte_itfinfo[slot_index].has_v6_conn = has_v6; mpte->mpte_itfinfo[slot_index].has_nat64_conn = has_nat64; } - mptcp_ask_for_nat64(ifp); goto out; }