2006-06-05 15:41:08 +03:00
|
|
|
/*
|
2014-06-01 09:46:42 +03:00
|
|
|
* Copyright (c) 2006-2014 Erik Ekman <yarrick@kryo.se>,
|
|
|
|
* 2006-2009 Bjorn Andersson <flex@kryo.se>
|
2015-03-05 23:06:23 +02:00
|
|
|
* 2013 Peter Sagerson <psagers.github@ignorare.net>
|
2006-06-05 15:41:08 +03:00
|
|
|
*
|
2014-08-07 22:14:10 +03:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
2006-06-05 15:41:08 +03:00
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2006-06-08 19:30:50 +03:00
|
|
|
#include <stdlib.h>
|
2006-06-05 15:41:08 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2006-06-05 15:48:30 +03:00
|
|
|
#include <stdint.h>
|
2006-06-05 15:41:08 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2009-01-25 00:19:11 +02:00
|
|
|
|
2015-03-05 23:06:23 +02:00
|
|
|
#ifdef DARWIN
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/kern_control.h>
|
|
|
|
#include <sys/sys_domain.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <net/if_utun.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#endif
|
|
|
|
|
2011-04-23 21:55:59 +03:00
|
|
|
#ifndef IFCONFIGPATH
|
2012-06-02 18:19:30 +03:00
|
|
|
#define IFCONFIGPATH "PATH=/sbin:/bin "
|
2011-04-23 21:55:59 +03:00
|
|
|
#endif
|
|
|
|
|
2019-08-24 17:43:34 +03:00
|
|
|
#ifndef ROUTEPATH
|
|
|
|
#define ROUTEPATH "PATH=/sbin:/bin "
|
|
|
|
#endif
|
|
|
|
|
2009-01-25 00:19:11 +02:00
|
|
|
#ifdef WINDOWS32
|
|
|
|
#include "windows.h"
|
2014-02-05 23:36:53 +02:00
|
|
|
#include <winioctl.h>
|
2009-01-25 12:56:32 +02:00
|
|
|
|
2014-06-11 21:50:35 +03:00
|
|
|
static HANDLE dev_handle;
|
|
|
|
static struct tun_data data;
|
2009-01-25 12:56:32 +02:00
|
|
|
|
2009-06-14 23:12:35 +03:00
|
|
|
static void get_name(char *ifname, int namelen, char *dev_name);
|
|
|
|
|
2009-01-25 12:56:32 +02:00
|
|
|
#define TAP_CONTROL_CODE(request,method) CTL_CODE(FILE_DEVICE_UNKNOWN, request, method, FILE_ANY_ACCESS)
|
|
|
|
#define TAP_IOCTL_CONFIG_TUN TAP_CONTROL_CODE(10, METHOD_BUFFERED)
|
|
|
|
#define TAP_IOCTL_SET_MEDIA_STATUS TAP_CONTROL_CODE(6, METHOD_BUFFERED)
|
|
|
|
|
|
|
|
#define TAP_ADAPTER_KEY "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
|
2009-06-14 22:50:35 +03:00
|
|
|
#define NETWORK_KEY "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
|
2009-01-25 12:56:32 +02:00
|
|
|
#define TAP_DEVICE_SPACE "\\\\.\\Global\\"
|
2009-03-21 14:51:59 +02:00
|
|
|
#define TAP_VERSION_ID_0801 "tap0801"
|
|
|
|
#define TAP_VERSION_ID_0901 "tap0901"
|
2009-01-25 12:56:32 +02:00
|
|
|
#define KEY_COMPONENT_ID "ComponentId"
|
|
|
|
#define NET_CFG_INST_ID "NetCfgInstanceId"
|
2009-01-25 00:19:11 +02:00
|
|
|
#else
|
2006-06-05 15:41:08 +03:00
|
|
|
#include <err.h>
|
2006-06-24 13:17:16 +03:00
|
|
|
#include <netinet/in.h>
|
2012-02-11 00:26:27 +02:00
|
|
|
#include <arpa/inet.h>
|
2009-01-25 12:56:32 +02:00
|
|
|
|
|
|
|
#define TUN_MAX_TRY 50
|
2009-01-25 00:19:11 +02:00
|
|
|
#endif
|
2006-06-05 15:41:08 +03:00
|
|
|
|
|
|
|
#include "tun.h"
|
2009-01-25 00:19:11 +02:00
|
|
|
#include "common.h"
|
2006-06-05 15:41:08 +03:00
|
|
|
|
2014-06-11 21:50:35 +03:00
|
|
|
static char if_name[250];
|
2009-01-25 21:53:20 +02:00
|
|
|
|
2006-06-05 15:41:08 +03:00
|
|
|
#ifdef LINUX
|
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <linux/if_tun.h>
|
|
|
|
|
2014-06-01 09:34:18 +03:00
|
|
|
int
|
|
|
|
open_tun(const char *tun_device)
|
2006-06-05 15:41:08 +03:00
|
|
|
{
|
|
|
|
int i;
|
2006-06-05 17:43:04 +03:00
|
|
|
int tun_fd;
|
|
|
|
struct ifreq ifreq;
|
2011-04-23 21:55:59 +03:00
|
|
|
#ifdef ANDROID
|
|
|
|
char *tunnel = "/dev/tun";
|
|
|
|
#else
|
2006-06-24 13:21:50 +03:00
|
|
|
char *tunnel = "/dev/net/tun";
|
2011-04-23 21:55:59 +03:00
|
|
|
#endif
|
2006-06-05 15:41:08 +03:00
|
|
|
|
2006-06-24 13:21:50 +03:00
|
|
|
if ((tun_fd = open(tunnel, O_RDWR)) < 0) {
|
2014-08-07 21:03:46 +03:00
|
|
|
warn("open_tun: %s", tunnel);
|
2006-06-11 17:42:19 +03:00
|
|
|
return -1;
|
2006-06-05 17:02:42 +03:00
|
|
|
}
|
2006-06-05 15:41:08 +03:00
|
|
|
|
2006-11-08 23:45:28 +02:00
|
|
|
memset(&ifreq, 0, sizeof(ifreq));
|
2006-06-05 15:41:08 +03:00
|
|
|
|
2014-06-01 09:34:18 +03:00
|
|
|
ifreq.ifr_flags = IFF_TUN;
|
2006-06-05 15:41:08 +03:00
|
|
|
|
2006-06-24 13:21:50 +03:00
|
|
|
if (tun_device != NULL) {
|
2006-06-25 14:15:18 +03:00
|
|
|
strncpy(ifreq.ifr_name, tun_device, IFNAMSIZ);
|
2007-08-26 18:47:32 +03:00
|
|
|
ifreq.ifr_name[IFNAMSIZ-1] = '\0';
|
2006-06-25 14:15:18 +03:00
|
|
|
strncpy(if_name, tun_device, sizeof(if_name));
|
2007-08-26 18:47:32 +03:00
|
|
|
if_name[sizeof(if_name)-1] = '\0';
|
2006-06-05 15:41:08 +03:00
|
|
|
|
2006-06-25 14:15:18 +03:00
|
|
|
if (ioctl(tun_fd, TUNSETIFF, (void *) &ifreq) != -1) {
|
2009-02-28 16:35:03 +02:00
|
|
|
fprintf(stderr, "Opened %s\n", ifreq.ifr_name);
|
2014-06-04 11:40:36 +03:00
|
|
|
fd_set_close_on_exec(tun_fd);
|
2006-06-25 14:15:18 +03:00
|
|
|
return tun_fd;
|
|
|
|
}
|
2006-06-05 15:41:08 +03:00
|
|
|
|
2006-06-25 14:15:18 +03:00
|
|
|
if (errno != EBUSY) {
|
2014-08-07 21:03:46 +03:00
|
|
|
warn("open_tun: ioctl[TUNSETIFF]");
|
2006-06-25 14:15:18 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2006-06-24 13:21:50 +03:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < TUN_MAX_TRY; i++) {
|
|
|
|
snprintf(ifreq.ifr_name, IFNAMSIZ, "dns%d", i);
|
|
|
|
|
|
|
|
if (ioctl(tun_fd, TUNSETIFF, (void *) &ifreq) != -1) {
|
2009-02-28 16:35:03 +02:00
|
|
|
fprintf(stderr, "Opened %s\n", ifreq.ifr_name);
|
2006-06-24 13:21:50 +03:00
|
|
|
snprintf(if_name, sizeof(if_name), "dns%d", i);
|
2014-06-04 11:40:36 +03:00
|
|
|
fd_set_close_on_exec(tun_fd);
|
2006-06-24 13:21:50 +03:00
|
|
|
return tun_fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errno != EBUSY) {
|
2014-08-07 21:03:46 +03:00
|
|
|
warn("open_tun: ioctl[TUNSETIFF]");
|
2006-06-24 13:21:50 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2006-06-05 17:02:42 +03:00
|
|
|
}
|
2006-06-05 15:41:08 +03:00
|
|
|
|
2006-06-25 15:05:46 +03:00
|
|
|
warn("open_tun: Couldn't set interface name");
|
2006-06-24 13:21:50 +03:00
|
|
|
}
|
2009-06-24 19:40:52 +03:00
|
|
|
warn("error when opening tun");
|
2006-06-11 17:42:19 +03:00
|
|
|
return -1;
|
2006-06-05 15:41:08 +03:00
|
|
|
}
|
|
|
|
|
2014-06-11 21:50:35 +03:00
|
|
|
#elif WINDOWS32
|
2006-06-05 15:41:08 +03:00
|
|
|
|
2009-01-25 12:56:32 +02:00
|
|
|
static void
|
2009-06-14 23:12:35 +03:00
|
|
|
get_device(char *device, int device_len, const char *wanted_dev)
|
2009-01-25 12:56:32 +02:00
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
HKEY adapter_key;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TAP_ADAPTER_KEY, 0, KEY_READ, &adapter_key);
|
|
|
|
|
|
|
|
if (status != ERROR_SUCCESS) {
|
2020-07-24 20:02:41 +03:00
|
|
|
warnx("Error opening registry key " TAP_ADAPTER_KEY);
|
2009-01-25 12:56:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-06-01 09:34:18 +03:00
|
|
|
|
2009-01-25 12:56:32 +02:00
|
|
|
while (TRUE) {
|
|
|
|
char name[256];
|
|
|
|
char unit[256];
|
|
|
|
char component[256];
|
|
|
|
|
|
|
|
char cid_string[256] = KEY_COMPONENT_ID;
|
|
|
|
HKEY device_key;
|
|
|
|
DWORD datatype;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
/* Iterate through all adapter of this kind */
|
|
|
|
len = sizeof(name);
|
|
|
|
status = RegEnumKeyEx(adapter_key, index, name, &len, NULL, NULL, NULL, NULL);
|
|
|
|
if (status == ERROR_NO_MORE_ITEMS) {
|
|
|
|
break;
|
|
|
|
} else if (status != ERROR_SUCCESS) {
|
2020-07-24 20:02:41 +03:00
|
|
|
warnx("Error enumerating subkeys of registry key " TAP_ADAPTER_KEY);
|
2009-01-25 12:56:32 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(unit, sizeof(unit), TAP_ADAPTER_KEY "\\%s", name);
|
|
|
|
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, unit, 0, KEY_READ, &device_key);
|
|
|
|
if (status != ERROR_SUCCESS) {
|
|
|
|
warnx("Error opening registry key %s", unit);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check component id */
|
|
|
|
len = sizeof(component);
|
|
|
|
status = RegQueryValueEx(device_key, cid_string, NULL, &datatype, (LPBYTE)component, &len);
|
|
|
|
if (status != ERROR_SUCCESS || datatype != REG_SZ) {
|
|
|
|
goto next;
|
|
|
|
}
|
2009-03-21 14:51:59 +02:00
|
|
|
if (strncmp(TAP_VERSION_ID_0801, component, strlen(TAP_VERSION_ID_0801)) == 0 ||
|
|
|
|
strncmp(TAP_VERSION_ID_0901, component, strlen(TAP_VERSION_ID_0901)) == 0) {
|
2009-01-25 12:56:32 +02:00
|
|
|
/* We found a TAP32 device, get its NetCfgInstanceId */
|
|
|
|
char iid_string[256] = NET_CFG_INST_ID;
|
2014-06-01 09:34:18 +03:00
|
|
|
|
2009-01-25 12:56:32 +02:00
|
|
|
status = RegQueryValueEx(device_key, iid_string, NULL, &datatype, (LPBYTE) device, (DWORD *) &device_len);
|
|
|
|
if (status != ERROR_SUCCESS || datatype != REG_SZ) {
|
|
|
|
warnx("Error reading registry key %s\\%s on TAP device", unit, iid_string);
|
|
|
|
} else {
|
2009-06-14 23:12:35 +03:00
|
|
|
/* Done getting GUID of TAP device,
|
|
|
|
* now check if the name is the requested one */
|
|
|
|
if (wanted_dev) {
|
|
|
|
char name[250];
|
|
|
|
get_name(name, sizeof(name), device);
|
|
|
|
if (strncmp(name, wanted_dev, strlen(wanted_dev))) {
|
|
|
|
/* Skip if name mismatch */
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Get the if name */
|
|
|
|
get_name(if_name, sizeof(if_name), device);
|
2009-01-25 12:56:32 +02:00
|
|
|
RegCloseKey(device_key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
next:
|
|
|
|
RegCloseKey(device_key);
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
RegCloseKey(adapter_key);
|
|
|
|
}
|
|
|
|
|
2009-06-14 22:50:35 +03:00
|
|
|
static void
|
2009-06-14 23:12:35 +03:00
|
|
|
get_name(char *ifname, int namelen, char *dev_name)
|
2009-06-14 22:50:35 +03:00
|
|
|
{
|
|
|
|
char path[256];
|
|
|
|
char name_str[256] = "Name";
|
|
|
|
LONG status;
|
|
|
|
HKEY conn_key;
|
|
|
|
DWORD len;
|
|
|
|
DWORD datatype;
|
|
|
|
|
2009-06-14 23:12:35 +03:00
|
|
|
memset(ifname, 0, namelen);
|
2009-06-14 22:50:35 +03:00
|
|
|
|
|
|
|
snprintf(path, sizeof(path), NETWORK_KEY "\\%s\\Connection", dev_name);
|
|
|
|
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_READ, &conn_key);
|
|
|
|
if (status != ERROR_SUCCESS) {
|
|
|
|
fprintf(stderr, "Could not look up name of interface %s: error opening key\n", dev_name);
|
|
|
|
RegCloseKey(conn_key);
|
|
|
|
return;
|
|
|
|
}
|
2009-06-14 23:12:35 +03:00
|
|
|
len = namelen;
|
|
|
|
status = RegQueryValueEx(conn_key, name_str, NULL, &datatype, (LPBYTE)ifname, &len);
|
2009-06-14 22:50:35 +03:00
|
|
|
if (status != ERROR_SUCCESS || datatype != REG_SZ) {
|
|
|
|
fprintf(stderr, "Could not look up name of interface %s: error reading value\n", dev_name);
|
|
|
|
RegCloseKey(conn_key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
RegCloseKey(conn_key);
|
|
|
|
}
|
|
|
|
|
2009-01-25 16:22:07 +02:00
|
|
|
DWORD WINAPI tun_reader(LPVOID arg)
|
|
|
|
{
|
|
|
|
struct tun_data *tun = arg;
|
|
|
|
char buf[64*1024];
|
|
|
|
int len;
|
|
|
|
int res;
|
|
|
|
OVERLAPPED olpd;
|
|
|
|
int sock;
|
|
|
|
|
2014-05-31 22:22:03 +03:00
|
|
|
sock = open_dns_from_host("127.0.0.1", 0, AF_INET, 0);
|
2009-01-25 16:22:07 +02:00
|
|
|
|
|
|
|
olpd.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
|
|
|
|
|
|
|
while(TRUE) {
|
|
|
|
olpd.Offset = 0;
|
|
|
|
olpd.OffsetHigh = 0;
|
|
|
|
res = ReadFile(tun->tun, buf, sizeof(buf), (LPDWORD) &len, &olpd);
|
|
|
|
if (!res) {
|
|
|
|
WaitForSingleObject(olpd.hEvent, INFINITE);
|
|
|
|
res = GetOverlappedResult(dev_handle, &olpd, (LPDWORD) &len, FALSE);
|
2014-06-01 09:34:18 +03:00
|
|
|
res = sendto(sock, buf, len, 0, (struct sockaddr*) &(tun->addr),
|
2014-02-05 23:36:53 +02:00
|
|
|
tun->addrlen);
|
2009-01-25 16:22:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-01 09:34:18 +03:00
|
|
|
int
|
|
|
|
open_tun(const char *tun_device)
|
2009-01-25 00:19:11 +02:00
|
|
|
{
|
2009-01-25 12:56:32 +02:00
|
|
|
char adapter[256];
|
|
|
|
char tapfile[512];
|
2009-01-25 16:22:07 +02:00
|
|
|
int tunfd;
|
2014-02-05 23:36:53 +02:00
|
|
|
struct sockaddr_storage localsock;
|
|
|
|
int localsock_len;
|
2009-01-25 12:56:32 +02:00
|
|
|
|
|
|
|
memset(adapter, 0, sizeof(adapter));
|
2009-06-14 23:30:35 +03:00
|
|
|
memset(if_name, 0, sizeof(if_name));
|
2009-06-14 23:12:35 +03:00
|
|
|
get_device(adapter, sizeof(adapter), tun_device);
|
2009-01-25 12:56:32 +02:00
|
|
|
|
2009-06-14 22:50:35 +03:00
|
|
|
if (strlen(adapter) == 0 || strlen(if_name) == 0) {
|
2009-06-14 23:30:35 +03:00
|
|
|
if (tun_device) {
|
|
|
|
warnx("No TAP adapters found. Try without -d.");
|
|
|
|
} else {
|
|
|
|
warnx("No TAP adapters found. Version 0801 and 0901 are supported.");
|
|
|
|
}
|
2009-01-25 12:56:32 +02:00
|
|
|
return -1;
|
2009-01-25 23:40:04 +02:00
|
|
|
}
|
2014-06-01 09:34:18 +03:00
|
|
|
|
2009-06-14 23:12:35 +03:00
|
|
|
fprintf(stderr, "Opening device %s\n", if_name);
|
2009-06-14 23:30:35 +03:00
|
|
|
snprintf(tapfile, sizeof(tapfile), "%s%s.tap", TAP_DEVICE_SPACE, adapter);
|
2009-01-25 16:22:07 +02:00
|
|
|
dev_handle = CreateFile(tapfile, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, NULL);
|
2009-01-25 12:56:32 +02:00
|
|
|
if (dev_handle == INVALID_HANDLE_VALUE) {
|
2009-06-14 23:30:35 +03:00
|
|
|
warnx("Could not open device!");
|
2009-01-25 12:56:32 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-01-25 16:22:07 +02:00
|
|
|
/* Use a UDP connection to forward packets from tun,
|
|
|
|
* so we can still use select() in main code.
|
2014-06-01 09:34:18 +03:00
|
|
|
* A thread does blocking reads on tun device and
|
2009-01-25 16:22:07 +02:00
|
|
|
* sends data as udp to this socket */
|
2014-06-01 09:34:18 +03:00
|
|
|
|
2014-02-05 23:36:53 +02:00
|
|
|
localsock_len = get_addr("127.0.0.1", 55353, AF_INET, 0, &localsock);
|
|
|
|
tunfd = open_dns(&localsock, localsock_len);
|
2009-01-25 16:22:07 +02:00
|
|
|
|
|
|
|
data.tun = dev_handle;
|
2014-02-05 23:36:53 +02:00
|
|
|
memcpy(&(data.addr), &localsock, localsock_len);
|
|
|
|
data.addrlen = localsock_len;
|
2009-01-25 16:22:07 +02:00
|
|
|
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)tun_reader, &data, 0, NULL);
|
2014-06-01 09:34:18 +03:00
|
|
|
|
2009-01-25 16:22:07 +02:00
|
|
|
return tunfd;
|
2009-01-25 00:19:11 +02:00
|
|
|
}
|
2014-06-11 21:50:35 +03:00
|
|
|
|
|
|
|
#else /* BSD and friends */
|
|
|
|
|
2015-03-05 23:06:23 +02:00
|
|
|
#ifdef DARWIN
|
|
|
|
|
|
|
|
/* Extract the device number from the name, if given. The value returned will
|
|
|
|
* be suitable for sockaddr_ctl.sc_unit, which means 0 for auto-assign, or
|
|
|
|
* (n + 1) for manual.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
utun_unit(const char *dev)
|
|
|
|
{
|
|
|
|
const char *unit_str = dev;
|
|
|
|
int unit = 0;
|
|
|
|
|
2021-05-13 21:11:49 +03:00
|
|
|
if (!dev)
|
|
|
|
return -1;
|
|
|
|
|
2015-03-05 23:06:23 +02:00
|
|
|
while (*unit_str != '\0' && !isdigit(*unit_str))
|
|
|
|
unit_str++;
|
|
|
|
|
|
|
|
if (isdigit(*unit_str))
|
|
|
|
unit = strtol(unit_str, NULL, 10) + 1;
|
|
|
|
|
|
|
|
return unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
open_utun(const char *dev)
|
|
|
|
{
|
|
|
|
struct sockaddr_ctl addr;
|
|
|
|
struct ctl_info info;
|
|
|
|
char ifname[10];
|
|
|
|
socklen_t ifname_len = sizeof(ifname);
|
2021-05-14 14:38:51 +03:00
|
|
|
int unit;
|
2015-03-05 23:06:23 +02:00
|
|
|
int fd = -1;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
fd = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL);
|
|
|
|
if (fd < 0) {
|
|
|
|
warn("open_utun: socket(PF_SYSTEM)");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look up the kernel controller ID for utun devices. */
|
|
|
|
bzero(&info, sizeof(info));
|
|
|
|
strncpy(info.ctl_name, UTUN_CONTROL_NAME, MAX_KCTL_NAME);
|
|
|
|
|
|
|
|
err = ioctl(fd, CTLIOCGINFO, &info);
|
|
|
|
if (err != 0) {
|
|
|
|
warn("open_utun: ioctl(CTLIOCGINFO)");
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Connecting to the socket creates the utun device. */
|
|
|
|
addr.sc_len = sizeof(addr);
|
|
|
|
addr.sc_family = AF_SYSTEM;
|
|
|
|
addr.ss_sysaddr = AF_SYS_CONTROL;
|
|
|
|
addr.sc_id = info.ctl_id;
|
2021-05-14 14:38:51 +03:00
|
|
|
unit = utun_unit(dev);
|
|
|
|
if (unit < 0) {
|
2021-05-13 21:11:49 +03:00
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
2021-05-14 14:38:51 +03:00
|
|
|
addr.sc_unit = unit;
|
2015-03-05 23:06:23 +02:00
|
|
|
|
|
|
|
err = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
|
|
|
|
if (err != 0) {
|
|
|
|
warn("open_utun: connect");
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve the assigned interface name. */
|
|
|
|
err = getsockopt(fd, SYSPROTO_CONTROL, UTUN_OPT_IFNAME, ifname, &ifname_len);
|
|
|
|
if (err != 0) {
|
|
|
|
warn("open_utun: getsockopt(UTUN_OPT_IFNAME)");
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(if_name, ifname, sizeof(if_name));
|
|
|
|
|
|
|
|
fprintf(stderr, "Opened %s\n", ifname);
|
|
|
|
fd_set_close_on_exec(fd);
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-06-11 21:50:35 +03:00
|
|
|
int
|
|
|
|
open_tun(const char *tun_device)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int tun_fd;
|
|
|
|
char tun_name[50];
|
|
|
|
|
2020-07-03 17:48:05 +03:00
|
|
|
if (tun_device != NULL) {
|
2015-03-05 23:06:23 +02:00
|
|
|
#ifdef DARWIN
|
2020-07-03 17:48:05 +03:00
|
|
|
if (!strncmp(tun_device, "utun", 4)) {
|
|
|
|
tun_fd = open_utun(tun_device);
|
|
|
|
if (tun_fd >= 0) {
|
|
|
|
return tun_fd;
|
|
|
|
}
|
2015-03-05 23:06:23 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-11 21:50:35 +03:00
|
|
|
snprintf(tun_name, sizeof(tun_name), "/dev/%s", tun_device);
|
|
|
|
strncpy(if_name, tun_device, sizeof(if_name));
|
|
|
|
if_name[sizeof(if_name)-1] = '\0';
|
|
|
|
|
|
|
|
if ((tun_fd = open(tun_name, O_RDWR)) < 0) {
|
2014-08-07 21:03:46 +03:00
|
|
|
warn("open_tun: %s", tun_name);
|
2014-06-11 21:50:35 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "Opened %s\n", tun_name);
|
|
|
|
fd_set_close_on_exec(tun_fd);
|
|
|
|
return tun_fd;
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < TUN_MAX_TRY; i++) {
|
|
|
|
snprintf(tun_name, sizeof(tun_name), "/dev/tun%d", i);
|
|
|
|
|
|
|
|
if ((tun_fd = open(tun_name, O_RDWR)) >= 0) {
|
|
|
|
fprintf(stderr, "Opened %s\n", tun_name);
|
|
|
|
snprintf(if_name, sizeof(if_name), "tun%d", i);
|
|
|
|
fd_set_close_on_exec(tun_fd);
|
|
|
|
return tun_fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errno == ENOENT)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-01-21 18:39:54 +02:00
|
|
|
#ifdef DARWIN
|
|
|
|
fprintf(stderr, "No tun devices found, trying utun\n");
|
|
|
|
for (i = 0; i < TUN_MAX_TRY; i++) {
|
|
|
|
snprintf(tun_name, sizeof(tun_name), "utun%d", i);
|
2021-05-13 21:11:49 +03:00
|
|
|
tun_fd = open_utun(tun_name);
|
2021-01-21 18:39:54 +02:00
|
|
|
if (tun_fd >= 0) {
|
|
|
|
return tun_fd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-11 21:50:35 +03:00
|
|
|
warn("open_tun: Failed to open tunneling device");
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-06-01 09:34:18 +03:00
|
|
|
#endif
|
2006-06-05 15:41:08 +03:00
|
|
|
|
2014-06-01 09:34:18 +03:00
|
|
|
void
|
|
|
|
close_tun(int tun_fd)
|
2006-06-05 15:41:08 +03:00
|
|
|
{
|
|
|
|
if (tun_fd >= 0)
|
|
|
|
close(tun_fd);
|
|
|
|
}
|
|
|
|
|
2014-06-11 21:50:35 +03:00
|
|
|
#ifdef WINDOWS32
|
2014-06-01 09:34:18 +03:00
|
|
|
int
|
|
|
|
write_tun(int tun_fd, char *data, size_t len)
|
2006-06-05 15:41:08 +03:00
|
|
|
{
|
2014-06-11 21:50:35 +03:00
|
|
|
DWORD written;
|
|
|
|
DWORD res;
|
|
|
|
OVERLAPPED olpd;
|
|
|
|
|
|
|
|
data += 4;
|
|
|
|
len -= 4;
|
|
|
|
|
|
|
|
olpd.Offset = 0;
|
|
|
|
olpd.OffsetHigh = 0;
|
|
|
|
olpd.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
|
|
|
res = WriteFile(dev_handle, data, len, &written, &olpd);
|
|
|
|
if (!res && GetLastError() == ERROR_IO_PENDING) {
|
|
|
|
WaitForSingleObject(olpd.hEvent, INFINITE);
|
|
|
|
res = GetOverlappedResult(dev_handle, &olpd, &written, FALSE);
|
|
|
|
if (written != len) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
read_tun(int tun_fd, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
int bytes;
|
|
|
|
memset(buf, 0, 4);
|
|
|
|
|
|
|
|
bytes = recv(tun_fd, buf + 4, len - 4, 0);
|
|
|
|
if (bytes < 0) {
|
|
|
|
return bytes;
|
|
|
|
} else {
|
|
|
|
return bytes + 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2020-07-03 18:06:14 +03:00
|
|
|
static int
|
|
|
|
tun_uses_header(void)
|
2014-06-11 21:50:35 +03:00
|
|
|
{
|
2015-03-05 23:06:23 +02:00
|
|
|
#if defined (FREEBSD) || defined (NETBSD)
|
|
|
|
/* FreeBSD/NetBSD has no header */
|
2020-07-03 18:06:14 +03:00
|
|
|
return 0;
|
2015-03-05 23:06:23 +02:00
|
|
|
#elif defined (DARWIN)
|
|
|
|
/* Darwin tun has no header, Darwin utun does */
|
2020-07-03 18:06:14 +03:00
|
|
|
return !strncmp(if_name, "utun", 4);
|
2015-03-05 23:06:23 +02:00
|
|
|
#else /* LINUX/OPENBSD */
|
2020-07-03 18:06:14 +03:00
|
|
|
return 1;
|
2015-03-05 23:06:23 +02:00
|
|
|
#endif
|
2020-07-03 18:06:14 +03:00
|
|
|
}
|
2015-03-05 23:06:23 +02:00
|
|
|
|
2020-07-03 18:06:14 +03:00
|
|
|
int
|
|
|
|
write_tun(int tun_fd, char *data, size_t len)
|
|
|
|
{
|
|
|
|
if (!tun_uses_header()) {
|
2015-03-05 23:06:23 +02:00
|
|
|
data += 4;
|
|
|
|
len -= 4;
|
|
|
|
} else {
|
2021-12-30 07:28:53 +02:00
|
|
|
int i = data[4] & 0xf0;
|
2006-06-11 16:49:36 +03:00
|
|
|
#ifdef LINUX
|
2021-12-30 07:09:16 +02:00
|
|
|
|
|
|
|
if (i == 64) {
|
|
|
|
// Look at the fifth bype
|
2015-04-08 09:42:05 +03:00
|
|
|
// Linux prefixes with 32 bits ethertype
|
|
|
|
// 0x0800 for IPv4, 0x86DD for IPv6
|
2021-12-30 07:09:16 +02:00
|
|
|
data[0] = 0x00;
|
|
|
|
data[1] = 0x00;
|
|
|
|
data[2] = 0x08;
|
|
|
|
data[3] = 0x00;
|
|
|
|
} else { /* 96 for IPV6 */
|
|
|
|
data[0] = 0x00;
|
|
|
|
data[1] = 0x00;
|
|
|
|
data[2] = 0x86;
|
|
|
|
data[3] = 0xDD;
|
|
|
|
}
|
2015-04-08 08:40:19 +03:00
|
|
|
#else /* OPENBSD and DARWIN(utun) */
|
2015-04-08 09:42:05 +03:00
|
|
|
// BSDs prefix with 32 bits address family
|
|
|
|
// AF_INET for IPv4, AF_INET6 for IPv6
|
2021-12-30 07:09:16 +02:00
|
|
|
if (i == 64) {
|
|
|
|
data[0] = 0x00;
|
|
|
|
data[1] = 0x00;
|
|
|
|
data[2] = 0x00;
|
|
|
|
data[3] = 0x02;
|
|
|
|
} else { /* 96 for IPV6 */
|
|
|
|
data[0] = 0x00;
|
|
|
|
data[1] = 0x00;
|
|
|
|
data[2] = 0x00;
|
2021-12-30 07:28:53 +02:00
|
|
|
data[3] = 0x1E;
|
|
|
|
|
|
|
|
}
|
2015-03-05 23:06:23 +02:00
|
|
|
#endif
|
|
|
|
}
|
2006-06-11 16:49:36 +03:00
|
|
|
|
|
|
|
if (write(tun_fd, data, len) != len) {
|
2006-06-06 01:36:05 +03:00
|
|
|
warn("write_tun");
|
2006-06-05 17:02:42 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2006-06-05 15:41:08 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-26 18:47:32 +03:00
|
|
|
ssize_t
|
2014-06-01 09:34:18 +03:00
|
|
|
read_tun(int tun_fd, char *buf, size_t len)
|
2006-06-05 15:41:08 +03:00
|
|
|
{
|
2020-07-03 18:06:14 +03:00
|
|
|
if (!tun_uses_header()) {
|
2015-03-05 23:06:23 +02:00
|
|
|
int bytes;
|
|
|
|
memset(buf, 0, 4);
|
|
|
|
|
|
|
|
bytes = read(tun_fd, buf + 4, len - 4);
|
|
|
|
if (bytes < 0) {
|
|
|
|
return bytes;
|
|
|
|
} else {
|
|
|
|
return bytes + 4;
|
|
|
|
}
|
2009-01-25 16:22:07 +02:00
|
|
|
} else {
|
2015-03-05 23:06:23 +02:00
|
|
|
return read(tun_fd, buf, len);
|
2009-01-25 16:22:07 +02:00
|
|
|
}
|
2006-06-05 15:41:08 +03:00
|
|
|
}
|
2014-06-11 21:50:35 +03:00
|
|
|
#endif
|
2006-06-05 15:41:08 +03:00
|
|
|
|
2006-06-11 18:19:07 +03:00
|
|
|
int
|
2021-12-27 22:15:01 +02:00
|
|
|
tun_setip(const char *ip, const char *other_ip, int netbits, int forward_v6)
|
2006-06-11 18:19:07 +03:00
|
|
|
{
|
|
|
|
char cmdline[512];
|
2021-12-28 05:14:05 +02:00
|
|
|
char v6_cmdline[512];
|
2009-01-04 14:39:28 +02:00
|
|
|
int netmask;
|
|
|
|
struct in_addr net;
|
|
|
|
int i;
|
2021-12-28 05:14:05 +02:00
|
|
|
int v6_r;
|
2007-06-17 15:19:23 +03:00
|
|
|
#ifndef LINUX
|
2009-01-04 14:39:28 +02:00
|
|
|
int r;
|
2007-06-17 15:19:23 +03:00
|
|
|
#endif
|
2009-01-25 21:53:20 +02:00
|
|
|
#ifdef WINDOWS32
|
|
|
|
DWORD status;
|
|
|
|
DWORD ipdata[3];
|
|
|
|
struct in_addr addr;
|
|
|
|
DWORD len;
|
2014-05-31 11:19:46 +03:00
|
|
|
#else
|
2013-05-20 20:39:05 +03:00
|
|
|
const char *display_ip;
|
2014-05-31 11:19:46 +03:00
|
|
|
#ifndef LINUX
|
|
|
|
struct in_addr netip;
|
|
|
|
#endif
|
|
|
|
#endif
|
2009-01-25 21:53:20 +02:00
|
|
|
|
2009-01-04 14:39:28 +02:00
|
|
|
netmask = 0;
|
|
|
|
for (i = 0; i < netbits; i++) {
|
|
|
|
netmask = (netmask << 1) | 1;
|
|
|
|
}
|
|
|
|
netmask <<= (32 - netbits);
|
|
|
|
net.s_addr = htonl(netmask);
|
2006-06-11 18:19:07 +03:00
|
|
|
|
2009-01-25 21:53:20 +02:00
|
|
|
if (inet_addr(ip) == INADDR_NONE) {
|
2009-02-28 16:35:03 +02:00
|
|
|
fprintf(stderr, "Invalid IP: %s!\n", ip);
|
2009-01-25 21:53:20 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#ifndef WINDOWS32
|
2013-05-20 20:39:05 +03:00
|
|
|
# ifdef FREEBSD
|
|
|
|
display_ip = other_ip; /* FreeBSD wants other IP as second IP */
|
|
|
|
# else
|
|
|
|
display_ip = ip;
|
|
|
|
# endif
|
2021-12-28 05:14:05 +02:00
|
|
|
fprintf(stderr, "Setting IPv6 of %s to ::%s\n", if_name, ip);
|
|
|
|
|
|
|
|
snprintf(v6_cmdline, sizeof(cmdline),
|
|
|
|
IFCONFIGPATH "ifconfig %s inet6 add ::%s/64",
|
|
|
|
if_name,
|
|
|
|
display_ip);
|
|
|
|
|
|
|
|
v6_r = system(v6_cmdline);
|
|
|
|
|
|
|
|
if (v6_r != 0) {
|
|
|
|
return v6_r;
|
|
|
|
}
|
2014-06-01 09:34:18 +03:00
|
|
|
snprintf(cmdline, sizeof(cmdline),
|
2011-04-23 21:55:59 +03:00
|
|
|
IFCONFIGPATH "ifconfig %s %s %s netmask %s",
|
2009-01-25 21:53:20 +02:00
|
|
|
if_name,
|
|
|
|
ip,
|
2013-05-20 20:39:05 +03:00
|
|
|
display_ip,
|
2009-01-25 21:53:20 +02:00
|
|
|
inet_ntoa(net));
|
2014-06-01 09:34:18 +03:00
|
|
|
|
2009-02-28 16:35:03 +02:00
|
|
|
fprintf(stderr, "Setting IP of %s to %s\n", if_name, ip);
|
2006-06-11 18:19:07 +03:00
|
|
|
#ifndef LINUX
|
2012-07-31 23:09:53 +03:00
|
|
|
netip.s_addr = inet_addr(ip);
|
|
|
|
netip.s_addr = netip.s_addr & net.s_addr;
|
2009-01-25 21:53:20 +02:00
|
|
|
r = system(cmdline);
|
2020-07-24 19:56:30 +03:00
|
|
|
if (r != 0) {
|
2009-01-25 21:53:20 +02:00
|
|
|
return r;
|
2006-06-23 10:58:36 +03:00
|
|
|
} else {
|
2014-06-01 09:34:18 +03:00
|
|
|
|
2009-01-25 21:53:20 +02:00
|
|
|
snprintf(cmdline, sizeof(cmdline),
|
2019-08-24 17:43:34 +03:00
|
|
|
ROUTEPATH "route add %s/%d %s",
|
2012-07-31 23:09:53 +03:00
|
|
|
inet_ntoa(netip), netbits, ip);
|
2006-06-11 18:19:07 +03:00
|
|
|
}
|
2012-07-31 23:09:53 +03:00
|
|
|
fprintf(stderr, "Adding route %s/%d to %s\n", inet_ntoa(netip), netbits, ip);
|
2009-01-25 21:53:20 +02:00
|
|
|
#endif
|
|
|
|
return system(cmdline);
|
2009-01-25 00:19:11 +02:00
|
|
|
#else /* WINDOWS32 */
|
2009-01-25 16:22:07 +02:00
|
|
|
|
2009-01-25 12:56:32 +02:00
|
|
|
/* Set device as connected */
|
2009-02-28 16:35:03 +02:00
|
|
|
fprintf(stderr, "Enabling interface '%s'\n", if_name);
|
2009-01-25 12:56:32 +02:00
|
|
|
status = 1;
|
2014-06-01 09:34:18 +03:00
|
|
|
r = DeviceIoControl(dev_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status,
|
2009-01-25 13:28:23 +02:00
|
|
|
sizeof(status), &status, sizeof(status), &len, NULL);
|
2009-01-25 21:53:20 +02:00
|
|
|
if (!r) {
|
2009-02-28 16:35:03 +02:00
|
|
|
fprintf(stderr, "Failed to enable interface\n");
|
2009-01-25 13:28:23 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-01 09:34:18 +03:00
|
|
|
|
2009-01-25 13:28:23 +02:00
|
|
|
if (inet_aton(ip, &addr)) {
|
2009-01-25 22:39:44 +02:00
|
|
|
ipdata[0] = (DWORD) addr.s_addr; /* local ip addr */
|
|
|
|
ipdata[1] = net.s_addr & ipdata[0]; /* network addr */
|
|
|
|
ipdata[2] = (DWORD) net.s_addr; /* netmask */
|
2009-01-25 13:28:23 +02:00
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-01-25 22:39:44 +02:00
|
|
|
|
|
|
|
/* Tell ip/networkaddr/netmask to device for arp use */
|
2014-06-01 09:34:18 +03:00
|
|
|
r = DeviceIoControl(dev_handle, TAP_IOCTL_CONFIG_TUN, &ipdata,
|
2009-01-25 13:28:23 +02:00
|
|
|
sizeof(ipdata), &ipdata, sizeof(ipdata), &len, NULL);
|
2009-01-25 21:53:20 +02:00
|
|
|
if (!r) {
|
2009-02-28 16:35:03 +02:00
|
|
|
fprintf(stderr, "Failed to set interface in TUN mode\n");
|
2009-01-25 13:28:23 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2009-01-25 21:53:20 +02:00
|
|
|
|
2009-01-25 22:39:44 +02:00
|
|
|
/* use netsh to set ip address */
|
2009-02-28 16:35:03 +02:00
|
|
|
fprintf(stderr, "Setting IP of interface '%s' to %s (can take a few seconds)...\n", if_name, ip);
|
2009-01-25 22:39:44 +02:00
|
|
|
snprintf(cmdline, sizeof(cmdline), "netsh interface ip set address \"%s\" static %s %s",
|
|
|
|
if_name, ip, inet_ntoa(net));
|
|
|
|
return system(cmdline);
|
2009-01-25 00:19:11 +02:00
|
|
|
#endif
|
2021-12-27 22:15:01 +02:00
|
|
|
|
|
|
|
if (forward_v6) {
|
|
|
|
snprintf(cmdline, sizeof(cmdline),
|
|
|
|
IFCONFIGPATH "ifconfig %s inet6 add ::%s/64",
|
|
|
|
if_name,
|
|
|
|
ip);
|
|
|
|
|
|
|
|
fprintf(stderr, "Setting IP of %s to %s\n", if_name, ip);
|
|
|
|
}
|
2006-06-11 18:19:07 +03:00
|
|
|
}
|
|
|
|
|
2014-06-01 09:34:18 +03:00
|
|
|
int
|
2009-01-07 20:16:49 +02:00
|
|
|
tun_setmtu(const unsigned mtu)
|
2006-06-11 18:19:07 +03:00
|
|
|
{
|
2009-01-25 00:19:11 +02:00
|
|
|
#ifndef WINDOWS32
|
2006-06-11 18:19:07 +03:00
|
|
|
char cmdline[512];
|
|
|
|
|
2009-03-04 23:37:42 +02:00
|
|
|
if (mtu > 200 && mtu <= 1500) {
|
2014-06-01 09:34:18 +03:00
|
|
|
snprintf(cmdline, sizeof(cmdline),
|
2011-04-23 21:55:59 +03:00
|
|
|
IFCONFIGPATH "ifconfig %s mtu %u",
|
2006-06-11 18:24:20 +03:00
|
|
|
if_name,
|
2006-06-11 18:19:07 +03:00
|
|
|
mtu);
|
2014-06-01 09:34:18 +03:00
|
|
|
|
2009-02-28 16:35:03 +02:00
|
|
|
fprintf(stderr, "Setting MTU of %s to %u\n", if_name, mtu);
|
2006-06-11 18:19:07 +03:00
|
|
|
return system(cmdline);
|
2006-06-11 21:07:26 +03:00
|
|
|
} else {
|
2007-11-27 22:04:13 +02:00
|
|
|
warn("MTU out of range: %u\n", mtu);
|
2006-06-11 18:19:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2009-01-25 00:19:11 +02:00
|
|
|
#else /* WINDOWS32 */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
#endif
|
2006-06-11 18:19:07 +03:00
|
|
|
}
|
|
|
|
|