port-tun.c (215116) | port-tun.c (294332) |
---|---|
1/* 2 * Copyright (c) 2005 Reyk Floeter <reyk@openbsd.org> 3 * 4 * Permission to use, copy, modify, and distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --- 18 unchanged lines hidden (view full) --- 27#include <fcntl.h> 28#include <stdarg.h> 29#include <string.h> 30#include <unistd.h> 31 32#include "openbsd-compat/sys-queue.h" 33#include "log.h" 34#include "misc.h" | 1/* 2 * Copyright (c) 2005 Reyk Floeter <reyk@openbsd.org> 3 * 4 * Permission to use, copy, modify, and distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --- 18 unchanged lines hidden (view full) --- 27#include <fcntl.h> 28#include <stdarg.h> 29#include <string.h> 30#include <unistd.h> 31 32#include "openbsd-compat/sys-queue.h" 33#include "log.h" 34#include "misc.h" |
35#include "buffer.h" | 35#include "sshbuf.h" |
36#include "channels.h" | 36#include "channels.h" |
37#include "ssherr.h" |
|
37 38/* 39 * This is the portable version of the SSH tunnel forwarding, it 40 * uses some preprocessor definitions for various platform-specific 41 * settings. 42 * 43 * SSH_TUN_LINUX Use the (newer) Linux tun/tap device 44 * SSH_TUN_FREEBSD Use the FreeBSD tun/tap device --- 160 unchanged lines hidden (view full) --- 205sys_tun_infilter(struct Channel *c, char *buf, int len) 206{ 207#if defined(SSH_TUN_PREPEND_AF) 208 char rbuf[CHAN_RBUF]; 209 struct ip *iph; 210#endif 211 u_int32_t *af; 212 char *ptr = buf; | 38 39/* 40 * This is the portable version of the SSH tunnel forwarding, it 41 * uses some preprocessor definitions for various platform-specific 42 * settings. 43 * 44 * SSH_TUN_LINUX Use the (newer) Linux tun/tap device 45 * SSH_TUN_FREEBSD Use the FreeBSD tun/tap device --- 160 unchanged lines hidden (view full) --- 206sys_tun_infilter(struct Channel *c, char *buf, int len) 207{ 208#if defined(SSH_TUN_PREPEND_AF) 209 char rbuf[CHAN_RBUF]; 210 struct ip *iph; 211#endif 212 u_int32_t *af; 213 char *ptr = buf; |
214 int r; |
|
213 214#if defined(SSH_TUN_PREPEND_AF) 215 if (len <= 0 || len > (int)(sizeof(rbuf) - sizeof(*af))) 216 return (-1); 217 ptr = (char *)&rbuf[0]; 218 bcopy(buf, ptr + sizeof(u_int32_t), len); 219 len += sizeof(u_int32_t); 220 af = (u_int32_t *)ptr; --- 16 unchanged lines hidden (view full) --- 237 238 af = (u_int32_t *)ptr; 239 if (*af == htonl(AF_INET6)) 240 *af = htonl(OPENBSD_AF_INET6); 241 else 242 *af = htonl(OPENBSD_AF_INET); 243#endif 244 | 215 216#if defined(SSH_TUN_PREPEND_AF) 217 if (len <= 0 || len > (int)(sizeof(rbuf) - sizeof(*af))) 218 return (-1); 219 ptr = (char *)&rbuf[0]; 220 bcopy(buf, ptr + sizeof(u_int32_t), len); 221 len += sizeof(u_int32_t); 222 af = (u_int32_t *)ptr; --- 16 unchanged lines hidden (view full) --- 239 240 af = (u_int32_t *)ptr; 241 if (*af == htonl(AF_INET6)) 242 *af = htonl(OPENBSD_AF_INET6); 243 else 244 *af = htonl(OPENBSD_AF_INET); 245#endif 246 |
245 buffer_put_string(&c->input, ptr, len); | 247 if ((r = sshbuf_put_string(&c->input, ptr, len)) != 0) 248 fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
246 return (0); 247} 248 249u_char * 250sys_tun_outfilter(struct Channel *c, u_char **data, u_int *dlen) 251{ 252 u_char *buf; 253 u_int32_t *af; | 249 return (0); 250} 251 252u_char * 253sys_tun_outfilter(struct Channel *c, u_char **data, u_int *dlen) 254{ 255 u_char *buf; 256 u_int32_t *af; |
257 int r; 258 size_t xxx_dlen; |
|
254 | 259 |
255 *data = buffer_get_string(&c->output, dlen); | 260 /* XXX new API is incompatible with this signature. */ 261 if ((r = sshbuf_get_string(&c->output, data, &xxx_dlen)) != 0) 262 fatal("%s: buffer error: %s", __func__, ssh_err(r)); 263 if (dlen != NULL) 264 *dlen = xxx_dlen; |
256 if (*dlen < sizeof(*af)) 257 return (NULL); 258 buf = *data; 259 260#if defined(SSH_TUN_PREPEND_AF) 261 *dlen -= sizeof(u_int32_t); 262 buf = *data + sizeof(u_int32_t); 263#elif defined(SSH_TUN_COMPAT_AF) 264 af = ntohl(*(u_int32_t *)buf); 265 if (*af == OPENBSD_AF_INET6) 266 *af = htonl(AF_INET6); 267 else 268 *af = htonl(AF_INET); 269#endif 270 271 return (buf); 272} 273#endif /* SSH_TUN_FILTER */ | 265 if (*dlen < sizeof(*af)) 266 return (NULL); 267 buf = *data; 268 269#if defined(SSH_TUN_PREPEND_AF) 270 *dlen -= sizeof(u_int32_t); 271 buf = *data + sizeof(u_int32_t); 272#elif defined(SSH_TUN_COMPAT_AF) 273 af = ntohl(*(u_int32_t *)buf); 274 if (*af == OPENBSD_AF_INET6) 275 *af = htonl(AF_INET6); 276 else 277 *af = htonl(AF_INET); 278#endif 279 280 return (buf); 281} 282#endif /* SSH_TUN_FILTER */ |