[prev in list] [next in list] [prev in thread] [next in thread]
List: bochs-cvs
Subject: [Bochs-cvs] [13928] trunk/bochs
From: vruppert--- via Bochs-cvs <bochs-cvs () lists ! sourceforge ! net>
Date: 2020-08-25 19:04:06
Message-ID: 1598382246.322543.9470 () sfp-scm-3 ! v30 ! lw ! sourceforge ! com
[Download RAW message or body]
Revision: 13928
Author: vruppert
Date: 2020-08-25 19:04:05 +0000 (Tue, 25 Aug 2020)
Log Message:
-----------
Started implementing config file support for the 'vnet' module similar to the
'slirp' one. File name can be specified with the "script" parameter. Currently
supported parameters: bootfile, hostname and pktlog.
Modified Paths:
--------------
trunk/bochs/.bochsrc
trunk/bochs/CHANGES
trunk/bochs/doc/docbook/user/user.dbk
trunk/bochs/doc/man/bochsrc.5
trunk/bochs/iodev/network/eth_slirp.cc
trunk/bochs/iodev/network/eth_vnet.cc
trunk/bochs/iodev/network/netmod.cc
trunk/bochs/iodev/network/netmod.h
Modified: trunk/bochs/.bochsrc
===================================================================
--- trunk/bochs/.bochsrc 2020-08-24 15:31:14 UTC (rev 13927)
+++ trunk/bochs/.bochsrc 2020-08-25 19:04:05 UTC (rev 13928)
@@ -1033,8 +1033,8 @@
# The 'socket' module uses this parameter to specify the UDP port for
# receiving packets and (optional) the host to connect.
#
-# SCRIPT: The script value is optional, and is the name of a script that
-# is executed after bochs initialize the network interface. You can use
+# SCRIPT: The script value is optional, and is the name of a script that
+# is executed after bochs initialize the network interface. You can use
# this script to configure this network interface, or enable masquerading.
# This is mainly useful for the tun/tap devices that only exist during
# Bochs execution. The network interface name is supplied to the script
@@ -1041,8 +1041,8 @@
# as first parameter.
# The 'slirp' module uses this parameter to specify a config file for
# setting up an alternative IP configuration or additional features.
-# The 'vnet' module uses this parameter to specify a file name for logging
-# packets in text format.
+# The 'vnet' module also uses this parameter to specify a config file similar
+# to slirp, but with only a few settings.
#
# BOOTROM: The bootrom value is optional, and is the name of the ROM image
# to load. Note that this feature is only implemented for the PCI version of
Modified: trunk/bochs/CHANGES
===================================================================
--- trunk/bochs/CHANGES 2020-08-24 15:31:14 UTC (rev 13927)
+++ trunk/bochs/CHANGES 2020-08-25 19:04:05 UTC (rev 13928)
@@ -16,10 +16,11 @@
- Added "multiple NICs" support to the NE2000 and E1000 devices. Up to 4 devices
per model are supported. Use the zero-based "card" parameter to specify \
device.
- Added experimental FTP service for networking modules 'vnet' and 'socket'.
- - Fixes for network boot support with iPXE (modules 'slirp' and 'socket').
+ - Fixes for iPXE network boot support (modules 'slirp', 'socket', 'vnet').
+ - Added config file support for the 'vnet' module (similar to 'slirp').
- Added log file support to 'bxhub' utility (networking module 'socket').
- Packet logging in text format for the 'slirp' and 'vnet' modules controlled
- by runtime option (slirp: "pktlog" option in config / vnet: "script" \
parameter). + by runtime option ("pktlog" option in config).
- VGA
- Removed lfb_enabled switch from Bochs VBE code. Now banked and LFB writes
to VRAM are always valid. Fixes GRUB bootloader menu when using Bochs VBE.
Modified: trunk/bochs/doc/docbook/user/user.dbk
===================================================================
--- trunk/bochs/doc/docbook/user/user.dbk 2020-08-24 15:31:14 UTC (rev 13927)
+++ trunk/bochs/doc/docbook/user/user.dbk 2020-08-25 19:04:05 UTC (rev 13928)
@@ -4743,8 +4743,8 @@
Bochs execution. The network interface name is supplied to the script
as first parameter. The 'slirp' module uses this parameter to specify a config
file for setting up an alternative IP configuration or additional features.
-The 'vnet' module uses this parameter to specify a file name for logging
-packets in text format.
+The 'vnet' module also uses this parameter to specify a config file similar
+to slirp, but with only a few settings.
BOOTROM: The bootrom value is optional, and is the name of the ROM image
to load. Note that this feature is only implemented for the PCI version of
Modified: trunk/bochs/doc/man/bochsrc.5
===================================================================
--- trunk/bochs/doc/man/bochsrc.5 2020-08-24 15:31:14 UTC (rev 13927)
+++ trunk/bochs/doc/man/bochsrc.5 2020-08-25 19:04:05 UTC (rev 13928)
@@ -1,5 +1,5 @@
.\"Document Author: Timothy R. Butler - tbutler@uninetsolutions.com"
-.TH bochsrc 5 "16 Jul 2020" "bochsrc" "The Bochs Project"
+.TH bochsrc 5 "25 Aug 2020" "bochsrc" "The Bochs Project"
.\"SKIP_SECTION"
.SH NAME
bochsrc \- Configuration file for Bochs.
@@ -1170,8 +1170,8 @@
Bochs execution. The network interface name is supplied to the script
as first parameter. The 'slirp' module uses this parameter to specify
a config file for setting up an alternative IP configuration or additional
-features. The 'vnet' module uses this parameter to specify a file name for
-logging packets in text format.
+features. The 'vnet' module also uses this parameter to specify a config file
+similar to slirp, but with only a few settings.
BOOTROM:
The bootrom value is optional, and is the name of the ROM image
Modified: trunk/bochs/iodev/network/eth_slirp.cc
===================================================================
--- trunk/bochs/iodev/network/eth_slirp.cc 2020-08-24 15:31:14 UTC (rev 13927)
+++ trunk/bochs/iodev/network/eth_slirp.cc 2020-08-25 19:04:05 UTC (rev 13928)
@@ -144,21 +144,6 @@
}
}
-static size_t strip_whitespace(char *s)
-{
- size_t ptr = 0;
- char *tmp = (char*)malloc(strlen(s)+1);
- strcpy(tmp, s);
- while (s[ptr] == ' ') ptr++;
- if (ptr > 0) strcpy(s, tmp+ptr);
- free(tmp);
- ptr = strlen(s);
- while ((ptr > 0) && (s[ptr-1] == ' ')) {
- s[--ptr] = 0;
- }
- return ptr;
-}
-
bx_bool bx_slirp_pktmover_c::parse_slirp_conf(const char *conf)
{
FILE *fd = NULL;
Modified: trunk/bochs/iodev/network/eth_vnet.cc
===================================================================
--- trunk/bochs/iodev/network/eth_vnet.cc 2020-08-24 15:31:14 UTC (rev 13927)
+++ trunk/bochs/iodev/network/eth_vnet.cc 2020-08-25 19:04:05 UTC (rev 13928)
@@ -90,6 +90,7 @@
bx_devmodel_c *dev, const char *script);
void sendpkt(void *buf, unsigned io_len);
private:
+ bx_bool parse_vnet_conf(const char *conf);
void guest_to_host(const Bit8u *buf, unsigned io_len);
void host_to_guest(void);
@@ -96,6 +97,7 @@
vnet_server_c vnet_server;
dhcp_cfg_t dhcp;
+ char *hostname;
static void rx_timer_handler(void *);
void rx_timer(void);
@@ -106,6 +108,7 @@
unsigned tx_time;
bx_bool vnet_logging;
+ char *pktlog_fn;
FILE *pktlog_txt;
#if BX_ETH_VNET_PCAP_LOGGING
pcap_t *pcapp;
@@ -134,6 +137,85 @@
{
}
+bx_vnet_pktmover_c::~bx_vnet_pktmover_c()
+{
+ if (vnet_logging) {
+ fclose(pktlog_txt);
+ }
+ bx_vnet_instances--;
+}
+
+bx_bool bx_vnet_pktmover_c::parse_vnet_conf(const char *conf)
+{
+ FILE *fd = NULL;
+ char line[512];
+ char *ret, *param, *val;
+ bx_bool format_checked = 0;
+ size_t len1 = 0, len2;
+
+ 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, "# vnet config", 14)) {
+ format_checked = 1;
+ } else {
+ BX_ERROR(("vnet config: wrong file format"));
+ fclose(fd);
+ return 0;
+ }
+ } else {
+ if (line[0] == '#') continue;
+ param = strtok(line, "=");
+ if (param != NULL) {
+ len1 = strip_whitespace(param);
+ val = strtok(NULL, "");
+ if (val == NULL) {
+ BX_ERROR(("vnet config: missing value for parameter '%s'", param));
+ continue;
+ }
+ } else {
+ continue;
+ }
+ len2 = strip_whitespace(val);
+ if ((len1 == 0) || (len2 == 0)) continue;
+ if (!stricmp(param, "hostname")) {
+ if (len2 < 33) {
+ hostname = (char*)malloc(len2+1);
+ strcpy(hostname, val);
+ } else {
+ BX_ERROR(("vnet: wrong format for 'hostname'"));
+ }
+ } else if (!stricmp(param, "bootfile")) {
+ if (len2 < 128) {
+ strcpy(dhcp.bootfile, val);
+ } else {
+ BX_ERROR(("vnet: wrong format for 'bootfile'"));
+ }
+ } else if (!stricmp(param, "pktlog")) {
+ if (len2 < BX_PATHNAME_LEN) {
+ pktlog_fn = (char*)malloc(len2+1);
+ strcpy(pktlog_fn, val);
+ } else {
+ BX_ERROR(("vnet: wrong format for 'pktlog'"));
+ }
+ } else {
+ BX_ERROR(("vnet: unknown option '%s'", line));
+ }
+ }
+ }
+ } while (!feof(fd));
+ fclose(fd);
+ return 1;
+}
+
void bx_vnet_pktmover_c::pktmover_init(
const char *netif, const char *macaddr,
eth_rx_handler_t rxh, eth_rx_status_t rxstat,
@@ -154,8 +236,15 @@
memcpy(dhcp.srv_ipv4addr[VNET_MISC], default_ftp_ipv4addr, 4);
memcpy(dhcp.client_base_ipv4addr, dhcp_base_ipv4addr, 4);
strcpy(dhcp.bootfile, default_bootfile);
+ hostname = NULL;
+ pktlog_fn = NULL;
+ if ((strlen(script) > 0) && (strcmp(script, "none"))) {
+ if (!parse_vnet_conf(script)) {
+ BX_ERROR(("reading vnet config failed"));
+ }
+ }
vnet_server.init(dev, &dhcp, netif);
- vnet_server.init_client(0, (Bit8u*)macaddr, NULL);
+ vnet_server.init_client(0, (Bit8u*)macaddr, hostname);
Bit32u status = this->rxstat(this->netdev) & BX_NETDEV_SPEED;
this->netdev_speed = (status == BX_NETDEV_1GBIT) ? 1000 :
@@ -167,8 +256,8 @@
BX_INFO(("'vnet' network driver initialized"));
bx_vnet_instances++;
- if ((strlen(script) > 0) && (strcmp(script, "none"))) {
- pktlog_txt = fopen(script, "wb");
+ if (pktlog_fn != NULL) {
+ pktlog_txt = fopen(pktlog_fn, "wb");
vnet_logging = (pktlog_txt != NULL);
} else {
vnet_logging = 0;
@@ -193,14 +282,6 @@
#endif
}
-bx_vnet_pktmover_c::~bx_vnet_pktmover_c()
-{
- if (vnet_logging) {
- fclose(pktlog_txt);
- }
- bx_vnet_instances--;
-}
-
void bx_vnet_pktmover_c::sendpkt(void *buf, unsigned io_len)
{
guest_to_host((const Bit8u *)buf,io_len);
Modified: trunk/bochs/iodev/network/netmod.cc
===================================================================
--- trunk/bochs/iodev/network/netmod.cc 2020-08-24 15:31:14 UTC (rev 13927)
+++ trunk/bochs/iodev/network/netmod.cc 2020-08-25 19:04:05 UTC (rev 13928)
@@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
-// Copyright (C) 2001-2017 The Bochs Project
+// Copyright (C) 2001-2020 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@@ -228,4 +228,19 @@
fflush(pktlog_txt);
}
+size_t strip_whitespace(char *s)
+{
+ size_t ptr = 0;
+ char *tmp = (char*)malloc(strlen(s)+1);
+ strcpy(tmp, s);
+ while (s[ptr] == ' ') ptr++;
+ if (ptr > 0) strcpy(s, tmp+ptr);
+ free(tmp);
+ ptr = strlen(s);
+ while ((ptr > 0) && (s[ptr-1] == ' ')) {
+ s[--ptr] = 0;
+ }
+ return ptr;
+}
+
#endif /* if BX_NETWORKING */
Modified: trunk/bochs/iodev/network/netmod.h
===================================================================
--- trunk/bochs/iodev/network/netmod.h 2020-08-24 15:31:14 UTC (rev 13927)
+++ trunk/bochs/iodev/network/netmod.h 2020-08-25 19:04:05 UTC (rev 13928)
@@ -88,6 +88,7 @@
int execute_script(bx_devmodel_c *netdev, const char *name, char* arg1);
void BOCHSAPI_MSVCONLY write_pktlog_txt(FILE *pktlog_txt, const Bit8u *buf, unsigned \
len, bx_bool host_to_guest); +size_t strip_whitespace(char *s);
//
// The eth_pktmover class is used by ethernet chip emulations
_______________________________________________
Bochs-cvs mailing list
Bochs-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bochs-cvs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic