From eaddb7d24aef17eee3e1b266fe2aeed7d40ca7e6 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Sat, 29 Oct 2011 14:13:33 -0700 Subject: [PATCH] Added support for integrated Tap networking interfaces on OSX --- 0readme_ethernet.txt | 36 ++++++++++++++++++++++++++++++------ makefile | 2 +- sim_ether.c | 21 +++++++++++++++++++-- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/0readme_ethernet.txt b/0readme_ethernet.txt index 5bdf18a6..3e6f8998 100644 --- a/0readme_ethernet.txt +++ b/0readme_ethernet.txt @@ -43,9 +43,9 @@ bridge, or route TAP devices for you. Integrated Universal TUN/TAP support can be used for host<->simulator network traffic (on the platforms where it is available) by using the SIMH command: "attach xq tap:tapN" (i.e. attach xq tap:tap0). Platforms that this has been -tested on include: Linux, FreeBSD, OpenBSD, NetBSD. Each of these platforms -has some way to create a tap pseudo device and then bridge it with a physical -network interface. +tested on include: Linux, FreeBSD, OpenBSD, NetBSD and OSX. Each of these +platforms has some way to create a tap pseudo device (and possibly then to +bridge it with a physical network interface). The following steps were performed to get a working SIMH vax simulator sharing a physical NIC and allowing Host<->SIMH vax communications: @@ -117,6 +117,29 @@ NetBSD (NetBSD 5.0.2) # Run simulator and "attach xq tap:tap0" +OSX (Snow Leopard) + OSX Does NOT have native support for tun/tap interfaces. It also does not have native + support for bridging. + + Mattias Nissler has created tun/tap functionality available at http://tuntaposx,sourceforge.net/ + + We'll punt on bridging for the sake of this example and move on to use a basic tap + based internal network so a host and guest can communicate directly. + + Download the install package from: + http://sourceforge.net/projects/tuntaposx/files/tuntap/20090913/tuntap_20090913.tar.gz + + Expand the tarball to a directory. + Invoke the package installer tuntap_20090913.pkg + Click through the various prompts accepting things and eventually installing the package. + + # Run simulator and: + sim> attach xq tap:tap0 + sim> ! ifconfig tap0 192.168.6.1 netmask 255.255.255.0 + + Simulated system uses IP address 192.168.6.2 and host uses 192.167.6.1 and things work. + As far as I can tell you must run as root for this to work. + ------------------------------------------------------------------------------- Windows notes: @@ -331,14 +354,15 @@ Dave Change Log =============================================================================== - 07-Jul-11 MB VMS Pcap (from Mike Burke) - - Fixed Alpha issues - - Added OpenVMS Integrety support + 29-Oct-11 MP Added support for integrated Tap networking interfaces on OSX 17-Aug-11 RMS Fix from Sergey Oboguev relating to XU and XQ Auto Config and vector assignments 12-Aug-11 MP Cleaned up payload length determination Fixed race condition detecting reflections when threaded reading and writing is enabled + 07-Jul-11 MB VMS Pcap (from Mike Burke) + - Fixed Alpha issues + - Added OpenVMS Integrety support 20-Apr-11 MP Fixed save/restore behavior 12-Jan-11 DTH Added SHOW XU FILTERS modifier 11-Jan-11 DTH Corrected DEUNA/DELUA SELFTEST command, enabling use by diff --git a/makefile b/makefile index 98499b57..4004965d 100644 --- a/makefile +++ b/makefile @@ -66,7 +66,7 @@ ifeq ($(WIN32),) # Provide support for Tap networking on Linux NETWORK_TAP_CCDEFS = -DUSE_TAP_NETWORK endif - ifeq (bsdtuntap,$(shell if $(TEST) -e /usr/include/net/if_tun.h; then echo bsdtuntap; fi)) + ifeq (bsdtuntap,$(shell if $(TEST) -e /usr/include/net/if_tun.h -o -e /Library/Extensions/tap.kext; then echo bsdtuntap; fi)) # Provide support for Tap networking NETWORK_TAP_CCDEFS = -DUSE_TAP_NETWORK -DUSE_BSDTUNTAP endif diff --git a/sim_ether.c b/sim_ether.c index a66ab23c..04692446 100644 --- a/sim_ether.c +++ b/sim_ether.c @@ -787,7 +787,7 @@ void eth_show_dev (FILE* st, ETH_DEV* dev) #elif defined(USE_BSDTUNTAP) #include #include -#include +#include #else /* We don't know how to do this on the current platform */ #undef USE_TAP_NETWORK #endif @@ -1399,6 +1399,23 @@ t_stat eth_open(ETH_DEV* dev, char* name, DEVICE* dptr, uint32 dbit) dev->fd_handle = tun; strcpy(savname, savname+4); } +#if defined (__APPLE__) + if (1) { + struct ifreq ifr; + int s; + + memset (&ifr, 0, sizeof(ifr)); + ifr.ifr_addr.sa_family = AF_INET; + strncpy(ifr.ifr_name, savname+4, sizeof(ifr.ifr_name)); + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) { + if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) >= 0) { + ifr.ifr_flags |= IFF_UP; + ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr); + } + close(s); + } + } +#endif } else { strncpy(errbuf, strerror(errno), sizeof(errbuf)-1); } @@ -1465,7 +1482,7 @@ t_stat eth_open(ETH_DEV* dev, char* name, DEVICE* dptr, uint32 dbit) #endif #endif /* !defined (USE_READER_THREAD */ #if defined (__APPLE__) - if (1) { + if (dev->pcap_mode) { /* Deliver packets immediately, needed for OS X 10.6.2 and later * (Snow-Leopard). * See this thread on libpcap and Mac Os X 10.6 Snow Leopard on