PATCH, RFC: Slirp improvements
Quoted 11 lines
I tried harder to change the SLIRP queue stuff to something saner by hiding the pointer access inside inlined functions. Still when I changed the 32 bit pointers to native 64 bit (or moved the pointers outside the packet), qemu crashes. Must be some devilishly hidden access somewhere. I already fixed one, which involved recycling port number fields for buffer pointers. IMHO there should be some kind of corporeal punishments mandated by law for writing this kind of mess. Maybe it would even be easier to create a new userland IP stack based on Linux from scratch instead of fixing this.
I think I'll just commit in the log part, unless there are objections.
IMHO you should add a context in the 'struct socket' structure so that you can avoid adding a context in all the functions manipulating this structure. The same holds for mbuf.
Regards,
Fabrice.
Quoted 10 lines · Fabrice Bellard
Quoted 10 lines
I tried harder to change the SLIRP queue stuff to something saner by hiding the pointer access inside inlined functions. Still when I changed the 32 bit pointers to native 64 bit (or moved the pointers outside the packet), qemu crashes. Must be some devilishly hidden access somewhere. I already fixed one, which involved recycling port number fields for buffer pointers. IMHO there should be some kind of corporeal punishments mandated by law for writing this kind of mess. Maybe it would even be easier to create a new userland IP stack based on Linux from scratch instead of fixing this.
Quoted 5 lines
Quoted 1 line
I think I'll just commit in the log part, unless there are objections.
IMHO you should add a context in the 'struct socket' structure so that you can avoid adding a context in all the functions manipulating this structure. The same holds for mbuf.
That way some changes could be avoided, maybe gain some performance. Somehow I feel this reverses the hierarchy, though.
I extracted the logging parts and safest fixes into two patches. Comments?
slirp/bootp.c +1 -1
@@ -149,7 +149,7 @@if ((m =m_get ()) ==NULL )return ; - m->m_data += if_maxlinkhdr; + m->m_data +=IF_MAXLINKHDR ; rbp = (struct bootp_t *)m->m_data; m->m_data +=sizeof (struct udpiphdr );memset (rbp,0 ,sizeof (struct bootp_t ));
slirp/debug.c +2 -2
@@ -92,9 +92,9 @@lprint (" \r\n" ); -if (if_comp &IF_COMPRESS ) +if (IF_COMP &IF_COMPRESS )strcpy (buff,"on" ); -else if (if_comp &IF_NOCOMPRESS ) +else if (IF_COMP &IF_NOCOMPRESS )strcpy (buff,"off" );else strcpy (buff,"off (for now)" );
slirp/if.c +0 -20
@@ -7,9 +7,6 @@#include <slirp.h> -int if_mtu, if_mru; -int if_comp; -int if_maxlinkhdr;int if_queued =0 ;/* Number of packets queued so far */ int if_thresh =10 ;/* Number of packets queued before we start sending * (to prevent allocing too many mbufs) */
@@ -41,23 +38,6 @@void if_init () { -#if 0 -/* -* Set if_maxlinkhdr to 48 because it's 40 bytes for TCP/IP, -* and 8 bytes for PPP, but need to have it on an 8byte boundary -*/ -#ifdef USE_PPP - if_maxlinkhdr =48 ; -#else - if_maxlinkhdr =40 ; -#endif -#else -/* 2 for alignment, 14 for ethernet, 40 for TCP/IP */ - if_maxlinkhdr =2 +14 +40 ; -#endif - if_mtu =1500 ; - if_mru =1500 ; - if_comp =IF_AUTOCOMP ; if_fastq.ifq_next = if_fastq.ifq_prev = &if_fastq; if_batchq.ifq_next = if_batchq.ifq_prev = &if_batchq;// sl_compress_init(&comp_s);
slirp/if.h +19 -6
@@ -13,12 +13,25 @@#define IF_AUTOCOMP 0x04/* Autodetect (default) */ #define IF_NOCIDCOMP 0x08/* CID compression */ -/* Needed for FreeBSD */ -#undef if_mtu -extern int if_mtu; -extern int if_mru;/* MTU and MRU */ -extern int if_comp;/* Flags for compression */ -extern int if_maxlinkhdr; +#define IF_MTU 1500 +#define IF_MRU 1500 +#define IF_COMP IF_AUTOCOMP/* Flags for compression */ + +#if 0 +/* +* Set if_maxlinkhdr to 48 because it's 40 bytes for TCP/IP, +* and 8 bytes for PPP, but need to have it on an 8byte boundary +*/ +#ifdef USE_PPP +#define IF_MAXLINKHDR 48 +#else +#define IF_MAXLINKHDR 40 +#endif +#else +/* 2 for alignment, 14 for ethernet, 40 for TCP/IP */ +#define IF_MAXLINKHDR (2 + 14 + 40) +#endif +extern int if_queued;/* Number of packets queued so far */ extern int if_thresh;/* Number of packets queued before we start sending * (to prevent allocing too many mbufs) */
slirp/ip_icmp.c +1 -1
@@ -46,7 +46,7 @@char icmp_ping_msg[] ="This is a psuedo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST packets.\n" ;/* list of actions for icmp_error() on RX of an icmp message */ -static int icmp_flush[19 ] = { +static const int icmp_flush[19 ] = {/* ECHO REPLY (0) */ 0 ,1 ,1 ,
slirp/ip_input.c +15 -16
@@ -45,14 +45,19 @@#include <slirp.h> #include "ip_icmp.h" -int ip_defttl; -#ifdef LOG_ENABLED struct ipstat ipstat;#endif struct ipq ipq; +static struct ip *ip_reass (registerstruct ipasfrag *ip, + registerstruct ipq *fp); +static void ip_freef (struct ipq *fp); +static void ip_enq (registerstruct ipasfrag *p, + registerstruct ipasfrag *prev); +static void ip_deq (registerstruct ipasfrag *p); +/* * IP initialization: fill in IP protocol switch table. * All protocols not implemented in kernel go to raw IP protocol handler.
@@ -64,7 +69,6 @@ ip_id = tt.tv_sec &0xffff ;udp_init ();tcp_init (); - ip_defttl =IPDEFTTL ; }/*
@@ -239,10 +243,8 @@* reassembly of this datagram already exists, then it * is given as fp; otherwise have to make a chain. */ -struct ip * -ip_reass (ip ,fp ) - register struct ipasfrag *ip; - registerstruct ipq *fp; +static struct ip * +ip_reass (registerstruct ipasfrag *ip, registerstruct ipq *fp) { registerstruct mbuf *m =dtom (ip); registerstruct ipasfrag *q;
@@ -398,9 +400,8 @@* Free a fragment reassembly header and all * associated datagrams. */ -void -ip_freef (fp) -struct ipq *fp; +static void +ip_freef (struct ipq *fp) { registerstruct ipasfrag *q, *p;
@@ -418,9 +419,8 @@* Put an ip fragment on a reassembly chain. * Like insque, but pointers in middle of structure. */ -void -ip_enq (p, prev) - registerstruct ipasfrag *p, *prev; +static void +ip_enq (registerstruct ipasfrag *p, registerstruct ipasfrag *prev) {DEBUG_CALL ("ip_enq" );DEBUG_ARG ("prev = %lx" , (long )prev);
@@ -433,9 +433,8 @@/* * To ip_enq as remque is to insque. */ -void -ip_deq (p) - registerstruct ipasfrag *p; +static void +ip_deq (registerstruct ipasfrag *p) { ((struct ipasfrag *)(p->ipf_prev))->ipf_next = p->ipf_next; ((struct ipasfrag *)(p->ipf_next))->ipf_prev = p->ipf_prev;
slirp/ip_output.c +3 -3
@@ -96,7 +96,7 @@/* * If small enough for interface, can just send directly. */ -if ((u_int16_t )ip->ip_len <= if_mtu) { +if ((u_int16_t )ip->ip_len <=IF_MTU ) { ip->ip_len =htons ((u_int16_t )ip->ip_len); ip->ip_off =htons ((u_int16_t )ip->ip_off); ip->ip_sum =0 ;
@@ -116,7 +116,7 @@ goto bad; } - len = (if_mtu - hlen) &~7 ;/* ip databytes per packet */ + len = (IF_MTU - hlen) &~7 ;/* ip databytes per packet */ if (len <8 ) { error =-1 ; goto bad;
@@ -140,7 +140,7 @@STAT (ipstat.ips_odropped++); goto sendorfree; } - m->m_data += if_maxlinkhdr; + m->m_data +=IF_MAXLINKHDR ; mhip = mtod(m, struct ip *); *mhip = *ip;
slirp/main.h +0 -1
@@ -42,7 +42,6 @@extern char *socket_path;extern int towrite_max;extern int ppp_exit; -extern int so_options;extern int tcp_keepintvl;extern uint8_t client_ethaddr[6 ];
slirp/mbuf.c +10 -17
@@ -21,27 +21,20 @@char *mclrefcnt;int mbuf_alloced =0 ;struct mbuf m_freelist, m_usedlist; -int mbuf_thresh =30 ; +#define MBUF_THRESH 30int mbuf_max =0 ; -int msize; + +/* +* Find a nice value for msize +* XXX if_maxlinkhdr already in mtu +*/ +#define MSIZE (IF_MTU + IF_MAXLINKHDR + sizeof(struct m_hdr ) + 6)void m_init () { m_freelist.m_next = m_freelist.m_prev = &m_freelist; m_usedlist.m_next = m_usedlist.m_prev = &m_usedlist; -msize_init (); -} - -void -msize_init () -{ -/* -* Find a nice value for msize -* XXX if_maxlinkhdr already in mtu -*/ - msize = (if_mtu>if_mru?if_mtu:if_mru) + - if_maxlinkhdr +sizeof (struct m_hdr ) +6 ; }/*
@@ -61,10 +54,10 @@DEBUG_CALL ("m_get" );if (m_freelist.m_next == &m_freelist) { - m = (struct mbuf *)malloc (msize); + m = (struct mbuf *)malloc (MSIZE );if (m ==NULL ) goto end_error; mbuf_alloced++; -if (mbuf_alloced > mbuf_thresh) +if (mbuf_alloced >MBUF_THRESH ) flags =M_DOFREE ;if (mbuf_alloced > mbuf_max) mbuf_max = mbuf_alloced;
@@ -78,7 +71,7 @@ m->m_flags = (flags |M_USEDLIST );/* Initialise it */ - m->m_size = msize -sizeof (struct m_hdr ); + m->m_size =MSIZE -sizeof (struct m_hdr ); m->m_data = m->m_dat; m->m_len =0 ; m->m_nextpkt =0 ;
slirp/mbuf.h +0 -1
@@ -135,7 +135,6 @@extern int mbuf_max; void m_init _P((void)); -void msize_init _P((void)); struct mbuf * m_get _P((void)); void m_free _P((struct mbuf *)); void m_cat _P((register struct mbuf *, register struct mbuf *));
slirp/misc.c +10 -13
@@ -8,8 +8,7 @@#define WANT_SYS_IOCTL_H #include <slirp.h> -u_int curtime, time_fasttimo, last_slowtimo, detach_time; -u_int detach_wait =600000 ;/* 10 minutes */ +u_int curtime, time_fasttimo, last_slowtimo;#if 0 int x_port =-1 ;
@@ -214,10 +213,7 @@#ifdef _WIN32int -fork_exec (so, ex, do_pty) -struct socket *so; -char *ex; -int do_pty; +fork_exec (struct socket *so,const char *ex,int do_pty) {/* not implemented */ return 0 ;
@@ -225,6 +221,7 @@#else +#ifndef CONFIG_QEMU int slirp_openpty(amaster, aslave) int *amaster, *aslave;
@@ -289,6 +286,7 @@return (-1 ); #endif } +#endif /* * XXX This is ugly
@@ -302,23 +300,20 @@* do_ptr = 2 Fork/exec using pty */ int -fork_exec (so, ex, do_pty) -struct socket *so; -char *ex; -int do_pty; +fork_exec (struct socket *so,const char *ex,int do_pty) {int s;struct sockaddr_in addr;int addrlen =sizeof (addr);int opt; -int master; +int master =-1 ;char *argv[256 ];#if 0 char buff[256 ];#endif /* don't want to clobber the original */ char *bptr; -char *curarg; +const char *curarg;int c, i, ret;DEBUG_CALL ("fork_exec" );
@@ -327,10 +322,12 @@DEBUG_ARG ("do_pty = %lx" , (long )do_pty);if (do_pty ==2 ) { +#if 0 if (slirp_openpty (&master, &s) ==-1 ) {lprint ("Error: openpty failed: %s\n" ,strerror (errno));return 0 ; } +#endif }else { addr.sin_family =AF_INET ; addr.sin_port =0 ;
@@ -390,7 +387,7 @@dup2 (s,0 );dup2 (s,1 );dup2 (s,2 ); -for (s =3 ; s <=255 ; s++) +for (s =getdtablesize () -1 ; s >=3 ; s--)close (s); i =0 ;
slirp/misc.h +3 -3
@@ -12,12 +12,12 @@int ex_pty;/* Do we want a pty? */ int ex_addr;/* The last byte of the address */ int ex_fport;/* Port to telnet to */ -char *ex_exec;/* Command line of what to exec */ +const char *ex_exec;/* Command line of what to exec */ struct ex_list *ex_next; };extern struct ex_list *exec_list; -extern u_int curtime, time_fasttimo, last_slowtimo, detach_time, detach_wait; +extern u_int curtime, time_fasttimo, last_slowtimo; extern int (*lprint_print) _P((void *, const char *, va_list));extern char *lprint_ptr, *lprint_ptr2, **lprint_arg;
@@ -74,7 +74,7 @@ inline void slirp_remque _P((void *)); int add_exec _P((struct ex_list **, int, char *, int, int)); int slirp_openpty _P((int *, int *)); -int fork_exec _P((struct socket *, char *, int)); +int fork_exec (struct socket *so,const char *ex,int do_pty); void snooze_hup _P((int)); void snooze _P((void)); void relay _P((int));
slirp/sbuf.c +4 -4
@@ -7,6 +7,8 @@#include <slirp.h> +static void sbappendsb (struct sbuf *sb,struct mbuf *m); +/* Done as a macro in socket.h */ /* int * sbspace(struct sockbuff *sb)
@@ -133,10 +135,8 @@* Copy the data from m into sb * The caller is responsible to make sure there's enough room */ -void -sbappendsb (sb, m) -struct sbuf *sb; -struct mbuf *m; +static void +sbappendsb (struct sbuf *sb,struct mbuf *m) {int len, n, nn;
slirp/sbuf.h +0 -1
@@ -25,7 +25,6 @@ void sbdrop _P((struct sbuf *, int)); void sbreserve _P((struct sbuf *, int)); void sbappend _P((struct socket *, struct mbuf *)); -void sbappendsb _P((struct sbuf *, struct mbuf *)); void sbcopy _P((struct sbuf *, int, int, char *));#endif
slirp/slirp.c +12 -3
@@ -12,7 +12,7 @@/* virtual address alias for host */ struct in_addr alias_addr; -const uint8_t special_ethaddr[6 ] = { +static const uint8_t special_ethaddr[6 ] = {0x52 ,0x54 ,0x00 ,0x12 ,0x35 ,0x00 };
@@ -93,7 +93,9 @@if (!f)return -1 ; +#ifdef DEBUG lprint ("IP address of your DNS(s): " ); +#endif while (fgets (buff,512 , f) !=NULL ) {if (sscanf (buff,"nameserver%*[ \t]%256s" , buff2) ==1 ) {if (!inet_aton (buff2, &tmp_addr))
@@ -103,13 +105,20 @@/* If it's the first one, set it to dns_addr */ if (!found) *pdns_addr = tmp_addr; +#ifdef DEBUG else lprint(", "); +#endif if (++found >3 ) { +#ifdef DEBUG lprint ("(more)" ); +#endif break ; - }else + } +#ifdef DEBUG + else lprint("%s", inet_ntoa(tmp_addr)); +#endif } }fclose (f);
@@ -121,7 +130,7 @@#endif #ifdef _WIN32 -void slirp_cleanup (void ) +static void slirp_cleanup (void ) {WSACleanup (); }
slirp/slirp.h +4 -9
@@ -6,7 +6,7 @@//#define DEBUG 1 // Uncomment the following line to enable SLIRP statistics printing in Qemu -//#define LOG_ENABLED +#define LOG_ENABLED #ifdef LOG_ENABLED #define STAT (expr) expr
@@ -292,6 +292,9 @@#define DEFAULT_BAUD 115200 +#define SO_OPTIONS DO_KEEPALIVE +#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL) +/* cksum.c */ int cksum (struct mbuf *m,int len);
@@ -302,10 +305,6 @@/* ip_input.c */ void ip_init _P((void)); void ip_input _P((struct mbuf *)); -struct ip * ip_reass _P((register struct ipasfrag *, register struct ipq *)); -void ip_freef _P((struct ipq *)); -void ip_enq _P((register struct ipasfrag *, register struct ipasfrag *)); -void ip_deq _P((register struct ipasfrag *)); void ip_slowtimo _P((void)); void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
@@ -313,10 +312,7 @@ int ip_output _P((struct socket *, struct mbuf *));/* tcp_input.c */ -int tcp_reass _P((register struct tcpcb *, register struct tcpiphdr *, struct mbuf *)); void tcp_input _P((register struct mbuf *, int, struct socket *)); -void tcp_dooptions _P((struct tcpcb *, u_char *, int, struct tcpiphdr *)); -void tcp_xmit_timer _P((register struct tcpcb *, int)); int tcp_mss _P((register struct tcpcb *, u_int));/* tcp_output.c */
@@ -329,7 +325,6 @@ void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int)); struct tcpcb * tcp_newtcpcb _P((struct socket *)); struct tcpcb * tcp_close _P((register struct tcpcb *)); -void tcp_drain _P((void)); void tcp_sockclosed _P((struct tcpcb *)); int tcp_fconnect _P((struct socket *)); void tcp_connect _P((struct socket *));
slirp/socket.c +15 -11
@@ -13,12 +13,16 @@#include <sys/filio.h> #endif -void +static void sofcantrcvmore (struct socket *so); +static void sofcantsendmore (struct socket *so); + +#if 0 +static void so_init () {/* Nothing yet */ } - +#endif struct socket *solookup (head ,laddr ,lport ,faddr ,fport )
@@ -421,7 +425,7 @@int len, n;if (!(m =m_get ()))return ; - m->m_data += if_maxlinkhdr; + m->m_data +=IF_MAXLINKHDR ;/* * XXX Shouldn't FIONREAD packets destined for port 53,
@@ -604,12 +608,13 @@return so; } +#if 0 /* * Data is available in so_rcv * Just write() the data to the socket * XXX not yet... */ -void +static void sorwakeup (so)struct socket *so; {
@@ -622,12 +627,13 @@* We have room for a read() if we want to * For now, don't read, it'll be done in the main loop */ -void +static void sowwakeup (so)struct socket *so; {/* Nothing, yet */ } +#endif /* * Various session state calls
@@ -652,9 +658,8 @@ so->so_state |=SS_ISFCONNECTED ;/* Clobber other states */ } -void -sofcantrcvmore (so) -struct socket *so; +static void +sofcantrcvmore (struct socket *so) {if ((so->so_state &SS_NOFDREF ) ==0 ) {shutdown (so->s,0 );
@@ -669,9 +674,8 @@ so->so_state |=SS_FCANTRCVMORE ; } -void -sofcantsendmore (so) -struct socket *so; +static void +sofcantsendmore (struct socket *so) {if ((so->so_state &SS_NOFDREF ) ==0 ) {shutdown (so->s,1 );/* send FIN to fhost */
slirp/socket.h +0 -5
@@ -81,7 +81,6 @@ };#endif -void so_init _P((void)); struct socket * solookup _P((struct socket *, struct in_addr, u_int, struct in_addr, u_int)); struct socket * socreate _P((void)); void sofree _P((struct socket *));
@@ -92,12 +91,8 @@ void sorecvfrom _P((struct socket *)); int sosendto _P((struct socket *, struct mbuf *)); struct socket * solisten _P((u_int, u_int32_t, u_int, int)); -void sorwakeup _P((struct socket *)); -void sowwakeup _P((struct socket *)); void soisfconnecting _P((register struct socket *)); void soisfconnected _P((register struct socket *)); -void sofcantrcvmore _P((struct socket *)); -void sofcantsendmore _P((struct socket *)); void soisfdisconnected _P((struct socket *)); void sofwdrain _P((struct socket *));
slirp/tcp.h +1 -3
@@ -42,8 +42,6 @@#define PR_SLOWHZ 2/* 2 slow timeouts per second (approx) */ #define PR_FASTHZ 5/* 5 fast timeouts per second (not important) */ -extern int tcp_rcvspace; -extern int tcp_sndspace;extern struct socket *tcp_last_so;#define TCP_SNDSPACE 8192
@@ -172,6 +170,6 @@extern tcp_seq tcp_iss;/* tcp initial send seq # */ -extern char *tcpstates[]; +extern const char *const tcpstates[];#endif
slirp/tcp_input.c +28 -29
130 lines not on this page · raw message
slirp/tcp_output.c +5 -5
@@ -48,14 +48,14 @@* Since this is only used in "stats socket", we give meaning * names instead of the REAL names */ -char *tcpstates[] = { +const char *const tcpstates[] = {/* "CLOSED", "LISTEN", "SYN_SENT", "SYN_RCVD", */ "REDIRECT" ,"LISTEN" ,"SYN_SENT" ,"SYN_RCVD" ,"ESTABLISHED" ,"CLOSE_WAIT" ,"FIN_WAIT_1" ,"CLOSING" ,"LAST_ACK" ,"FIN_WAIT_2" ,"TIME_WAIT" , }; -u_char tcp_outflags[TCP_NSTATES ] = { +static const u_char tcp_outflags[TCP_NSTATES ] = {TH_RST |TH_ACK ,0 ,TH_SYN ,TH_SYN |TH_ACK ,TH_ACK ,TH_ACK ,TH_FIN |TH_ACK ,TH_FIN |TH_ACK ,TH_FIN |TH_ACK ,TH_ACK ,TH_ACK ,
@@ -354,7 +354,7 @@ error =1 ; goto out; } - m->m_data += if_maxlinkhdr; + m->m_data +=IF_MAXLINKHDR ; m->m_len = hdrlen;/*
@@ -396,7 +396,7 @@ error =1 ; goto out; } - m->m_data += if_maxlinkhdr; + m->m_data +=IF_MAXLINKHDR ; m->m_len = hdrlen; }
@@ -536,7 +536,7 @@ ((struct ip *)ti)->ip_len = m->m_len; - ((struct ip *)ti)->ip_ttl = ip_defttl; + ((struct ip *)ti)->ip_ttl =IPDEFTTL ; ((struct ip *)ti)->ip_tos = so->so_iptos;/* #if BSD >= 43 */
slirp/tcp_subr.c +13 -26
@@ -46,11 +46,8 @@#include <slirp.h> /* patchable/settable parameters for tcp */ -int tcp_mssdflt =TCP_MSS ; -int tcp_rttdflt =TCPTV_SRTTDFLT /PR_SLOWHZ ; -int tcp_do_rfc1323 =0 ;/* Don't do rfc1323 performance enhancements */ -int tcp_rcvspace;/* You may want to change this */ -int tcp_sndspace;/* Keep small if you have an error prone link */ +/* Don't do rfc1323 performance enhancements */ +#define TCP_DO_RFC1323 0/* * Tcp initialization
@@ -60,14 +57,6 @@ { tcp_iss =1 ;/* wrong */ tcb.so_next = tcb.so_prev = &tcb; - -/* tcp_rcvspace = our Window we advertise to the remote */ - tcp_rcvspace =TCP_RCVSPACE ; - tcp_sndspace =TCP_SNDSPACE ; - -/* Make sure tcp_sndspace is at least 2*MSS */ -if (tcp_sndspace <2 *(min (if_mtu, if_mru) -sizeof (struct tcpiphdr ))) - tcp_sndspace =2 *(min (if_mtu, if_mru) -sizeof (struct tcpiphdr )); }/*
@@ -145,7 +134,7 @@#else tlen =0 ;#endif - m->m_data += if_maxlinkhdr; + m->m_data +=IF_MAXLINKHDR ; *mtod(m, struct tcpiphdr *) = *ti; ti = mtod(m, struct tcpiphdr *); flags =TH_ACK ;
@@ -186,7 +175,7 @@if (flags &TH_RST ) ((struct ip *)ti)->ip_ttl =MAXTTL ;else - ((struct ip *)ti)->ip_ttl = ip_defttl; + ((struct ip *)ti)->ip_ttl =IPDEFTTL ; (void )ip_output ((struct socket *)0 , m); }
@@ -208,9 +197,9 @@memset ((char *) tp,0 ,sizeof (struct tcpcb )); tp->seg_next = tp->seg_prev = (tcpiphdrp_32 )tp; - tp->t_maxseg = tcp_mssdflt; + tp->t_maxseg =TCP_MSS ; - tp->t_flags = tcp_do_rfc1323 ? (TF_REQ_SCALE |TF_REQ_TSTMP ) :0 ; + tp->t_flags =TCP_DO_RFC1323 ? (TF_REQ_SCALE |TF_REQ_TSTMP ) :0 ; tp->t_socket = so;/*
@@ -219,7 +208,7 @@* reasonable initial retransmit time. */ tp->t_srtt =TCPTV_SRTTBASE ; - tp->t_rttvar = tcp_rttdflt *PR_SLOWHZ <<2 ; + tp->t_rttvar =TCPTV_SRTTDFLT <<2 ; tp->t_rttmin =TCPTV_MIN ; TCPT_RANGESET(tp->t_rxtcur,
@@ -309,6 +298,7 @@return ((struct tcpcb *)0 ); } +#ifdef notdefvoid tcp_drain () {
@@ -319,9 +309,6 @@* When a source quench is received, close congestion window * to one segment. We will gradually open it again as we proceed. */ - -#ifdef notdef -void tcp_quench (i ,errno )
@@ -556,7 +543,7 @@/* * Set the socket's type of service field */ -struct tos_t tcptos[] = { +static const struct tos_t tcptos[] = { {0 ,20 ,IPTOS_THROUGHPUT ,0 },/* ftp data */ {21 ,21 ,IPTOS_LOWDELAY ,EMU_FTP },/* ftp control */ {0 ,23 ,IPTOS_LOWDELAY ,0 },/* telnet */
@@ -572,7 +559,7 @@ {0, 0, 0, 0} }; -struct emu_t *tcpemu =0 ; +static struct emu_t *tcpemu =0 ;/* * Return TOS according to the above table
@@ -665,7 +652,7 @@ so_rcv->sb_rptr += m->m_len; m->m_data[m->m_len] =0 ;/* NULL terminate */ if (strchr (m->m_data,'\r' ) ||strchr (m->m_data,'\n' )) { -if (sscanf (so_rcv->sb_data,"%d%*[ ,]%d" , &n1, &n2) ==2 ) { +if (sscanf (so_rcv->sb_data,"%u%*[ ,]%u" , &n1, &n2) ==2 ) {HTONS (n1);HTONS (n2);/* n2 is the one on our host */
@@ -991,7 +978,7 @@/* * Need to emulate the PORT command */ - x =sscanf (bptr,"ORT %d,%d,%d,%d,%d,%d\r\n%256[^\177]" , + x =sscanf (bptr,"ORT %u,%u,%u,%u,%u,%u\r\n%256[^\177]" , &n1, &n2, &n3, &n4, &n5, &n6, buff);if (x <6 )return 1 ;
@@ -1022,7 +1009,7 @@/* * Need to emulate the PASV response */ - x =sscanf (bptr,"27 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n%256[^\177]" , + x =sscanf (bptr,"27 Entering Passive Mode (%u,%u,%u,%u,%u,%u)\r\n%256[^\177]" , &n1, &n2, &n3, &n4, &n5, &n6, buff);if (x <6 )return 1 ;
slirp/tcp_timer.c +11 -17
@@ -36,17 +36,14 @@#include <slirp.h> -int tcp_keepidle =TCPTV_KEEP_IDLE ; -int tcp_keepintvl =TCPTV_KEEPINTVL ; -int tcp_maxidle; -int so_options =DO_KEEPALIVE ; -#ifdef LOG_ENABLED struct tcpstat tcpstat;/* tcp statistics */ #endif u_int32_t tcp_now;/* for RFC 1323 timestamps */ +static struct tcpcb *tcp_timers (registerstruct tcpcb *tp,int timer); +/* * Fast timeout routine for processing delayed acks */
@@ -84,7 +81,6 @@DEBUG_CALL ("tcp_slowtimo" ); - tcp_maxidle =TCPTV_KEEPCNT * tcp_keepintvl;/* * Search through tcb's and update active timers. */
@@ -130,16 +126,14 @@ tp->t_timer[i] =0 ; } -int tcp_backoff[TCP_MAXRXTSHIFT +1 ] = +const int tcp_backoff[TCP_MAXRXTSHIFT +1 ] = {1 ,2 ,4 ,8 ,16 ,32 ,64 ,64 ,64 ,64 ,64 ,64 ,64 };/* * TCP timer processing. */ -struct tcpcb * -tcp_timers (tp ,timer ) - register struct tcpcb *tp; -int timer; +static struct tcpcb * +tcp_timers (registerstruct tcpcb *tp,int timer) { registerint rexmt;
@@ -155,8 +149,8 @@*/ case TCPT_2MSL :if (tp->t_state !=TCPS_TIME_WAIT && - tp->t_idle <= tcp_maxidle) - tp->t_timer[TCPT_2MSL ] = tcp_keepintvl; + tp->t_idle <=TCP_MAXIDLE ) + tp->t_timer[TCPT_2MSL ] =TCPTV_KEEPINTVL ;else tp =tcp_close (tp);break ;
@@ -287,8 +281,8 @@ goto dropit;/* if (tp->t_socket->so_options & SO_KEEPALIVE && */ -if ((so_options ) && tp->t_state <=TCPS_CLOSE_WAIT ) { -if (tp->t_idle >= tcp_keepidle + tcp_maxidle) +if ((SO_OPTIONS ) && tp->t_state <=TCPS_CLOSE_WAIT ) { +if (tp->t_idle >=TCPTV_KEEP_IDLE +TCP_MAXIDLE ) goto dropit;/* * Send a packet designed to force a response
@@ -314,9 +308,9 @@tcp_respond (tp, &tp->t_template, (struct mbuf *)NULL , tp->rcv_nxt, tp->snd_una -1 ,0 );#endif - tp->t_timer[TCPT_KEEP ] = tcp_keepintvl; + tp->t_timer[TCPT_KEEP ] =TCPTV_KEEPINTVL ; }else - tp->t_timer[TCPT_KEEP ] = tcp_keepidle; + tp->t_timer[TCPT_KEEP ] =TCPTV_KEEP_IDLE ;break ; dropit:
slirp/tcp_timer.h +1 -6
@@ -126,17 +126,12 @@ (tv) = (tvmax); \ } -extern int tcp_keepidle;/* time before keepalive probes begin */ -extern int tcp_keepintvl;/* time between keepalive probes */ -extern int tcp_maxidle;/* time to drop after starting probes */ -extern int tcp_ttl;/* time to live for TCP segs */ -extern int tcp_backoff[]; +extern const int tcp_backoff[];struct tcpcb ; void tcp_fasttimo _P((void)); void tcp_slowtimo _P((void)); void tcp_canceltimers _P((struct tcpcb *)); -struct tcpcb * tcp_timers _P((register struct tcpcb *, int));#endif
slirp/tftp.c +4 -4
@@ -34,7 +34,7 @@int timestamp; }; -struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX ]; +static struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX ];const char *tftp_prefix;
@@ -143,7 +143,7 @@memset (m->m_data,0 , m->m_size); - m->m_data += if_maxlinkhdr; + m->m_data +=IF_MAXLINKHDR ; tp = (void *)m->m_data; m->m_data +=sizeof (struct udpiphdr );
@@ -183,7 +183,7 @@memset (m->m_data,0 , m->m_size); - m->m_data += if_maxlinkhdr; + m->m_data +=IF_MAXLINKHDR ; tp = (void *)m->m_data; m->m_data +=sizeof (struct udpiphdr );
@@ -230,7 +230,7 @@memset (m->m_data,0 , m->m_size); - m->m_data += if_maxlinkhdr; + m->m_data +=IF_MAXLINKHDR ; tp = (void *)m->m_data; m->m_data +=sizeof (struct udpiphdr );
slirp/udp.h +0 -2
@@ -106,8 +106,6 @@ int udp_output _P((struct socket *, struct mbuf *, struct sockaddr_in *)); int udp_attach _P((struct socket *)); void udp_detach _P((struct socket *)); -u_int8_t udp_tos _P((struct socket *)); -void udp_emu _P((struct socket *, struct mbuf *)); struct socket * udp_listen _P((u_int, u_int32_t, u_int, int)); int udp_output2(struct socket *so, struct mbuf *m, struct sockaddr_in *saddr, struct sockaddr_in *daddr,
slirp/udp.c +13 -13
@@ -51,14 +51,17 @@struct socket udb; +static u_int8_t udp_tos (struct socket *so); +static void udp_emu (struct socket *so,struct mbuf *m); +/* * UDP protocol implementation. * Per RFC 768, August, 1980. */ #ifndef COMPAT_42 -int udpcksum =1 ; +#define UDPCKSUM 1#else -int udpcksum =0 ;/* XXX */ +#define UDPCKSUM 0/* XXX */ #endif struct socket *udp_last_so = &udb;
@@ -132,7 +135,7 @@/* * Checksum extended UDP header and data. */ -if (udpcksum && uh->uh_sum) { +if (UDPCKSUM && uh->uh_sum) { ((struct ipovly *)ip)->ih_next =0 ; ((struct ipovly *)ip)->ih_prev =0 ; ((struct ipovly *)ip)->ih_x1 =0 ;
@@ -292,13 +295,13 @@* Stuff checksum and output datagram. */ ui->ui_sum =0 ; -if (udpcksum) { +if (UDPCKSUM ) {if ((ui->ui_sum =cksum (m,/* sizeof (struct udpiphdr) + */ m->m_len)) ==0 ) ui->ui_sum =0xffff ; } ((struct ip *)ui)->ip_len = m->m_len; - ((struct ip *)ui)->ip_ttl = ip_defttl; + ((struct ip *)ui)->ip_ttl =IPDEFTTL ; ((struct ip *)ui)->ip_tos = iptos;STAT (udpstat.udps_opackets++);
@@ -369,7 +372,7 @@sofree (so); } -struct tos_t udptos[] = { +static const struct tos_t udptos[] = { {0 ,53 ,IPTOS_LOWDELAY ,0 },/* DNS */ {517 ,517 ,IPTOS_LOWDELAY ,EMU_TALK },/* talk */ {518 ,518 ,IPTOS_LOWDELAY ,EMU_NTALK },/* ntalk */
@@ -377,9 +380,8 @@ {0, 0, 0, 0} }; -u_int8_t -udp_tos (so) -struct socket *so; +static u_int8_t +udp_tos (struct socket *so) {int i =0 ;
@@ -402,10 +404,8 @@/* * Here, talk/ytalk/ntalk requests must be emulated */ -void -udp_emu (so, m) -struct socket *so; -struct mbuf *m; +static void +udp_emu (struct socket *so,struct mbuf *m) {struct sockaddr_in addr;int addrlen =sizeof (addr);
slirp/debug.c +38 -19
134 lines not on this page · raw message
slirp/debug.h +0 -10
@@ -37,14 +37,4 @@#endif void debug_init _P((char *, int)); -//void ttystats _P((struct ttys *)); -void allttystats _P((void)); -void ipstats _P((void)); -void vjstats _P((void)); -void tcpstats _P((void)); -void udpstats _P((void)); -void icmpstats _P((void)); -void mbufstats _P((void)); -void sockstats _P((void)); -void slirp_exit _P((int));
slirp/icmp_var.h +2 -0
@@ -64,6 +64,8 @@ { "stats", CTLTYPE_STRUCT }, \ } +#ifdef LOG_ENABLED extern struct icmpstat icmpstat; +#endif #endif
slirp/ip.h +3 -1
@@ -272,6 +272,7 @@int8_t ipopt_list[MAX_IPOPTLEN ];/* options proper */ }; +#ifdef LOG_ENABLED /* * Structure attached to inpcb.ip_moptions and * passed to ip_output when IP multicast options are in use.
@@ -306,8 +307,9 @@ };extern struct ipstat ipstat; +#endif +extern struct ipq ipq;/* ip reass. queue */ extern u_int16_t ip_id;/* ip packet ctr, for ids */ -extern int ip_defttl;/* default IP ttl */ #endif
slirp/ip_icmp.c +9 -7
@@ -37,7 +37,9 @@#include "slirp.h" #include "ip_icmp.h" +#ifdef LOG_ENABLED struct icmpstat icmpstat; +#endif /* The message sent when emulating PING */ /* Be nice and tell them it's just a psuedo-ping packet */
@@ -83,14 +85,14 @@DEBUG_ARG ("m = %lx" , (long )m);DEBUG_ARG ("m_len = %d" , m->m_len); - icmpstat.icps_received++; +STAT (icmpstat.icps_received++);/* * Locate icmp structure in mbuf, and check * that its not corrupted and of at least minimum length. */ if (icmplen <ICMP_MINLEN ) {/* min 8 bytes payload */ - icmpstat.icps_tooshort++; +STAT (icmpstat.icps_tooshort++); freeit:m_freem (m); goto end_error;
@@ -100,7 +102,7 @@ m->m_data += hlen; icp = mtod(m, struct icmp *);if (cksum (m, icmplen)) { - icmpstat.icps_checksum++; +STAT (icmpstat.icps_checksum++); goto freeit; } m->m_len += hlen;
@@ -170,12 +172,12 @@case ICMP_TSTAMP :case ICMP_MASKREQ :case ICMP_REDIRECT : - icmpstat.icps_notsupp++; +STAT (icmpstat.icps_notsupp++);m_freem (m);break ;default : - icmpstat.icps_badtype++; +STAT (icmpstat.icps_badtype++);m_freem (m); }/* swith */
@@ -314,7 +316,7 @@ (void )ip_output ((struct socket *)NULL , m); - icmpstat.icps_reflect++; +STAT (icmpstat.icps_reflect++); end_error:return ;
@@ -371,5 +373,5 @@ (void )ip_output ((struct socket *)NULL , m); - icmpstat.icps_reflect++; +STAT (icmpstat.icps_reflect++); }
slirp/ip_input.c +18 -14
@@ -46,7 +46,11 @@#include "ip_icmp.h" int ip_defttl; + +#ifdef LOG_ENABLED struct ipstat ipstat; +#endif +struct ipq ipq;/*
@@ -78,23 +82,23 @@DEBUG_ARG ("m = %lx" , (long )m);DEBUG_ARG ("m_len = %d" , m->m_len); - ipstat.ips_total++; +STAT (ipstat.ips_total++);if (m->m_len <sizeof (struct ip )) { - ipstat.ips_toosmall++; +STAT (ipstat.ips_toosmall++);return ; } ip = mtod(m, struct ip *);if (ip->ip_v !=IPVERSION ) { - ipstat.ips_badvers++; +STAT (ipstat.ips_badvers++); goto bad; } hlen = ip->ip_hl <<2 ;if (hlen<sizeof (struct ip ) || hlen>m->m_len) {/* min header length */ - ipstat.ips_badhlen++;/* or packet too short */ +STAT (ipstat.ips_badhlen++);/* or packet too short */ goto bad; }
@@ -103,7 +107,7 @@* if (ip->ip_sum) { */ if (cksum (m,hlen)) { - ipstat.ips_badsum++; +STAT (ipstat.ips_badsum++); goto bad; }
@@ -112,7 +116,7 @@*/ NTOHS (ip->ip_len);if (ip->ip_len < hlen) { - ipstat.ips_badlen++; +STAT (ipstat.ips_badlen++); goto bad; }NTOHS (ip->ip_id);
@@ -125,7 +129,7 @@* Drop packet if shorter than we expect. */ if (m->m_len < ip->ip_len) { - ipstat.ips_tooshort++; +STAT (ipstat.ips_tooshort++); goto bad; }/* Should drop packet if mbuf too long? hmmm... */
@@ -192,11 +196,11 @@* attempt reassembly; if it succeeds, proceed. */ if (((struct ipasfrag *)ip)->ipf_mff &1 || ip->ip_off) { - ipstat.ips_fragments++; +STAT (ipstat.ips_fragments++); ip =ip_reass ((struct ipasfrag *)ip, fp);if (ip ==0 )return ; - ipstat.ips_reassembled++; +STAT (ipstat.ips_reassembled++); m =dtom (ip); }else if (fp)
@@ -208,7 +212,7 @@/* * Switch out to protocol's input routine. */ - ipstat.ips_delivered++; +STAT (ipstat.ips_delivered++);switch (ip->ip_p) {case IPPROTO_TCP :tcp_input (m, hlen, (struct socket *)NULL );
@@ -220,7 +224,7 @@icmp_input (m, hlen);break ;default : - ipstat.ips_noproto++; +STAT (ipstat.ips_noproto++);m_free (m); }return ;
@@ -385,7 +389,7 @@return ((struct ip *)ip); dropfrag: - ipstat.ips_fragdropped++; +STAT (ipstat.ips_fragdropped++);m_freem (m);return (0 ); }
@@ -457,7 +461,7 @@ --fp->ipq_ttl; fp = (struct ipq *) fp->next;if (((struct ipq *)(fp->prev))->ipq_ttl ==0 ) { - ipstat.ips_fragtimeout++; +STAT (ipstat.ips_fragtimeout++);ip_freef ((struct ipq *) fp->prev); } }
@@ -664,7 +668,7 @@/* Not yet */ icmp_error (m, type, code,0 ,0 ); - ipstat.ips_badoptions++; +STAT (ipstat.ips_badoptions++);return (1 ); }
slirp/ip_output.c +5 -5
@@ -80,7 +80,7 @@ ip->ip_off &=IP_DF ; ip->ip_id =htons (ip_id++); ip->ip_hl = hlen >>2 ; - ipstat.ips_localout++; +STAT (ipstat.ips_localout++);/* * Verify that we have any chance at all of being able to queue
@@ -112,7 +112,7 @@*/ if (ip->ip_off &IP_DF ) { error =-1 ; - ipstat.ips_cantfrag++; +STAT (ipstat.ips_cantfrag++); goto bad; }
@@ -137,7 +137,7 @@ m =m_get ();if (m ==0 ) { error =-1 ; - ipstat.ips_odropped++; +STAT (ipstat.ips_odropped++); goto sendorfree; } m->m_data += if_maxlinkhdr;
@@ -170,7 +170,7 @@ mhip->ip_sum =cksum (m, mhlen); *mnext = m; mnext = &m->m_nextpkt; - ipstat.ips_ofragments++; +STAT (ipstat.ips_ofragments++); }/* * Update first fragment by trimming what's been copied out
@@ -193,7 +193,7 @@ }if (error ==0 ) - ipstat.ips_fragmented++; +STAT (ipstat.ips_fragmented++); } done:
slirp/misc.c +2 -0
@@ -603,6 +603,7 @@ }#endif +#ifndef CONFIG_QEMU int (*lprint_print) _P((void *, const char *, va_list));char *lprint_ptr, *lprint_ptr2, **lprint_arg;
@@ -754,6 +755,7 @@ lprint("Adding emulation for %s to port %d/%d\r\n", buff1, emup->lport, emup->fport); } +#endif #ifdef BAD_SPRINTF
slirp/slirp.h +22 -1
@@ -3,7 +3,16 @@#define CONFIG_QEMU -#define DEBUG 1 +//#define DEBUG 1 + +// Uncomment the following line to enable SLIRP statistics printing in Qemu +//#define LOG_ENABLED + +#ifdef LOG_ENABLED +#define STAT (expr) expr +#else +#define STAT (expr) do { } while(0) +#endif #ifndef CONFIG_QEMU #include "version.h"
@@ -253,7 +262,19 @@ long gethostid _P((void));#endif +#ifdef CONFIG_QEMU +static inline void lprint (const char *format, ...) +{ +#ifdef LOG_ENABLED +va_list args; +va_start (args, format); +term_vprintf (format, args); +va_end (args); +#endif +} +#else void lprint _P((const char *, ...)); +#endif extern int do_echo;
slirp/tcp_input.c +39 -39
231 lines not on this page · raw message
slirp/tcp_output.c +12 -12
@@ -263,7 +263,7 @@/* * No reason to send a segment, just return. */ - tcpstat.tcps_didnuttin++; +STAT (tcpstat.tcps_didnuttin++);return (0 );
@@ -339,13 +339,13 @@*/ if (len) {if (tp->t_force && len ==1 ) - tcpstat.tcps_sndprobe++; +STAT (tcpstat.tcps_sndprobe++);else if (SEQ_LT (tp->snd_nxt, tp->snd_max)) { - tcpstat.tcps_sndrexmitpack++; - tcpstat.tcps_sndrexmitbyte += len; +STAT (tcpstat.tcps_sndrexmitpack++); +STAT (tcpstat.tcps_sndrexmitbyte += len); }else { - tcpstat.tcps_sndpack++; - tcpstat.tcps_sndbyte += len; +STAT (tcpstat.tcps_sndpack++); +STAT (tcpstat.tcps_sndbyte += len); } m =m_get ();
@@ -382,13 +382,13 @@ flags |=TH_PUSH ; }else {if (tp->t_flags &TF_ACKNOW ) - tcpstat.tcps_sndacks++; +STAT (tcpstat.tcps_sndacks++);else if (flags & (TH_SYN |TH_FIN |TH_RST )) - tcpstat.tcps_sndctrl++; +STAT (tcpstat.tcps_sndctrl++);else if (SEQ_GT (tp->snd_up, tp->snd_una)) - tcpstat.tcps_sndurg++; +STAT (tcpstat.tcps_sndurg++);else - tcpstat.tcps_sndwinup++; +STAT (tcpstat.tcps_sndwinup++); m =m_get ();if (m ==NULL ) {
@@ -500,7 +500,7 @@if (tp->t_rtt ==0 ) { tp->t_rtt =1 ; tp->t_rtseq = startseq; - tcpstat.tcps_segstimed++; +STAT (tcpstat.tcps_segstimed++); } }
@@ -567,7 +567,7 @@*/ return (error); } - tcpstat.tcps_sndtotal++; +STAT (tcpstat.tcps_sndtotal++);/* * Data sent (as far as we can tell).
slirp/tcp_subr.c +5 -5
@@ -255,9 +255,9 @@if (TCPS_HAVERCVDSYN (tp->t_state)) { tp->t_state =TCPS_CLOSED ; (void )tcp_output (tp); - tcpstat.tcps_drops++; +STAT (tcpstat.tcps_drops++); }else - tcpstat.tcps_conndrops++; +STAT (tcpstat.tcps_conndrops++);/* if (errno == ETIMEDOUT && tp->t_softerror) * errno = tp->t_softerror; */
@@ -305,7 +305,7 @@sbfree (&so->so_rcv);sbfree (&so->so_snd);sofree (so); - tcpstat.tcps_closed++; +STAT (tcpstat.tcps_closed++);return ((struct tcpcb *)0 ); }
@@ -528,7 +528,7 @@*/ /* soisconnecting(so); */ /* NOFDREF used instead */ - tcpstat.tcps_connattempt++; +STAT (tcpstat.tcps_connattempt++); tp->t_state =TCPS_SYN_SENT ; tp->t_timer[TCPT_KEEP ] =TCPTV_KEEP_INIT ;
@@ -857,7 +857,7 @@/*soisfconnecting(ns);*/ - tcpstat.tcps_connattempt++; +STAT (tcpstat.tcps_connattempt++); tp->t_state =TCPS_SYN_SENT ; tp->t_timer[TCPT_KEEP ] =TCPTV_KEEP_INIT ;
slirp/if.h +2 -0
@@ -29,6 +29,7 @@#define ifs_init (ifm) ((ifm)->ifs_next = (ifm)->ifs_prev = (ifm)) +#ifdef LOG_ENABLED /* Interface statistics */ struct slirp_ifstats { u_int out_pkts; /* Output packets */
@@ -46,5 +47,6 @@u_int in_mbad;/* Bad incoming packets */ }; +#endif #endif
slirp/tcp_timer.c +10 -7
@@ -41,7 +41,10 @@int tcp_maxidle;int so_options =DO_KEEPALIVE ; +#ifdef LOG_ENABLED struct tcpstat tcpstat;/* tcp statistics */ +#endif +u_int32_t tcp_now;/* for RFC 1323 timestamps */ /*
@@ -62,7 +65,7 @@ (tp->t_flags & TF_DELACK)) { tp->t_flags &= ~TF_DELACK ; tp->t_flags |=TF_ACKNOW ; - tcpstat.tcps_delack++; +STAT (tcpstat.tcps_delack++); (void )tcp_output (tp); } }
@@ -192,7 +195,7 @@* We tried our best, now the connection must die! */ tp->t_rxtshift =TCP_MAXRXTSHIFT ; - tcpstat.tcps_timeoutdrop++; +STAT (tcpstat.tcps_timeoutdrop++); tp =tcp_drop (tp, tp->t_softerror);/* tp->t_softerror : ETIMEDOUT); */ /* XXX */ return (tp);/* XXX */
@@ -204,7 +207,7 @@*/ tp->t_rxtshift =6 ; } - tcpstat.tcps_rexmttimeo++; +STAT (tcpstat.tcps_rexmttimeo++); rexmt =TCP_REXMTVAL (tp) * tcp_backoff[tp->t_rxtshift];TCPT_RANGESET (tp->t_rxtcur, rexmt, (short )tp->t_rttmin,TCPTV_REXMTMAX );/* XXX */
@@ -267,7 +270,7 @@* Force a byte to be output, if possible. */ case TCPT_PERSIST : - tcpstat.tcps_persisttimeo++; +STAT (tcpstat.tcps_persisttimeo++);tcp_setpersist (tp); tp->t_force =1 ; (void )tcp_output (tp);
@@ -279,7 +282,7 @@* or drop connection if idle for too long. */ case TCPT_KEEP : - tcpstat.tcps_keeptimeo++; +STAT (tcpstat.tcps_keeptimeo++);if (tp->t_state <TCPS_ESTABLISHED ) goto dropit;
@@ -299,7 +302,7 @@* by the protocol spec, this requires the * correspondent TCP to respond. */ - tcpstat.tcps_keepprobe++; +STAT (tcpstat.tcps_keepprobe++);#ifdef TCP_COMPAT_42 /* * The keepalive packet must have nonzero length
@@ -317,7 +320,7 @@break ; dropit: - tcpstat.tcps_keepdrops++; +STAT (tcpstat.tcps_keepdrops++); tp =tcp_drop (tp,0 );/* ETIMEDOUT); */ break ; }
slirp/tcp_var.h +3 -0
@@ -185,6 +185,7 @@#endif #define REASS_MBUF (ti) (*(mbufp_32 *)&((ti)->ti_t)) +#ifdef LOG_ENABLED /* * TCP statistics. * Many of these should be kept per connection,
@@ -247,6 +248,8 @@ };extern struct tcpstat tcpstat;/* tcp statistics */ +#endif +extern u_int32_t tcp_now;/* for RFC 1323 timestamps */ #endif
slirp/udp.h +5 -0
@@ -72,6 +72,7 @@#define ui_ulen ui_u.uh_ulen#define ui_sum ui_u.uh_sum +#ifdef LOG_ENABLED struct udpstat { /* input statistics: */ u_long udps_ipackets; /* total input packets */
@@ -85,6 +86,7 @@/* output statistics: */ u_long udps_opackets; /* total output packets */ }; +#endif /* * Names for UDP sysctl objects
@@ -92,7 +94,10 @@#define UDPCTL_CHECKSUM 1/* checksum UDP packets */ #define UDPCTL_MAXID 2 +#ifdef LOG_ENABLED extern struct udpstat udpstat; +#endif +extern struct socket udb;struct mbuf ;
slirp/udp.c +7 -5
@@ -45,7 +45,9 @@#include <slirp.h> #include "ip_icmp.h" +#ifdef LOG_ENABLED struct udpstat udpstat; +#endif struct socket udb;
@@ -86,7 +88,7 @@DEBUG_ARG ("m = %lx" , (long )m);DEBUG_ARG ("iphlen = %d" , iphlen); - udpstat.udps_ipackets++; +STAT (udpstat.udps_ipackets++);/* * Strip IP options, if any; should skip this,
@@ -113,7 +115,7 @@if (ip->ip_len != len) {if (len > ip->ip_len) { - udpstat.udps_badlen++; +STAT (udpstat.udps_badlen++); goto bad; }m_adj (m, len - ip->ip_len);
@@ -140,7 +142,7 @@* if (uh->uh_sum) { */ if (cksum (m, len +sizeof (struct ip ))) { - udpstat.udps_badsum++; +STAT (udpstat.udps_badsum++); goto bad; } }
@@ -181,7 +183,7 @@if (tmp == &udb) { so =NULL ; }else { - udpstat.udpps_pcbcachemiss++; +STAT (udpstat.udpps_pcbcachemiss++); udp_last_so = so; } }
@@ -299,7 +301,7 @@ ((struct ip *)ui)->ip_ttl = ip_defttl; ((struct ip *)ui)->ip_tos = iptos; - udpstat.udps_opackets++; +STAT (udpstat.udps_opackets++); error =ip_output (so, m);
monitor.c +4 -0
@@ -1365,6 +1365,10 @@ { "cpustats", "", do_info_cpu_stats, "", "show CPU statistics", }, #endif +#if defined(CONFIG_SLIRP) + { "slirp", "", do_info_slirp, + "", "show SLIRP statistics", }, +#endif { NULL, NULL, }, };
slirp/libslirp.h +2 -0
@@ -26,6 +26,8 @@extern const char *tftp_prefix;extern char slirp_hostname[33 ]; +void slirp_stats (void ); + #ifdef __cplusplus }#endif
vl.c +4 -0
@@ -3781,6 +3781,10 @@ }#endif /* !defined(_WIN32) */ +void do_info_slirp (void ) +{ +slirp_stats (); +}#endif /* CONFIG_SLIRP */
vl.h +3 -0
@@ -439,6 +439,9 @@extern int nb_nics;extern NICInfo nd_table[MAX_NICS ]; +/* SLIRP */ +void do_info_slirp (void ); +/* timers */ typedef struct QEMUClock QEMUClock ;