Added log file support to the 'bxhub' utility. Log output can be sent to file
specified with command line option, otherwise stderr is used.
This commit is contained in:
parent
455c28b3da
commit
d30dcfdd3c
@ -13,6 +13,7 @@ Changes after 2.6.11:
|
||||
- I/O Devices
|
||||
- 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 log file support to 'bxhub' utility (networking module 'socket').
|
||||
- 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.
|
||||
- VGA DDC: Added "ddc" parameter to the "vga" option to make it possible
|
||||
|
@ -8160,6 +8160,7 @@ extensions:
|
||||
<listitem><para>Command line options for 'bxhub' added for base UDP port and 'vnet' server features</para></listitem>
|
||||
<listitem><para>Support for connects from up to 6 Bochs sessions</para></listitem>
|
||||
<listitem><para>Support for connecting 'bxhub' on other machine</para></listitem>
|
||||
<listitem><para>Limited DNS server for 'vnet' and connected clients</para></listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
@ -8201,6 +8202,8 @@ Supported options:
|
||||
-base=... base UDP port (bxhub uses 2 ports per Bochs session)
|
||||
-mac=... host MAC address (default is b0:c4:20:00:00:0f)
|
||||
-tftp=... enable TFTP support using specified directory
|
||||
-loglev=... set log level (0 - 3, default 1)
|
||||
-logfile=... send log output to file
|
||||
--help display this help and exit
|
||||
</screen>
|
||||
</para>
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#ifdef BXHUB
|
||||
#include "config.h"
|
||||
#include "misc/bxcompat.h"
|
||||
#else
|
||||
#include "iodev.h"
|
||||
#endif
|
||||
@ -62,6 +63,7 @@ Bit16u ip_checksum(const Bit8u *buf, unsigned buf_len)
|
||||
// VNET server definitions
|
||||
|
||||
#ifdef BXHUB
|
||||
#include <stdarg.h>
|
||||
#include "misc/bxcompat.h"
|
||||
#include "osdep.h"
|
||||
#else
|
||||
@ -166,6 +168,9 @@ static const Bit8u subnetmask_ipv4addr[4] = {0xff,0xff,0xff,0x00};
|
||||
|
||||
vnet_server_c::vnet_server_c()
|
||||
{
|
||||
#ifdef BXHUB
|
||||
logfd = stderr;
|
||||
#endif
|
||||
l4data_used = 0;
|
||||
|
||||
register_layer4_handler(0x11, INET_PORT_BOOTP_SERVER, udpipv4_dhcp_handler);
|
||||
@ -184,6 +189,12 @@ vnet_server_c::~vnet_server_c()
|
||||
delete [] client[c].hostname;
|
||||
}
|
||||
}
|
||||
#ifdef BXHUB
|
||||
if (logfd != stderr) {
|
||||
fclose(logfd);
|
||||
}
|
||||
logfd = stderr;
|
||||
#endif
|
||||
}
|
||||
|
||||
void vnet_server_c::init(bx_devmodel_c *_netdev, dhcp_cfg_t *dhcpc, const char *tftp_rootdir)
|
||||
@ -206,6 +217,24 @@ void vnet_server_c::init_client(Bit8u clientid, const Bit8u *macaddr, const Bit8
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BXHUB
|
||||
void vnet_server_c::init_log(const char *logfn)
|
||||
{
|
||||
logfd = fopen(logfn, "w");
|
||||
}
|
||||
|
||||
void vnet_server_c::bx_printf(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char msg[128];
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(msg, sizeof(msg), fmt, ap);
|
||||
fprintf(logfd, "%s\n", msg);
|
||||
va_end(ap);
|
||||
}
|
||||
#endif
|
||||
|
||||
bx_bool vnet_server_c::find_client(const Bit8u *mac_addr, Bit8u *clientid)
|
||||
{
|
||||
for (Bit8u c = 0; c < VNET_MAX_CLIENTS; c++) {
|
||||
@ -928,18 +957,6 @@ int vnet_server_c::udpipv4_dhcp_handler_ns(const Bit8u *ipheader,
|
||||
|
||||
// TFTP support
|
||||
|
||||
typedef struct tftp_session {
|
||||
char filename[BX_PATHNAME_LEN];
|
||||
Bit16u tid;
|
||||
bx_bool write;
|
||||
unsigned options;
|
||||
size_t tsize_val;
|
||||
unsigned blksize_val;
|
||||
unsigned timeout_val;
|
||||
unsigned timestamp;
|
||||
struct tftp_session *next;
|
||||
} tftp_session_t;
|
||||
|
||||
tftp_session_t *tftp_sessions = NULL;
|
||||
|
||||
tftp_session_t *tftp_new_session(Bit16u req_tid, bx_bool mode, const char *tpath, const char *tname)
|
||||
@ -1097,8 +1114,8 @@ int tftp_send_optack(Bit8u *buffer, tftp_session_t *s)
|
||||
return (p - buffer);
|
||||
}
|
||||
|
||||
void tftp_parse_options(bx_devmodel_c *netdev, const char *mode, const Bit8u *data,
|
||||
unsigned data_len, tftp_session_t *s)
|
||||
void vnet_server_c::tftp_parse_options(const char *mode, const Bit8u *data,
|
||||
unsigned data_len, tftp_session_t *s)
|
||||
{
|
||||
while (mode < (const char*)data + data_len) {
|
||||
if (memcmp(mode, "octet\0", 6) == 0) {
|
||||
@ -1174,7 +1191,7 @@ int vnet_server_c::udpipv4_tftp_handler_ns(const Bit8u *ipheader,
|
||||
// options
|
||||
if (strlen((char*)reply) < data_len - 2) {
|
||||
const char *mode = (const char*)data + 2 + strlen((char*)reply) + 1;
|
||||
tftp_parse_options(netdev, mode, data, data_len, s);
|
||||
tftp_parse_options(mode, data, data_len, s);
|
||||
}
|
||||
if (!(s->options & TFTP_OPTION_OCTET)) {
|
||||
return tftp_send_error(reply, 4, "Unsupported transfer mode", NULL);
|
||||
@ -1211,7 +1228,7 @@ int vnet_server_c::udpipv4_tftp_handler_ns(const Bit8u *ipheader,
|
||||
// options
|
||||
if (strlen((char*)reply) < data_len - 2) {
|
||||
const char *mode = (const char*)data + 2 + strlen((char*)reply) + 1;
|
||||
tftp_parse_options(netdev, mode, data, data_len, s);
|
||||
tftp_parse_options(mode, data, data_len, s);
|
||||
}
|
||||
if (!(s->options & TFTP_OPTION_OCTET)) {
|
||||
return tftp_send_error(reply, 4, "Unsupported transfer mode", NULL);
|
||||
|
@ -123,6 +123,18 @@ typedef struct {
|
||||
#endif
|
||||
Bit16u ip_checksum(const Bit8u *buf, unsigned buf_len);
|
||||
|
||||
typedef struct tftp_session {
|
||||
char filename[BX_PATHNAME_LEN];
|
||||
Bit16u tid;
|
||||
bx_bool write;
|
||||
unsigned options;
|
||||
size_t tsize_val;
|
||||
unsigned blksize_val;
|
||||
unsigned timeout_val;
|
||||
unsigned timestamp;
|
||||
struct tftp_session *next;
|
||||
} tftp_session_t;
|
||||
|
||||
// VNET server
|
||||
|
||||
#define VNET_MAX_CLIENTS 6
|
||||
@ -147,6 +159,9 @@ public:
|
||||
void init(bx_devmodel_c *netdev, dhcp_cfg_t *dhcpc, const char *tftp_rootdir);
|
||||
void init_client(Bit8u clientid, const Bit8u *macaddr, const Bit8u *default_ipv4addr);
|
||||
int handle_packet(const Bit8u *buf, unsigned len, Bit8u *reply);
|
||||
#ifdef BXHUB
|
||||
void init_log(const char *logfn);
|
||||
#endif
|
||||
|
||||
layer4_handler_t get_layer4_handler(unsigned ipprotocol, unsigned port);
|
||||
bx_bool register_layer4_handler(unsigned ipprotocol, unsigned port,
|
||||
@ -154,6 +169,9 @@ public:
|
||||
bx_bool unregister_layer4_handler(unsigned ipprotocol, unsigned port);
|
||||
|
||||
private:
|
||||
#ifdef BXHUB
|
||||
void bx_printf(const char *fmt, ...);
|
||||
#endif
|
||||
bx_bool find_client(const Bit8u *mac_addr, Bit8u *clientid);
|
||||
|
||||
int process_arp(Bit8u clientid, const Bit8u *buf, unsigned len, Bit8u *reply);
|
||||
@ -188,6 +206,12 @@ private:
|
||||
unsigned sourceport, unsigned targetport,
|
||||
const Bit8u *data, unsigned data_len, Bit8u *reply);
|
||||
|
||||
void tftp_parse_options(const char *mode, const Bit8u *data, unsigned data_len,
|
||||
tftp_session_t *s);
|
||||
|
||||
#ifdef BXHUB
|
||||
FILE *logfd;
|
||||
#endif
|
||||
bx_devmodel_c *netdev;
|
||||
dhcp_cfg_t *dhcp;
|
||||
const char *tftp_root;
|
||||
|
@ -3,7 +3,7 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2013 Volker Ruppert
|
||||
// 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
|
||||
@ -76,9 +76,9 @@ extern const char *hdimage_mode_names[];
|
||||
#define BX_PANIC(x) { (printf) x ; printf("\n"); myexit(1); }
|
||||
#define BX_FATAL(x) { (printf) x ; printf("\n"); myexit(1); }
|
||||
#else
|
||||
#define BX_DEBUG(x) { if (bx_loglev == 3) { (printf) x ; printf("\n"); } }
|
||||
#define BX_INFO(x) { if (bx_loglev >= 2) { (printf) x ; printf("\n"); } }
|
||||
#define BX_ERROR(x) { if (bx_loglev >= 1) { (printf) x ; printf("\n"); } }
|
||||
#define BX_DEBUG(x) { if (bx_loglev == 3) { (bx_printf) x ; } }
|
||||
#define BX_INFO(x) { if (bx_loglev >= 2) { (bx_printf) x ; } }
|
||||
#define BX_ERROR(x) { if (bx_loglev >= 1) { (bx_printf) x ; } }
|
||||
#endif
|
||||
#define BX_ASSERT(x)
|
||||
|
||||
|
@ -97,6 +97,7 @@ static Bit8u default_guest_ipv4addr[4] = {10, 0, 2, 15};
|
||||
static dhcp_cfg_t dhcp;
|
||||
static vnet_server_c vnet_server;
|
||||
int bx_loglev;
|
||||
static char bx_logfname[BX_PATHNAME_LEN];
|
||||
|
||||
|
||||
bx_bool handle_packet(hub_client_t *client, Bit8u *buf, unsigned len)
|
||||
@ -167,6 +168,7 @@ void print_usage()
|
||||
" -mac=... host MAC address (default is b0:c4:20:00:00:0f)\n"
|
||||
" -tftp=... enable TFTP support using specified directory\n"
|
||||
" -loglev=... set log level (0 - 3, default 1)\n"
|
||||
" -logfile=... send log output to file\n"
|
||||
" --help display this help and exit\n\n");
|
||||
}
|
||||
|
||||
@ -181,6 +183,7 @@ int parse_cmdline(int argc, char *argv[])
|
||||
bx_loglev = 1;
|
||||
port_base = 40000;
|
||||
tftp_root[0] = 0;
|
||||
bx_logfname[0] = 0;
|
||||
memcpy(host_macaddr, default_host_macaddr, ETHERNET_MAC_ADDR_LEN);
|
||||
while ((arg < argc) && (ret == 1)) {
|
||||
// parse next arg
|
||||
@ -228,6 +231,9 @@ int parse_cmdline(int argc, char *argv[])
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
else if (!strncmp("-logfile=", argv[arg], 9)) {
|
||||
strcpy(bx_logfname, &argv[arg][9]);
|
||||
}
|
||||
else if (argv[arg][0] == '-') {
|
||||
printf("Unknown option: %s\n\n", argv[arg]);
|
||||
ret = 0;
|
||||
@ -321,6 +327,11 @@ int CDECL main(int argc, char **argv)
|
||||
} else {
|
||||
printf("TFTP support disabled\n");
|
||||
}
|
||||
|
||||
if (strlen(bx_logfname) > 0) {
|
||||
vnet_server.init_log(bx_logfname);
|
||||
printf("Using log file '%s'\n", bx_logfname);
|
||||
}
|
||||
printf("Press CTRL+C to quit bxhub\n");
|
||||
|
||||
while (1) {
|
||||
|
Loading…
Reference in New Issue
Block a user