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
This commit is contained in:
jlemon 2003-02-19 22:18:06 +00:00
parent 6ececd4417
commit 79a1ebfa6f
5 changed files with 69 additions and 80 deletions

View File

@ -674,15 +674,14 @@ tcp_output(struct tcpcb *tp)
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 @@ tcp_output(struct tcpcb *tp)
{
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 @@ tcp_output(struct tcpcb *tp)
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:

View File

@ -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;
struct ip *ip;
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));
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);
}

View File

@ -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,

View File

@ -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;
struct ip *ip;
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));
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);
}

View File

@ -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);