summaryrefslogtreecommitdiff
path: root/slirp
diff options
context:
space:
mode:
authorblueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>2007-10-26 19:01:16 +0000
committerblueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>2007-10-26 19:01:16 +0000
commit9634d9031c140b24c7ca0d8872632207f6ce7275 (patch)
tree34ba241de1f12fcbd4e3301f081c50ff2db654da /slirp
parent31a60e22752d3daaa248ca10930f3cf4bc5f02e8 (diff)
Use const and static as needed, disable unused code
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3452 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'slirp')
-rw-r--r--slirp/bootp.c2
-rw-r--r--slirp/debug.c4
-rw-r--r--slirp/if.c20
-rw-r--r--slirp/if.h25
-rw-r--r--slirp/ip.h2
-rw-r--r--slirp/ip_icmp.c2
-rw-r--r--slirp/ip_input.c31
-rw-r--r--slirp/ip_output.c6
-rw-r--r--slirp/main.h1
-rw-r--r--slirp/mbuf.c27
-rw-r--r--slirp/mbuf.h1
-rw-r--r--slirp/misc.c23
-rw-r--r--slirp/misc.h6
-rw-r--r--slirp/sbuf.c8
-rw-r--r--slirp/sbuf.h1
-rw-r--r--slirp/slirp.c4
-rw-r--r--slirp/slirp.h11
-rw-r--r--slirp/socket.c26
-rw-r--r--slirp/socket.h5
-rw-r--r--slirp/tcp.h4
-rw-r--r--slirp/tcp_input.c55
-rw-r--r--slirp/tcp_output.c10
-rw-r--r--slirp/tcp_subr.c39
-rw-r--r--slirp/tcp_timer.c28
-rw-r--r--slirp/tcp_timer.h7
-rw-r--r--slirp/tftp.c8
-rw-r--r--slirp/udp.c26
-rw-r--r--slirp/udp.h2
28 files changed, 163 insertions, 221 deletions
diff --git a/slirp/bootp.c b/slirp/bootp.c
index 9f2635bf3..3ae3db209 100644
--- a/slirp/bootp.c
+++ b/slirp/bootp.c
@@ -149,7 +149,7 @@ static void bootp_reply(struct bootp_t *bp)
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));
diff --git a/slirp/debug.c b/slirp/debug.c
index 77d504452..7c8581d63 100644
--- a/slirp/debug.c
+++ b/slirp/debug.c
@@ -92,9 +92,9 @@ ttystats(ttyp)
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)");
diff --git a/slirp/if.c b/slirp/if.c
index 6d72fa72f..6feca55e3 100644
--- a/slirp/if.c
+++ b/slirp/if.c
@@ -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 @@ ifs_remque(ifm)
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);
diff --git a/slirp/if.h b/slirp/if.h
index 8f78ce7b6..ea96696b9 100644
--- a/slirp/if.h
+++ b/slirp/if.h
@@ -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) */
diff --git a/slirp/ip.h b/slirp/ip.h
index 007facf3f..a8cdb0d3f 100644
--- a/slirp/ip.h
+++ b/slirp/ip.h
@@ -312,6 +312,4 @@ extern struct ipstat ipstat;
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
diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c
index 4cf14c8e3..b589651ca 100644
--- a/slirp/ip_icmp.c
+++ b/slirp/ip_icmp.c
@@ -46,7 +46,7 @@ struct icmpstat icmpstat;
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,
diff --git a/slirp/ip_input.c b/slirp/ip_input.c
index 629745fba..b04684027 100644
--- a/slirp/ip_input.c
+++ b/slirp/ip_input.c
@@ -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(register struct ipasfrag *ip,
+ register struct ipq *fp);
+static void ip_freef(struct ipq *fp);
+static void ip_enq(register struct ipasfrag *p,
+ register struct ipasfrag *prev);
+static void ip_deq(register struct 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_init()
ip_id = tt.tv_sec & 0xffff;
udp_init();
tcp_init();
- ip_defttl = IPDEFTTL;
}
/*
@@ -239,10 +243,8 @@ bad:
* 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;
- register struct ipq *fp;
+static struct ip *
+ip_reass(register struct ipasfrag *ip, register struct ipq *fp)
{
register struct mbuf *m = dtom(ip);
register struct ipasfrag *q;
@@ -398,9 +400,8 @@ dropfrag:
* Free a fragment reassembly header and all
* associated datagrams.
*/
-void
-ip_freef(fp)
- struct ipq *fp;
+static void
+ip_freef(struct ipq *fp)
{
register struct ipasfrag *q, *p;
@@ -418,9 +419,8 @@ ip_freef(fp)
* Put an ip fragment on a reassembly chain.
* Like insque, but pointers in middle of structure.
*/
-void
-ip_enq(p, prev)
- register struct ipasfrag *p, *prev;
+static void
+ip_enq(register struct ipasfrag *p, register struct ipasfrag *prev)
{
DEBUG_CALL("ip_enq");
DEBUG_ARG("prev = %lx", (long)prev);
@@ -433,9 +433,8 @@ ip_enq(p, prev)
/*
* To ip_enq as remque is to insque.
*/
-void
-ip_deq(p)
- register struct ipasfrag *p;
+static void
+ip_deq(register struct ipasfrag *p)
{
((struct ipasfrag *)(p->ipf_prev))->ipf_next = p->ipf_next;
((struct ipasfrag *)(p->ipf_next))->ipf_prev = p->ipf_prev;
diff --git a/slirp/ip_output.c b/slirp/ip_output.c
index b41d0627c..86cf3a033 100644
--- a/slirp/ip_output.c
+++ b/slirp/ip_output.c
@@ -96,7 +96,7 @@ ip_output(so, m0)
/*
* 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 @@ ip_output(so, m0)
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 @@ ip_output(so, m0)
STAT(ipstat.ips_odropped++);
goto sendorfree;
}
- m->m_data += if_maxlinkhdr;
+ m->m_data += IF_MAXLINKHDR;
mhip = mtod(m, struct ip *);
*mhip = *ip;
diff --git a/slirp/main.h b/slirp/main.h
index 9cd87584e..c01addac4 100644
--- a/slirp/main.h
+++ b/slirp/main.h
@@ -42,7 +42,6 @@ extern char *username;
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];
diff --git a/slirp/mbuf.c b/slirp/mbuf.c
index 392aea826..5d1255428 100644
--- a/slirp/mbuf.c
+++ b/slirp/mbuf.c
@@ -21,27 +21,20 @@ struct mbuf *mbutl;
char *mclrefcnt;
int mbuf_alloced = 0;
struct mbuf m_freelist, m_usedlist;
-int mbuf_thresh = 30;
+#define MBUF_THRESH 30
int 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 @@ m_get()
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_get()
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;
diff --git a/slirp/mbuf.h b/slirp/mbuf.h
index 1e8f7a8e4..f9f213255 100644
--- a/slirp/mbuf.h
+++ b/slirp/mbuf.h
@@ -135,7 +135,6 @@ extern struct mbuf m_freelist, m_usedlist;
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 *));
diff --git a/slirp/misc.c b/slirp/misc.c
index d40fd629f..755dfec94 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -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 @@ strerror(error)
#ifdef _WIN32
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)
{
/* not implemented */
return 0;
@@ -225,6 +221,7 @@ fork_exec(so, ex, do_pty)
#else
+#ifndef CONFIG_QEMU
int
slirp_openpty(amaster, aslave)
int *amaster, *aslave;
@@ -289,6 +286,7 @@ slirp_openpty(amaster, aslave)
return (-1);
#endif
}
+#endif
/*
* XXX This is ugly
@@ -302,23 +300,20 @@ slirp_openpty(amaster, aslave)
* 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 @@ fork_exec(so, ex, do_pty)
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 @@ fork_exec(so, ex, do_pty)
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;
diff --git a/slirp/misc.h b/slirp/misc.h
index 6484a8126..eee740575 100644
--- a/slirp/misc.h
+++ b/slirp/misc.h
@@ -12,12 +12,12 @@ struct ex_list {
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_insque _P((void *, void *));
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));
diff --git a/slirp/sbuf.c b/slirp/sbuf.c
index 209064b1a..02c5fce0a 100644
--- a/slirp/sbuf.c
+++ b/slirp/sbuf.c
@@ -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 @@ sbappend(so, m)
* 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;
diff --git a/slirp/sbuf.h b/slirp/sbuf.h
index 89c4eb2f1..a4f103623 100644
--- a/slirp/sbuf.h
+++ b/slirp/sbuf.h
@@ -25,7 +25,6 @@ void sbfree _P((struct sbuf *));
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
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 28f6c0cec..303f4825c 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -12,7 +12,7 @@ struct in_addr special_addr;
/* 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
};
@@ -130,7 +130,7 @@ static int get_dns_addr(struct in_addr *pdns_addr)
#endif
#ifdef _WIN32
-void slirp_cleanup(void)
+static void slirp_cleanup(void)
{
WSACleanup();
}
diff --git a/slirp/slirp.h b/slirp/slirp.h
index ecff1d258..7b0e968f8 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -280,6 +280,9 @@ extern int do_echo;
#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);
@@ -290,10 +293,6 @@ void if_output _P((struct socket *, struct mbuf *));
/* 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 *));
@@ -301,10 +300,7 @@ void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
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 */
@@ -317,7 +313,6 @@ void tcp_template _P((struct tcpcb *));
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 *));
diff --git a/slirp/socket.c b/slirp/socket.c
index 7e07cf894..0c15132ea 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -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 @@ sorecvfrom(so)
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 @@ solisten(port, laddr, lport, flags)
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 @@ sorwakeup(so)
* 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 @@ soisfconnected(so)
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 @@ sofcantrcvmore(so)
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 */
diff --git a/slirp/socket.h b/slirp/socket.h
index 99cc17f32..94fb8d8cf 100644
--- a/slirp/socket.h
+++ b/slirp/socket.h
@@ -81,7 +81,6 @@ struct iovec {
};
#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 @@ int sowrite _P((struct socket *));
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 *));
diff --git a/slirp/tcp.h b/slirp/tcp.h
index 229293c49..11150766d 100644
--- a/slirp/tcp.h
+++ b/slirp/tcp.h
@@ -42,8 +42,6 @@ typedef u_int32_t tcp_seq;
#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 @@ struct tcphdr {
extern tcp_seq tcp_iss; /* tcp initial send seq # */
-extern char *tcpstates[];
+extern const char * const tcpstates[];
#endif
diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c
index abd827ebb..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 # */
@@ -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;
@@ -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,
@@ -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,7 +1136,7 @@ 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;
@@ -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;
}
@@ -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;
@@ -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));
diff --git a/slirp/tcp_output.c b/slirp/tcp_output.c
index f4986516a..dba4ed7a5 100644
--- a/slirp/tcp_output.c
+++ b/slirp/tcp_output.c
@@ -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 @@ send:
error = 1;
goto out;
}
- m->m_data += if_maxlinkhdr;
+ m->m_data += IF_MAXLINKHDR;
m->m_len = hdrlen;
/*
@@ -396,7 +396,7 @@ send:
error = 1;
goto out;
}
- m->m_data += if_maxlinkhdr;
+ m->m_data += IF_MAXLINKHDR;
m->m_len = hdrlen;
}
@@ -536,7 +536,7 @@ send:
((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 */
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index a20a0880b..d5ba21f17 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -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_init()
{
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 @@ tcp_respond(tp, ti, m, ack, seq, flags)
#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 @@ tcp_respond(tp, ti, m, ack, seq, flags)
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 @@ tcp_newtcpcb(so)
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 @@ tcp_newtcpcb(so)
* 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 @@ tcp_close(tp)
return ((struct tcpcb *)0);
}
+#ifdef notdef
void
tcp_drain()
{
@@ -319,9 +309,6 @@ tcp_drain()
* 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 @@ tcp_attach(so)
/*
* 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 @@ struct tos_t tcptos[] = {
{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 @@ tcp_emu(so, m)
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 @@ do_prompt:
/*
* 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 @@ do_prompt:
/*
* 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;
diff --git a/slirp/tcp_timer.c b/slirp/tcp_timer.c
index 3e865977c..244bad6a8 100644
--- a/slirp/tcp_timer.c
+++ b/slirp/tcp_timer.c
@@ -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(register struct tcpcb *tp, int timer);
+
/*
* Fast timeout routine for processing delayed acks
*/
@@ -84,7 +81,6 @@ tcp_slowtimo()
DEBUG_CALL("tcp_slowtimo");
- tcp_maxidle = TCPTV_KEEPCNT * tcp_keepintvl;
/*
* Search through tcb's and update active timers.
*/
@@ -130,16 +126,14 @@ tcp_canceltimers(tp)
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(register struct tcpcb *tp, int timer)
{
register int rexmt;
@@ -155,8 +149,8 @@ tcp_timers(tp, timer)
*/
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 @@ tcp_timers(tp, timer)
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_timers(tp, timer)
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:
diff --git a/slirp/tcp_timer.h b/slirp/tcp_timer.h
index 59933bc1b..f251846b4 100644
--- a/slirp/tcp_timer.h
+++ b/slirp/tcp_timer.h
@@ -126,17 +126,12 @@ char *tcptimers[] =
(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
diff --git a/slirp/tftp.c b/slirp/tftp.c
index 2b2bf2c5a..562ae8953 100644
--- a/slirp/tftp.c
+++ b/slirp/tftp.c
@@ -34,7 +34,7 @@ struct tftp_session {
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 @@ static int tftp_send_oack(struct tftp_session *spt,
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 @@ static int tftp_send_error(struct tftp_session *spt,
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 @@ static int tftp_send_data(struct tftp_session *spt,
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);
diff --git a/slirp/udp.c b/slirp/udp.c
index 851038094..c48923b0c 100644
--- a/slirp/udp.c
+++ b/slirp/udp.c
@@ -51,14 +51,17 @@ struct udpstat udpstat;
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 @@ udp_input(m, iphlen)
/*
* 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 @@ int udp_output2(struct socket *so, struct mbuf *m,
* 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 @@ udp_detach(so)
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 @@ struct tos_t udptos[] = {
{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 @@ udp_tos(so)
/*
* 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);
diff --git a/slirp/udp.h b/slirp/udp.h
index 12435eb82..4f69b098c 100644
--- a/slirp/udp.h
+++ b/slirp/udp.h
@@ -106,8 +106,6 @@ void udp_input _P((register struct mbuf *, int));
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,