From: henning Date: Fri, 18 Apr 2014 15:13:01 +0000 (+0000) Subject: pf_send_tcp: ask the stack to do the cksum instead of doing it manually X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=674c6722fd99bcab1a0b18f93e169f91bf0f521f;p=openbsd pf_send_tcp: ask the stack to do the cksum instead of doing it manually ok benno lteo naddy (back in january) --- diff --git a/sys/net/pf.c b/sys/net/pf.c index c2a1fa554dc..662957d30de 100644 --- a/sys/net/pf.c +++ b/sys/net/pf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf.c,v 1.871 2014/04/14 09:06:42 mpi Exp $ */ +/* $OpenBSD: pf.c,v 1.872 2014/04/18 15:13:01 henning Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -2377,15 +2377,21 @@ pf_send_tcp(const struct pf_rule *r, sa_family_t af, m->m_data += max_linkhdr; m->m_pkthdr.len = m->m_len = len; m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.csum_flags |= M_TCP_CSUM_OUT; bzero(m->m_data, len); switch (af) { #ifdef INET case AF_INET: h = mtod(m, struct ip *); - - /* IP header fields included in the TCP checksum */ h->ip_p = IPPROTO_TCP; h->ip_len = htons(tlen); + h->ip_v = 4; + h->ip_hl = sizeof(*h) >> 2; + h->ip_tos = IPTOS_LOWDELAY; + h->ip_len = htons(len); + h->ip_off = htons(ip_mtudisc ? IP_DF : 0); + h->ip_ttl = ttl ? ttl : ip_defttl; + h->ip_sum = 0; h->ip_src.s_addr = saddr->v4.s_addr; h->ip_dst.s_addr = daddr->v4.s_addr; @@ -2395,10 +2401,10 @@ pf_send_tcp(const struct pf_rule *r, sa_family_t af, #ifdef INET6 case AF_INET6: h6 = mtod(m, struct ip6_hdr *); - - /* IP header fields included in the TCP checksum */ h6->ip6_nxt = IPPROTO_TCP; h6->ip6_plen = htons(tlen); + h6->ip6_vfc |= IPV6_VERSION; + h6->ip6_hlim = IPV6_DEFHLIM; memcpy(&h6->ip6_src, &saddr->v6, sizeof(struct in6_addr)); memcpy(&h6->ip6_dst, &daddr->v6, sizeof(struct in6_addr)); @@ -2427,17 +2433,6 @@ pf_send_tcp(const struct pf_rule *r, sa_family_t af, switch (af) { #ifdef INET case AF_INET: - /* TCP checksum */ - th->th_sum = in_cksum(m, len); - - /* Finish the IP header */ - h->ip_v = 4; - h->ip_hl = sizeof(*h) >> 2; - h->ip_tos = IPTOS_LOWDELAY; - h->ip_len = htons(len); - h->ip_off = htons(ip_mtudisc ? IP_DF : 0); - h->ip_ttl = ttl ? ttl : ip_defttl; - h->ip_sum = 0; if (eh == NULL) { ip_output(m, (void *)NULL, (void *)NULL, 0, (void *)NULL, (void *)NULL); @@ -2464,13 +2459,6 @@ pf_send_tcp(const struct pf_rule *r, sa_family_t af, #endif /* INET */ #ifdef INET6 case AF_INET6: - /* TCP checksum */ - th->th_sum = in6_cksum(m, IPPROTO_TCP, - sizeof(struct ip6_hdr), tlen); - - h6->ip6_vfc |= IPV6_VERSION; - h6->ip6_hlim = IPV6_DEFHLIM; - ip6_output(m, NULL, NULL, 0, NULL, NULL, NULL); break; #endif /* INET6 */