From owner-svn-src-head@FreeBSD.ORG Tue Oct 23 08:33:15 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5A33E2E9; Tue, 23 Oct 2012 08:33:15 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6E6B18FC08; Tue, 23 Oct 2012 08:33:14 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q9N8XEQ5020947; Tue, 23 Oct 2012 08:33:14 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q9N8XEas020937; Tue, 23 Oct 2012 08:33:14 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201210230833.q9N8XEas020937@svn.freebsd.org> From: Gleb Smirnoff Date: Tue, 23 Oct 2012 08:33:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r241923 - in head/sys: netinet netipsec X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Oct 2012 08:33:15 -0000 Author: glebius Date: Tue Oct 23 08:33:13 2012 New Revision: 241923 URL: http://svn.freebsd.org/changeset/base/241923 Log: Do not reduce ip_len by size of IP header in the ip_input() before passing a packet to protocol input routines. For several protocols this mean that now protocol needs to do subtraction itself, and for another half this means that we do not need to add header length back to the packet. Make ip_stripoptions() to adjust ip_len, since now we enter this function with a packet header whose ip_len does represent length of entire packet, not payload only. Modified: head/sys/netinet/igmp.c head/sys/netinet/ip_icmp.c head/sys/netinet/ip_input.c head/sys/netinet/ip_options.c head/sys/netinet/raw_ip.c head/sys/netinet/sctp_input.c head/sys/netinet/tcp_input.c head/sys/netinet/udp_usrreq.c head/sys/netipsec/xform_ah.c Modified: head/sys/netinet/igmp.c ============================================================================== --- head/sys/netinet/igmp.c Tue Oct 23 08:22:01 2012 (r241922) +++ head/sys/netinet/igmp.c Tue Oct 23 08:33:13 2012 (r241923) @@ -1442,7 +1442,7 @@ igmp_input(struct mbuf *m, int off) ip = mtod(m, struct ip *); iphlen = off; - igmplen = ntohs(ip->ip_len); + igmplen = ntohs(ip->ip_len) - off; /* * Validate lengths. Modified: head/sys/netinet/ip_icmp.c ============================================================================== --- head/sys/netinet/ip_icmp.c Tue Oct 23 08:22:01 2012 (r241922) +++ head/sys/netinet/ip_icmp.c Tue Oct 23 08:33:13 2012 (r241923) @@ -359,7 +359,7 @@ icmp_input(struct mbuf *m, int off) struct ip *ip = mtod(m, struct ip *); struct sockaddr_in icmpsrc, icmpdst, icmpgw; int hlen = off; - int icmplen = ntohs(ip->ip_len); + int icmplen = ntohs(ip->ip_len) - off; int i, code; void (*ctlfunc)(int, struct sockaddr *, void *); int fibnum; @@ -592,8 +592,6 @@ icmp_input(struct mbuf *m, int off) } ifa_free(&ia->ia_ifa); reflect: - /* Since ip_input() deducts this. */ - ip->ip_len = htons(ntohs(ip->ip_len) + hlen); ICMPSTAT_INC(icps_reflect); ICMPSTAT_INC(icps_outhist[icp->icmp_type]); icmp_reflect(m); Modified: head/sys/netinet/ip_input.c ============================================================================== --- head/sys/netinet/ip_input.c Tue Oct 23 08:22:01 2012 (r241922) +++ head/sys/netinet/ip_input.c Tue Oct 23 08:33:13 2012 (r241923) @@ -731,12 +731,6 @@ ours: ip_len = ntohs(ip->ip_len); } - /* - * Further protocols expect the packet length to be w/o the - * IP header. - */ - ip->ip_len = htons(ip_len - hlen); - #ifdef IPSEC /* * enforce IPsec policy checking if we are seeing last header. Modified: head/sys/netinet/ip_options.c ============================================================================== --- head/sys/netinet/ip_options.c Tue Oct 23 08:22:01 2012 (r241922) +++ head/sys/netinet/ip_options.c Tue Oct 23 08:33:13 2012 (r241923) @@ -470,7 +470,7 @@ ip_stripoptions(struct mbuf *m) m->m_len -= olen; if (m->m_flags & M_PKTHDR) m->m_pkthdr.len -= olen; - ip->ip_v = IPVERSION; + ip->ip_len = htons(ntohs(ip->ip_len) - olen); ip->ip_hl = sizeof(struct ip) >> 2; } Modified: head/sys/netinet/raw_ip.c ============================================================================== --- head/sys/netinet/raw_ip.c Tue Oct 23 08:22:01 2012 (r241922) +++ head/sys/netinet/raw_ip.c Tue Oct 23 08:33:13 2012 (r241923) @@ -287,12 +287,9 @@ rip_input(struct mbuf *m, int off) ifp = m->m_pkthdr.rcvif; /* - * Add back the IP header length which was - * removed by ip_input(). Raw sockets do - * not modify the packet except for some - * byte order swaps. + * Applications on raw sockets expect host byte order. */ - ip->ip_len = ntohs(ip->ip_len) + off; + ip->ip_len = ntohs(ip->ip_len); ip->ip_off = ntohs(ip->ip_off); hash = INP_PCBHASH_RAW(proto, ip->ip_src.s_addr, @@ -506,7 +503,8 @@ rip_output(struct mbuf *m, struct socket ip->ip_id = ip_newid(); /* - * Applications on raw sockets expect host byte order. + * Applications on raw sockets pass us packets + * in host byte order. */ ip->ip_len = htons(ip->ip_len); ip->ip_off = htons(ip->ip_off); Modified: head/sys/netinet/sctp_input.c ============================================================================== --- head/sys/netinet/sctp_input.c Tue Oct 23 08:22:01 2012 (r241922) +++ head/sys/netinet/sctp_input.c Tue Oct 23 08:33:13 2012 (r241923) @@ -6038,7 +6038,7 @@ sctp_input_with_port(struct mbuf *i_pak, dst.sin_len = sizeof(struct sockaddr_in); dst.sin_port = sh->dest_port; dst.sin_addr = ip->ip_dst; - length = ntohs(ip->ip_len) + iphlen; + length = ntohs(ip->ip_len); /* Validate mbuf chain length with IP payload length. */ if (SCTP_HEADER_LEN(m) != length) { SCTPDBG(SCTP_DEBUG_INPUT1, Modified: head/sys/netinet/tcp_input.c ============================================================================== --- head/sys/netinet/tcp_input.c Tue Oct 23 08:22:01 2012 (r241922) +++ head/sys/netinet/tcp_input.c Tue Oct 23 08:33:13 2012 (r241923) @@ -641,7 +641,7 @@ tcp_input(struct mbuf *m, int off0) } ip = mtod(m, struct ip *); th = (struct tcphdr *)((caddr_t)ip + off0); - tlen = ntohs(ip->ip_len); + tlen = ntohs(ip->ip_len) - off0; if (m->m_pkthdr.csum_flags & CSUM_DATA_VALID) { if (m->m_pkthdr.csum_flags & CSUM_PSEUDO_HDR) Modified: head/sys/netinet/udp_usrreq.c ============================================================================== --- head/sys/netinet/udp_usrreq.c Tue Oct 23 08:22:01 2012 (r241922) +++ head/sys/netinet/udp_usrreq.c Tue Oct 23 08:33:13 2012 (r241923) @@ -392,7 +392,7 @@ udp_input(struct mbuf *m, int off) * reflect UDP length, drop. */ len = ntohs((u_short)uh->uh_ulen); - ip_len = ntohs(ip->ip_len); + ip_len = ntohs(ip->ip_len) - iphlen; if (ip_len != len) { if (len > ip_len || len < sizeof(struct udphdr)) { UDPSTAT_INC(udps_badlen); @@ -601,7 +601,6 @@ udp_input(struct mbuf *m, int off) if (badport_bandlim(BANDLIM_ICMP_UNREACH) < 0) goto badunlocked; *ip = save_ip; - ip->ip_len = htons(ip_len + iphlen); icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0); return; } Modified: head/sys/netipsec/xform_ah.c ============================================================================== --- head/sys/netipsec/xform_ah.c Tue Oct 23 08:22:01 2012 (r241922) +++ head/sys/netipsec/xform_ah.c Tue Oct 23 08:33:13 2012 (r241923) @@ -305,9 +305,6 @@ ah_massage_headers(struct mbuf **m0, int ip->ip_ttl = 0; ip->ip_sum = 0; - if (!out) - ip->ip_len = htons(ntohs(ip->ip_len) + skip); - if (alg == CRYPTO_MD5_KPDK || alg == CRYPTO_SHA1_KPDK) ip->ip_off &= htons(IP_DF); else