* THE SOFTWARE.
*/
+#include "qemu/osdep.h"
#include "tap_int.h"
#include "tap-linux.h"
#include "net/tap.h"
#include <net/if.h>
#include <sys/ioctl.h>
-#include "sysemu/sysemu.h"
-#include "qemu-common.h"
+#include "qapi/error.h"
#include "qemu/error-report.h"
+#include "qemu/cutils.h"
#define PATH_NET_TUN "/dev/net/tun"
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
if (ioctl(fd, TUNGETFEATURES, &features) == -1) {
- error_report("warning: TUNGETFEATURES failed: %s", strerror(errno));
+ warn_report("TUNGETFEATURES failed: %s", strerror(errno));
features = 0;
}
return -1;
}
pstrcpy(ifname, ifname_size, ifr.ifr_name);
- fcntl(fd, F_SETFL, O_NONBLOCK);
+ g_unix_set_fd_nonblocking(fd, true, NULL);
return fd;
}
}
}
-int tap_probe_vnet_hdr(int fd)
+int tap_probe_vnet_hdr(int fd, Error **errp)
{
struct ifreq ifr;
+ memset(&ifr, 0, sizeof(ifr));
if (ioctl(fd, TUNGETIFF, &ifr) != 0) {
- error_report("TUNGETIFF ioctl() failed: %s", strerror(errno));
- return 0;
+ /* TUNGETIFF is available since kernel v2.6.27 */
+ error_setg_errno(errp, errno,
+ "Unable to query TUNGETIFF on FD %d", fd);
+ return -1;
}
return ifr.ifr_flags & IFF_VNET_HDR;
pstrcpy(ifname, sizeof(ifr.ifr_name), ifr.ifr_name);
return 0;
}
+
+int tap_fd_set_steering_ebpf(int fd, int prog_fd)
+{
+ if (ioctl(fd, TUNSETSTEERINGEBPF, (void *) &prog_fd) != 0) {
+ error_report("Issue while setting TUNSETSTEERINGEBPF:"
+ " %s with fd: %d, prog_fd: %d",
+ strerror(errno), fd, prog_fd);
+
+ return -1;
+ }
+
+ return 0;
+}