Some work on the vnet server code.
- FTP: handle the hidden flag on Windows the same way as on other platforms. - TCP/IP: fixed some gcc 9 warnings (checked with Cygwin gcc 9.3). - DHCP: changed the way to set up the default client IPv4 address.
This commit is contained in:
parent
1eb0439279
commit
a4bf5843f0
@ -20,7 +20,7 @@
|
||||
|
||||
// virtual Ethernet locator
|
||||
//
|
||||
// An implementation of ARP, ping(ICMP-echo), DHCP and read/write TFTP.
|
||||
// An implementation of ARP, ping(ICMP-echo), DHCP and read/write FTP and TFTP.
|
||||
// Virtual host acts as a DHCP server for guest.
|
||||
// Limited DNS server for 'vnet' and the client only.
|
||||
// There are no connections between the virtual host and real ethernets.
|
||||
@ -31,7 +31,8 @@
|
||||
// Guest IP: 192.168.10.15
|
||||
// Guest netmask: 255.255.255.0
|
||||
// Guest broadcast: 192.168.10.255
|
||||
// TFTP server uses ethdev value for the root directory and doesn't overwrite files
|
||||
// FTP and TFTP server using the ethdev value for the root directory
|
||||
// TFTP doesn't overwrite files
|
||||
|
||||
#define BX_PLUGGABLE
|
||||
|
||||
@ -71,7 +72,7 @@ void CDECL libvnet_net_plugin_fini(void)
|
||||
|
||||
static const Bit8u default_host_ipv4addr[4] = {192,168,10,1};
|
||||
static const Bit8u default_dns_ipv4addr[4] = {192,168,10,2};
|
||||
static const Bit8u default_guest_ipv4addr[4] = {192,168,10,15};
|
||||
static const Bit8u dhcp_base_ipv4addr[4] = {192,168,10,15};
|
||||
|
||||
static Bit8u packet_buffer[BX_PACKET_BUFSIZE];
|
||||
static unsigned packet_len;
|
||||
@ -147,8 +148,9 @@ void bx_vnet_pktmover_c::pktmover_init(
|
||||
|
||||
memcpy(dhcp.host_ipv4addr, default_host_ipv4addr, 4);
|
||||
memcpy(dhcp.dns_ipv4addr, default_dns_ipv4addr, 4);
|
||||
memcpy(dhcp.client_base_ipv4addr, dhcp_base_ipv4addr, 4);
|
||||
vnet_server.init(dev, &dhcp, netif);
|
||||
vnet_server.init_client(0, (Bit8u*)macaddr, (Bit8u*)&default_guest_ipv4addr);
|
||||
vnet_server.init_client(0, (Bit8u*)macaddr);
|
||||
|
||||
Bit32u status = this->rxstat(this->netdev) & BX_NETDEV_SPEED;
|
||||
this->netdev_speed = (status == BX_NETDEV_1GBIT) ? 1000 :
|
||||
|
@ -231,11 +231,12 @@ void vnet_server_c::init(bx_devmodel_c *_netdev, dhcp_cfg_t *dhcpc, const char *
|
||||
}
|
||||
}
|
||||
|
||||
void vnet_server_c::init_client(Bit8u clientid, const Bit8u *macaddr, const Bit8u *default_ipv4addr)
|
||||
void vnet_server_c::init_client(Bit8u clientid, const Bit8u *macaddr)
|
||||
{
|
||||
if (clientid < VNET_MAX_CLIENTS) {
|
||||
client[clientid].macaddr = macaddr;
|
||||
client[clientid].default_ipv4addr = default_ipv4addr;
|
||||
memcpy(client[clientid].default_ipv4addr, dhcp->client_base_ipv4addr, 4);
|
||||
client[clientid].default_ipv4addr[3] += clientid;
|
||||
memset(client[clientid].ipv4addr, 0, 4);
|
||||
client[clientid].hostname = new char[256];
|
||||
client[clientid].hostname[0] = 0;
|
||||
@ -494,7 +495,8 @@ void vnet_server_c::host_to_guest_ipv4(const Bit8u clientid, bx_bool dns_srv, Bi
|
||||
|
||||
iphdr->version = 4;
|
||||
l3header_len = (iphdr->header_len << 2);
|
||||
iphdr->id = htons(++packet_counter);
|
||||
iphdr->id = htons(packet_counter);
|
||||
packet_counter++;
|
||||
if (dns_srv) {
|
||||
memcpy(iphdr->src_addr, dhcp->dns_ipv4addr, 4);
|
||||
} else {
|
||||
@ -906,7 +908,8 @@ void vnet_server_c::tcpipv4_send_fin(tcp_conn_t *tcp_conn, bx_bool host_fin)
|
||||
memset(replybuf, 0, MIN_RX_PACKET_LEN);
|
||||
tcphdr->flags.fin = 1;
|
||||
tcphdr->flags.ack = 1;
|
||||
tcphdr->seq_num = htonl(tcp_conn->host_seq_num++);
|
||||
tcphdr->seq_num = htonl(tcp_conn->host_seq_num);
|
||||
tcp_conn->host_seq_num++;
|
||||
tcphdr->ack_num = htonl(tcp_conn->guest_seq_num);
|
||||
tcphdr->window = htons(tcp_conn->window);
|
||||
tcp_conn->state = TCP_DISCONNECTING;
|
||||
@ -1645,7 +1648,7 @@ void vnet_server_c::ftp_list_directory(tcp_conn_t *tcpc_cmd, tcp_conn_t *tcpc_da
|
||||
while ((dent=readdir(dir)) != NULL) {
|
||||
linebuf[0] = 0;
|
||||
if (strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..") &&
|
||||
(hidden || (dent->d_name[0] != '.' ))) {
|
||||
(hidden || (dent->d_name[0] != '.'))) {
|
||||
sprintf(path, "%s/%s", abspath, dent->d_name);
|
||||
if (!nlst) {
|
||||
if (stat(path, &st) >= 0) {
|
||||
@ -1687,7 +1690,8 @@ void vnet_server_c::ftp_list_directory(tcp_conn_t *tcpc_cmd, tcp_conn_t *tcpc_da
|
||||
if (hFind != INVALID_HANDLE_VALUE) {
|
||||
do {
|
||||
linebuf[0] = 0;
|
||||
if (strcmp(finddata.cFileName, ".") && strcmp(finddata.cFileName, "..")) {
|
||||
if (strcmp(finddata.cFileName, ".") && strcmp(finddata.cFileName, "..") &&
|
||||
(hidden || (finddata.cFileName[0] != '.'))) {
|
||||
if (!nlst) {
|
||||
FileTimeToSystemTime(&finddata.ftLastWriteTime, &gmtsystime);
|
||||
GetTimeZoneInformation(&tzi);
|
||||
|
@ -160,6 +160,7 @@ typedef struct {
|
||||
Bit8u host_macaddr[6];
|
||||
Bit8u host_ipv4addr[4];
|
||||
Bit8u dns_ipv4addr[4];
|
||||
Bit8u client_base_ipv4addr[4];
|
||||
} dhcp_cfg_t;
|
||||
|
||||
// vnet functions shared with bxhub
|
||||
@ -233,7 +234,7 @@ public:
|
||||
virtual ~vnet_server_c();
|
||||
|
||||
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);
|
||||
void init_client(Bit8u clientid, const Bit8u *macaddr);
|
||||
void handle_packet(const Bit8u *buf, unsigned len);
|
||||
unsigned get_packet(Bit8u *buf);
|
||||
#ifdef BXHUB
|
||||
@ -254,7 +255,6 @@ private:
|
||||
void bx_printf(const char *fmt, ...);
|
||||
#endif
|
||||
bx_bool find_client(const Bit8u *mac_addr, Bit8u *clientid);
|
||||
bx_bool find_client2(const Bit8u *ipv4addr, Bit8u *clientid);
|
||||
|
||||
void host_to_guest(Bit8u clientid, Bit8u *buf, unsigned len, unsigned l3type);
|
||||
|
||||
@ -330,7 +330,7 @@ private:
|
||||
struct {
|
||||
bx_bool init;
|
||||
const Bit8u *macaddr;
|
||||
const Bit8u *default_ipv4addr;
|
||||
Bit8u default_ipv4addr[4];
|
||||
Bit8u ipv4addr[4];
|
||||
char *hostname;
|
||||
} client[VNET_MAX_CLIENTS];
|
||||
|
@ -86,6 +86,7 @@ typedef struct {
|
||||
const Bit8u default_host_macaddr[6] = {0xb0, 0xc4, 0x20, 0x00, 0x00, 0x0f};
|
||||
const Bit8u default_host_ipv4addr[4] = {10, 0, 2, 2};
|
||||
const Bit8u default_dns_ipv4addr[4] = {10, 0, 2, 3};
|
||||
const Bit8u dhcp_base_ipv4addr[4] = {10, 0, 2, 15};
|
||||
|
||||
static Bit16u port_base = 40000;
|
||||
static char tftp_root[BX_PATHNAME_LEN];
|
||||
@ -93,7 +94,6 @@ static Bit8u host_macaddr[6];
|
||||
static int client_max;
|
||||
static Bit8u n_clients;
|
||||
static hub_client_t hclient[BXHUB_MAX_CLIENTS];
|
||||
static Bit8u default_guest_ipv4addr[4] = {10, 0, 2, 15};
|
||||
static dhcp_cfg_t dhcp;
|
||||
static vnet_server_c vnet_server;
|
||||
int bx_loglev;
|
||||
@ -112,9 +112,7 @@ bx_bool handle_packet(hub_client_t *client, Bit8u *buf, unsigned len)
|
||||
client->sout.sin_addr.s_addr = client->sin.sin_addr.s_addr;
|
||||
client->id = n_clients++;
|
||||
memcpy(client->macaddr, ethhdr->src_mac_addr, 6);
|
||||
memcpy(client->default_ipv4addr, default_guest_ipv4addr, 4);
|
||||
client->default_ipv4addr[3] += client->id;
|
||||
vnet_server.init_client(client->id, client->macaddr, client->default_ipv4addr);
|
||||
vnet_server.init_client(client->id, client->macaddr);
|
||||
client->reply_buffer = new Bit8u[BX_PACKET_BUFSIZE];
|
||||
client->init = 1;
|
||||
}
|
||||
@ -315,6 +313,7 @@ int CDECL main(int argc, char **argv)
|
||||
memcpy(dhcp.host_macaddr, host_macaddr, ETHERNET_MAC_ADDR_LEN);
|
||||
memcpy(dhcp.host_ipv4addr, &default_host_ipv4addr[0], 4);
|
||||
memcpy(dhcp.dns_ipv4addr, &default_dns_ipv4addr, 4);
|
||||
memcpy(dhcp.client_base_ipv4addr, &dhcp_base_ipv4addr, 4);
|
||||
vnet_server.init(NULL, &dhcp, tftp_root);
|
||||
printf("Host MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
host_macaddr[0], host_macaddr[1], host_macaddr[2],
|
||||
|
Loading…
x
Reference in New Issue
Block a user