Added stubs for IPv6 packets in the slirp and vnet server code and some cleanups.

This commit is contained in:
Volker Ruppert 2020-06-14 08:44:10 +00:00
parent b521611c68
commit 4bcc3ba13c
4 changed files with 44 additions and 33 deletions

View File

@ -27,42 +27,13 @@
#ifndef BX_NETMOD_H
#define BX_NETMOD_H
#ifndef BXHUB
// Pseudo device that loads the lowlevel networking module
class BOCHSAPI bx_netmod_ctl_c : public logfunctions {
public:
bx_netmod_ctl_c();
virtual ~bx_netmod_ctl_c() {}
void init(void);
void exit(void);
virtual void* init_module(bx_list_c *base, void* rxh, void* rxstat, bx_devmodel_c *dev);
};
BOCHSAPI extern bx_netmod_ctl_c bx_netmod_ctl;
#endif
#define BX_PACKET_BUFSIZE 1514 // Maximum size of an ethernet frame
// device receive status definitions
#define BX_NETDEV_RXREADY 0x0001
#define BX_NETDEV_SPEED 0x000e
#define BX_NETDEV_10MBIT 0x0002
#define BX_NETDEV_100MBIT 0x0004
#define BX_NETDEV_1GBIT 0x0008
// this should not be smaller than an arp reply with an ethernet header
#define MIN_RX_PACKET_LEN 60
typedef void (*eth_rx_handler_t)(void *arg, const void *buf, unsigned len);
typedef Bit32u (*eth_rx_status_t)(void *arg);
static const Bit8u broadcast_macaddr[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
#ifndef BXHUB
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);
#endif
BX_CPP_INLINE Bit16u get_net2(const Bit8u *buf)
{
return (((Bit16u)*buf) << 8) |
@ -92,6 +63,32 @@ BX_CPP_INLINE void put_net4(Bit8u *buf,Bit32u data)
}
#ifndef BXHUB
// Pseudo device that loads the lowlevel networking module
class BOCHSAPI bx_netmod_ctl_c : public logfunctions {
public:
bx_netmod_ctl_c();
virtual ~bx_netmod_ctl_c() {}
void init(void);
void exit(void);
virtual void* init_module(bx_list_c *base, void* rxh, void* rxstat, bx_devmodel_c *dev);
};
BOCHSAPI extern bx_netmod_ctl_c bx_netmod_ctl;
// device receive status definitions
#define BX_NETDEV_RXREADY 0x0001
#define BX_NETDEV_SPEED 0x000e
#define BX_NETDEV_10MBIT 0x0002
#define BX_NETDEV_100MBIT 0x0004
#define BX_NETDEV_1GBIT 0x0008
typedef void (*eth_rx_handler_t)(void *arg, const void *buf, unsigned len);
typedef Bit32u (*eth_rx_status_t)(void *arg);
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);
//
// The eth_pktmover class is used by ethernet chip emulations
// to interface to the outside world. An instance of this

View File

@ -92,6 +92,7 @@ Bit16u ip_checksum(const Bit8u *buf, unsigned buf_len)
#define ETHERNET_TYPE_IPV4 0x0800
#define ETHERNET_TYPE_ARP 0x0806
#define ETHERNET_TYPE_IPV6 0x86dd
#define ARP_OPCODE_REQUEST 1
#define ARP_OPCODE_REPLY 2
@ -175,6 +176,8 @@ Bit16u ip_checksum(const Bit8u *buf, unsigned buf_len)
#define TFTP_BUFFER_SIZE 1024
static const Bit8u mcast_ipv6_mac_prefix[2] = {0x33,0x33};
static Bit8u broadcast_ipv4addr[3][4] =
{
{ 0, 0, 0, 0},
@ -284,7 +287,8 @@ void vnet_server_c::handle_packet(const Bit8u *buf, unsigned len)
if (!find_client(ethhdr->src_mac_addr, &clientid))
return;
if (!memcmp(&ethhdr->dst_mac_addr, dhcp->host_macaddr, 6) ||
!memcmp(&ethhdr->dst_mac_addr, &broadcast_macaddr[0], 6)) {
!memcmp(&ethhdr->dst_mac_addr, broadcast_macaddr, 6) ||
!memcmp(&ethhdr->dst_mac_addr, mcast_ipv6_mac_prefix, 2)) {
switch (ntohs(ethhdr->type)) {
case ETHERNET_TYPE_IPV4:
process_ipv4(clientid, buf, len);
@ -292,6 +296,9 @@ void vnet_server_c::handle_packet(const Bit8u *buf, unsigned len)
case ETHERNET_TYPE_ARP:
process_arp(clientid, buf, len);
break;
case ETHERNET_TYPE_IPV6:
BX_ERROR(("IPv6 packet not supported yet"));
break;
default: // unknown packet type.
break;
}

View File

@ -725,6 +725,7 @@ void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
arp_input(slirp, pkt, pkt_len);
break;
case ETH_P_IP:
case ETH_P_IPV6:
m = m_get(slirp);
if (!m)
return;
@ -738,7 +739,11 @@ void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
m->m_data += 2 + ETH_HLEN;
m->m_len -= 2 + ETH_HLEN;
ip_input(m);
if (proto = ETH_P_IP) {
ip_input(m);
} else {
BX_ERROR(("IPv6 packet not supported yet"));
}
break;
default:
break;

View File

@ -1,3 +1,4 @@
/////////////////////////////////////////////////////////////////////////
// $Id$
/////////////////////////////////////////////////////////////////////////
@ -186,8 +187,9 @@ void free(void *ptr);
#define ETH_ALEN 6
#define ETH_HLEN 14
#define ETH_P_IP 0x0800 /* Internet Protocol packet */
#define ETH_P_ARP 0x0806 /* Address Resolution packet */
#define ETH_P_IP 0x0800 /* Internet Protocol packet */
#define ETH_P_ARP 0x0806 /* Address Resolution packet */
#define ETH_P_IPV6 0x86dd /* IP version 6 packet */
#define ARPOP_REQUEST 1 /* ARP request */
#define ARPOP_REPLY 2 /* ARP reply */