[GXemul-devel] [PATCH] Update TAP networking to let it work on a Linux host
Status: Alpha
Brought to you by:
gavare
From: Jan-Benedict G. <jb...@lu...> - 2023-03-28 08:38:59
|
Hi! There is probably already a (to-be-pushed-to-upstream-SVN) patch available to enable TAP networking unter Linux, but nonetheless, here's what I have locally for the time being. I'm using it this way (here as an example for a DECstation booting the NetBSD installer: There are CI builds for NetBSD HEAD running, storing the ISO and sets (along with the kernel) in tarballs. This is extracted and GXemul started with it, on a local TAP interface bridged with a physical wired NIC: tar xzf /var/cache/laminar/netbsd-rel-pmax-mipsel.tar.gz dd bs=1M count=1024 if=/dev/zero of=netbsd.img ISO="$(ls images/*.iso | head -1)" TAP=threemax tunctl -t "${TAP}" || true ip link set "${TAP}" up || true brctl addif br0 "${TAP}" || true # gxemul @3maxconfig gxemul -E decstation -e 3max \ -L threemax \ -l 10:11:12:13:14:16 \ -d netbsd.img \ -d "6c:${ISO}" \ -o "-a" \ -j netbsd pmax/binary/kernel/netbsd-INSTALL.gz The plan is to prepare as many simulated systems as possible to exercise as many NetBSD variants as possible. DECstations are just one example, SIMH is already running (VAX), as well as Qemu (amd64). Seems that more archs are reachable (alpha with a small Qemu patch, aarch64, ...) These simulators are used to just do test installations (and throw away the resulting disk images), but my goal is to also install "master" disk images and run these with overlays. All three simulators (Qemu, SIMH, GXemul) support this type of configuration, so that's ideal to start a nice farm of build hosts. The only difference is that they're getting a fresh overlay and a different MAC address. Oh, and here's the Linux TAP patch. There are others around that also set the IFF_ONE_QUEUE if available (cf. http://svn.exactcode.de/t2/trunk/package/emulators/gxemul/linux-tap.patch for example), but I'm not sure if that's needed or really beneficial. diff --git a/src/net/net_tap.c b/src/net/net_tap.c index 188276e..d920695 100644 --- a/src/net/net_tap.c +++ b/src/net/net_tap.c @@ -48,6 +48,11 @@ #include "misc.h" #include "net.h" +#ifdef __linux__ +# include <linux/if.h> +# include <linux/if_tun.h> +#endif + /* * net_tap_rx_for_nic(): * @@ -166,7 +171,11 @@ bool net_tap_init(struct net *net, const char *tapdev) int fd; int one = 1; +#ifdef __linux__ + fd = open("/dev/net/tun", O_RDWR); +#else fd = open(tapdev, O_RDWR); +#endif if (fd < 0) { debugmsg(SUBSYS_NET, "tap", VERBOSITY_ERROR, "unable to open tap device '%s': %s", @@ -174,6 +183,22 @@ bool net_tap_init(struct net *net, const char *tapdev) return false; } +#ifdef __linux__ + struct ifreq ifr; + + memset(&ifr, 0, sizeof(ifr)); + ifr.ifr_flags = IFF_TAP | IFF_NO_PI; + strncpy(ifr.ifr_name, tapdev, IFNAMSIZ); + + if (ioctl(fd, TUNSETIFF, &ifr) < 0) { + debugmsg(SUBSYS_NET, "tap", VERBOSITY_ERROR, + "unable to attach to " + "tap device '%s': %s", tapdev, strerror(errno)); + close(fd); + return false; + } +#endif + if (ioctl(fd, FIONBIO, &one) < 0) { debugmsg(SUBSYS_NET, "tap", VERBOSITY_ERROR, "unable to set non-blocking mode on " MfG, JBG -- |