* Re: Problem with ioctl(fd, TUNSETIFF, ...)
@ 2004-01-30 19:21 Eric Brower
0 siblings, 0 replies; 2+ messages in thread
From: Eric Brower @ 2004-01-30 19:21 UTC (permalink / raw)
To: ultralinux
The definition of TUNSETIF is:
#define TUNSETIFF _IOW('T', 202, int)
indicating the argument is an "int" rather than a "struct ifreq*". This
trickery (as I understand it) would work on 32-bit systems, but not
64-bit.
The .../arch/sparc64/kernel/ioctl32.c translation for this ioctl is
"COMPATIBLE_IOCTL" which would be correct if an int was really expected,
but is not correct when a struct ifreq* is passed. There are already
translations in ioctl32.c to deal with an argument of type struct
ifreq*, so you might wish to take a look at them and change the
COMPATIBLE_IOCTL entry to an appropriate HANDLE_IOCTL entry. Take a
look at dev_ifsioc() for starters.
I've cc'd the ultralinux list, which is more appropriate for this matter.
E
Erwann Abalea wrote:
> Hello,
>
> 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
> networking/tuntap.txt).
>
> 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)
> {
> close(fd);
> 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?
>
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: Problem with ioctl(fd, TUNSETIFF, ...)
@ 2004-02-02 0:12 David S. Miller
0 siblings, 0 replies; 2+ messages in thread
From: David S. Miller @ 2004-02-02 0:12 UTC (permalink / raw)
To: ultralinux
On Fri, 30 Jan 2004 11:21:46 -0800
Eric Brower <ebrower@usa.net> wrote:
> The definition of TUNSETIF is:
>
> #define TUNSETIFF _IOW('T', 202, int)
>
> indicating the argument is an "int" rather than a "struct ifreq*". This
> trickery (as I understand it) would work on 32-bit systems, but not
> 64-bit.
Good spotting Eric, this should fix it in 2.4.x
# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.1306 -> 1.1307
# arch/sparc64/kernel/ioctl32.c 1.45 -> 1.46
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 04/02/01 davem@nuts.davemloft.net 1.1307
# [SPARC64]: Fix TUNSETIFF ioctl compat, it takes an ifreq ptr not an int.
#
# Thanks to Eric Brower for spotting this.
# --------------------------------------------
#
diff -Nru a/arch/sparc64/kernel/ioctl32.c b/arch/sparc64/kernel/ioctl32.c
--- a/arch/sparc64/kernel/ioctl32.c Sun Feb 1 16:08:53 2004
+++ b/arch/sparc64/kernel/ioctl32.c Sun Feb 1 16:08:53 2004
@@ -4524,7 +4524,6 @@
/* Big T */
COMPATIBLE_IOCTL(TUNSETNOCSUM)
COMPATIBLE_IOCTL(TUNSETDEBUG)
-COMPATIBLE_IOCTL(TUNSETIFF)
COMPATIBLE_IOCTL(TUNSETPERSIST)
COMPATIBLE_IOCTL(TUNSETOWNER)
/* Big V */
@@ -5146,6 +5145,7 @@
HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc)
HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc)
HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc)
+HANDLE_IOCTL(TUNSETIFF, dev_ifsioc)
HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl)
HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl)
HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-02-02 0:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-30 19:21 Problem with ioctl(fd, TUNSETIFF, ...) Eric Brower
-- strict thread matches above, loose matches on Subject: below --
2004-02-02 0:12 David S. Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox