diff options
Diffstat (limited to 'slirp/tcp_input.c')
-rw-r--r-- | slirp/tcp_input.c | 133 |
1 files changed, 66 insertions, 67 deletions
diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c index 04f655312..17a9387f0 100644 --- a/slirp/tcp_input.c +++ b/slirp/tcp_input.c @@ -47,7 +47,7 @@ struct socket tcb; -int tcprexmtthresh = 3; +#define TCPREXMTTHRESH 3 struct socket *tcp_last_so = &tcb; tcp_seq tcp_iss; /* tcp initial send seq # */ @@ -79,8 +79,8 @@ tcp_seq tcp_iss; /* tcp initial send seq # */ tp->t_flags |= TF_DELACK; \ (tp)->rcv_nxt += (ti)->ti_len; \ flags = (ti)->ti_flags & TH_FIN; \ - tcpstat.tcps_rcvpack++;\ - tcpstat.tcps_rcvbyte += (ti)->ti_len;\ + STAT(tcpstat.tcps_rcvpack++); \ + STAT(tcpstat.tcps_rcvbyte += (ti)->ti_len); \ if (so->so_emu) { \ if (tcp_emu((so),(m))) sbappend((so), (m)); \ } else \ @@ -99,8 +99,8 @@ tcp_seq tcp_iss; /* tcp initial send seq # */ tp->t_flags |= TF_DELACK; \ (tp)->rcv_nxt += (ti)->ti_len; \ flags = (ti)->ti_flags & TH_FIN; \ - tcpstat.tcps_rcvpack++;\ - tcpstat.tcps_rcvbyte += (ti)->ti_len;\ + STAT(tcpstat.tcps_rcvpack++); \ + STAT(tcpstat.tcps_rcvbyte += (ti)->ti_len); \ if (so->so_emu) { \ if (tcp_emu((so),(m))) sbappend(so, (m)); \ } else \ @@ -112,12 +112,13 @@ tcp_seq tcp_iss; /* tcp initial send seq # */ } \ } #endif +static void tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt, + struct tcpiphdr *ti); +static void tcp_xmit_timer(register struct tcpcb *tp, int rtt); -int -tcp_reass(tp, ti, m) - register struct tcpcb *tp; - register struct tcpiphdr *ti; - struct mbuf *m; +static int +tcp_reass(register struct tcpcb *tp, register struct tcpiphdr *ti, + struct mbuf *m) { register struct tcpiphdr *q; struct socket *so = tp->t_socket; @@ -150,8 +151,8 @@ tcp_reass(tp, ti, m) i = q->ti_seq + q->ti_len - ti->ti_seq; if (i > 0) { if (i >= ti->ti_len) { - tcpstat.tcps_rcvduppack++; - tcpstat.tcps_rcvdupbyte += ti->ti_len; + STAT(tcpstat.tcps_rcvduppack++); + STAT(tcpstat.tcps_rcvdupbyte += ti->ti_len); m_freem(m); /* * Try to present any queued data @@ -167,8 +168,8 @@ tcp_reass(tp, ti, m) } q = (struct tcpiphdr *)(q->ti_next); } - tcpstat.tcps_rcvoopack++; - tcpstat.tcps_rcvoobyte += ti->ti_len; + STAT(tcpstat.tcps_rcvoopack++); + STAT(tcpstat.tcps_rcvoobyte += ti->ti_len); REASS_MBUF(ti) = (mbufp_32) m; /* XXX */ /* @@ -275,7 +276,7 @@ tcp_input(m, iphlen, inso) } - tcpstat.tcps_rcvtotal++; + STAT(tcpstat.tcps_rcvtotal++); /* * Get IP and TCP header together in first mbuf. * Note: IP leaves IP header in first mbuf. @@ -308,7 +309,7 @@ tcp_input(m, iphlen, inso) * ti->ti_sum = cksum(m, len); * if (ti->ti_sum) { */ if(cksum(m, len)) { - tcpstat.tcps_rcvbadsum++; + STAT(tcpstat.tcps_rcvbadsum++); goto drop; } @@ -318,7 +319,7 @@ tcp_input(m, iphlen, inso) */ off = ti->ti_off << 2; if (off < sizeof (struct tcphdr) || off > tlen) { - tcpstat.tcps_rcvbadoff++; + STAT(tcpstat.tcps_rcvbadoff++); goto drop; } tlen -= off; @@ -375,7 +376,7 @@ findso: ti->ti_dst, ti->ti_dport); if (so) tcp_last_so = so; - ++tcpstat.tcps_socachemiss; + STAT(tcpstat.tcps_socachemiss++); } /* @@ -402,8 +403,8 @@ findso: goto dropwithreset; } - sbreserve(&so->so_snd, tcp_sndspace); - sbreserve(&so->so_rcv, tcp_rcvspace); + sbreserve(&so->so_snd, TCP_SNDSPACE); + sbreserve(&so->so_rcv, TCP_RCVSPACE); /* tcp_last_so = so; */ /* XXX ? */ /* tp = sototcpcb(so); */ @@ -448,10 +449,10 @@ findso: * Reset idle time and keep-alive timer. */ tp->t_idle = 0; - if (so_options) - tp->t_timer[TCPT_KEEP] = tcp_keepintvl; + if (SO_OPTIONS) + tp->t_timer[TCPT_KEEP] = TCPTV_KEEPINTVL; else - tp->t_timer[TCPT_KEEP] = tcp_keepidle; + tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_IDLE; /* * Process options if not in LISTEN state, @@ -503,7 +504,7 @@ findso: /* * this is a pure ack for outstanding data. */ - ++tcpstat.tcps_predack; + STAT(tcpstat.tcps_predack++); /* if (ts_present) * tcp_xmit_timer(tp, tcp_now-ts_ecr+1); * else @@ -511,8 +512,8 @@ findso: SEQ_GT(ti->ti_ack, tp->t_rtseq)) tcp_xmit_timer(tp, tp->t_rtt); acked = ti->ti_ack - tp->snd_una; - tcpstat.tcps_rcvackpack++; - tcpstat.tcps_rcvackbyte += acked; + STAT(tcpstat.tcps_rcvackpack++); + STAT(tcpstat.tcps_rcvackbyte += acked); sbdrop(&so->so_snd, acked); tp->snd_una = ti->ti_ack; m_freem(m); @@ -556,10 +557,10 @@ findso: * with nothing on the reassembly queue and * we have enough buffer space to take it. */ - ++tcpstat.tcps_preddat; + STAT(tcpstat.tcps_preddat++); tp->rcv_nxt += ti->ti_len; - tcpstat.tcps_rcvpack++; - tcpstat.tcps_rcvbyte += ti->ti_len; + STAT(tcpstat.tcps_rcvpack++); + STAT(tcpstat.tcps_rcvbyte += ti->ti_len); /* * Add data to socket buffer. */ @@ -726,7 +727,7 @@ findso: tp->t_flags |= TF_ACKNOW; tp->t_state = TCPS_SYN_RECEIVED; tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; - tcpstat.tcps_accepts++; + STAT(tcpstat.tcps_accepts++); goto trimthenstep6; } /* case TCPS_LISTEN */ @@ -767,7 +768,7 @@ findso: tcp_rcvseqinit(tp); tp->t_flags |= TF_ACKNOW; if (tiflags & TH_ACK && SEQ_GT(tp->snd_una, tp->iss)) { - tcpstat.tcps_connects++; + STAT(tcpstat.tcps_connects++); soisfconnected(so); tp->t_state = TCPS_ESTABLISHED; @@ -801,8 +802,8 @@ trimthenstep6: m_adj(m, -todrop); ti->ti_len = tp->rcv_wnd; tiflags &= ~TH_FIN; - tcpstat.tcps_rcvpackafterwin++; - tcpstat.tcps_rcvbyteafterwin += todrop; + STAT(tcpstat.tcps_rcvpackafterwin++); + STAT(tcpstat.tcps_rcvbyteafterwin += todrop); } tp->snd_wl1 = ti->ti_seq - 1; tp->rcv_up = ti->ti_seq; @@ -873,11 +874,11 @@ trimthenstep6: */ tp->t_flags |= TF_ACKNOW; todrop = ti->ti_len; - tcpstat.tcps_rcvduppack++; - tcpstat.tcps_rcvdupbyte += todrop; + STAT(tcpstat.tcps_rcvduppack++); + STAT(tcpstat.tcps_rcvdupbyte += todrop); } else { - tcpstat.tcps_rcvpartduppack++; - tcpstat.tcps_rcvpartdupbyte += todrop; + STAT(tcpstat.tcps_rcvpartduppack++); + STAT(tcpstat.tcps_rcvpartdupbyte += todrop); } m_adj(m, todrop); ti->ti_seq += todrop; @@ -896,7 +897,7 @@ trimthenstep6: if ((so->so_state & SS_NOFDREF) && tp->t_state > TCPS_CLOSE_WAIT && ti->ti_len) { tp = tcp_close(tp); - tcpstat.tcps_rcvafterclose++; + STAT(tcpstat.tcps_rcvafterclose++); goto dropwithreset; } @@ -906,9 +907,9 @@ trimthenstep6: */ todrop = (ti->ti_seq+ti->ti_len) - (tp->rcv_nxt+tp->rcv_wnd); if (todrop > 0) { - tcpstat.tcps_rcvpackafterwin++; + STAT(tcpstat.tcps_rcvpackafterwin++); if (todrop >= ti->ti_len) { - tcpstat.tcps_rcvbyteafterwin += ti->ti_len; + STAT(tcpstat.tcps_rcvbyteafterwin += ti->ti_len); /* * If a new connection request is received * while in TIME_WAIT, drop the old connection @@ -931,11 +932,11 @@ trimthenstep6: */ if (tp->rcv_wnd == 0 && ti->ti_seq == tp->rcv_nxt) { tp->t_flags |= TF_ACKNOW; - tcpstat.tcps_rcvwinprobe++; + STAT(tcpstat.tcps_rcvwinprobe++); } else goto dropafterack; } else - tcpstat.tcps_rcvbyteafterwin += todrop; + STAT(tcpstat.tcps_rcvbyteafterwin += todrop); m_adj(m, -todrop); ti->ti_len -= todrop; tiflags &= ~(TH_PUSH|TH_FIN); @@ -976,7 +977,7 @@ trimthenstep6: /* so->so_error = ECONNRESET; */ close: tp->t_state = TCPS_CLOSED; - tcpstat.tcps_drops++; + STAT(tcpstat.tcps_drops++); tp = tcp_close(tp); goto drop; @@ -1015,7 +1016,7 @@ trimthenstep6: if (SEQ_GT(tp->snd_una, ti->ti_ack) || SEQ_GT(ti->ti_ack, tp->snd_max)) goto dropwithreset; - tcpstat.tcps_connects++; + STAT(tcpstat.tcps_connects++); tp->t_state = TCPS_ESTABLISHED; /* * The sent SYN is ack'ed with our sequence number +1 @@ -1072,7 +1073,7 @@ trimthenstep6: if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) { if (ti->ti_len == 0 && tiwin == tp->snd_wnd) { - tcpstat.tcps_rcvdupack++; + STAT(tcpstat.tcps_rcvdupack++); DEBUG_MISC((dfd," dup ack m = %lx so = %lx \n", (long )m, (long )so)); /* @@ -1102,7 +1103,7 @@ trimthenstep6: if (tp->t_timer[TCPT_REXMT] == 0 || ti->ti_ack != tp->snd_una) tp->t_dupacks = 0; - else if (++tp->t_dupacks == tcprexmtthresh) { + else if (++tp->t_dupacks == TCPREXMTTHRESH) { tcp_seq onxt = tp->snd_nxt; u_int win = min(tp->snd_wnd, tp->snd_cwnd) / 2 / @@ -1121,7 +1122,7 @@ trimthenstep6: if (SEQ_GT(onxt, tp->snd_nxt)) tp->snd_nxt = onxt; goto drop; - } else if (tp->t_dupacks > tcprexmtthresh) { + } else if (tp->t_dupacks > TCPREXMTTHRESH) { tp->snd_cwnd += tp->t_maxseg; (void) tcp_output(tp); goto drop; @@ -1135,17 +1136,17 @@ trimthenstep6: * If the congestion window was inflated to account * for the other side's cached packets, retract it. */ - if (tp->t_dupacks > tcprexmtthresh && + if (tp->t_dupacks > TCPREXMTTHRESH && tp->snd_cwnd > tp->snd_ssthresh) tp->snd_cwnd = tp->snd_ssthresh; tp->t_dupacks = 0; if (SEQ_GT(ti->ti_ack, tp->snd_max)) { - tcpstat.tcps_rcvacktoomuch++; + STAT(tcpstat.tcps_rcvacktoomuch++); goto dropafterack; } acked = ti->ti_ack - tp->snd_una; - tcpstat.tcps_rcvackpack++; - tcpstat.tcps_rcvackbyte += acked; + STAT(tcpstat.tcps_rcvackpack++); + STAT(tcpstat.tcps_rcvackbyte += acked); /* * If we have a timestamp reply, update smoothed @@ -1227,7 +1228,7 @@ trimthenstep6: */ if (so->so_state & SS_FCANTRCVMORE) { soisfdisconnected(so); - tp->t_timer[TCPT_2MSL] = tcp_maxidle; + tp->t_timer[TCPT_2MSL] = TCP_MAXIDLE; } tp->t_state = TCPS_FIN_WAIT_2; } @@ -1284,7 +1285,7 @@ step6: /* keep track of pure window updates */ if (ti->ti_len == 0 && tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd) - tcpstat.tcps_rcvwinupd++; + STAT(tcpstat.tcps_rcvwinupd++); tp->snd_wnd = tiwin; tp->snd_wl1 = ti->ti_seq; tp->snd_wl2 = ti->ti_ack; @@ -1490,12 +1491,8 @@ drop: /* int *ts_present; * u_int32_t *ts_val, *ts_ecr; */ -void -tcp_dooptions(tp, cp, cnt, ti) - struct tcpcb *tp; - u_char *cp; - int cnt; - struct tcpiphdr *ti; +static void +tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti) { u_int16_t mss; int opt, optlen; @@ -1605,10 +1602,8 @@ tcp_pulloutofband(so, ti, m) * and update averages and current timeout. */ -void -tcp_xmit_timer(tp, rtt) - register struct tcpcb *tp; - int rtt; +static void +tcp_xmit_timer(register struct tcpcb *tp, int rtt) { register short delta; @@ -1616,7 +1611,7 @@ tcp_xmit_timer(tp, rtt) DEBUG_ARG("tp = %lx", (long)tp); DEBUG_ARG("rtt = %d", rtt); - tcpstat.tcps_rttupdated++; + STAT(tcpstat.tcps_rttupdated++); if (tp->t_srtt != 0) { /* * srtt is stored as fixed point with 3 bits after the @@ -1707,7 +1702,7 @@ tcp_mss(tp, offer) DEBUG_ARG("tp = %lx", (long)tp); DEBUG_ARG("offer = %d", offer); - mss = min(if_mtu, if_mru) - sizeof(struct tcpiphdr); + mss = min(IF_MTU, IF_MRU) - sizeof(struct tcpiphdr); if (offer) mss = min(mss, offer); mss = max(mss, 32); @@ -1716,8 +1711,12 @@ tcp_mss(tp, offer) tp->snd_cwnd = mss; - sbreserve(&so->so_snd, tcp_sndspace+((tcp_sndspace%mss)?(mss-(tcp_sndspace%mss)):0)); - sbreserve(&so->so_rcv, tcp_rcvspace+((tcp_rcvspace%mss)?(mss-(tcp_rcvspace%mss)):0)); + sbreserve(&so->so_snd, TCP_SNDSPACE + ((TCP_SNDSPACE % mss) ? + (mss - (TCP_SNDSPACE % mss)) : + 0)); + sbreserve(&so->so_rcv, TCP_RCVSPACE + ((TCP_RCVSPACE % mss) ? + (mss - (TCP_RCVSPACE % mss)) : + 0)); DEBUG_MISC((dfd, " returning mss = %d\n", mss)); |