Commit 31a60e22 authored by blueswir1's avatar blueswir1
Browse files

Make Slirp statistics gathering and output conditional to LOG_ENABLED

Add 'info slirp' command to monitor to display statistics
Disable Slirp debugging code by default


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3451 c046a42c-6fe2-441c-8c8c-71466251a162
parent 7d294b61
......@@ -1364,6 +1364,10 @@ static term_cmd_t info_cmds[] = {
#if defined(TARGET_PPC)
{ "cpustats", "", do_info_cpu_stats,
"", "show CPU statistics", },
#endif
#if defined(CONFIG_SLIRP)
{ "slirp", "", do_info_slirp,
"", "show SLIRP statistics", },
#endif
{ NULL, NULL, },
};
......
......@@ -20,6 +20,7 @@ extern char *strerror _P((int));
/* Carry over one item from main.c so that the tty's restored.
* Only done when the tty being used is /dev/tty --RedWolf */
#ifndef CONFIG_QEMU
extern struct termios slirp_tty_settings;
extern int slirp_tty_restore;
......@@ -70,7 +71,9 @@ dump_packet(dat, n)
}
}
#endif
#endif
#ifdef LOG_ENABLED
#if 0
/*
* Statistic routines
......@@ -80,7 +83,7 @@ dump_packet(dat, n)
* the link as well.
*/
void
static void
ttystats(ttyp)
struct ttys *ttyp;
{
......@@ -119,8 +122,8 @@ ttystats(ttyp)
lprint(" %6d bad input packets\r\n", is->in_mbad);
}
void
allttystats()
static void
allttystats(void)
{
struct ttys *ttyp;
......@@ -129,8 +132,8 @@ allttystats()
}
#endif
void
ipstats()
static void
ipstats(void)
{
lprint(" \r\n");
......@@ -153,9 +156,9 @@ ipstats()
lprint(" %6d total packets delivered\r\n", ipstat.ips_delivered);
}
#if 0
void
vjstats()
#ifndef CONFIG_QEMU
static void
vjstats(void)
{
lprint(" \r\n");
......@@ -172,8 +175,8 @@ vjstats()
}
#endif
void
tcpstats()
static void
tcpstats(void)
{
lprint(" \r\n");
......@@ -240,8 +243,8 @@ tcpstats()
}
void
udpstats()
static void
udpstats(void)
{
lprint(" \r\n");
......@@ -254,8 +257,8 @@ udpstats()
lprint(" %6d datagrams sent\r\n", udpstat.udps_opackets);
}
void
icmpstats()
static void
icmpstats(void)
{
lprint(" \r\n");
lprint("ICMP stats:\r\n");
......@@ -267,8 +270,8 @@ icmpstats()
lprint(" %6d ICMP packets sent in reply\r\n", icmpstat.icps_reflect);
}
void
mbufstats()
static void
mbufstats(void)
{
struct mbuf *m;
int i;
......@@ -291,8 +294,8 @@ mbufstats()
lprint(" %6d mbufs queued as packets\r\n\r\n", if_queued);
}
void
sockstats()
static void
sockstats(void)
{
char buff[256];
int n;
......@@ -331,8 +334,9 @@ sockstats()
so->so_rcv.sb_cc, so->so_snd.sb_cc);
}
}
#endif
#if 0
#ifndef CONFIG_QEMU
void
slirp_exit(exit_status)
int exit_status;
......@@ -374,3 +378,18 @@ slirp_exit(exit_status)
exit(exit_status);
}
#endif
void
slirp_stats(void)
{
#ifdef LOG_ENABLED
ipstats();
tcpstats();
udpstats();
icmpstats();
mbufstats();
sockstats();
#else
lprint("SLIRP statistics code not compiled.\n");
#endif
}
......@@ -37,14 +37,4 @@ extern int slirp_debug;
#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));
......@@ -64,6 +64,8 @@ struct icmpstat {
{ "stats", CTLTYPE_STRUCT }, \
}
#ifdef LOG_ENABLED
extern struct icmpstat icmpstat;
#endif
#endif
......@@ -29,6 +29,7 @@ extern struct mbuf *next_m;
#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 @@ struct slirp_ifstats {
u_int in_mbad; /* Bad incoming packets */
};
#endif
#endif
......@@ -272,6 +272,7 @@ struct ipoption {
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,11 @@ struct ipstat {
};
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
......@@ -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 @@ icmp_input(m, hlen)
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 @@ icmp_input(m, hlen)
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 @@ icmp_input(m, hlen)
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 @@ icmp_error(msrc, type, code, minsize, message)
(void ) ip_output((struct socket *)NULL, m);
icmpstat.icps_reflect++;
STAT(icmpstat.icps_reflect++);
end_error:
return;
......@@ -371,5 +373,5 @@ icmp_reflect(m)
(void ) ip_output((struct socket *)NULL, m);
icmpstat.icps_reflect++;
STAT(icmpstat.icps_reflect++);
}
......@@ -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 @@ ip_input(m)
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 @@ ip_input(m)
* if (ip->ip_sum) {
*/
if(cksum(m,hlen)) {
ipstat.ips_badsum++;
STAT(ipstat.ips_badsum++);
goto bad;
}
......@@ -112,7 +116,7 @@ ip_input(m)
*/
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 @@ ip_input(m)
* 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 @@ ip_input(m)
* 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 @@ ip_input(m)
/*
* 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 @@ ip_input(m)
icmp_input(m, hlen);
break;
default:
ipstat.ips_noproto++;
STAT(ipstat.ips_noproto++);
m_free(m);
}
return;
......@@ -385,7 +389,7 @@ insert:
return ((struct ip *)ip);
dropfrag:
ipstat.ips_fragdropped++;
STAT(ipstat.ips_fragdropped++);
m_freem(m);
return (0);
}
......@@ -457,7 +461,7 @@ ip_slowtimo()
--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 @@ bad:
/* Not yet */
icmp_error(m, type, code, 0, 0);
ipstat.ips_badoptions++;
STAT(ipstat.ips_badoptions++);
return (1);
}
......
......@@ -80,7 +80,7 @@ ip_output(so, m0)
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 @@ ip_output(so, m0)
*/
if (ip->ip_off & IP_DF) {
error = -1;
ipstat.ips_cantfrag++;
STAT(ipstat.ips_cantfrag++);
goto bad;
}
......@@ -137,7 +137,7 @@ ip_output(so, m0)
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 @@ ip_output(so, m0)
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 @@ sendorfree:
}
if (error == 0)
ipstat.ips_fragmented++;
STAT(ipstat.ips_fragmented++);
}
done:
......
......@@ -26,6 +26,8 @@ int slirp_add_exec(int do_pty, const char *args, int addr_low_byte,
extern const char *tftp_prefix;
extern char slirp_hostname[33];
void slirp_stats(void);
#ifdef __cplusplus
}
#endif
......
......@@ -603,6 +603,16 @@ relay(s)
}
#endif
#ifdef CONFIG_QEMU
void lprint(const char *format, ...)
{
va_list args;
va_start(args, format);
term_vprintf(format, args);
va_end(args);
}
#else
int (*lprint_print) _P((void *, const char *, va_list));
char *lprint_ptr, *lprint_ptr2, **lprint_arg;
......@@ -754,6 +764,7 @@ add_emu(buff)
lprint("Adding emulation for %s to port %d/%d\r\n", buff1, emup->lport, emup->fport);
}
#endif
#ifdef BAD_SPRINTF
......
......@@ -93,7 +93,9 @@ static int get_dns_addr(struct in_addr *pdns_addr)
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 @@ static int get_dns_addr(struct in_addr *pdns_addr)
/* 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);
......
......@@ -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"
......
......@@ -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 \
......@@ -150,8 +150,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 +167,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 +275,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 +308,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 +318,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 +375,7 @@ findso:
ti->ti_dst, ti->ti_dport);
if (so)
tcp_last_so = so;
++tcpstat.tcps_socachemiss;
STAT(tcpstat.tcps_socachemiss++);
}
/*
......@@ -503,7 +503,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 +511,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 +556,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 +726,7 @@ findso: