aboutsummaryrefslogtreecommitdiff
path: root/slirp/socket.c
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2009-06-24 14:42:31 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-06-29 08:52:49 -0500
commit460fec67ee3807bb2eb189587ffe803a48f317e5 (patch)
tree398605fd3595389ac29b7af0e0151a19edf25ff5 /slirp/socket.c
parentb5302e1a9d8a47bd29a3e1876fba34be111728a2 (diff)
slirp: Factor out internal state structure
The essence of this patch is to stuff (almost) all global variables of the slirp stack into the structure Slirp. In this step, we still keep the structure as global variable, directly accessible by the whole stack. Changes to the external interface of slirp will be applied in the following patches. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'slirp/socket.c')
-rw-r--r--slirp/socket.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/slirp/socket.c b/slirp/socket.c
index f7b212fba8..d8fbe89a74 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -41,7 +41,7 @@ solookup(struct socket *head, struct in_addr laddr, u_int lport,
* insque() it into the correct linked-list
*/
struct socket *
-socreate(void)
+socreate(Slirp *slirp)
{
struct socket *so;
@@ -50,6 +50,7 @@ socreate(void)
memset(so, 0, sizeof(struct socket));
so->so_state = SS_NOFDREF;
so->s = -1;
+ so->slirp = slirp;
}
return(so);
}
@@ -60,15 +61,17 @@ socreate(void)
void
sofree(struct socket *so)
{
+ Slirp *slirp = so->slirp;
+
if (so->so_emu==EMU_RSH && so->extra) {
sofree(so->extra);
so->extra=NULL;
}
- if (so == tcp_last_so)
- tcp_last_so = &tcb;
- else if (so == udp_last_so)
- udp_last_so = &udb;
-
+ if (so == slirp->tcp_last_so) {
+ slirp->tcp_last_so = &slirp->tcb;
+ } else if (so == slirp->udp_last_so) {
+ slirp->udp_last_so = &slirp->udb;
+ }
m_free(so->so_m);
if(so->so_next && so->so_prev)
@@ -473,7 +476,10 @@ sorecvfrom(struct socket *so)
int n;
#endif
- if (!(m = m_get())) return;
+ m = m_get(so->slirp);
+ if (!m) {
+ return;
+ }
m->m_data += IF_MAXLINKHDR;
/*
@@ -533,6 +539,7 @@ sorecvfrom(struct socket *so)
int
sosendto(struct socket *so, struct mbuf *m)
{
+ Slirp *slirp = so->slirp;
int ret;
struct sockaddr_in addr;
@@ -541,10 +548,10 @@ sosendto(struct socket *so, struct mbuf *m)
DEBUG_ARG("m = %lx", (long)m);
addr.sin_family = AF_INET;
- if ((so->so_faddr.s_addr & vnetwork_mask.s_addr) ==
- vnetwork_addr.s_addr) {
+ if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) ==
+ slirp->vnetwork_addr.s_addr) {
/* It's an alias */
- if (so->so_faddr.s_addr == vnameserver_addr.s_addr) {
+ if (so->so_faddr.s_addr == slirp->vnameserver_addr.s_addr) {
addr.sin_addr = dns_addr;
} else {
addr.sin_addr = loopback_addr;
@@ -576,7 +583,8 @@ sosendto(struct socket *so, struct mbuf *m)
* Listen for incoming TCP connections
*/
struct socket *
-tcp_listen(u_int32_t haddr, u_int hport, u_int32_t laddr, u_int lport, int flags)
+tcp_listen(Slirp *slirp, u_int32_t haddr, u_int hport, u_int32_t laddr,
+ u_int lport, int flags)
{
struct sockaddr_in addr;
struct socket *so;
@@ -590,7 +598,8 @@ tcp_listen(u_int32_t haddr, u_int hport, u_int32_t laddr, u_int lport, int flags
DEBUG_ARG("lport = %d", lport);
DEBUG_ARG("flags = %x", flags);
- if ((so = socreate()) == NULL) {
+ so = socreate(slirp);
+ if (!so) {
return NULL;
}
@@ -599,7 +608,7 @@ tcp_listen(u_int32_t haddr, u_int hport, u_int32_t laddr, u_int lport, int flags
free(so);
return NULL;
}
- insque(so,&tcb);
+ insque(so, &slirp->tcb);
/*
* SS_FACCEPTONCE sockets must time out.
@@ -637,7 +646,7 @@ tcp_listen(u_int32_t haddr, u_int hport, u_int32_t laddr, u_int lport, int flags
getsockname(s,(struct sockaddr *)&addr,&addrlen);
so->so_fport = addr.sin_port;
if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr)
- so->so_faddr = vhost_addr;
+ so->so_faddr = slirp->vhost_addr;
else
so->so_faddr = addr.sin_addr;