Patchwork [v1,5/5] slirp: fold curtime into slirp instance

login
register
mail settings
Submitter pingfan liu
Date Aug. 8, 2013, 6:26 a.m.
Message ID <1375943171-1063-6-git-send-email-pingfank@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/265662/
State New
Headers show

Comments

pingfan liu - Aug. 8, 2013, 6:26 a.m.
Each slirp instance will work on its own curtime updated when _prepare.
This patch help to fold the remaining main-loop's related stuff into GSource,
and isolated from main-loop.

Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
---
 main-loop.c         |  3 ---
 slirp/ip_icmp.c     |  4 ++--
 slirp/libslirp.h    |  2 +-
 slirp/main.h        |  1 -
 slirp/misc.c        |  4 ++--
 slirp/slirp.c       | 17 +++++++----------
 slirp/slirp.h       |  1 +
 slirp/socket.c      |  8 ++++----
 slirp/tcp_subr.c    |  2 +-
 slirp/tftp.c        |  4 ++--
 slirp/udp.c         |  4 ++--
 stubs/Makefile.objs |  1 -
 stubs/slirp.c       |  7 -------
 13 files changed, 22 insertions(+), 36 deletions(-)
 delete mode 100644 stubs/slirp.c

Patch

diff --git a/main-loop.c b/main-loop.c
index c0da803..ee655ad 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -457,9 +457,6 @@  int main_loop_wait(int nonblocking)
     /* poll any events */
     g_array_set_size(gpollfds, 0); /* reset for new iteration */
     /* XXX: separate device handlers from system ones */
-#ifdef CONFIG_SLIRP
-    slirp_update_timeout(&timeout);
-#endif
     qemu_iohandler_fill(gpollfds);
     ret = os_host_main_loop_wait(timeout);
     qemu_iohandler_poll(gpollfds, ret);
diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c
index 9f1cb08..da9efc4 100644
--- a/slirp/ip_icmp.c
+++ b/slirp/ip_icmp.c
@@ -89,7 +89,7 @@  static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
     so->so_iptos = ip->ip_tos;
     so->so_type = IPPROTO_ICMP;
     so->so_state = SS_ISFCONNECTED;
-    so->so_expire = curtime + SO_EXPIRE;
+    so->so_expire = so->slirp->curtime + SO_EXPIRE;
 
     addr.sin_family = AF_INET;
     addr.sin_addr = so->so_faddr;
@@ -184,7 +184,7 @@  icmp_input(struct mbuf *m, int hlen)
           slirp->vnetwork_addr.s_addr) {
 	/* It's an alias */
 	if (so->so_faddr.s_addr == slirp->vnameserver_addr.s_addr) {
-	  if (get_dns_addr(&addr.sin_addr) < 0)
+	  if (get_dns_addr(&addr.sin_addr, slirp->curtime) < 0)
 	    addr.sin_addr = loopback_addr;
 	} else {
 	  addr.sin_addr = loopback_addr;
diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 2dc131f..3e10a68 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -6,7 +6,7 @@ 
 struct Slirp;
 typedef struct Slirp Slirp;
 
-int get_dns_addr(struct in_addr *pdns_addr);
+int get_dns_addr(struct in_addr *pdns_addr, u_int curtime);
 
 Slirp *slirp_init(int restricted, struct in_addr vnetwork,
                   struct in_addr vnetmask, struct in_addr vhost,
diff --git a/slirp/main.h b/slirp/main.h
index f2e58cf..d7e9726 100644
--- a/slirp/main.h
+++ b/slirp/main.h
@@ -30,7 +30,6 @@  extern int ctty_closed;
 
 extern char *slirp_tty;
 extern char *exec_shell;
-extern u_int curtime;
 extern struct in_addr loopback_addr;
 extern unsigned long loopback_mask;
 extern char *username;
diff --git a/slirp/misc.c b/slirp/misc.c
index 0bcc481..b62de16 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -314,7 +314,7 @@  void slirp_connection_info(Slirp *slirp, Monitor *mon)
             dst_port = so->so_lport;
         } else {
             snprintf(buf, sizeof(buf), "  UDP[%d sec]",
-                         (so->so_expire - curtime) / 1000);
+                         (so->so_expire - so->slirp->curtime) / 1000);
             src.sin_addr = so->so_laddr;
             src.sin_port = so->so_lport;
             dst_addr = so->so_faddr;
@@ -330,7 +330,7 @@  void slirp_connection_info(Slirp *slirp, Monitor *mon)
 
     for (so = slirp->icmp.so_next; so != &slirp->icmp; so = so->so_next) {
         snprintf(buf, sizeof(buf), "  ICMP[%d sec]",
-                     (so->so_expire - curtime) / 1000);
+                     (so->so_expire - so->slirp->curtime) / 1000);
         src.sin_addr = so->so_laddr;
         dst_addr = so->so_faddr;
         monitor_printf(mon, "%-19s %3d %15s  -    ", buf, so->s,
diff --git a/slirp/slirp.c b/slirp/slirp.c
index ecc4d88..bbe7161 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -40,8 +40,6 @@  static const uint8_t special_ethaddr[ETH_ALEN] = {
 
 static const uint8_t zero_ethaddr[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
 
-u_int curtime;
-
 static QTAILQ_HEAD(slirp_instances, Slirp) slirp_instances =
     QTAILQ_HEAD_INITIALIZER(slirp_instances);
 
@@ -50,7 +48,7 @@  static u_int dns_addr_time;
 
 #ifdef _WIN32
 
-int get_dns_addr(struct in_addr *pdns_addr)
+int get_dns_addr(struct in_addr *pdns_addr, u_int curtime)
 {
     FIXED_INFO *FixedInfo=NULL;
     ULONG    BufLen;
@@ -104,7 +102,7 @@  static void winsock_cleanup(void)
 
 static struct stat dns_addr_stat;
 
-int get_dns_addr(struct in_addr *pdns_addr)
+int get_dns_addr(struct in_addr *pdns_addr, u_int curtime)
 {
     char buff[512];
     char buff2[257];
@@ -258,19 +256,17 @@  void slirp_cleanup(Slirp *slirp)
 #define CONN_CANFSEND(so) (((so)->so_state & (SS_FCANTSENDMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
 #define CONN_CANFRCV(so) (((so)->so_state & (SS_FCANTRCVMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
 
-void slirp_update_timeout(uint32_t *timeout)
-{
-    curtime = qemu_get_clock_ms(rt_clock);
-}
-
 gboolean slirp_prepare(GSource *source, gint *time)
 {
     EventsGSource *slirp_src = (EventsGSource *)source;
     Slirp *slirp = slirp_src->opaque;
     struct socket *so, *so_next;
     int events = 0;
+    u_int curtime;
 
-    *time = MIN(1000, *time);
+    *time = 1000;
+    curtime = qemu_get_clock_ms(rt_clock);
+    slirp->curtime = curtime;
     /*
      * *_slowtimo needs calling if there are IP fragments
      * in the fragment queue, or there are TCP connections active
@@ -407,6 +403,7 @@  gboolean slirp_handler(gpointer data)
     Slirp *slirp = src->opaque;
     struct socket *so, *so_next;
     int ret;
+    u_int curtime = slirp->curtime;
 
     /*
      * See if anything has timed out
diff --git a/slirp/slirp.h b/slirp/slirp.h
index 008360e..018d4a9 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -206,6 +206,7 @@  struct Slirp {
     u_int time_fasttimo;
     u_int last_slowtimo;
     int do_slowtimo;
+    u_int curtime;
 
     /* virtual network configuration */
     struct in_addr vnetwork_addr;
diff --git a/slirp/socket.c b/slirp/socket.c
index 4da7dfa..8820b30 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -520,9 +520,9 @@  sorecvfrom(struct socket *so)
 	   */
 	    if (so->so_expire) {
 	      if (so->so_fport == htons(53))
-		so->so_expire = curtime + SO_EXPIREFAST;
+		so->so_expire = so->slirp->curtime + SO_EXPIREFAST;
 	      else
-		so->so_expire = curtime + SO_EXPIRE;
+		so->so_expire =  so->slirp->curtime + SO_EXPIRE;
 	    }
 
 	    /*
@@ -553,7 +553,7 @@  sosendto(struct socket *so, struct mbuf *m)
 	    slirp->vnetwork_addr.s_addr) {
 	  /* It's an alias */
 	  if (so->so_faddr.s_addr == slirp->vnameserver_addr.s_addr) {
-	    if (get_dns_addr(&addr.sin_addr) < 0)
+	    if (get_dns_addr(&addr.sin_addr, slirp->curtime) < 0)
 	      addr.sin_addr = loopback_addr;
 	  } else {
 	    addr.sin_addr = loopback_addr;
@@ -575,7 +575,7 @@  sosendto(struct socket *so, struct mbuf *m)
 	 * but only if it's an expirable socket
 	 */
 	if (so->so_expire)
-		so->so_expire = curtime + SO_EXPIRE;
+		so->so_expire = slirp->curtime + SO_EXPIRE;
 	so->so_state &= SS_PERSISTENT_MASK;
 	so->so_state |= SS_ISFCONNECTED; /* So that it gets select()ed */
 	return 0;
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index 043f28f..69dbeec 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -347,7 +347,7 @@  int tcp_fconnect(struct socket *so)
         slirp->vnetwork_addr.s_addr) {
       /* It's an alias */
       if (so->so_faddr.s_addr == slirp->vnameserver_addr.s_addr) {
-	if (get_dns_addr(&addr.sin_addr) < 0)
+	if (get_dns_addr(&addr.sin_addr, slirp->curtime) < 0)
 	  addr.sin_addr = loopback_addr;
       } else {
 	addr.sin_addr = loopback_addr;
diff --git a/slirp/tftp.c b/slirp/tftp.c
index 1a79c45..5ef772e 100644
--- a/slirp/tftp.c
+++ b/slirp/tftp.c
@@ -32,7 +32,7 @@  static inline int tftp_session_in_use(struct tftp_session *spt)
 
 static inline void tftp_session_update(struct tftp_session *spt)
 {
-    spt->timestamp = curtime;
+    spt->timestamp = spt->slirp->curtime;
 }
 
 static void tftp_session_terminate(struct tftp_session *spt)
@@ -57,7 +57,7 @@  static int tftp_session_allocate(Slirp *slirp, struct tftp_t *tp)
         goto found;
 
     /* sessions time out after 5 inactive seconds */
-    if ((int)(curtime - spt->timestamp) > 5000) {
+    if ((int)(slirp->curtime - spt->timestamp) > 5000) {
         tftp_session_terminate(spt);
         goto found;
     }
diff --git a/slirp/udp.c b/slirp/udp.c
index b105f87..e0c90df 100644
--- a/slirp/udp.c
+++ b/slirp/udp.c
@@ -313,7 +313,7 @@  int
 udp_attach(struct socket *so)
 {
   if((so->s = qemu_socket(AF_INET,SOCK_DGRAM,0)) != -1) {
-    so->so_expire = curtime + SO_EXPIRE;
+    so->so_expire = so->slirp->curtime + SO_EXPIRE;
     insque(so, &so->slirp->udb);
   }
   return(so->s);
@@ -361,7 +361,7 @@  udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
 	    return NULL;
 	}
 	so->s = qemu_socket(AF_INET,SOCK_DGRAM,0);
-	so->so_expire = curtime + SO_EXPIRE;
+	so->so_expire = slirp->curtime + SO_EXPIRE;
 	insque(so, &slirp->udb);
 
 	addr.sin_family = AF_INET;
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 9b701b4..dafc452 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -19,7 +19,6 @@  stub-obj-y += mon-set-error.o
 stub-obj-y += pci-drive-hot-add.o
 stub-obj-y += reset.o
 stub-obj-y += set-fd-handler.o
-stub-obj-y += slirp.o
 stub-obj-y += sysbus.o
 stub-obj-y += vm-stop.o
 stub-obj-y += vmstate.o
diff --git a/stubs/slirp.c b/stubs/slirp.c
deleted file mode 100644
index c343364..0000000
--- a/stubs/slirp.c
+++ /dev/null
@@ -1,7 +0,0 @@ 
-#include "qemu-common.h"
-#include "slirp/slirp.h"
-
-void slirp_update_timeout(uint32_t *timeout)
-{
-}
-