diff options
Diffstat (limited to 'sys/netinet/tcp_subr.c')
-rw-r--r-- | sys/netinet/tcp_subr.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index ee62998..d4c552f 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -39,6 +39,7 @@ #include "opt_ipsec.h" #include "opt_tcpdebug.h" +#include <stddef.h> #include <sys/param.h> #include <sys/systm.h> #include <sys/callout.h> @@ -93,6 +94,8 @@ #include <netinet6/ipsec.h> #endif /*IPSEC*/ +#include <machine/in_cksum.h> + int tcp_mssdflt = TCP_MSS; SYSCTL_INT(_net_inet_tcp, TCPCTL_MSSDFLT, mssdflt, CTLFLAG_RW, &tcp_mssdflt , 0, "Default TCP Maximum Segment Size"); @@ -242,17 +245,19 @@ tcp_template(tp) ip6->ip6_plen = sizeof(struct tcphdr); ip6->ip6_src = inp->in6p_laddr; ip6->ip6_dst = inp->in6p_faddr; + n->tt_t.th_sum = 0; } else #endif { - register struct ipovly *ipov; - - ipov = (struct ipovly *)n->tt_ipgen; - bzero(ipov->ih_x1, sizeof(ipov->ih_x1)); - ipov->ih_pr = IPPROTO_TCP; - ipov->ih_len = htons(sizeof (struct tcpiphdr) - sizeof (struct ip)); - ipov->ih_src = inp->inp_laddr; - ipov->ih_dst = inp->inp_faddr; + struct ip *ip = (struct ip *)n->tt_ipgen; + + bzero(ip, sizeof(struct ip)); /* XXX overkill? */ + ip->ip_vhl = IP_VHL_BORING; + ip->ip_p = IPPROTO_TCP; + ip->ip_src = inp->inp_laddr; + ip->ip_dst = inp->inp_faddr; + n->tt_t.th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, + htons(sizeof(struct tcphdr) + IPPROTO_TCP)); } n->tt_t.th_sport = inp->inp_lport; n->tt_t.th_dport = inp->inp_fport; @@ -262,7 +267,6 @@ tcp_template(tp) n->tt_t.th_off = 5; n->tt_t.th_flags = 0; n->tt_t.th_win = 0; - n->tt_t.th_sum = 0; n->tt_t.th_urp = 0; return (n); } @@ -296,7 +300,6 @@ tcp_respond(tp, ipgen, th, m, ack, seq, flags) struct route *ro = 0; struct route sro; struct ip *ip; - struct ipovly *ipov; struct tcphdr *nth; #ifdef INET6 struct route_in6 *ro6 = 0; @@ -311,7 +314,6 @@ tcp_respond(tp, ipgen, th, m, ack, seq, flags) ip6 = ipgen; #endif /* INET6 */ ip = ipgen; - ipov = ipgen; if (tp) { if (!(flags & TH_RST)) { @@ -358,7 +360,6 @@ tcp_respond(tp, ipgen, th, m, ack, seq, flags) { bcopy((caddr_t)ip, mtod(m, caddr_t), sizeof(struct ip)); ip = mtod(m, struct ip *); - ipov = mtod(m, struct ipovly *); nth = (struct tcphdr *)(ip + 1); } bcopy((caddr_t)th, (caddr_t)nth, sizeof(struct tcphdr)); @@ -400,8 +401,9 @@ tcp_respond(tp, ipgen, th, m, ack, seq, flags) } else #endif { - ipov->ih_len = htons((u_short)(sizeof (struct tcphdr) + tlen)); tlen += sizeof (struct tcpiphdr); + ip->ip_len = tlen; + ip->ip_ttl = ip_defttl; } m->m_len = tlen; m->m_pkthdr.len = tlen; @@ -416,7 +418,6 @@ tcp_respond(tp, ipgen, th, m, ack, seq, flags) else nth->th_win = htons((u_short)win); nth->th_urp = 0; - nth->th_sum = 0; #ifdef INET6 if (isipv6) { nth->th_sum = in6_cksum(m, IPPROTO_TCP, @@ -429,14 +430,10 @@ tcp_respond(tp, ipgen, th, m, ack, seq, flags) } else #endif /* INET6 */ { - bzero(ipov->ih_x1, sizeof(ipov->ih_x1)); - nth->th_sum = in_cksum(m, tlen); -#ifdef INET6 - /* Re-initialization for later version check */ - ip->ip_vhl = IP_MAKE_VHL(IPVERSION, 0); -#endif /* INET6 */ - ip->ip_len = tlen; - ip->ip_ttl = ip_defttl; + nth->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, + htons((u_short)(tlen - sizeof(struct ip) + ip->ip_p))); + m->m_pkthdr.csum_flags = CSUM_TCP; + m->m_pkthdr.csum_data = offsetof(struct tcphdr, th_sum); } #ifdef TCPDEBUG if (tp == NULL || (tp->t_inpcb->inp_socket->so_options & SO_DEBUG)) |