# --- T2-COPYRIGHT-BEGIN --- # t2/package/*/gxemul/linux-tap.patch # Copyright (C) 2022 - 2026 The T2 SDE Project # SPDX-License-Identifier: GPL-2.0 or patched project license # --- T2-COPYRIGHT-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; }