summaryrefslogtreecommitdiffstats
path: root/sys/netinet
diff options
context:
space:
mode:
authorjlemon <jlemon@FreeBSD.org>2003-02-19 22:18:06 +0000
committerjlemon <jlemon@FreeBSD.org>2003-02-19 22:18:06 +0000
commit79a1ebfa6f53d733dc4775c2031ff3d16e53b75c (patch)
tree8563c7bec384ef864223fce476020ed3fb16ccd9 /sys/netinet
parent6ececd4417e9635c5b55583283f2640c2fb05a6b (diff)
downloadFreeBSD-src-79a1ebfa6f53d733dc4775c2031ff3d16e53b75c.zip
FreeBSD-src-79a1ebfa6f53d733dc4775c2031ff3d16e53b75c.tar.gz
Convert tcp_fillheaders(tp, ...) -> tcpip_fillheaders(inp, ...) so the
routine does not require a tcpcb to operate. Since we no longer keep template mbufs around, move pseudo checksum out of this routine, and merge it with the length update. Sponsored by: DARPA, NAI Labs
Diffstat (limited to 'sys/netinet')
-rw-r--r--sys/netinet/tcp_output.c13
-rw-r--r--sys/netinet/tcp_subr.c67
-rw-r--r--sys/netinet/tcp_timer.c2
-rw-r--r--sys/netinet/tcp_timewait.c67
-rw-r--r--sys/netinet/tcp_var.h4
5 files changed, 71 insertions, 82 deletions
diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c
index a917ed3..2cb6acf 100644
--- a/sys/netinet/tcp_output.c
+++ b/sys/netinet/tcp_output.c
@@ -674,15 +674,14 @@ send:
if (isipv6) {
ip6 = mtod(m, struct ip6_hdr *);
th = (struct tcphdr *)(ip6 + 1);
- tcp_fillheaders(tp, ip6, th);
+ tcpip_fillheaders(tp->t_inpcb, ip6, th);
} else
#endif /* INET6 */
{
ip = mtod(m, struct ip *);
ipov = (struct ipovly *)ip;
th = (struct tcphdr *)(ip + 1);
- /* this picks up the pseudo header (w/o the length) */
- tcp_fillheaders(tp, ip, th);
+ tcpip_fillheaders(tp->t_inpcb, ip, th);
}
/*
@@ -772,9 +771,8 @@ send:
{
m->m_pkthdr.csum_flags = CSUM_TCP;
m->m_pkthdr.csum_data = offsetof(struct tcphdr, th_sum);
- if (len + optlen)
- th->th_sum = in_addword(th->th_sum,
- htons((u_short)(optlen + len)));
+ th->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr,
+ htons(sizeof(struct tcphdr) + IPPROTO_TCP + len + optlen));
/* IP version must be set here for ipv4/ipv6 checking later */
KASSERT(ip->ip_v == IPVERSION,
@@ -894,10 +892,7 @@ send:
tp->t_inpcb->in6p_route.ro_rt ?
tp->t_inpcb->in6p_route.ro_rt->rt_ifp
: NULL);
- else
#endif /* INET6 */
- ip->ip_ttl = tp->t_inpcb->inp_ip_ttl; /* XXX */
- ip->ip_tos = tp->t_inpcb->inp_ip_tos; /* XXX */
/*
* See if we should do MTU discovery. We do it only if the following
* are true:
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index 844f279..3c43acb 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -267,13 +267,12 @@ tcp_init()
* of the tcpcb each time to conserve mbufs.
*/
void
-tcp_fillheaders(tp, ip_ptr, tcp_ptr)
- struct tcpcb *tp;
+tcpip_fillheaders(inp, ip_ptr, tcp_ptr)
+ struct inpcb *inp;
void *ip_ptr;
void *tcp_ptr;
{
- struct inpcb *inp = tp->t_inpcb;
- struct tcphdr *tcp_hdr = (struct tcphdr *)tcp_ptr;
+ struct tcphdr *th = (struct tcphdr *)tcp_ptr;
#ifdef INET6
if ((inp->inp_vflag & INP_IPV6) != 0) {
@@ -288,36 +287,34 @@ tcp_fillheaders(tp, ip_ptr, tcp_ptr)
ip6->ip6_plen = sizeof(struct tcphdr);
ip6->ip6_src = inp->in6p_laddr;
ip6->ip6_dst = inp->in6p_faddr;
- tcp_hdr->th_sum = 0;
} else
#endif
{
- struct ip *ip = (struct ip *) ip_ptr;
-
- ip->ip_v = IPVERSION;
- ip->ip_hl = 5;
- ip->ip_tos = 0;
- ip->ip_len = 0;
- ip->ip_id = 0;
- ip->ip_off = 0;
- ip->ip_ttl = 0;
- ip->ip_sum = 0;
- ip->ip_p = IPPROTO_TCP;
- ip->ip_src = inp->inp_laddr;
- ip->ip_dst = inp->inp_faddr;
- tcp_hdr->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr,
- htons(sizeof(struct tcphdr) + IPPROTO_TCP));
+ struct ip *ip;
+
+ ip = (struct ip *)ip_ptr;
+ ip->ip_v = IPVERSION;
+ ip->ip_hl = 5;
+ ip->ip_tos = inp->inp_ip_tos;
+ ip->ip_len = 0;
+ ip->ip_id = 0;
+ ip->ip_off = 0;
+ ip->ip_ttl = inp->inp_ip_ttl;
+ ip->ip_sum = 0;
+ ip->ip_p = IPPROTO_TCP;
+ ip->ip_src = inp->inp_laddr;
+ ip->ip_dst = inp->inp_faddr;
}
-
- tcp_hdr->th_sport = inp->inp_lport;
- tcp_hdr->th_dport = inp->inp_fport;
- tcp_hdr->th_seq = 0;
- tcp_hdr->th_ack = 0;
- tcp_hdr->th_x2 = 0;
- tcp_hdr->th_off = 5;
- tcp_hdr->th_flags = 0;
- tcp_hdr->th_win = 0;
- tcp_hdr->th_urp = 0;
+ th->th_sport = inp->inp_lport;
+ th->th_dport = inp->inp_fport;
+ th->th_seq = 0;
+ th->th_ack = 0;
+ th->th_x2 = 0;
+ th->th_off = 5;
+ th->th_flags = 0;
+ th->th_win = 0;
+ th->th_urp = 0;
+ th->th_sum = 0; /* in_pseudo() is called later for ipv4 */
}
/*
@@ -326,8 +323,8 @@ tcp_fillheaders(tp, ip_ptr, tcp_ptr)
* use for this function is in keepalives, which use tcp_respond.
*/
struct tcptemp *
-tcp_maketemplate(tp)
- struct tcpcb *tp;
+tcpip_maketemplate(inp)
+ struct inpcb *inp;
{
struct mbuf *m;
struct tcptemp *n;
@@ -338,7 +335,7 @@ tcp_maketemplate(tp)
m->m_len = sizeof(struct tcptemp);
n = mtod(m, struct tcptemp *);
- tcp_fillheaders(tp, (void *)&n->tt_ipgen, (void *)&n->tt_t);
+ tcpip_fillheaders(inp, (void *)&n->tt_ipgen, (void *)&n->tt_t);
return (n);
}
@@ -1505,7 +1502,7 @@ ipsec_hdrsiz_tcp(tp)
th = (struct tcphdr *)(ip6 + 1);
m->m_pkthdr.len = m->m_len =
sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
- tcp_fillheaders(tp, ip6, th);
+ tcpip_fillheaders(inp, ip6, th);
hdrsiz = ipsec6_hdrsiz(m, IPSEC_DIR_OUTBOUND, inp);
} else
#endif /* INET6 */
@@ -1513,7 +1510,7 @@ ipsec_hdrsiz_tcp(tp)
ip = mtod(m, struct ip *);
th = (struct tcphdr *)(ip + 1);
m->m_pkthdr.len = m->m_len = sizeof(struct tcpiphdr);
- tcp_fillheaders(tp, ip, th);
+ tcpip_fillheaders(inp, ip, th);
hdrsiz = ipsec4_hdrsiz(m, IPSEC_DIR_OUTBOUND, inp);
}
diff --git a/sys/netinet/tcp_timer.c b/sys/netinet/tcp_timer.c
index 2cf153b..8a68579 100644
--- a/sys/netinet/tcp_timer.c
+++ b/sys/netinet/tcp_timer.c
@@ -305,7 +305,7 @@ tcp_timer_keep(xtp)
* correspondent TCP to respond.
*/
tcpstat.tcps_keepprobe++;
- t_template = tcp_maketemplate(tp);
+ t_template = tcpip_maketemplate(inp);
if (t_template) {
tcp_respond(tp, t_template->tt_ipgen,
&t_template->tt_t, (struct mbuf *)NULL,
diff --git a/sys/netinet/tcp_timewait.c b/sys/netinet/tcp_timewait.c
index 844f279..3c43acb 100644
--- a/sys/netinet/tcp_timewait.c
+++ b/sys/netinet/tcp_timewait.c
@@ -267,13 +267,12 @@ tcp_init()
* of the tcpcb each time to conserve mbufs.
*/
void
-tcp_fillheaders(tp, ip_ptr, tcp_ptr)
- struct tcpcb *tp;
+tcpip_fillheaders(inp, ip_ptr, tcp_ptr)
+ struct inpcb *inp;
void *ip_ptr;
void *tcp_ptr;
{
- struct inpcb *inp = tp->t_inpcb;
- struct tcphdr *tcp_hdr = (struct tcphdr *)tcp_ptr;
+ struct tcphdr *th = (struct tcphdr *)tcp_ptr;
#ifdef INET6
if ((inp->inp_vflag & INP_IPV6) != 0) {
@@ -288,36 +287,34 @@ tcp_fillheaders(tp, ip_ptr, tcp_ptr)
ip6->ip6_plen = sizeof(struct tcphdr);
ip6->ip6_src = inp->in6p_laddr;
ip6->ip6_dst = inp->in6p_faddr;
- tcp_hdr->th_sum = 0;
} else
#endif
{
- struct ip *ip = (struct ip *) ip_ptr;
-
- ip->ip_v = IPVERSION;
- ip->ip_hl = 5;
- ip->ip_tos = 0;
- ip->ip_len = 0;
- ip->ip_id = 0;
- ip->ip_off = 0;
- ip->ip_ttl = 0;
- ip->ip_sum = 0;
- ip->ip_p = IPPROTO_TCP;
- ip->ip_src = inp->inp_laddr;
- ip->ip_dst = inp->inp_faddr;
- tcp_hdr->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr,
- htons(sizeof(struct tcphdr) + IPPROTO_TCP));
+ struct ip *ip;
+
+ ip = (struct ip *)ip_ptr;
+ ip->ip_v = IPVERSION;
+ ip->ip_hl = 5;
+ ip->ip_tos = inp->inp_ip_tos;
+ ip->ip_len = 0;
+ ip->ip_id = 0;
+ ip->ip_off = 0;
+ ip->ip_ttl = inp->inp_ip_ttl;
+ ip->ip_sum = 0;
+ ip->ip_p = IPPROTO_TCP;
+ ip->ip_src = inp->inp_laddr;
+ ip->ip_dst = inp->inp_faddr;
}
-
- tcp_hdr->th_sport = inp->inp_lport;
- tcp_hdr->th_dport = inp->inp_fport;
- tcp_hdr->th_seq = 0;
- tcp_hdr->th_ack = 0;
- tcp_hdr->th_x2 = 0;
- tcp_hdr->th_off = 5;
- tcp_hdr->th_flags = 0;
- tcp_hdr->th_win = 0;
- tcp_hdr->th_urp = 0;
+ th->th_sport = inp->inp_lport;
+ th->th_dport = inp->inp_fport;
+ th->th_seq = 0;
+ th->th_ack = 0;
+ th->th_x2 = 0;
+ th->th_off = 5;
+ th->th_flags = 0;
+ th->th_win = 0;
+ th->th_urp = 0;
+ th->th_sum = 0; /* in_pseudo() is called later for ipv4 */
}
/*
@@ -326,8 +323,8 @@ tcp_fillheaders(tp, ip_ptr, tcp_ptr)
* use for this function is in keepalives, which use tcp_respond.
*/
struct tcptemp *
-tcp_maketemplate(tp)
- struct tcpcb *tp;
+tcpip_maketemplate(inp)
+ struct inpcb *inp;
{
struct mbuf *m;
struct tcptemp *n;
@@ -338,7 +335,7 @@ tcp_maketemplate(tp)
m->m_len = sizeof(struct tcptemp);
n = mtod(m, struct tcptemp *);
- tcp_fillheaders(tp, (void *)&n->tt_ipgen, (void *)&n->tt_t);
+ tcpip_fillheaders(inp, (void *)&n->tt_ipgen, (void *)&n->tt_t);
return (n);
}
@@ -1505,7 +1502,7 @@ ipsec_hdrsiz_tcp(tp)
th = (struct tcphdr *)(ip6 + 1);
m->m_pkthdr.len = m->m_len =
sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
- tcp_fillheaders(tp, ip6, th);
+ tcpip_fillheaders(inp, ip6, th);
hdrsiz = ipsec6_hdrsiz(m, IPSEC_DIR_OUTBOUND, inp);
} else
#endif /* INET6 */
@@ -1513,7 +1510,7 @@ ipsec_hdrsiz_tcp(tp)
ip = mtod(m, struct ip *);
th = (struct tcphdr *)(ip + 1);
m->m_pkthdr.len = m->m_len = sizeof(struct tcpiphdr);
- tcp_fillheaders(tp, ip, th);
+ tcpip_fillheaders(inp, ip, th);
hdrsiz = ipsec4_hdrsiz(m, IPSEC_DIR_OUTBOUND, inp);
}
diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h
index 6461c34..137b042 100644
--- a/sys/netinet/tcp_var.h
+++ b/sys/netinet/tcp_var.h
@@ -476,8 +476,8 @@ struct rtentry *
void tcp_setpersist(struct tcpcb *);
void tcp_slowtimo(void);
struct tcptemp *
- tcp_maketemplate(struct tcpcb *);
-void tcp_fillheaders(struct tcpcb *, void *, void *);
+ tcpip_maketemplate(struct inpcb *);
+void tcpip_fillheaders(struct inpcb *, void *, void *);
struct tcpcb *
tcp_timers(struct tcpcb *, int);
void tcp_trace(int, int, struct tcpcb *, void *, struct tcphdr *, int);
OpenPOWER on IntegriCloud