NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/39233: OpenSSH fails to initialize tun(4) tunnels correctly
The following reply was made to PR bin/39233; it has been noted by GNATS.
From: Taylor R Campbell <campbell%mumble.net@localhost>
To: cube%cubidou.net@localhost
Cc: gnats-bugs%NetBSD.org@localhost
Subject: Re: bin/39233: OpenSSH fails to initialize tun(4) tunnels correctly
Date: Mon, 28 Jul 2008 16:06:38 -0400
This is a multi-part message in MIME format.
--=_i07pdvDj0yTsQ9jeHFVr2rwrkkBRyGtP
..actually attached this time.
--=_i07pdvDj0yTsQ9jeHFVr2rwrkkBRyGtP
Content-Type: text/plain; charset="iso-8859-1"; name="ssh-tun"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="ssh-tun.patch"
Index: misc.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/crypto/dist/ssh/misc.c,v
retrieving revision 1.21
diff -u -r1.21 misc.c
--- misc.c 6 Apr 2008 23:38:19 -0000 1.21
+++ misc.c 28 Jul 2008 17:41:32 -0000
@@ -35,6 +35,9 @@
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
+#ifdef __NetBSD__
+# include <net/if_tun.h>
+#endif
=20
#include <errno.h>
#include <fcntl.h>
@@ -636,20 +639,62 @@
return -1;
}
=20
+#if defined(__NetBSD__)
+
+# define TUN_POINTOPOINT_DEVICE "tun"
+# define TUN_ETHERNET_DEVICE "tap"
+
+static int
+tun_set_if_mode(int tun, int mode, int fd, int sock, struct ifreq *ifr)
+{
+ if (mode =3D=3D SSH_TUNMODE_POINTOPOINT) {
+ int one =3D 1;
+ return ioctl(fd, TUNSIFHEAD, &one);
+ }
+ return 0;
+}
+
+#elif defined(__OpenBSD__) || defined(__FreeBSD__)
+
+# define TUN_POINTOPOINT_DEVICE "tun"
+# define TUN_ETHERNET_DEVICE "tun"
+
+static int
+tun_set_if_mode(int tun, int mode, int fd, int sock, struct ifreq *ifr)
+{
+ ifr->ifr_flags &=3D ~IFF_IP;
+ if (mode =3D=3D SSH_TUNMODE_ETHERNET)
+ ifr->ifr_flags |=3D IFF_LINK0;
+ else
+ ifr->ifr_flags &=3D ~IFF_LINK0;
+ return ioctl(sock, SIOCSIFFLAGS, ifr);
+}
+
+#endif
+
int
tun_open(int tun, int mode)
{
struct ifreq ifr;
- char name[100];
+ char name[100], *device;
int fd =3D -1, sock;
=20
+ if (mode =3D=3D SSH_TUNMODE_POINTOPOINT)
+ device =3D TUN_POINTOPOINT_DEVICE;
+ else if (mode =3D=3D SSH_TUNMODE_ETHERNET)
+ device =3D TUN_ETHERNET_DEVICE;
+ else {
+ debug("%s: invalid tunnel mode %d", __func__, tun);
+ return (-1);
+ }
+
/* Open the tunnel device */
if (tun <=3D SSH_TUNID_MAX) {
- snprintf(name, sizeof(name), "/dev/tun%d", tun);
+ snprintf(name, sizeof(name), "/dev/%s%d", device, tun);
fd =3D open(name, O_RDWR);
} else if (tun =3D=3D SSH_TUNID_ANY) {
for (tun =3D 100; tun >=3D 0; tun--) {
- snprintf(name, sizeof(name), "/dev/tun%d", tun);
+ snprintf(name, sizeof(name), "/dev/%s%d", device, tun);
if ((fd =3D open(name, O_RDWR)) >=3D 0)
break;
}
@@ -666,7 +711,7 @@
debug("%s: %s mode %d fd %d", __func__, name, mode, fd);
=20
/* Set the tunnel device operation mode */
- snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "tun%d", tun);
+ snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s%d", device, tun);
if ((sock =3D socket(PF_UNIX, SOCK_STREAM, 0)) =3D=3D -1)
goto failed;
=20
@@ -674,12 +719,7 @@
goto failed;
=20
/* Set interface mode */
- ifr.ifr_flags &=3D ~IFF_UP;
- if (mode =3D=3D SSH_TUNMODE_ETHERNET)
- ifr.ifr_flags |=3D IFF_LINK0;
- else
- ifr.ifr_flags &=3D ~IFF_LINK0;
- if (ioctl(sock, SIOCSIFFLAGS, &ifr) =3D=3D -1)
+ if (tun_set_if_mode(tun, mode, fd, sock, &ifr) =3D=3D -1)
goto failed;
=20
/* Bring interface up */
--=_i07pdvDj0yTsQ9jeHFVr2rwrkkBRyGtP--
Home |
Main Index |
Thread Index |
Old Index