Author: lidl
Date: Thu Oct 13 03:10:04 2016
New Revision: 307173
URL: https://svnweb.freebsd.org/changeset/base/307173

Log:
  MFC r306458: Properly preserve ip_tos bits for IPv4 packets
  
  Restructure code slightly to save ip_tos bits earlier.  Fix the bug
  where the ip_tos field is zeroed out before assigning to the iptos
  variable. Restore the ip_tos and ip_ver fields only if they have
  been zeroed during the pseudo-header checksum calculation.

Modified:
  stable/11/sys/netinet/tcp_input.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/netinet/tcp_input.c
==============================================================================
--- stable/11/sys/netinet/tcp_input.c   Thu Oct 13 03:08:32 2016        
(r307172)
+++ stable/11/sys/netinet/tcp_input.c   Thu Oct 13 03:10:04 2016        
(r307173)
@@ -601,7 +601,7 @@ tcp_input(struct mbuf **mp, int *offp, i
 #ifdef TCP_SIGNATURE
        uint8_t sig_checked = 0;
 #endif
-       uint8_t iptos = 0;
+       uint8_t iptos;
        struct m_tag *fwd_tag = NULL;
 #ifdef INET6
        struct ip6_hdr *ip6 = NULL;
@@ -673,6 +673,7 @@ tcp_input(struct mbuf **mp, int *offp, i
                        /* XXX stat */
                        goto drop;
                }
+               iptos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
        }
 #endif
 #if defined(INET) && defined(INET6)
@@ -699,6 +700,7 @@ tcp_input(struct mbuf **mp, int *offp, i
                th = (struct tcphdr *)((caddr_t)ip + off0);
                tlen = ntohs(ip->ip_len) - off0;
 
+               iptos = ip->ip_tos;
                if (m->m_pkthdr.csum_flags & CSUM_DATA_VALID) {
                        if (m->m_pkthdr.csum_flags & CSUM_PSEUDO_HDR)
                                th->th_sum = m->m_pkthdr.csum_data;
@@ -719,29 +721,20 @@ tcp_input(struct mbuf **mp, int *offp, i
                        ipov->ih_len = htons(tlen);
                        th->th_sum = in_cksum(m, len);
                        /* Reset length for SDT probes. */
-                       ip->ip_len = htons(tlen + off0);
+                       ip->ip_len = htons(len);
+                       /* Reset TOS bits */
+                       ip->ip_tos = iptos;
+                       /* Re-initialization for later version check */
+                       ip->ip_v = IPVERSION;
                }
 
                if (th->th_sum) {
                        TCPSTAT_INC(tcps_rcvbadsum);
                        goto drop;
                }
-               /* Re-initialization for later version check */
-               ip->ip_v = IPVERSION;
        }
 #endif /* INET */
 
-#ifdef INET6
-       if (isipv6)
-               iptos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
-#endif
-#if defined(INET) && defined(INET6)
-       else
-#endif
-#ifdef INET
-               iptos = ip->ip_tos;
-#endif
-
        /*
         * Check that TCP offset makes sense,
         * pull out TCP options and adjust length.              XXX
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to