2



On Banana PI-R1 (ARMv7), with qemu-i386-static, I'm trying to execute Barracuda VPN client statically linked for x86. Following this topic works : Running X86 binaries on armv7

But, when the VPN tries to open the TUN device is gets an «Unsupported ioctl: cmd=0x400454ca» «TUNSETIFF: Function not implemented» error.

I can reproduce the same error making a C sample, it works when compiled on native ARM but fails when compiled for i386 (only when used qemu-i386-static) :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <linux/if_tun.h>
#include <fcntl.h>

static int tun_alloc_old(char *dev) {
    char tunname[IFNAMSIZ];

    sprintf(tunname, "/dev/%s", dev);
    return open(tunname, O_RDWR);
}

static int tun_alloc(char *dev) {
    struct ifreq    ifr;
    int     fd;
    int     err;

    if ((fd = open("/dev/net/tun", O_RDWR)) < 0)
        return tun_alloc_old(dev);

    memset(&ifr, 0, sizeof(ifr));

    ifr.ifr_flags = IFF_TUN;
    if (*dev)
        strncpy(ifr.ifr_name, dev, IFNAMSIZ);

    if ((err = ioctl(fd, TUNSETIFF, (void*)&ifr)) < 0) {
        close(fd);
        perror("TUNSETIFF");
        return err;
    }

    strcpy(dev, ifr.ifr_name);
    return fd;
}

int main(void) {
        char tun[20] = "tun0";

        printf("fd=%d, if=%s\n", tun_alloc(tun), tun);
        return 0;
}

Normal result (native i386 or ARM) :

# ./main
fd=3, if=tun0

And with the emulator :

# qemu-i386-static ./main
Unsupported ioctl: cmd=0x400454ca
TUNSETIFF: Function not implemented
fd=-1, if=tun0
  • I never used qemu but that IOCTL is part of the TUN/TAP driver. On a normal linux machine I would do modprobe tun, but I do not know whether qemu has something like modprobe. – grochmal Aug 10 '16 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.