# --- T2-COPYRIGHT-NOTE-BEGIN --- # T2 SDE: package/*/gxemul/linux-tap.patch # Copyright (C) 2022 The T2 SDE Project # # This Copyright note is generated by scripts/Create-CopyPatch, # more information can be found in the files COPYING and README. # # This patch file is dual-licensed. It is available under the license the # patched project is licensed under, as long as it is an OpenSource license # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms # of the GNU General Public License version 2 as used by the T2 SDE. # --- T2-COPYRIGHT-NOTE-END --- --- gxemul-0.7.0/src/net/net_tap.c.vanilla 2022-07-19 12:56:49.595843435 +0200 +++ gxemul-0.7.0/src/net/net_tap.c 2022-07-19 13:06:28.069820370 +0200 @@ -45,6 +45,9 @@ #include #include +#include +#include + #include "misc.h" #include "net.h" @@ -163,13 +163,36 @@ */ bool net_tap_init(struct net *net, const char *tapdev) { - int fd; + int fd, ret, features; int one = 1; - fd = open(tapdev, O_RDWR); + fd = open("/dev/net/tun", O_RDWR); if (fd < 0) { debugmsg(SUBSYS_NET, "tap", VERBOSITY_ERROR, - "unable to open tap device '%s': %s", + "unable to open tap device '%s': %s", + tapdev, strerror(errno)); + return false; + } + + if (ioctl(fd, TUNGETFEATURES, &features) == -1) { + debugmsg(SUBSYS_NET, "tap", VERBOSITY_ERROR, "%s", strerror(errno)); + features = 0; + } + + struct ifreq ifr; + memset(&ifr, 0, sizeof(ifr)); + ifr.ifr_flags = IFF_TAP | IFF_NO_PI; + + if (features & IFF_ONE_QUEUE) { + ifr.ifr_flags |= IFF_ONE_QUEUE; + } + + strcpy(ifr.ifr_name, tapdev); + + ret = ioctl(fd, TUNSETIFF, (void *)&ifr); + if (ret != 0) { + debugmsg(SUBSYS_NET, "tap", VERBOSITY_ERROR, + "unable to configure tap device '%s': %s", tapdev, strerror(errno)); return false; }