Some work on the new slirp module
- applied remaining updates from Qemu slirp - add #if blocks to all slirp .cc files for conditional compilation - fixed some uninitialized variable warnings
This commit is contained in:
parent
402b2c01c9
commit
3f5d670384
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* QEMU compatibility functions
|
||||
*
|
||||
* Copyright (c) 2004 Fabrice Bellard
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -66,7 +66,29 @@ int inet_aton(const char *cp, struct in_addr *ia)
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int socket_set_fast_reuse(int fd)
|
||||
{
|
||||
#ifndef WIN32
|
||||
int val = 1, ret;
|
||||
|
||||
ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
|
||||
(const char *)&val, sizeof(val));
|
||||
|
||||
assert(ret == 0);
|
||||
|
||||
return ret;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int socket_set_nodelay(int fd)
|
||||
{
|
||||
int v = 1;
|
||||
return qemu_setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v));
|
||||
}
|
||||
|
||||
void qemu_set_cloexec(int fd)
|
||||
{
|
||||
#ifndef WIN32
|
||||
|
@ -129,11 +129,17 @@ struct iovec {
|
||||
void pstrcpy(char *buf, int buf_size, const char *str);
|
||||
int qemu_socket(int domain, int type, int protocol);
|
||||
#ifdef WIN32
|
||||
#define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
|
||||
setsockopt(sockfd, level, optname, (const char *)optval, optlen)
|
||||
#define qemu_recv(a,b,c,d) recv(a,(char*)b,c,d)
|
||||
int inet_aton(const char *cp, struct in_addr *ia);
|
||||
#else
|
||||
#define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
|
||||
setsockopt(sockfd, level, optname, (const void *)optval, optlen)
|
||||
#define qemu_recv(a,b,c,d) recv(a,b,c,d)
|
||||
#endif
|
||||
int socket_set_fast_reuse(int fd);
|
||||
int socket_set_nodelay(int fd);
|
||||
void qemu_set_nonblock(int fd);
|
||||
|
||||
#endif
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include "slirp.h"
|
||||
#include "libslirp.h"
|
||||
|
||||
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
|
||||
|
||||
#ifdef DEBUG
|
||||
int slirp_debug = DBG_CALL|DBG_MISC|DBG_ERROR;
|
||||
#endif
|
||||
@ -211,10 +213,9 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
|
||||
so->s = accept(s, (struct sockaddr *)&addr, &addrlen);
|
||||
} while (so->s < 0 && errno == EINTR);
|
||||
closesocket(s);
|
||||
socket_set_fast_reuse(so->s);
|
||||
opt = 1;
|
||||
setsockopt(so->s, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int));
|
||||
opt = 1;
|
||||
setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, (char *)&opt, sizeof(int));
|
||||
qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
|
||||
qemu_set_nonblock(so->s);
|
||||
|
||||
/* Append the telnet options now */
|
||||
@ -242,17 +243,4 @@ strdup(str)
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
u_sleep(int usec)
|
||||
{
|
||||
struct timeval t;
|
||||
fd_set fdset;
|
||||
|
||||
FD_ZERO(&fdset);
|
||||
|
||||
t.tv_sec = 0;
|
||||
t.tv_usec = usec * 1000;
|
||||
|
||||
select(0, &fdset, &fdset, &fdset, &t);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -20,8 +20,6 @@ struct ex_list {
|
||||
char *strdup(const char *);
|
||||
#endif
|
||||
|
||||
void do_wait(int);
|
||||
|
||||
#define EMU_NONE 0x0
|
||||
|
||||
/* TCP emulations */
|
||||
@ -51,22 +49,9 @@ struct emu_t {
|
||||
struct emu_t *next;
|
||||
};
|
||||
|
||||
extern int x_port, x_server, x_display;
|
||||
|
||||
int show_x(char *, struct socket *);
|
||||
void redir_x(uint32_t, int, int, int);
|
||||
void slirp_insque(void *, void *);
|
||||
void slirp_remque(void *);
|
||||
int add_exec(struct ex_list **, int, char *, struct in_addr, int);
|
||||
int slirp_openpty(int *, int *);
|
||||
int fork_exec(struct socket *so, const char *ex, int do_pty);
|
||||
void snooze_hup(int);
|
||||
void snooze(void);
|
||||
void relay(int);
|
||||
void add_emu(char *);
|
||||
void u_sleep(int);
|
||||
void fd_nonblock(int);
|
||||
void fd_block(int);
|
||||
int rsh_exec(struct socket *, struct socket *, char *, char *, char *);
|
||||
|
||||
#endif
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include "iodev.h"
|
||||
#include "slirp.h"
|
||||
|
||||
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
|
||||
|
||||
#define LOG_THIS genlog->
|
||||
|
||||
/* host loopback address */
|
||||
@ -916,3 +918,5 @@ void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port,
|
||||
if (ret > 0)
|
||||
tcp_output(sototcpcb(so));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -7,6 +7,9 @@
|
||||
|
||||
#include "slirp.h"
|
||||
#include "ip_icmp.h"
|
||||
|
||||
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
|
||||
|
||||
#ifdef __sun__
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
@ -86,7 +89,7 @@ size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np)
|
||||
int n, lss, total;
|
||||
struct sbuf *sb = &so->so_snd;
|
||||
int len = sb->sb_datalen - sb->sb_cc;
|
||||
int mss = so->so_tcpcb->t_maxseg;
|
||||
u_short mss = so->so_tcpcb->t_maxseg;
|
||||
|
||||
DEBUG_CALL("sopreprbuf");
|
||||
DEBUG_ARG("so = %lx", (long )so);
|
||||
@ -102,7 +105,7 @@ size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np)
|
||||
/* Should never succeed, but... */
|
||||
if ((int)iov[0].iov_len > len)
|
||||
iov[0].iov_len = len;
|
||||
if ((int)iov[0].iov_len > mss)
|
||||
if (iov[0].iov_len > mss)
|
||||
iov[0].iov_len -= iov[0].iov_len%mss;
|
||||
n = 1;
|
||||
} else {
|
||||
@ -129,7 +132,7 @@ size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np)
|
||||
} else
|
||||
n = 2;
|
||||
} else {
|
||||
if ((int)iov[0].iov_len > mss)
|
||||
if (iov[0].iov_len > mss)
|
||||
iov[0].iov_len -= iov[0].iov_len%mss;
|
||||
n = 1;
|
||||
}
|
||||
@ -148,9 +151,9 @@ size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np)
|
||||
int
|
||||
soread(struct socket *so)
|
||||
{
|
||||
int n, nn;
|
||||
int n = 0, nn;
|
||||
struct sbuf *sb = &so->so_snd;
|
||||
struct iovec iov[2];
|
||||
struct iovec iov[2] = {NULL, 0};
|
||||
|
||||
DEBUG_CALL("soread");
|
||||
DEBUG_ARG("so = %lx", (long )so);
|
||||
@ -210,7 +213,7 @@ int soreadbuf(struct socket *so, const char *buf, int size)
|
||||
{
|
||||
int n, nn, copy = size;
|
||||
struct sbuf *sb = &so->so_snd;
|
||||
struct iovec iov[2];
|
||||
struct iovec iov[2] = {NULL, 0};
|
||||
|
||||
DEBUG_CALL("soreadbuf");
|
||||
DEBUG_ARG("so = %lx", (long )so);
|
||||
@ -625,7 +628,7 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
|
||||
addr.sin_port = hport;
|
||||
|
||||
if (((s = qemu_socket(AF_INET,SOCK_STREAM,0)) < 0) ||
|
||||
(setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)) < 0) ||
|
||||
(socket_set_fast_reuse(s) < 0) ||
|
||||
(bind(s,(struct sockaddr *)&addr, sizeof(addr)) < 0) ||
|
||||
(listen(s,1) < 0)) {
|
||||
int tmperrno = errno; /* Don't clobber the real reason we failed */
|
||||
@ -640,7 +643,7 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
|
||||
qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
|
||||
|
||||
getsockname(s,(struct sockaddr *)&addr,&addrlen);
|
||||
so->so_fport = addr.sin_port;
|
||||
@ -725,3 +728,5 @@ sofwdrain(struct socket *so)
|
||||
else
|
||||
sofcantsendmore(so);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -40,6 +40,8 @@
|
||||
|
||||
#include "slirp.h"
|
||||
|
||||
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
|
||||
|
||||
/* patchable/settable parameters for tcp */
|
||||
/* Don't do rfc1323 performance enhancements */
|
||||
#define TCP_DO_RFC1323 0
|
||||
@ -337,10 +339,9 @@ int tcp_fconnect(struct socket *so)
|
||||
struct sockaddr_in addr;
|
||||
|
||||
qemu_set_nonblock(s);
|
||||
socket_set_fast_reuse(s);
|
||||
opt = 1;
|
||||
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt, sizeof(opt));
|
||||
opt = 1;
|
||||
setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt, sizeof(opt));
|
||||
qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) ==
|
||||
@ -426,12 +427,10 @@ void tcp_connect(struct socket *inso)
|
||||
return;
|
||||
}
|
||||
qemu_set_nonblock(s);
|
||||
socket_set_fast_reuse(s);
|
||||
opt = 1;
|
||||
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt, sizeof(int));
|
||||
opt = 1;
|
||||
setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt, sizeof(int));
|
||||
opt = 1;
|
||||
setsockopt(s,IPPROTO_TCP,TCP_NODELAY,(char *)&opt, sizeof(int));
|
||||
qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
|
||||
socket_set_nodelay(s);
|
||||
|
||||
so->so_fport = addr.sin_port;
|
||||
so->so_faddr = addr.sin_addr;
|
||||
@ -927,3 +926,5 @@ int tcp_ctl(struct socket *so)
|
||||
sb->sb_wptr += sb->sb_cc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -41,6 +41,8 @@
|
||||
#include "slirp.h"
|
||||
#include "ip_icmp.h"
|
||||
|
||||
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
|
||||
|
||||
static uint8_t udp_tos(struct socket *so);
|
||||
|
||||
void
|
||||
@ -81,7 +83,7 @@ udp_input(register struct mbuf *m, int iphlen)
|
||||
* but we don't yet have a way to check the checksum
|
||||
* with options still present.
|
||||
*/
|
||||
if(iphlen > (int)sizeof(struct ip)) {
|
||||
if ((size_t)iphlen > sizeof(struct ip)) {
|
||||
ip_stripoptions(m, (struct mbuf *)0);
|
||||
iphlen = sizeof(struct ip);
|
||||
}
|
||||
@ -354,7 +356,7 @@ udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
struct socket *so;
|
||||
socklen_t addrlen = sizeof(struct sockaddr_in), opt = 1;
|
||||
socklen_t addrlen = sizeof(struct sockaddr_in);
|
||||
|
||||
so = socreate(slirp);
|
||||
if (!so) {
|
||||
@ -372,7 +374,7 @@ udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
|
||||
udp_detach(so);
|
||||
return NULL;
|
||||
}
|
||||
setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
|
||||
socket_set_fast_reuse(so->s);
|
||||
|
||||
getsockname(so->s,(struct sockaddr *)&addr,&addrlen);
|
||||
so->so_fport = addr.sin_port;
|
||||
@ -392,3 +394,5 @@ udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
|
||||
|
||||
return so;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user