Added support for the bootfile option in the slirp config file.

Moved slirp config parameters to the ethernet module object.
Added initial documentation for the built-in slirp support
This commit is contained in:
Volker Ruppert 2014-03-03 16:32:11 +00:00
parent f62c8f158f
commit 25f9b4346a
5 changed files with 60 additions and 32 deletions

View File

@ -984,6 +984,7 @@ speaker: enabled=1, mode=sound
# ne2k: ioaddr=0x300, irq=9, mac=b0:c4:20:00:00:01, ethmod=vde, ethdev="/tmp/vde.ctl"
# ne2k: ioaddr=0x300, irq=9, mac=b0:c4:20:00:00:01, ethmod=vnet, ethdev="c:/temp"
# ne2k: mac=b0:c4:20:00:00:01, ethmod=slirp, script=/usr/local/bin/slirp, bootrom=ne2k_pci.rom
# ne2k: mac=b0:c4:20:00:00:01, ethmod=slirp_new, script=slirp.conf
#=======================================================================
# pcipnic: Bochs/Etherboot pseudo-NIC
@ -1007,7 +1008,7 @@ speaker: enabled=1, mode=sound
# The E1000 accepts the same syntax (for mac, ethmod, ethdev, script, bootrom)
# and supports the same networking modules as the NE2000 adapter.
#=======================================================================
#e1000: enabled=1, mac=52:54:00:12:34:56, ethmod=slirp, script=/usr/local/bin/slirp
#e1000: enabled=1, mac=52:54:00:12:34:56, ethmod=slirp_new, script=slirp.conf
#=======================================================================
# USB_UHCI:

View File

@ -4414,6 +4414,7 @@ ne2k: ioaddr=0x300, irq=9, mac=b0:c4:20:00:00:01, ethmod=vnet, ethdev="c:/temp"
ne2k: ioaddr=0x300, irq=9, mac=fe:fd:00:00:00:01, ethmod=tap, ethdev=tap0
ne2k: ioaddr=0x300, irq=9, mac=fe:fd:00:00:00:01, ethmod=tuntap, ethdev=/dev/net/tun0, script=./tunconfig
ne2k: mac=fe:fd:00:00:00:01, ethmod=slirp, script=/usr/local/bin/slirp, bootrom=ne2k_pci.rom
ne2k: mac=b0:c4:20:00:00:01, ethmod=slirp_new, script=slirp.conf
IOADDR, IRQ: You probably won't need to change ioaddr and irq, unless there
are IRQ conflicts. These parameters are ignored if the NE2000 is assigned to
@ -4537,9 +4538,20 @@ version where this module was added.
overwrite files.
</entry>
<entry>Yes, for TFTP</entry>
<entry>Yes</entry>
<entry>Yes, for Slirp binary</entry>
<entry>2.5</entry>
</row>
<row>
<entry>slirp_new</entry>
<entry>Built-in Slirp support with DHCP / TFTP servers. Adds user mode
networking to Bochs. The "script" parameter can be used to set up an
alternative configuration. The TFTP server uses the 'ethdev' value for
the root directory and currently operates in read-only mode.
</entry>
<entry>Yes, for TFTP</entry>
<entry>Yes, for Slirp config</entry>
<entry>2.6.2.svn</entry>
</row>
<row>
<entry>win32</entry>
<entry>Win32 packetmover - WinPCap driver required.

View File

@ -1,5 +1,5 @@
.\"Document Author: Timothy R. Butler - tbutler@uninetsolutions.com"
.TH bochsrc 5 "28 Dec 2013" "bochsrc" "The Bochs Project"
.TH bochsrc 5 "03 Mar 2014" "bochsrc" "The Bochs Project"
.\"SKIP_SECTION"
.SH NAME
bochsrc \- Configuration file for Bochs.
@ -1053,12 +1053,13 @@ be other restrictions too. To be safe, just use the b0:c4... address.
ETHMOD:
The ethmod value defines which low level OS specific module to be used
to access physical ethernet interface. Current implemented values include
- fbsd : ethernet on freebsd and openbsd
- linux : ethernet on linux
- win32 : ethernet on win32
- tap : ethernet through a linux tap interface
- tuntap : ethernet through a linux tuntap interface
- slirp : ethernet backend for Slirp with builtin DHCP / TFTP servers
- fbsd : ethernet on freebsd and openbsd
- linux : ethernet on linux
- win32 : ethernet on win32
- tap : ethernet through a linux tap interface
- tuntap : ethernet through a linux tuntap interface
- slirp : ethernet backend for Slirp with builtin DHCP / TFTP servers
- slirp_new : built-in Slirp support
If you don't want to make connections to any physical networks,
you can use the following 'ethmod's to simulate a virtual network.
@ -1099,6 +1100,7 @@ Examples:
ne2k: ioaddr=0x300, irq=9, mac=b0:c4:20:00:00:01, ethmod=vde, ethdev="/tmp/vde.ctl"
ne2k: ioaddr=0x300, irq=9, mac=b0:c4:20:00:00:01, ethmod=vnet, ethdev="c:/temp"
ne2k: mac=b0:c4:20:00:00:01, ethmod=slirp, script=/usr/local/bin/slirp, bootrom=ne2k_pci.rom
ne2k: mac=b0:c4:20:00:00:01, ethmod=slirp_new, script=slirp.conf
.TP
.I "pcipnic:"
@ -1118,7 +1120,7 @@ with the --eanble-e1000 configure option. The E1000 accepts the same syntax
modules as the NE2000 adapter.
Example:
e1000: enabled=1, mac=52:54:00:12:34:56, ethmod=slirp, script=/usr/local/bin/slirp
e1000: enabled=1, mac=52:54:00:12:34:56, ethmod=slirp_new, script=slirp.conf
.TP
.I "usb_uhci:"

View File

@ -52,8 +52,11 @@ 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 *);
int restricted;
struct in_addr net, mask, host, dhcp, dns;
char *bootfile, *hostname;
bx_bool parse_slirp_conf(const char *conf);
static void rx_timer_handler(void *);
};
@ -72,12 +75,16 @@ protected:
bx_slirp_new_pktmover_c::bx_slirp_new_pktmover_c()
{
slirp = NULL;
bootfile = NULL;
hostname = NULL;
}
bx_slirp_new_pktmover_c::~bx_slirp_new_pktmover_c()
{
if (slirp != NULL) {
slirp_cleanup(slirp);
if (bootfile != NULL) free(bootfile);
if (hostname != NULL) free(hostname);
if (--bx_slirp_instances == 0) {
bx_pc_system.deactivate_timer(rx_timer_index);
#ifndef WIN32
@ -87,10 +94,7 @@ 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)
bx_bool bx_slirp_new_pktmover_c::parse_slirp_conf(const char *conf)
{
FILE *fd = NULL;
char line[512];
@ -123,36 +127,46 @@ bx_bool bx_slirp_new_pktmover_c::parse_slirp_conf(const char *conf, int *restric
} else {
continue;
}
int len = strlen(param);
while ((len > 0) && (param[len-1] == ' ')) {
param[--len] = 0;
int len1 = strlen(param);
int len2 = strlen(val);
while ((len1 > 0) && (param[len1-1] == ' ')) {
param[--len1] = 0;
}
if ((len1 == 0) || (len2 == 0)) continue;
if (!strcmp(param, "restricted")) {
*restricted = atoi(val);
restricted = atoi(val);
} else if (!strcmp(param, "hostname")) {
if (strlen(val) < 33) {
if (len2 < 33) {
hostname = (char*)malloc(len2+1);
strcpy(hostname, val);
} else {
BX_ERROR(("slirp: wrong format for 'hostname'"));
}
} else if (!strcmp(param, "bootfile")) {
if (len2 < 128) {
bootfile = (char*)malloc(len2+1);
strcpy(bootfile, val);
} else {
BX_ERROR(("slirp: wrong format for 'bootfile'"));
}
} else if (!strcmp(param, "net")) {
if (!inet_aton(val, net)) {
if (!inet_aton(val, &net)) {
BX_ERROR(("slirp: wrong format for 'net'"));
}
} else if (!strcmp(param, "mask")) {
if (!inet_aton(val, mask)) {
if (!inet_aton(val, &mask)) {
BX_ERROR(("slirp: wrong format for 'mask'"));
}
} else if (!strcmp(param, "host")) {
if (!inet_aton(val, host)) {
if (!inet_aton(val, &host)) {
BX_ERROR(("slirp: wrong format for 'host'"));
}
} else if (!strcmp(param, "dhcp")) {
if (!inet_aton(val, dhcp)) {
if (!inet_aton(val, &dhcp)) {
BX_ERROR(("slirp: wrong format for 'dhcp'"));
}
} else if (!strcmp(param, "dns")) {
if (!inet_aton(val, dns)) {
if (!inet_aton(val, &dns)) {
BX_ERROR(("slirp: wrong format for 'dns'"));
}
} else {
@ -172,10 +186,8 @@ bx_slirp_new_pktmover_c::bx_slirp_new_pktmover_c(const char *netif,
bx_devmodel_c *dev,
const char *script)
{
struct in_addr net, mask, host, dhcp, dns;
int restricted = 0;
logfunctions *slirplog;
char hostname[33], prefix[10];
char bootfile[128], hostname[33], prefix[10];
this->netdev = dev;
BX_INFO(("slirp_new network driver"));
@ -200,16 +212,16 @@ 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 */
hostname[0] = 0;
restricted = 0;
if (strlen(script) > 0) {
if (!parse_slirp_conf(script, &restricted, hostname, &net, &mask, &host, &dhcp, &dns)) {
if (!parse_slirp_conf(script)) {
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,
slirp = slirp_init(restricted, net, mask, host, hostname, netif, bootfile, dhcp, dns,
NULL, this, slirplog);
bx_slirp_instances++;

View File

@ -16,3 +16,4 @@ mask = 255.255.255.0
host = 192.168.10.1
dhcp = 192.168.10.2
dns = 0.0.0.0
bootfile = pxelinux.0