Some work on the "Bochs side" of the new slirp module

- added support for a separate slirp config file specified with the "script"
  parameter. Added sample config in the "misc" subdirectory.
- now creating one logfunctions object per slirp instance and added new function
  slirp_warning() to send error messages to the Bochs log.
- regenerated dependencies for the iodev/network Makefile and updated command
  line example for generating them.
This commit is contained in:
Volker Ruppert 2014-03-02 20:24:26 +00:00
parent 39bb48cd69
commit f62c8f158f
8 changed files with 154 additions and 60 deletions

View File

@ -129,11 +129,12 @@ dist-clean: clean
###########################################
# dependencies generated by
# gcc -MM -I.. -I../.. -I../../instrument/stubs *.cc | sed -e 's/\.cc/.@CPP_SUFFIX@/g'
# gcc -MM -I.. -I../.. -I../../instrument/stubs slirp/*.cc | sed -e 's/\.cc/.@CPP_SUFFIX@/g'
# gcc -MM -I.. -I../.. -I../../instrument/stubs slirp/*.cc | \
# sed -e 's/^[^ ]/slirp\/&/g' -e 's/\.cc/.@CPP_SUFFIX@/g'
# gcc -MM -I.. -I../.. -I../../instrument/stubs *.cc | \
# sed -e 's/\.cc/.@CPP_SUFFIX@/g' -e 's/\.o:/.lo:/g'
# gcc -MM -I.. -I../.. -I../../instrument/stubs slirp/*.cc | \
# sed -e 's/\.cc/.@CPP_SUFFIX@/g' -e 's/\.o:/.lo:/g'
# sed -e 's/^[^ ]/slirp\/&/g' -e 's/\.cc/.@CPP_SUFFIX@/g' -e 's/\.o:/.lo:/g'
#
# This means that every source file is listed twice, once with a .o rule
# and then again with an identical .lo rule. The .lo rules are used when
@ -232,16 +233,11 @@ slirp/arp_table.o: slirp/arp_table.@CPP_SUFFIX@ slirp/slirp.h ../../config.h \
slirp/ip.h slirp/tcp.h slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h \
slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h \
slirp/if.h slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/bootp.o: slirp/bootp.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
../../param_names.h slirp/slirp.h slirp/slirp_config.h slirp/debug.h \
slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h slirp/tcp_var.h \
slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h \
slirp/sbuf.h slirp/socket.h slirp/if.h slirp/main.h slirp/misc.h \
slirp/bootp.h slirp/tftp.h
slirp/bootp.o: slirp/bootp.@CPP_SUFFIX@ slirp/slirp.h ../../config.h slirp/slirp_config.h \
slirp/debug.h slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h \
slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h \
slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h slirp/if.h \
slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/cksum.o: slirp/cksum.@CPP_SUFFIX@ slirp/slirp.h ../../config.h slirp/slirp_config.h \
slirp/debug.h slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h \
slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h \
@ -252,16 +248,11 @@ slirp/compat.o: slirp/compat.@CPP_SUFFIX@ slirp/slirp.h ../../config.h \
slirp/ip.h slirp/tcp.h slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h \
slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h \
slirp/if.h slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/dnssearch.o: slirp/dnssearch.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
../../param_names.h slirp/slirp.h slirp/slirp_config.h slirp/debug.h \
slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h slirp/tcp_var.h \
slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h \
slirp/sbuf.h slirp/socket.h slirp/if.h slirp/main.h slirp/misc.h \
slirp/bootp.h slirp/tftp.h
slirp/dnssearch.o: slirp/dnssearch.@CPP_SUFFIX@ slirp/slirp.h ../../config.h \
slirp/slirp_config.h slirp/debug.h slirp/libslirp.h slirp/compat.h \
slirp/ip.h slirp/tcp.h slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h \
slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h \
slirp/if.h slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/if.o: slirp/if.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h ../../osdep.h \
../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
@ -440,16 +431,11 @@ slirp/arp_table.lo: slirp/arp_table.@CPP_SUFFIX@ slirp/slirp.h ../../config.h \
slirp/ip.h slirp/tcp.h slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h \
slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h \
slirp/if.h slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/bootp.lo: slirp/bootp.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
../../param_names.h slirp/slirp.h slirp/slirp_config.h slirp/debug.h \
slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h slirp/tcp_var.h \
slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h \
slirp/sbuf.h slirp/socket.h slirp/if.h slirp/main.h slirp/misc.h \
slirp/bootp.h slirp/tftp.h
slirp/bootp.lo: slirp/bootp.@CPP_SUFFIX@ slirp/slirp.h ../../config.h slirp/slirp_config.h \
slirp/debug.h slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h \
slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h \
slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h slirp/if.h \
slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/cksum.lo: slirp/cksum.@CPP_SUFFIX@ slirp/slirp.h ../../config.h slirp/slirp_config.h \
slirp/debug.h slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h \
slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h \
@ -460,16 +446,11 @@ slirp/compat.lo: slirp/compat.@CPP_SUFFIX@ slirp/slirp.h ../../config.h \
slirp/ip.h slirp/tcp.h slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h \
slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h \
slirp/if.h slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/dnssearch.lo: slirp/dnssearch.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
../../param_names.h slirp/slirp.h slirp/slirp_config.h slirp/debug.h \
slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h slirp/tcp_var.h \
slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h \
slirp/sbuf.h slirp/socket.h slirp/if.h slirp/main.h slirp/misc.h \
slirp/bootp.h slirp/tftp.h
slirp/dnssearch.lo: slirp/dnssearch.@CPP_SUFFIX@ slirp/slirp.h ../../config.h \
slirp/slirp_config.h slirp/debug.h slirp/libslirp.h slirp/compat.h \
slirp/ip.h slirp/tcp.h slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h \
slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h \
slirp/if.h slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/if.lo: slirp/if.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h ../../osdep.h \
../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \

View File

@ -52,6 +52,8 @@ private:
Slirp *slirp;
unsigned netdev_speed;
bx_bool parse_slirp_conf(const char *conf, int *, char *, struct in_addr *, struct in_addr *,
struct in_addr *, struct in_addr *, struct in_addr *);
static void rx_timer_handler(void *);
};
@ -85,6 +87,84 @@ bx_slirp_new_pktmover_c::~bx_slirp_new_pktmover_c()
}
}
bx_bool bx_slirp_new_pktmover_c::parse_slirp_conf(const char *conf, int *restricted,
char *hostname, struct in_addr *net,
struct in_addr *mask, struct in_addr *host,
struct in_addr *dhcp, struct in_addr *dns)
{
FILE *fd = NULL;
char line[512];
char *ret, *param, *val;
bx_bool format_checked = 0;
fd = fopen(conf, "r");
if (fd == NULL) return 0;
do {
ret = fgets(line, sizeof(line)-1, fd);
line[sizeof(line) - 1] = '\0';
size_t len = strlen(line);
if ((len>0) && (line[len-1] < ' '))
line[len-1] = '\0';
if ((ret != NULL) && (strlen(line) > 0)) {
if (!format_checked) {
if (!strncmp(line, "# slirp config", 14)) {
format_checked = 1;
} else {
BX_ERROR(("slirp config: wrong file format"));
fclose(fd);
return 0;
}
} else {
if (line[0] == '#') continue;
param = strtok(line, "=");
if (param != NULL) {
val = strtok(NULL, " ");
} else {
continue;
}
int len = strlen(param);
while ((len > 0) && (param[len-1] == ' ')) {
param[--len] = 0;
}
if (!strcmp(param, "restricted")) {
*restricted = atoi(val);
} else if (!strcmp(param, "hostname")) {
if (strlen(val) < 33) {
strcpy(hostname, val);
} else {
BX_ERROR(("slirp: wrong format for 'hostname'"));
}
} else if (!strcmp(param, "net")) {
if (!inet_aton(val, net)) {
BX_ERROR(("slirp: wrong format for 'net'"));
}
} else if (!strcmp(param, "mask")) {
if (!inet_aton(val, mask)) {
BX_ERROR(("slirp: wrong format for 'mask'"));
}
} else if (!strcmp(param, "host")) {
if (!inet_aton(val, host)) {
BX_ERROR(("slirp: wrong format for 'host'"));
}
} else if (!strcmp(param, "dhcp")) {
if (!inet_aton(val, dhcp)) {
BX_ERROR(("slirp: wrong format for 'dhcp'"));
}
} else if (!strcmp(param, "dns")) {
if (!inet_aton(val, dns)) {
BX_ERROR(("slirp: wrong format for 'dns'"));
}
} else {
BX_ERROR(("slirp: unknown option '%s'", line));
}
}
}
} while (!feof(fd));
fclose(fd);
return 1;
}
bx_slirp_new_pktmover_c::bx_slirp_new_pktmover_c(const char *netif,
const char *macaddr,
eth_rx_handler_t rxh,
@ -93,6 +173,9 @@ bx_slirp_new_pktmover_c::bx_slirp_new_pktmover_c(const char *netif,
const char *script)
{
struct in_addr net, mask, host, dhcp, dns;
int restricted = 0;
logfunctions *slirplog;
char hostname[33], prefix[10];
this->netdev = dev;
BX_INFO(("slirp_new network driver"));
@ -117,7 +200,17 @@ bx_slirp_new_pktmover_c::bx_slirp_new_pktmover_c(const char *netif,
host.s_addr = htonl(0x0a000202); /* 10.0.2.2 */
dhcp.s_addr = htonl(0x0a00020f); /* 10.0.2.15 */
dns.s_addr = htonl(0x0a000203); /* 10.0.2.3 */
slirp = slirp_init(0, net, mask, host, NULL, netif, NULL, dhcp, dns, NULL, this);
hostname[0] = 0;
if (strlen(script) > 0) {
if (!parse_slirp_conf(script, &restricted, hostname, &net, &mask, &host, &dhcp, &dns)) {
BX_ERROR(("reading slirp config failed"));
}
}
slirplog = new logfunctions();
sprintf(prefix, "SLIRP%d", bx_slirp_instances);
slirplog->put(prefix);
slirp = slirp_init(restricted, net, mask, host, hostname, netif, NULL, dhcp, dns,
NULL, this, slirplog);
bx_slirp_instances++;
}

View File

@ -25,15 +25,10 @@
* THE SOFTWARE.
*/
#define BX_PLUGGABLE
#include "iodev.h"
#include "slirp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
#define LOG_THIS genlog->
/* XXX: only DHCP is supported */
#define LEASE_TIME (24 * 3600)
@ -303,7 +298,7 @@ static void bootp_reply(Slirp *slirp, const struct bootp_t *bp)
size_t spaceleft = sizeof(rbp->bp_vend) - (q - rbp->bp_vend);
val = slirp->vdnssearch_len;
if (val + 1 > (int)spaceleft) {
BX_ERROR(("DHCP packet size exceeded, omitting domain-search option."));
slirp_warning(slirp, "DHCP packet size exceeded, omitting domain-search option.");
} else {
memcpy(q, slirp->vdnssearch, val);
q += val;

View File

@ -25,18 +25,13 @@
* THE SOFTWARE.
*/
#define BX_PLUGGABLE
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "iodev.h"
#include "slirp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
#define LOG_THIS genlog->
static const uint8_t RFC3397_OPT_DOMAIN_SEARCH = 119;
static const uint8_t MAX_OPT_LEN = 255;
static const uint8_t OPT_HEADER_LEN = 2;
@ -124,13 +119,14 @@ static void domain_fixup_order(CompactDomain *cd, size_t n)
}
}
static void domain_mklabels(CompactDomain *cd, const char *input)
static void domain_mklabels(Slirp *s, CompactDomain *cd, const char *input)
{
uint8_t *len_marker = cd->labels;
uint8_t *output = len_marker; /* pre-incremented */
const char *in = input;
char cur_chr;
size_t len = 0;
char msg[80];
if (cd->len == 0) {
goto fail;
@ -162,7 +158,8 @@ static void domain_mklabels(CompactDomain *cd, const char *input)
return;
fail:
BX_ERROR(("failed to parse domain name '%s'\n", input));
sprintf(msg, "failed to parse domain name '%s'\n", input);
slirp_warning(s, msg);
cd->len = 0;
}
@ -279,7 +276,7 @@ int translate_dnssearch(Slirp *s, const char **names)
outptr = result;
for (i = 0; i < num_domains; i++) {
domains[i].labels = outptr;
domain_mklabels(domains + i, names[i]);
domain_mklabels(s, domains + i, names[i]);
outptr += domains[i].len;
}

View File

@ -17,7 +17,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
const char *vhostname, const char *tftp_path,
const char *bootfile, struct in_addr vdhcp_start,
struct in_addr vnameserver, const char **vdnssearch,
void *opaque);
void *opaque, void *logfn);
void slirp_cleanup(Slirp *slirp);
void slirp_select_fill(int *pnfds, fd_set *readfds, fd_set *writefds,

View File

@ -31,7 +31,7 @@
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
#define LOG_THIS genlog->
#define LOG_THIS ((logfunctions*)slirp->logfn)->
/* host loopback address */
struct in_addr loopback_addr;
@ -214,7 +214,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
const char *vhostname, const char *tftp_path,
const char *bootfile, struct in_addr vdhcp_start,
struct in_addr vnameserver, const char **vdnssearch,
void *opaque)
void *opaque, void *logfn)
{
Slirp *slirp = (Slirp*)malloc(sizeof(Slirp));
memset(slirp, 0, sizeof(Slirp));
@ -250,6 +250,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
}
slirp->opaque = opaque;
slirp->logfn = logfn;
QTAILQ_INSERT_TAIL(&slirp_instances, slirp, entry);
@ -869,6 +870,7 @@ int slirp_add_exec(Slirp *slirp, int do_pty, const void *args,
ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags)
{
if (so->s == -1 && so->extra) {
Slirp *slirp = so->slirp;
BX_ERROR(("slirp_send(): so->extra not supported"));
return len;
}
@ -924,4 +926,9 @@ void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port,
tcp_output(sototcpcb(so));
}
void slirp_warning(Slirp *slirp, const char *msg)
{
BX_ERROR((msg));
}
#endif

View File

@ -279,6 +279,7 @@ struct Slirp {
ArpTable arp_table;
void *opaque;
void *logfn;
};
extern Slirp *slirp_instance;
@ -305,6 +306,8 @@ void if_start(struct ttys *);
long gethostid(void);
#endif
void slirp_warning(Slirp *, const char *);
#ifndef _WIN32
#include <netdb.h>
#endif

18
bochs/misc/slirp.conf Normal file
View File

@ -0,0 +1,18 @@
# slirp config
# The line above is mandatory
# This is the classic slirp setup
# restricted = 0
# net = 10.0.2.0
# mask = 255.255.255.0
# host = 10.0.2.2
# dhcp = 10.0.2.15
# dns = 10.0.2.3
# This is the vnet setup
restricted = 1
net = 192.168.10.0
mask = 255.255.255.0
host = 192.168.10.1
dhcp = 192.168.10.2
dns = 0.0.0.0