]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/netinet/tcp_subr.c
xnu-4903.221.2.tar.gz
[apple/xnu.git] / bsd / netinet / tcp_subr.c
index 363dea99f8e46a9333ab2a3acac05999c9315914..1c9b36da3c9fe1f865af4187177cae0803389f0c 100644 (file)
@@ -90,6 +90,7 @@
 #include <net/route.h>
 #include <net/if.h>
 #include <net/content_filter.h>
+#include <net/ntstat.h>
 
 #define        tcp_minmssoverload fring
 #define        _IP_VHL
@@ -638,21 +639,11 @@ tcp_init(struct protosw *pp, struct domain *dp)
         * maximum allowed receive and send socket buffer size.
         */
        if (nmbclusters > 30720) {
-               #if CONFIG_EMBEDDED
-                       tcp_autorcvbuf_max = 2 * 1024 * 1024;
-                       tcp_autosndbuf_max = 2 * 1024 * 1024;
-               #else
-                       tcp_autorcvbuf_max = 1024 * 1024;
-                       tcp_autosndbuf_max = 1024 * 1024;
-               #endif /* CONFIG_EMBEDDED */
+               tcp_autorcvbuf_max = 2 * 1024 * 1024;
+               tcp_autosndbuf_max = 2 * 1024 * 1024;
+
                SYSCTL_SKMEM_UPDATE_FIELD(tcp.autorcvbufmax, tcp_autorcvbuf_max);
                SYSCTL_SKMEM_UPDATE_FIELD(tcp.autosndbufmax, tcp_autosndbuf_max);
-
-               /*
-                * Receive buffer max for cellular interfaces supporting
-                * Carrier Aggregation is higher
-                */
-               tcp_autorcvbuf_max_ca = 2 * 1024 * 1024;
        }
 }
 
@@ -925,7 +916,7 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m,
 #endif
 
 #if NECP
-       necp_mark_packet_from_socket(m, tp ? tp->t_inpcb : NULL, 0, 0);
+       necp_mark_packet_from_socket(m, tp ? tp->t_inpcb : NULL, 0, 0, 0);
 #endif /* NECP */
 
 #if IPSEC
@@ -950,6 +941,8 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m,
                m->m_pkthdr.pkt_flowid = tp->t_inpcb->inp_flowhash;
                m->m_pkthdr.pkt_flags |= (PKTF_FLOW_ID | PKTF_FLOW_LOCALSRC | PKTF_FLOW_ADV);
                m->m_pkthdr.pkt_proto = IPPROTO_TCP;
+               m->m_pkthdr.tx_tcp_pid = tp->t_inpcb->inp_socket->last_pid;
+               m->m_pkthdr.tx_tcp_e_pid = tp->t_inpcb->inp_socket->e_pid;
        }
 
 #if INET6
@@ -2138,17 +2131,29 @@ tcp_pcblist_n SYSCTL_HANDLER_ARGS
 
 
 SYSCTL_PROC(_net_inet_tcp, OID_AUTO, pcblist_n,
-           CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED, 0, 0,
-           tcp_pcblist_n, "S,xtcpcb_n", "List of active TCP connections");
+       CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED, 0, 0,
+       tcp_pcblist_n, "S,xtcpcb_n", "List of active TCP connections");
+
+static int
+tcp_progress_indicators SYSCTL_HANDLER_ARGS
+{
+#pragma unused(oidp, arg1, arg2)
+
+       return (ntstat_tcp_progress_indicators(req));
+}
+
+SYSCTL_PROC(_net_inet_tcp, OID_AUTO, progress,
+       CTLTYPE_STRUCT | CTLFLAG_RW | CTLFLAG_LOCKED | CTLFLAG_ANYBODY, 0, 0,
+       tcp_progress_indicators, "S", "Various items that indicate the current state of progress on the link");
 
 
 __private_extern__ void
 tcp_get_ports_used(uint32_t ifindex, int protocol, uint32_t flags,
     bitstr_t *bitfield)
 {
-               inpcb_get_ports_used(ifindex, protocol, flags, bitfield,
-                   &tcbinfo);
-       }
+       inpcb_get_ports_used(ifindex, protocol, flags, bitfield,
+           &tcbinfo);
+}
 
 __private_extern__ uint32_t
 tcp_count_opportunistic(unsigned int ifindex, u_int32_t flags)
@@ -2409,7 +2414,7 @@ tcp6_ctlinput(int cmd, struct sockaddr *sa, void *d, __unused struct ifnet *ifp)
        }
 
        if (m == NULL ||
-           (m->m_pkthdr.len < (int32_t) (off + offsetof(struct tcphdr, th_seq))))
+           (m->m_pkthdr.len < (int32_t) (off + offsetof(struct tcphdr, th_ack))))
                return;
 
        th = (struct tcphdr *)(void *)mtodo(m, off);
@@ -2873,15 +2878,15 @@ tcp_rtlookup6(struct inpcb *inp, unsigned int input_ifscope)
                if (inp->inp_last_outifp == NULL) {
                        inp->inp_last_outifp = rt->rt_ifp;
                }
-       }
 
-       /* Note if the peer is local */
-       if (rt != NULL && !(rt->rt_ifp->if_flags & IFF_POINTOPOINT) &&
-               (IN6_IS_ADDR_LOOPBACK(&inp->in6p_faddr) ||
-               IN6_IS_ADDR_LINKLOCAL(&inp->in6p_faddr) ||
-               rt->rt_gateway->sa_family == AF_LINK ||
-               in6_localaddr(&inp->in6p_faddr))) {
-               tp->t_flags |= TF_LOCAL;
+               /* Note if the peer is local */
+               if (!(rt->rt_ifp->if_flags & IFF_POINTOPOINT) &&
+                    (IN6_IS_ADDR_LOOPBACK(&inp->in6p_faddr) ||
+                    IN6_IS_ADDR_LINKLOCAL(&inp->in6p_faddr) ||
+                    rt->rt_gateway->sa_family == AF_LINK ||
+                    in6_localaddr(&inp->in6p_faddr))) {
+                       tp->t_flags |= TF_LOCAL;
+               }
        }
 
        /*
@@ -3311,15 +3316,25 @@ calculate_tcp_clock(void)
  * defined by the constant tcp_autorcvbuf_max.
  */
 void
-tcp_set_max_rwinscale(struct tcpcb *tp, struct socket *so,
-    u_int32_t rcvbuf_max)
+tcp_set_max_rwinscale(struct tcpcb *tp, struct socket *so, struct ifnet *ifp)
 {
-       u_int32_t maxsockbufsize;
+       uint32_t maxsockbufsize;
+       uint32_t rcvbuf_max;
+
        if (!tcp_do_rfc1323) {
                tp->request_r_scale = 0;
                return;
        }
 
+       /*
+        * When we start a connection and don't know about the interface, set
+        * the scaling factor simply to the max - we can always announce less.
+        */
+       if (!ifp || (IFNET_IS_CELLULAR(ifp) && (ifp->if_eflags & IFEF_3CA)))
+               rcvbuf_max = (tcp_autorcvbuf_max << 1);
+       else
+               rcvbuf_max = tcp_autorcvbuf_max;
+
        tp->request_r_scale = max(tcp_win_scale, tp->request_r_scale);
        maxsockbufsize = ((so->so_rcv.sb_flags & SB_USRSIZE) != 0) ?
                so->so_rcv.sb_hiwat : rcvbuf_max;
@@ -3332,14 +3347,20 @@ tcp_set_max_rwinscale(struct tcpcb *tp, struct socket *so,
 }
 
 int
-tcp_notsent_lowat_check(struct socket *so) {
+tcp_notsent_lowat_check(struct socket *so)
+{
        struct inpcb *inp = sotoinpcb(so);
        struct tcpcb *tp = NULL;
        int notsent = 0;
+
        if (inp != NULL) {
                tp = intotcpcb(inp);
        }
 
+       if (tp == NULL) {
+               return (0);
+       }
+
        notsent = so->so_snd.sb_cc -
                (tp->snd_nxt - tp->snd_una);