1
0
mirror of https://github.com/simh/simh.git synced 2026-01-27 20:37:50 +00:00

ETHER: Add Apple vmnet support when running on macOS

Base vmnet support covers bridged network interfaces and locally
accessible TAP network connections. These reflect the vmnet bridged
and host behaviors which are leveraged under the covers, but configured
using the original sim_ether commands.  The resulting bridged case
behaves like the Windows network connections do (with direct access
to and from the local LAN as well as the host system) using the natural
interface name.  NAT behaviors are specifically supported using the
original SLiRP code since the vmnet support depends on simulators
primarily getting IPv4 addressing via DHCP, but essentially no simh
simulators actually had OS network code which used DHCP and all
merely used static network address setup.  The vmnet (shared/NAT)
support can't be configured to operate with the same DHCP and static
IP addresses provided by the original SLiRP implementation and to
avoid the need to specifically change hard coded simulator IPv4
addresses before things could work.

- Detect which network interfaces are WiFi (when possible) and thus
  not useful candidates for bridging.
- Cleanly report when running as root is needed.
- Avoid allowing network connections to interfaces which aren't
  actually connected to a network.
- Add support to explicitly set TAP network host side network
  interface's IPv4 address and netmask.  This optional support is
  provided specifically for the Apple vmnet case, but not for other
  platforms using TAP network connections due to the various ways
  that must be handled with external commands.
- Add host system's IPv4 address, netmask, media type and connection
  state to interface descriptions visible via SHOW ETHERNET.
  Some system environments may have a significant number of potential
  network interfaces, most of which aren't interesting to connect
  simulators to.  Knowing which interfaces are actually in useful
  states helps users select the correct device.

The vmnet aspect of this functionality was originally inspired by
Calvin Buckley's pull request to the open-simh repository.  That
solution wouldn't actually operate well certainly for NAT cases due
to the forced DHCP to non-configurable address blocks and the lack
of any way to support static addresses TCP or  UDP port mapping.
This commit is contained in:
Mark Pizzolato
2025-06-06 14:51:46 -10:00
parent fd60c6b0f7
commit 61fe27cb47
7 changed files with 1491 additions and 638 deletions

View File

@@ -129,26 +129,34 @@ extern "C" {
#undef USE_SHARED
#endif
/* USE_SHARED implies shared pcap, so force HAVE_PCAP_NETWORK */
#if defined(USE_SHARED) && !defined(HAVE_PCAP_NETWORK)
#define HAVE_PCAP_NETWORK 1
#endif
/*
USE_BPF is defined to let this code leverage the libpcap/OS kernel provided
BPF packet filtering. This generally will enhance performance. It may not
be available in some environments and/or it may not work correctly, so
undefining this will still provide working code here.
*/
#if defined(HAVE_PCAP_NETWORK)
#if defined(HAVE_PCAP_NETWORK) || defined(USE_SHARED)
#define USE_BPF 1
#if defined (_WIN32) && !defined (BPF_CONST_STRING)
#if !defined(HAVE_PCAP_NETWORK)
#define HAVE_PCAP_NETWORK 1
#endif
#define BPF_CONST_STRING 1
#endif
#else
#define DONT_USE_PCAP_FINDALLDEVS 1
#endif
/* Generally avoid pcap APIs when running with vmnet.framework */
#if defined(HAVE_VMNET_NETWORK)
#define DONT_USE_PCAP_FINDALLDEVS 1
#if defined(HAVE_TAP_NETWORK)
#undef HAVE_TAP_NETWORK
#endif
#if defined(HAVE_VDE_NETWORK)
#undef HAVE_VDE_NETWORK
#endif
#endif
/* structure declarations */
@@ -157,6 +165,7 @@ extern "C" {
#define ETH_FILTER_MAX 20 /* maximum address filters */
#define ETH_DEV_NAME_MAX 256 /* maximum device name size */
#define ETH_DEV_DESC_MAX 256 /* maximum device description size */
#define ETH_DEV_INFO_MAX 256 /* maximum device info size */
#define ETH_MIN_PACKET 60 /* minimum ethernet packet size */
#define ETH_MAX_PACKET 1514 /* maximum ethernet packet size */
#define ETH_MAX_JUMBO_FRAME 65536 /* maximum ethernet jumbo frame size (or Offload Segment Size) */
@@ -234,6 +243,8 @@ typedef unsigned char ETH_MAC[6];
struct eth_list {
char name[ETH_DEV_NAME_MAX];
char desc[ETH_DEV_DESC_MAX];
char info[ETH_DEV_INFO_MAX];
char connect[ETH_DEV_NAME_MAX];
int eth_api;
};
@@ -256,12 +267,13 @@ struct eth_device {
SOCKET fd_handle; /* fd to kernel device (where needed) */
char* bpf_filter; /* bpf filter currently in effect */
int eth_api; /* Designator for which API is being used to move packets */
#define ETH_API_NONE 0 /* No API in use yet */
#define ETH_API_PCAP 1 /* Pcap API in use */
#define ETH_API_TAP 2 /* tun/tap API in use */
#define ETH_API_VDE 3 /* VDE API in use */
#define ETH_API_UDP 4 /* UDP API in use */
#define ETH_API_NAT 5 /* NAT (SLiRP) API in use */
#define ETH_API_NONE 0 /* No API in use yet */
#define ETH_API_PCAP 1 /* Pcap API in use */
#define ETH_API_TAP 2 /* tun/tap API in use */
#define ETH_API_VDE 3 /* VDE API in use */
#define ETH_API_UDP 4 /* UDP API in use */
#define ETH_API_NAT 5 /* NAT (SLiRP) API in use */
#define ETH_API_VMNET 6 /* Apple vmnet.framework in use */
ETH_PCALLBACK read_callback; /* read callback function */
ETH_PCALLBACK write_callback; /* write callback function */
ETH_PACK* read_packet; /* read packet */
@@ -277,6 +289,7 @@ struct eth_device {
ETH_MAC physical_addr; /* physical address of interface */
int32 have_host_nic_phy_addr; /* flag indicating that the host_nic_phy_hw_addr is valid */
ETH_MAC host_nic_phy_hw_addr; /* MAC address of the attached NIC */
ETH_BOOL host_nic_is_wifi; /* Attached NIC is a WiFi device */
uint32 jumbo_fragmented; /* Giant IPv4 Frames Fragmented */
uint32 jumbo_dropped; /* Giant Frames Dropped */
uint32 jumbo_truncated; /* Giant Frames too big for capture buffer - Dropped */