aboutsummaryrefslogtreecommitdiff
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
commit527e33ce73c0460186406679b20670ac9ebe6972 (patch)
treedf8a11ced70873338c2fc498a3aba2f32bf7a53d
parent93ebd039aab8b830e0887dd59360f2ba8de75c07 (diff)
downloadslirp-527e33ce73c0460186406679b20670ac9ebe6972.zip
slirp-527e33ce73c0460186406679b20670ac9ebe6972.tar.gz
slirp-527e33ce73c0460186406679b20670ac9ebe6972.tar.bz2
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
-rw-r--r--bootp.c2
-rw-r--r--debug.c4
-rw-r--r--if.c20
-rw-r--r--if.h25
-rw-r--r--ip.h2
-rw-r--r--ip_icmp.c2
-rw-r--r--ip_input.c19
-rw-r--r--ip_output.c6
-rw-r--r--main.h1
-rw-r--r--mbuf.c26
-rw-r--r--mbuf.h1
-rw-r--r--misc.c29
-rw-r--r--misc.h6
-rw-r--r--sbuf.c5
-rw-r--r--sbuf.h1
-rw-r--r--slirp.c6
-rw-r--r--slirp.h12
-rw-r--r--socket.c33
-rw-r--r--socket.h5
-rw-r--r--tcp.h4
-rw-r--r--tcp_input.c47
-rw-r--r--tcp_output.c10
-rw-r--r--tcp_subr.c39
-rw-r--r--tcp_timer.c27
-rw-r--r--tcp_timer.h7
-rw-r--r--tftp.c8
-rw-r--r--udp.c31
-rw-r--r--udp.h2
28 files changed, 171 insertions, 209 deletions
diff --git a/bootp.c b/bootp.c
index 3d07314..9bcb7e1 100644
--- a/bootp.c
+++ b/bootp.c
@@ -150,7 +150,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/debug.c b/debug.c
index 5030f06..4c988c4 100644
--- a/debug.c
+++ b/debug.c
@@ -88,9 +88,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/if.c b/if.c
index ad5061c..c939029 100644
--- a/if.c
+++ b/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) */
@@ -36,23 +33,6 @@ void ifs_remque(ifm) struct mbuf *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/if.h b/if.h
index 5092730..21d3f76 100644
--- a/if.h
+++ b/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/ip.h b/ip.h
index bc9d706..20c419a 100644
--- a/ip.h
+++ b/ip.h
@@ -310,6 +310,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/ip_icmp.c b/ip_icmp.c
index ad2384a..5e7956a 100644
--- a/ip_icmp.c
+++ b/ip_icmp.c
@@ -47,7 +47,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,
diff --git a/ip_input.c b/ip_input.c
index 7c65e8b..38210b3 100644
--- a/ip_input.c
+++ b/ip_input.c
@@ -45,14 +45,18 @@
#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.
@@ -63,7 +67,6 @@ void ip_init()
ip_id = tt.tv_sec & 0xffff;
udp_init();
tcp_init();
- ip_defttl = IPDEFTTL;
}
/*
@@ -235,8 +238,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;
@@ -393,7 +396,7 @@ 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;
@@ -411,7 +414,7 @@ void ip_freef(fp) struct ipq *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);
@@ -424,7 +427,7 @@ void ip_enq(p, prev) register struct ipasfrag *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/ip_output.c b/ip_output.c
index 6cafc55..a014249 100644
--- a/ip_output.c
+++ b/ip_output.c
@@ -94,7 +94,7 @@ struct mbuf *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;
@@ -114,7 +114,7 @@ struct mbuf *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;
@@ -138,7 +138,7 @@ struct mbuf *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/main.h b/main.h
index 97062f1..7c87c10 100644
--- a/main.h
+++ b/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/mbuf.c b/mbuf.c
index dfab6d7..ce3a644 100644
--- a/mbuf.c
+++ b/mbuf.c
@@ -21,25 +21,19 @@ 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;
}
/*
@@ -58,11 +52,11 @@ struct mbuf *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;
@@ -76,7 +70,7 @@ struct mbuf *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/mbuf.h b/mbuf.h
index 9272c4e..71766ce 100644
--- a/mbuf.h
+++ b/mbuf.h
@@ -134,7 +134,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/misc.c b/misc.c
index 7f1e477..e3b9457 100644
--- a/misc.c
+++ b/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;
@@ -197,9 +196,7 @@ char *strerror(error) int error;
#ifdef _WIN32
-int fork_exec(so, ex, do_pty) struct socket *so;
-char *ex;
-int do_pty;
+int fork_exec(struct socket *so, const char *ex, int do_pty)
{
/* not implemented */
return 0;
@@ -207,6 +204,7 @@ int do_pty;
#else
+#ifndef CONFIG_QEMU
int slirp_openpty(amaster, aslave) int *amaster, *aslave;
{
register int master, slave;
@@ -266,6 +264,7 @@ int slirp_openpty(amaster, aslave) int *amaster, *aslave;
return (-1);
#endif
}
+#endif
/*
* XXX This is ugly
@@ -278,22 +277,20 @@ int slirp_openpty(amaster, aslave) int *amaster, *aslave;
* do_pty = 1 Fork/exec using slirp.telnetd
* do_ptr = 2 Fork/exec using pty
*/
-int fork_exec(so, ex, do_pty) struct socket *so;
-char *ex;
-int do_pty;
+int 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");
@@ -302,10 +299,12 @@ int do_pty;
DEBUG_ARG("do_pty = %lx", (long)do_pty);
if (do_pty == 2) {
- if (slirp_openpty(&master, &s) == -1) {
- lprint("Error: openpty failed: %s\n", strerror(errno));
- return 0;
- }
+#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;
@@ -365,7 +364,7 @@ int 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/misc.h b/misc.h
index dbbc85d..af9e858 100644
--- a/misc.h
+++ b/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/sbuf.c b/sbuf.c
index 21ac4bc..ac2fbd8 100644
--- a/sbuf.c
+++ b/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)
@@ -125,8 +127,7 @@ struct mbuf *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/sbuf.h b/sbuf.h
index e3cd3d0..611694c 100644
--- a/sbuf.h
+++ b/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.c b/slirp.c
index 6b4feb8..41f4ebe 100644
--- a/slirp.c
+++ b/slirp.c
@@ -12,7 +12,9 @@ struct in_addr special_addr;
/* virtual address alias for host */
struct in_addr alias_addr;
-const uint8_t special_ethaddr[6] = { 0x52, 0x54, 0x00, 0x12, 0x35, 0x00 };
+static const uint8_t special_ethaddr[6] = {
+ 0x52, 0x54, 0x00, 0x12, 0x35, 0x00
+};
uint8_t client_ethaddr[6];
@@ -128,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.h b/slirp.h
index 1e57ddd..2a5a629 100644
--- a/slirp.h
+++ b/slirp.h
@@ -282,6 +282,9 @@ inline void remque_32 _P((void *));
#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);
@@ -292,10 +295,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 *));
@@ -303,11 +302,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 */
@@ -321,7 +316,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 *));
diff --git a/socket.c b/socket.c
index c7b381d..f6cec9b 100644
--- a/socket.c
+++ b/socket.c
@@ -13,11 +13,16 @@
#include <sys/filio.h>
#endif
-void so_init()
+static void sofcantrcvmore(struct socket *so);
+static void sofcantsendmore(struct socket *so);
+
+#if 0
+static void
+so_init()
{
- /* Nothing yet */
+ /* Nothing yet */
}
-
+#endif
struct socket *solookup(head, laddr, lport, faddr, fport) struct socket *head;
struct in_addr laddr;
@@ -418,7 +423,7 @@ void sorecvfrom(so) struct socket *so;
if (!(m = m_get()))
return;
- m->m_data += if_maxlinkhdr;
+ m->m_data += IF_MAXLINKHDR;
/*
* XXX Shouldn't FIONREAD packets destined for port 53,
@@ -603,15 +608,18 @@ int flags;
return so;
}
+#if 0
/*
* Data is available in so_rcv
* Just write() the data to the socket
* XXX not yet...
*/
-void sorwakeup(so) struct socket *so;
+static void
+sorwakeup(so)
+ struct socket *so;
{
- /* sowrite(so); */
- /* FD_CLR(so->s,&writefds); */
+/* sowrite(so); */
+/* FD_CLR(so->s,&writefds); */
}
/*
@@ -619,10 +627,13 @@ void sorwakeup(so) struct socket *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 sowwakeup(so) struct socket *so;
+static void
+sowwakeup(so)
+ struct socket *so;
{
- /* Nothing, yet */
+ /* Nothing, yet */
}
+#endif
/*
* Various session state calls
@@ -643,7 +654,7 @@ void soisfconnected(so) register struct socket *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);
@@ -659,7 +670,7 @@ void sofcantrcvmore(so) struct socket *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/socket.h b/socket.h
index 9568e9c..92e6ea4 100644
--- a/socket.h
+++ b/socket.h
@@ -88,7 +88,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));
@@ -100,12 +99,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/tcp.h b/tcp.h
index 445625a..08ccbef 100644
--- a/tcp.h
+++ b/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/tcp_input.c b/tcp_input.c
index ca6767d..41a3316 100644
--- a/tcp_input.c
+++ b/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 # */
@@ -116,10 +116,12 @@ 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;
@@ -401,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); */
@@ -447,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,
@@ -1100,7 +1102,7 @@ findso:
*/
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 / tp->t_maxseg;
@@ -1118,7 +1120,7 @@ findso:
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;
@@ -1132,7 +1134,7 @@ findso:
* If the congestion window was inflated to account
* for the other side's cached packets, retract it.
*/
- if (tp->t_dupacks > tcprexmtthresh && tp->snd_cwnd > tp->snd_ssthresh)
+ 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)) {
@@ -1222,7 +1224,7 @@ findso:
*/
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;
}
@@ -1484,10 +1486,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;
@@ -1594,8 +1594,7 @@ register struct mbuf *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;
@@ -1692,7 +1691,7 @@ u_int 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);
@@ -1702,11 +1701,11 @@ u_int offer;
tp->snd_cwnd = mss;
sbreserve(&so->so_snd,
- tcp_sndspace +
- ((tcp_sndspace % mss) ? (mss - (tcp_sndspace % mss)) : 0));
+ TCP_SNDSPACE +
+ ((TCP_SNDSPACE % mss) ? (mss - (TCP_SNDSPACE % mss)) : 0));
sbreserve(&so->so_rcv,
- tcp_rcvspace +
- ((tcp_rcvspace % mss) ? (mss - (tcp_rcvspace % mss)) : 0));
+ TCP_RCVSPACE +
+ ((TCP_RCVSPACE % mss) ? (mss - (TCP_RCVSPACE % mss)) : 0));
DEBUG_MISC((dfd, " returning mss = %d\n", mss));
diff --git a/tcp_output.c b/tcp_output.c
index e533605..a85885c 100644
--- a/tcp_output.c
+++ b/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,
@@ -350,7 +350,7 @@ send:
error = 1;
goto out;
}
- m->m_data += if_maxlinkhdr;
+ m->m_data += IF_MAXLINKHDR;
m->m_len = hdrlen;
/*
@@ -391,7 +391,7 @@ send:
error = 1;
goto out;
}
- m->m_data += if_maxlinkhdr;
+ m->m_data += IF_MAXLINKHDR;
m->m_len = hdrlen;
}
@@ -528,7 +528,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/tcp_subr.c b/tcp_subr.c
index 0160f49..d535d8d 100644
--- a/tcp_subr.c
+++ b/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
@@ -59,14 +56,6 @@ void 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));
}
/*
@@ -140,7 +129,7 @@ int 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;
@@ -187,7 +176,7 @@ int 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);
}
@@ -207,9 +196,9 @@ struct tcpcb *tcp_newtcpcb(so) struct socket *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;
/*
@@ -218,7 +207,7 @@ struct tcpcb *tcp_newtcpcb(so) struct socket *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,
@@ -306,6 +295,7 @@ struct tcpcb *tcp_close(tp) register struct tcpcb *tp;
return ((struct tcpcb *)0);
}
+#ifdef notdef
void tcp_drain()
{
/* XXX */
@@ -315,9 +305,6 @@ void 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)
int errno;
@@ -545,7 +532,7 @@ int tcp_attach(so) struct socket *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 */
@@ -561,7 +548,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
@@ -650,7 +637,7 @@ struct mbuf *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 */
@@ -977,7 +964,7 @@ do_prompt:
/*
* Need to emulate the PORT command
*/
- x = sscanf(bptr, "ORT %d,%d,%d,%d,%d,%d\r\n%256[^\177]", &n1, &n2,
+ 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;
@@ -1010,7 +997,7 @@ do_prompt:
*/
x = sscanf(
bptr,
- "27 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n%256[^\177]",
+ "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/tcp_timer.c b/tcp_timer.c
index 61d0c79..7ffb549 100644
--- a/tcp_timer.c
+++ b/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
*/
@@ -82,7 +79,6 @@ void tcp_slowtimo()
DEBUG_CALL("tcp_slowtimo");
- tcp_maxidle = TCPTV_KEEPCNT * tcp_keepintvl;
/*
* Search through tcb's and update active timers.
*/
@@ -125,14 +121,13 @@ void tcp_canceltimers(tp) struct tcpcb *tp;
tp->t_timer[i] = 0;
}
-int tcp_backoff[TCP_MAXRXTSHIFT + 1] = { 1, 2, 4, 8, 16, 32, 64,
- 64, 64, 64, 64, 64, 64 };
+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;
@@ -146,8 +141,8 @@ int timer;
* control block. Otherwise, check again in a bit.
*/
case TCPT_2MSL:
- if (tp->t_state != TCPS_TIME_WAIT && tp->t_idle <= tcp_maxidle)
- tp->t_timer[TCPT_2MSL] = tcp_keepintvl;
+ if (tp->t_state != TCPS_TIME_WAIT && tp->t_idle <= TCP_MAXIDLE)
+ tp->t_timer[TCPT_2MSL] = TCPTV_KEEPINTVL;
else
tp = tcp_close(tp);
break;
@@ -278,8 +273,8 @@ int 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
@@ -305,9 +300,9 @@ int 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/tcp_timer.h b/tcp_timer.h
index 7344c80..8ba1134 100644
--- a/tcp_timer.h
+++ b/tcp_timer.h
@@ -128,17 +128,12 @@ char *tcptimers[] = { "REXMT", "PERSIST", "KEEP", "2MSL" };
(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/tftp.c b/tftp.c
index 5b7a0cc..f879be8 100644
--- a/tftp.c
+++ b/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;
@@ -142,7 +142,7 @@ static int tftp_send_oack(struct tftp_session *spt, const char *key,
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);
@@ -180,7 +180,7 @@ static int tftp_send_error(struct tftp_session *spt, u_int16_t errorcode,
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);
@@ -226,7 +226,7 @@ static int tftp_send_data(struct tftp_session *spt, u_int16_t block_nr,
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/udp.c b/udp.c
index 29bb72b..de17953 100644
--- a/udp.c
+++ b/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;
@@ -129,7 +132,7 @@ int 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;
@@ -291,14 +294,14 @@ int udp_output2(struct socket *so, struct mbuf *m, struct sockaddr_in *saddr,
* 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++);
@@ -364,14 +367,15 @@ void udp_detach(so) struct socket *so;
sofree(so);
}
-struct tos_t udptos[] = { { 0, 53, IPTOS_LOWDELAY, 0 }, /* DNS */
- { 517, 517, IPTOS_LOWDELAY, EMU_TALK }, /* talk */
- { 518, 518, IPTOS_LOWDELAY, EMU_NTALK }, /* ntalk */
- { 0, 7648, IPTOS_LOWDELAY,
- EMU_CUSEEME }, /* Cu-Seeme */
- { 0, 0, 0, 0 } };
+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 */
+ { 0, 7648, IPTOS_LOWDELAY, EMU_CUSEEME }, /* Cu-Seeme */
+ { 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;
@@ -394,8 +398,7 @@ u_int8_t udp_tos(so) struct socket *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/udp.h b/udp.h
index be4161d..ff50211 100644
--- a/udp.h
+++ b/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, int iptos);