diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | Makefile.in | 4 | ||||
-rw-r--r-- | configure.ac | 12 | ||||
-rw-r--r-- | includes.h | 3 | ||||
-rw-r--r-- | misc.c | 2 | ||||
-rw-r--r-- | openbsd-compat/port-tun.c | 98 | ||||
-rw-r--r-- | openbsd-compat/port-tun.h | 2 |
7 files changed, 119 insertions, 11 deletions
@@ -1,3 +1,10 @@ | |||
1 | 20060101 | ||
2 | - (djm) [Makefile.in configure.ac includes.h misc.c] | ||
3 | [openbsd-compat/port-tun.c openbsd-compat/port-tun.h] Add support | ||
4 | for tunnel forwarding for FreeBSD and NetBSD. NetBSD's support is | ||
5 | limited to IPv4 tunnels only, and most versions don't support the | ||
6 | tap(4) device at all. | ||
7 | |||
1 | 20051229 | 8 | 20051229 |
2 | - (djm) OpenBSD CVS Sync | 9 | - (djm) OpenBSD CVS Sync |
3 | - stevesk@cvs.openbsd.org 2005/12/28 22:46:06 | 10 | - stevesk@cvs.openbsd.org 2005/12/28 22:46:06 |
@@ -3578,4 +3585,4 @@ | |||
3578 | - (djm) Trim deprecated options from INSTALL. Mention UsePAM | 3585 | - (djm) Trim deprecated options from INSTALL. Mention UsePAM |
3579 | - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu | 3586 | - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu |
3580 | 3587 | ||
3581 | $Id: ChangeLog,v 1.4059 2005/12/31 06:05:58 djm Exp $ | 3588 | $Id: ChangeLog,v 1.4060 2006/01/01 08:47:05 djm Exp $ |
diff --git a/Makefile.in b/Makefile.in index fcbc522f2..af881c521 100644 --- a/Makefile.in +++ b/Makefile.in | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id: Makefile.in,v 1.273 2005/05/29 07:22:29 dtucker Exp $ | 1 | # $Id: Makefile.in,v 1.274 2006/01/01 08:47:05 djm Exp $ |
2 | 2 | ||
3 | # uncomment if you run a non bourne compatable shell. Ie. csh | 3 | # uncomment if you run a non bourne compatable shell. Ie. csh |
4 | #SHELL = @SH@ | 4 | #SHELL = @SH@ |
@@ -139,7 +139,7 @@ sshd$(EXEEXT): libssh.a $(LIBCOMPAT) $(SSHDOBJS) | |||
139 | $(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(LIBWRAP) $(LIBPAM) $(LIBS) | 139 | $(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(LIBWRAP) $(LIBPAM) $(LIBS) |
140 | 140 | ||
141 | scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o progressmeter.o | 141 | scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o progressmeter.o |
142 | $(LD) -o $@ scp.o progressmeter.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) | 142 | $(LD) -o $@ scp.o progressmeter.o bufaux.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) |
143 | 143 | ||
144 | ssh-add$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-add.o | 144 | ssh-add$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-add.o |
145 | $(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) | 145 | $(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) |
diff --git a/configure.ac b/configure.ac index 26ed218d5..2f5906667 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id: configure.ac,v 1.319 2005/12/31 06:05:58 djm Exp $ | 1 | # $Id: configure.ac,v 1.320 2006/01/01 08:47:05 djm Exp $ |
2 | # | 2 | # |
3 | # Copyright (c) 1999-2004 Damien Miller | 3 | # Copyright (c) 1999-2004 Damien Miller |
4 | # | 4 | # |
@@ -346,10 +346,18 @@ mips-sony-bsd|mips-sony-newsos4) | |||
346 | if test "x$withval" != "xno" ; then | 346 | if test "x$withval" != "xno" ; then |
347 | need_dash_r=1 | 347 | need_dash_r=1 |
348 | fi | 348 | fi |
349 | AC_DEFINE(SSH_TUN_FREEBSD, 1, [Open tunnel devices the FreeBSD way]) | ||
350 | AC_CHECK_HEADER([net/if_tap.h], , | ||
351 | AC_DEFINE(SSH_TUN_NO_L2, 1, [No layer 2 tunnel support])) | ||
352 | AC_DEFINE(SSH_TUN_PREPEND_AF, 1, | ||
353 | [Prepend the address family to IP tunnel traffic]) | ||
349 | ;; | 354 | ;; |
350 | *-*-freebsd*) | 355 | *-*-freebsd*) |
351 | check_for_libcrypt_later=1 | 356 | check_for_libcrypt_later=1 |
352 | AC_DEFINE(LOCKED_PASSWD_PREFIX, "*LOCKED*", [Account locked with pw(1)]) | 357 | AC_DEFINE(LOCKED_PASSWD_PREFIX, "*LOCKED*", [Account locked with pw(1)]) |
358 | AC_DEFINE(SSH_TUN_FREEBSD, 1, [Open tunnel devices the FreeBSD way]) | ||
359 | AC_CHECK_HEADER([net/if_tap.h], , | ||
360 | AC_DEFINE(SSH_TUN_NO_L2, 1, [No layer 2 tunnel support])) | ||
353 | ;; | 361 | ;; |
354 | *-*-bsdi*) | 362 | *-*-bsdi*) |
355 | AC_DEFINE(SETEUID_BREAKS_SETUID) | 363 | AC_DEFINE(SETEUID_BREAKS_SETUID) |
@@ -369,7 +377,7 @@ mips-sony-bsd|mips-sony-newsos4) | |||
369 | *-*-openbsd*) | 377 | *-*-openbsd*) |
370 | AC_DEFINE(HAVE_ATTRIBUTE__SENTINEL__, 1, [OpenBSD's gcc has sentinel]) | 378 | AC_DEFINE(HAVE_ATTRIBUTE__SENTINEL__, 1, [OpenBSD's gcc has sentinel]) |
371 | AC_DEFINE(HAVE_ATTRIBUTE__BOUNDED__, 1, [OpenBSD's gcc has bounded]) | 379 | AC_DEFINE(HAVE_ATTRIBUTE__BOUNDED__, 1, [OpenBSD's gcc has bounded]) |
372 | AC_DEFINE(SSH_TUN_BSD, 1, [Open tunnel devices the BSD way]) | 380 | AC_DEFINE(SSH_TUN_OPENBSD, 1, [Open tunnel devices the OpenBSD way]) |
373 | ;; | 381 | ;; |
374 | *-*-solaris*) | 382 | *-*-solaris*) |
375 | if test "x$withval" != "xno" ; then | 383 | if test "x$withval" != "xno" ; then |
diff --git a/includes.h b/includes.h index cf2d6c699..808d5dc9a 100644 --- a/includes.h +++ b/includes.h | |||
@@ -148,9 +148,6 @@ static /**/const char *const rcsid[] = { (const char *)rcsid, "\100(#)" msg } | |||
148 | #include <netinet/in.h> /* For IPv6 macros */ | 148 | #include <netinet/in.h> /* For IPv6 macros */ |
149 | #include <netinet/ip.h> /* For IPTOS macros */ | 149 | #include <netinet/ip.h> /* For IPTOS macros */ |
150 | #include <netinet/tcp.h> | 150 | #include <netinet/tcp.h> |
151 | #ifdef HAVE_NET_IF_H | ||
152 | # include <net/if.h> | ||
153 | #endif | ||
154 | #include <arpa/inet.h> | 151 | #include <arpa/inet.h> |
155 | #if defined(HAVE_NETDB_H) | 152 | #if defined(HAVE_NETDB_H) |
156 | # include <netdb.h> | 153 | # include <netdb.h> |
@@ -543,7 +543,7 @@ tun_open(int tun, int mode) | |||
543 | { | 543 | { |
544 | #if defined(CUSTOM_SYS_TUN_OPEN) | 544 | #if defined(CUSTOM_SYS_TUN_OPEN) |
545 | return (sys_tun_open(tun, mode)); | 545 | return (sys_tun_open(tun, mode)); |
546 | #elif defined(SSH_TUN_BSD) | 546 | #elif defined(SSH_TUN_OPENBSD) |
547 | struct ifreq ifr; | 547 | struct ifreq ifr; |
548 | char name[100]; | 548 | char name[100]; |
549 | int fd = -1, sock; | 549 | int fd = -1, sock; |
diff --git a/openbsd-compat/port-tun.c b/openbsd-compat/port-tun.c index 479b46b7a..00a0442b1 100644 --- a/openbsd-compat/port-tun.c +++ b/openbsd-compat/port-tun.c | |||
@@ -89,6 +89,88 @@ sys_tun_open(int tun, int mode) | |||
89 | } | 89 | } |
90 | #endif /* SSH_TUN_LINUX */ | 90 | #endif /* SSH_TUN_LINUX */ |
91 | 91 | ||
92 | #ifdef SSH_TUN_FREEBSD | ||
93 | #include <sys/socket.h> | ||
94 | #include <net/if.h> | ||
95 | #include <net/if_tun.h> | ||
96 | |||
97 | int | ||
98 | sys_tun_open(int tun, int mode) | ||
99 | { | ||
100 | struct ifreq ifr; | ||
101 | char name[100]; | ||
102 | int fd = -1, sock, flag; | ||
103 | const char *tunbase = "tun"; | ||
104 | |||
105 | if (mode == SSH_TUNMODE_ETHERNET) { | ||
106 | #ifdef SSH_TUN_NO_L2 | ||
107 | debug("%s: no layer 2 tunnelling support", __func__); | ||
108 | return (-1); | ||
109 | #else | ||
110 | tunbase = "tap"; | ||
111 | #endif | ||
112 | } | ||
113 | |||
114 | /* Open the tunnel device */ | ||
115 | if (tun <= SSH_TUNID_MAX) { | ||
116 | snprintf(name, sizeof(name), "/dev/%s%d", tunbase, tun); | ||
117 | fd = open(name, O_RDWR); | ||
118 | } else if (tun == SSH_TUNID_ANY) { | ||
119 | for (tun = 100; tun >= 0; tun--) { | ||
120 | snprintf(name, sizeof(name), "/dev/%s%d", | ||
121 | tunbase, tun); | ||
122 | if ((fd = open(name, O_RDWR)) >= 0) | ||
123 | break; | ||
124 | } | ||
125 | } else { | ||
126 | debug("%s: invalid tunnel %u\n", __func__, tun); | ||
127 | return (-1); | ||
128 | } | ||
129 | |||
130 | if (fd < 0) { | ||
131 | debug("%s: %s open failed: %s", __func__, name, | ||
132 | strerror(errno)); | ||
133 | return (-1); | ||
134 | } | ||
135 | |||
136 | /* Turn on tunnel headers */ | ||
137 | flag = 1; | ||
138 | #if defined(TUNSIFHEAD) && !defined(SSH_TUN_PREPEND_AF) | ||
139 | if (mode != SSH_TUNMODE_ETHERNET && | ||
140 | ioctl(fd, TUNSIFHEAD, &flag) == -1) { | ||
141 | debug("%s: ioctl(%d, TUNSIFHEAD, 1): %s", __func__, fd, | ||
142 | strerror(errno)); | ||
143 | close(fd); | ||
144 | } | ||
145 | #endif | ||
146 | |||
147 | debug("%s: %s mode %d fd %d", __func__, name, mode, fd); | ||
148 | |||
149 | /* Set the tunnel device operation mode */ | ||
150 | snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s%d", tunbase, tun); | ||
151 | if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) | ||
152 | goto failed; | ||
153 | |||
154 | if (ioctl(sock, SIOCGIFFLAGS, &ifr) == -1) | ||
155 | goto failed; | ||
156 | ifr.ifr_flags |= IFF_UP; | ||
157 | if (ioctl(sock, SIOCSIFFLAGS, &ifr) == -1) | ||
158 | goto failed; | ||
159 | |||
160 | close(sock); | ||
161 | return (fd); | ||
162 | |||
163 | failed: | ||
164 | if (fd >= 0) | ||
165 | close(fd); | ||
166 | if (sock >= 0) | ||
167 | close(sock); | ||
168 | debug("%s: failed to set %s mode %d: %s", __func__, name, | ||
169 | mode, strerror(errno)); | ||
170 | return (-1); | ||
171 | } | ||
172 | #endif /* SSH_TUN_FREEBSD */ | ||
173 | |||
92 | /* | 174 | /* |
93 | * System-specific channel filters | 175 | * System-specific channel filters |
94 | */ | 176 | */ |
@@ -102,16 +184,29 @@ sys_tun_infilter(struct Channel *c, char *buf, int len) | |||
102 | { | 184 | { |
103 | #if defined(SSH_TUN_PREPEND_AF) | 185 | #if defined(SSH_TUN_PREPEND_AF) |
104 | char rbuf[CHAN_RBUF]; | 186 | char rbuf[CHAN_RBUF]; |
187 | struct ip *iph; | ||
105 | #endif | 188 | #endif |
106 | u_int32_t *af; | 189 | u_int32_t *af; |
107 | char *ptr = buf; | 190 | char *ptr = buf; |
108 | 191 | ||
109 | #if defined(SSH_TUN_PREPEND_AF) | 192 | #if defined(SSH_TUN_PREPEND_AF) |
110 | if (len > (int)(sizeof(rbuf) - sizeof(*af))) | 193 | if (len <= 0 || len > (int)(sizeof(rbuf) - sizeof(*af))) |
111 | return (-1); | 194 | return (-1); |
112 | ptr = (char *)&rbuf[0]; | 195 | ptr = (char *)&rbuf[0]; |
113 | bcopy(buf, ptr + sizeof(u_int32_t), len); | 196 | bcopy(buf, ptr + sizeof(u_int32_t), len); |
114 | len += sizeof(u_int32_t); | 197 | len += sizeof(u_int32_t); |
198 | af = (u_int32_t *)ptr; | ||
199 | |||
200 | iph = (struct ip *)(ptr + sizeof(u_int32_t)); | ||
201 | switch (iph->ip_v) { | ||
202 | case 6: | ||
203 | *af = AF_INET6; | ||
204 | break; | ||
205 | case 4: | ||
206 | default: | ||
207 | *af = AF_INET; | ||
208 | break; | ||
209 | } | ||
115 | #endif | 210 | #endif |
116 | 211 | ||
117 | #if defined(SSH_TUN_COMPAT_AF) | 212 | #if defined(SSH_TUN_COMPAT_AF) |
@@ -124,6 +219,7 @@ sys_tun_infilter(struct Channel *c, char *buf, int len) | |||
124 | else | 219 | else |
125 | *af = htonl(OPENBSD_AF_INET); | 220 | *af = htonl(OPENBSD_AF_INET); |
126 | #endif | 221 | #endif |
222 | |||
127 | buffer_put_string(&c->input, ptr, len); | 223 | buffer_put_string(&c->input, ptr, len); |
128 | return (0); | 224 | return (0); |
129 | } | 225 | } |
diff --git a/openbsd-compat/port-tun.h b/openbsd-compat/port-tun.h index 942610c6d..86d9272b4 100644 --- a/openbsd-compat/port-tun.h +++ b/openbsd-compat/port-tun.h | |||
@@ -19,7 +19,7 @@ | |||
19 | 19 | ||
20 | #include "channels.h" | 20 | #include "channels.h" |
21 | 21 | ||
22 | #if defined(SSH_TUN_LINUX) | 22 | #if defined(SSH_TUN_LINUX) || defined(SSH_TUN_FREEBSD) |
23 | # define CUSTOM_SYS_TUN_OPEN | 23 | # define CUSTOM_SYS_TUN_OPEN |
24 | int sys_tun_open(int, int); | 24 | int sys_tun_open(int, int); |
25 | #endif | 25 | #endif |