[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Problem with ioctl(fd, TUNSETIFF, ...)


I wanted to install OpenVPN on my firewall machine (an Ultra1 running
2.4.18), but unfortunately, I failed.

I managed to track the failing code, and tried to find equivalent
known-to-be-good code (found in the Linux Kernel documentation, in

The following code fails:
int tun_alloc(char *dev)
  struct ifreq ifr;
  int fd, err;

  if ((fd = open("/dev/net/tun", O_RDWR)) < 0)
    perror("Unable to open /dev/net/tun");
    return -1;

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

  /* Flags: IFF_TUN   - TUN device (no Ethernet headers)
   *        IFF_TAP   - TAP device
   *        IFF_NO_PI - Do not provide packet information
  ifr.ifr_flags = IFF_TUN;

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

  if ((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0)
    perror("ioctl(fd, TUNSETIFF, ...) error");
    return err;
  strcpy(dev, ifr.ifr_name);
  return fd;

I tested this in a small program (just add a main() asking for an
argument, and call the tun_alloc() with the given argument). It fails on 2
ultrasparc machines (an U1 and an U2 running the same kernel version, the
U1 also has the IPVS patch applied), and works on a standard PC also
running the 2.4.18 kernel. Tun/Tap support is compiled in (if it wasn't,
the failure would have been at the open() call).

What I get is:
Opening tun0
ioctl(fd, TUNSETIFF, ...) error: : Invalid argument

I also get something in my syslog.log file:
Jan 30 15:15:39 herisson kernel: sys32_ioctl(tun:4329): Unknown cmd fd(3) cmd(800454ca) arg(effffc70)

What am I doing wrong?

Erwann ABALEA <eabalea@certplus.com> - RSA PGP Key ID: 0x2D0EABD5
-+-UK in : Guide du Neuneu d'Usenet - Ce qui se conçoit bien ... -+-

Reply to: