49#if defined(TARGET_LINUX) || defined(TARGET_ANDROID)
50#include <linux/rtnetlink.h>
53#if defined(TARGET_NETBSD)
60#define METRIC_NOT_USED ((DWORD)-1)
106#ifndef TARGET_ANDROID
196 if (!strcmp(parm,
"default"))
227 if (!
strcmp(
string,
"vpn_gateway"))
233 *out =
rl->spec.remote_endpoint;
246 else if (!
strcmp(
string,
"net_gateway"))
252 *out =
rl->ngi.gateway.addr;
257 " ROUTE: net_gateway undefined -- unable to get default gateway from system");
266 else if (!
strcmp(
string,
"remote_host"))
272 *out =
rl->spec.remote_host;
308 struct in_addr special = { 0 };
328 special.s_addr = htonl(special.s_addr);
329 char buf[INET_ADDRSTRLEN];
330 inet_ntop(AF_INET, &special, buf,
sizeof(buf));
336 NULL, AF_INET, network_list);
386 " needs a gateway parameter for a --route option and no default was specified by either --route-gateway or --ifconfig options");
438 if (inet_pton(AF_INET6, r6o->
gateway, &
r6->gateway) != 1)
483 const char *gateway,
const char *metric,
int table_id)
546 l2 = ((~gateway->netmask) + 1) >> 1;
548 r1->gateway = target;
550 r1->netmask = ~(l2 - 1);
564#ifndef TARGET_ANDROID
595 const char *remote_endpoint,
int default_metric,
in_addr_t remote_host,
639 bool defined =
false;
674 struct addrinfo *netlist = NULL;
683 const struct addrinfo *curele;
684 for (curele = netlist; curele; curele = curele->ai_next)
689 new->
network = ntohl(((
struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr);
716 for (i = 0; bits >= 8; i++, bits -= 8)
718 if (
network->s6_addr[i] != host->s6_addr[i])
729 unsigned int mask = 0xff << (8 - bits);
731 if ((
network->s6_addr[i] & mask) == (host->s6_addr[i] & mask))
741 const char *remote_endpoint,
int default_metric,
742 const struct in6_addr *remote_host_ipv6,
struct env_set *es,
747 bool need_remote_ipv6_route;
753 if (remote_host_ipv6)
759 if (default_metric >= 0)
800 need_remote_ipv6_route =
false;
817#ifndef TARGET_ANDROID
825 need_remote_ipv6_route =
true;
827 "ROUTE6: %s/%u overlaps IPv6 remote %s, adding host route to VPN endpoint",
837 if (need_remote_ipv6_route)
845 r6->network = *remote_host_ipv6;
855 r6->iface = rl6->
rgi6.iface;
865 "ROUTE6: IPv6 route overlaps with IPv6 remote address, but could not determine IPv6 gateway address + interface, expect failure\n");
908 for (
int i = 0; i < rb->
n_bypass; ++i)
941 const char err[] =
"NOTE: unable to redirect IPv4 default gateway --";
950 msg(
M_WARN,
"%s VPN gateway parameter (--route-gateway or --ifconfig) is missing", err);
961 msg(
M_WARN,
"%s Cannot read current default gateway from system", err);
966#ifndef TARGET_ANDROID
998 dmsg(
D_ROUTE,
"ROUTE remote_host protocol differs from tunneled");
1057 rl->
iflags &= ~RL_DID_LOCAL;
1088 rl->
iflags &= ~RL_DID_REDIRECT_DEFAULT_GATEWAY;
1104 "WARNING: OpenVPN was configured to add an IPv4 "
1105 "route. However, no IPv4 has been configured for %s, "
1106 "therefore the route installation may fail or may not work "
1111#ifdef ENABLE_MANAGEMENT
1136 "WARNING: OpenVPN was configured to add an IPv6 "
1137 "route. However, no IPv6 has been configured for %s, "
1138 "therefore the route installation may fail or may not work "
1176 rl->
iflags &= ~RL_ROUTES_ADDED;
1198 rl6->
iflags &= ~RL_ROUTES_ADDED;
1214 return "default (not set)";
1235 msg(msglevel,
" [redirect_default_gateway local=%d]", (rol->
flags &
RG_LOCAL) != 0);
1279 msg(msglevel,
"%s",
BSTR(&out));
1310 msg(msglevel,
"%s",
BSTR(&out));
1415 && netmask == 0xFFFFFFFF)
1424 for (
int i = 0; i < rgi->
n_addrs; ++i)
1439#if defined(TARGET_LINUX) || defined(_WIN32) || defined(TARGET_DARWIN)
1465#if !defined(TARGET_LINUX)
1467#if !defined(TARGET_AIX)
1479#if defined(TARGET_LINUX)
1480 const char *
iface = NULL;
1499 msg(
D_ROUTE,
"NOTE: Linux route add command failed because route exists");
1504 msg(
M_WARN,
"ERROR: Linux route add command failed");
1508#elif defined(TARGET_ANDROID)
1513 snprintf(out,
sizeof(out),
"%s %s %s dev %s", network, netmask, gateway, rgi->iface);
1517 snprintf(out,
sizeof(out),
"%s %s %s", network, netmask, gateway);
1519 bool ret = management_android_control(
management,
"ROUTE", out);
1522#elif defined(_WIN32)
1526 network, netmask, gateway);
1539 const char *method =
"service";
1556 method =
"route.exe";
1561 method =
"ipapi [adaptive]";
1564 msg(
D_ROUTE,
"Route addition fallback to route.exe");
1567 &
argv, es, 0,
"ERROR: Windows route add command failed [adaptive]");
1570 method =
"route.exe";
1579 msg(
D_ROUTE,
"Route addition via %s %s", method,
1584#elif defined(TARGET_SOLARIS)
1608#elif defined(TARGET_FREEBSD)
1627#elif defined(TARGET_DRAGONFLY)
1646#elif defined(TARGET_DARWIN)
1673#elif defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)
1692#elif defined(TARGET_AIX)
1702#elif defined(TARGET_HAIKU)
1713 "Sorry, but I don't know how to do 'route' commands on this operating system. Try putting your routes in a --route-up script");
1723 r->
flags &= ~RT_ADDED;
1741 int bits_to_clear = 128 -
r6->netbits;
1743 while (
byte >= 0 && bits_to_clear > 0)
1745 if (bits_to_clear >= 8)
1747 r6->network.s6_addr[
byte--] = 0;
1752 r6->network.s6_addr[
byte--] &= (uint8_t)(0xff << bits_to_clear);
1763 bool gateway_needed =
false;
1775 if (
r6->iface != NULL)
1778 if (!IN6_IS_ADDR_UNSPECIFIED(&
r6->gateway))
1780 gateway_needed =
true;
1789#if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \
1790 || defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)
1796 if (
r6->iface != NULL && gateway_needed
1797 && IN6_IS_ADDR_LINKLOCAL(&
r6->gateway))
1799 size_t len = strlen(gateway) + 1 + strlen(
r6->iface) + 1;
1801 snprintf(tmp, len,
"%s%%%s", gateway,
r6->iface);
1807 msg(
D_ROUTE,
"add_route_ipv6(%s/%u -> %s metric %d) dev %s", network,
r6->netbits, gateway,
1808 r6->metric, device);
1810 msg(
D_ROUTE,
"add_route_ipv6(%s/%u -> %s metric %d) IF %lu", network,
r6->netbits, gateway,
1827 gateway_needed =
true;
1830 if (gateway_needed && IN6_IS_ADDR_UNSPECIFIED(&
r6->gateway))
1834 "parameter for a --route-ipv6 option and no default was set via "
1835 "--ifconfig-ipv6 or --route-ipv6-gateway option. Not installing "
1836 "IPv6 route to %s/%u.",
1837 network,
r6->netbits);
1842#if defined(TARGET_LINUX)
1846 metric =
r6->metric;
1850 int ret = net_route_v6_add(ctx, &
r6->network,
r6->netbits, gateway_needed ? &
r6->gateway : NULL,
1851 device,
r6->table_id, metric);
1854 msg(
D_ROUTE,
"NOTE: Linux route add command failed because route exists");
1859 msg(
M_WARN,
"ERROR: Linux route add command failed");
1863#elif defined(TARGET_ANDROID)
1866 snprintf(out,
sizeof(out),
"%s/%u %s", network,
r6->netbits, device);
1870#elif defined(_WIN32)
1880#elif defined(TARGET_SOLARIS)
1905#elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)
1922#elif defined(TARGET_DARWIN)
1939#elif defined(TARGET_OPENBSD)
1948#elif defined(TARGET_NETBSD)
1956#elif defined(TARGET_AIX)
1963#elif defined(TARGET_HAIKU)
1967 gateway,
r6->netbits);
1974 "Sorry, but I don't know how to do 'route ipv6' commands on this operating system. Try putting your routes in a --route-up script");
1984 r6->flags &= ~RT_ADDED;
1998#if !defined(TARGET_LINUX)
1999 const char *network;
2000#if !defined(TARGET_AIX)
2001 const char *netmask;
2003 const char *gateway;
2017#if !defined(TARGET_LINUX)
2019#if !defined(TARGET_AIX)
2031#if defined(TARGET_LINUX)
2042 msg(
M_WARN,
"ERROR: Linux route delete command failed");
2044#elif defined(_WIN32)
2047 network, netmask, gateway);
2054 msg(
D_ROUTE,
"Route deletion via service %s",
status ?
"succeeded" :
"failed");
2059 msg(
D_ROUTE,
"Route deletion via IPAPI %s",
status ?
"succeeded" :
"failed");
2070 msg(
D_ROUTE,
"Route deletion via IPAPI %s [adaptive]",
status ?
"succeeded" :
"failed");
2073 msg(
D_ROUTE,
"Route deletion fallback to route.exe");
2076 "ERROR: Windows route delete command failed [adaptive]");
2085#elif defined(TARGET_SOLARIS)
2092#elif defined(TARGET_FREEBSD)
2099#elif defined(TARGET_DRAGONFLY)
2106#elif defined(TARGET_DARWIN)
2111 network, netmask, rgi->iface);
2121#elif defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)
2128#elif defined(TARGET_ANDROID)
2132 "needed. The VpnService API allows routes to be set "
2133 "on connect only and will clean up automatically. "
2134 "Tried to delete route %s netmask %s gateway %s",
2135 network, netmask, gateway);
2136#elif defined(TARGET_AIX)
2145#elif defined(TARGET_HAIKU)
2155 "Sorry, but I don't know how to do 'route' commands on this operating system. Try putting your routes in a --route-up script");
2159 r->
flags &= ~RT_ADDED;
2170 const char *network;
2178#if !defined(TARGET_LINUX)
2179 const char *gateway;
2181#if !defined(TARGET_SOLARIS)
2182 bool gateway_needed =
false;
2184 if (
r6->iface != NULL)
2187 gateway_needed =
true;
2196 gateway_needed =
true;
2205#if !defined(TARGET_LINUX) && !defined(_WIN32)
2209#if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \
2210 || defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)
2216 if (
r6->iface != NULL && gateway_needed
2217 && IN6_IS_ADDR_LINKLOCAL(&
r6->gateway))
2219 size_t len = strlen(gateway) + 1 + strlen(
r6->iface) + 1;
2221 snprintf(tmp, len,
"%s%%%s", gateway,
r6->iface);
2226 msg(
D_ROUTE,
"delete_route_ipv6(%s/%u)", network,
r6->netbits);
2228#if defined(TARGET_LINUX)
2232 metric =
r6->metric;
2235 if (net_route_v6_del(ctx, &
r6->network,
r6->netbits, gateway_needed ? &
r6->gateway : NULL,
2236 device,
r6->table_id, metric)
2239 msg(
M_WARN,
"ERROR: Linux route v6 delete command failed");
2242#elif defined(_WIN32)
2252#elif defined(TARGET_SOLARIS)
2261#elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)
2277#elif defined(TARGET_DARWIN)
2293#elif defined(TARGET_OPENBSD)
2301#elif defined(TARGET_NETBSD)
2308#elif defined(TARGET_AIX)
2314#elif defined(TARGET_ANDROID)
2316 "needed. The VpnService API allows routes to be set "
2317 "on connect only and will clean up automatically. "
2318 "Tried to delete %s gateway %s",
2320 gateway_needed ? gateway :
"(not needed)");
2321#elif defined(TARGET_HAIKU)
2325 gateway,
r6->netbits);
2331 "Sorry, but I don't know how to do 'route ipv6' commands on this operating system. Try putting your routes in a --route-down script");
2347static const MIB_IPFORWARDTABLE *
2351 PMIB_IPFORWARDTABLE rt = NULL;
2354 status = GetIpForwardTable(NULL, &size, TRUE);
2355 if (
status == ERROR_INSUFFICIENT_BUFFER)
2357 rt = (PMIB_IPFORWARDTABLE)
gc_malloc(size,
false,
gc);
2358 status = GetIpForwardTable(rt, &size, TRUE);
2361 msg(
D_ROUTE,
"NOTE: GetIpForwardTable returned error: %s (code=%lu)",
2416 bool adapter_up =
false;
2430 for (r = rl->
routes, len = 0; r; r = r->
next, ++len)
2442 msg(
D_ROUTE,
"TEST ROUTES: %d/%d succeeded len=%d ret=%u a=%d u/d=%s",
2443 good, count, len, ret, ambig, adapter_up ?
"up" :
"down");
2449static const MIB_IPFORWARDROW *
2453 DWORD lowest_metric = MAXDWORD;
2454 const MIB_IPFORWARDROW *ret = NULL;
2459 for (DWORD i = 0; i < routes->dwNumEntries; ++i)
2461 const MIB_IPFORWARDROW *row = &routes->table[i];
2462 const in_addr_t net = ntohl(row->dwForwardDest);
2463 const in_addr_t mask = ntohl(row->dwForwardMask);
2464 const DWORD index = row->dwForwardIfIndex;
2465 const DWORD metric = row->dwForwardMetric1;
2471 if (!net && !mask && metric < lowest_metric)
2474 lowest_metric = metric;
2500 DWORD best_if_index;
2506 status = GetBestInterfaceEx((
struct sockaddr *)dest, &best_if_index);
2509 msg(
D_ROUTE,
"NOTE: GetBestInterfaceEx returned error: %s (code=%lu)",
2519 SOCKADDR_INET best_src;
2521 status = GetBestRoute2(&luid, best_if_index, NULL, dest, 0, best_route, &best_src);
2524 msg(
D_ROUTE,
"NOTE: GetIpForwardEntry2 returned error: %s (code=%lu)",
2543 sa.si_family = AF_INET;
2544 sa.Ipv4.sin_addr.s_addr = htonl(dest);
2547 MIB_IPFORWARD_ROW2 best_route;
2556 rgi->
gateway.
addr = ntohl(best_route.NextHop.Ipv4.sin_addr.S_un.S_addr);
2569 memcpy(rgi->
hwaddr, ai->Address, 6);
2573 in_addr_t nm = inet_addr(ai->IpAddressList.IpMask.String);
2593 bool on_tun =
false;
2598 ret = tun_adapter->Index;
2609 msg(
M_WARN,
"Warning: route gateway is not reachable on any active network adapters: %s",
2615 msg(
M_WARN,
"Warning: route gateway is ambiguous: %s (%d matches)",
2620 on_tun, count, ret);
2637 SOCKADDR_INET DestinationAddress;
2638 CLEAR(DestinationAddress);
2639 DestinationAddress.si_family = AF_INET6;
2642 DestinationAddress.Ipv6.sin6_addr = *dest;
2645 MIB_IPFORWARD_ROW2 BestRoute;
2654 msg(
D_ROUTE,
"GDG6: II=%lu DP=%s/%d NH=%s", BestRoute.InterfaceIndex,
2656 BestRoute.DestinationPrefix.PrefixLength,
2658 msg(
D_ROUTE,
"GDG6: Metric=%lu, Loopback=%u, AA=%u, I=%u", BestRoute.Metric,
2659 BestRoute.Loopback, BestRoute.AutoconfigureAddress, BestRoute.Immortal);
2666 if (IN6_IS_ADDR_UNSPECIFIED(&BestRoute.NextHop.Ipv6.sin6_addr))
2688 MIB_IPFORWARDROW fr;
2690 fr.dwForwardDest = htonl(r->
network);
2691 fr.dwForwardMask = htonl(r->
netmask);
2692 fr.dwForwardPolicy = 0;
2693 fr.dwForwardNextHop = htonl(r->
gateway);
2694 fr.dwForwardIfIndex = if_index;
2695 fr.dwForwardType = 4;
2696 fr.dwForwardProto = 3;
2697 fr.dwForwardAge = 0;
2698 fr.dwForwardNextHopAS = 0;
2707 msg(
M_WARN,
"Warning: address %s is not a network address in relation to netmask %s",
2711 status = CreateIpForwardEntry(&fr);
2717 else if (
status == ERROR_OBJECT_ALREADY_EXISTS)
2725 const DWORD forward_metric_limit = 2048;
2727 for (; fr.dwForwardMetric1 <= forward_metric_limit; ++fr.dwForwardMetric1)
2732 for (fr.dwForwardType = 4; fr.dwForwardType >= 3; --fr.dwForwardType)
2734 status = CreateIpForwardEntry(&fr);
2738 "ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=%lu and dwForwardType=%lu",
2739 fr.dwForwardMetric1, fr.dwForwardType);
2743 else if (
status != ERROR_BAD_ARGUMENTS)
2753 if (
status == ERROR_OBJECT_ALREADY_EXISTS)
2760 "ERROR: route addition failed using CreateIpForwardEntry: "
2761 "%s [status=%lu if_index=%lu]",
2781 MIB_IPFORWARDROW fr;
2784 fr.dwForwardDest = htonl(r->
network);
2785 fr.dwForwardMask = htonl(r->
netmask);
2786 fr.dwForwardPolicy = 0;
2787 fr.dwForwardNextHop = htonl(r->
gateway);
2788 fr.dwForwardIfIndex = if_index;
2790 const DWORD
status = DeleteIpForwardEntry(&fr);
2797 msg(
M_WARN,
"ERROR: route deletion failed using DeleteIpForwardEntry: %s",
2824 msg(
M_WARN,
"ERROR: route %s failed using service: %s [status=%d if_index=%lu]",
2851 .prefix.ipv4.s_addr = htonl(r->
network),
2852 .gateway.ipv4.s_addr = htonl(r->
gateway),
2853 .iface = { .index = if_index, .name =
"" },
2857 if (
msg.prefix_len == -1)
2859 msg.prefix_len = 32;
2873 PMIB_IPFORWARD_ROW2 fwd_row;
2878 fwd_row->ValidLifetime = 0xffffffff;
2879 fwd_row->PreferredLifetime = 0xffffffff;
2880 fwd_row->Protocol = MIB_IPPROTO_NETMGMT;
2882 fwd_row->DestinationPrefix.Prefix.si_family = AF_INET6;
2883 fwd_row->DestinationPrefix.Prefix.Ipv6.sin6_addr = r->
network;
2884 fwd_row->DestinationPrefix.PrefixLength = (UINT8)r->
netbits;
2885 fwd_row->NextHop.si_family = AF_INET6;
2886 fwd_row->NextHop.Ipv6.sin6_addr = r->
gateway;
2895 inet_pton(AF_INET6,
"fe80::8", &fwd_row->NextHop.Ipv6.sin6_addr);
2903 if (err != NO_ERROR)
2907 fwd_row->InterfaceLuid = luid;
2908 fwd_row->InterfaceIndex = 0;
2913 err = CreateIpForwardEntry2(fwd_row);
2917 err = DeleteIpForwardEntry2(fwd_row);
2921 if (err != NO_ERROR)
2926 msg(
M_WARN,
"ERROR: route %s failed using ipapi: %s [status=%lu if_index=%lu]",
2928 fwd_row->InterfaceIndex);
2932 msg(
D_ROUTE,
"IPv6 route addition using ipapi failed because route exists");
2937 msg(
D_ROUTE,
"IPv6 route %s using ipapi", add ?
"added" :
"deleted");
2969 inet_pton(AF_INET6,
"fe80::8", &
msg.gateway.ipv6);
2980 msg(
D_ROUTE,
"IPv6 route %s via service %s", add ?
"addition" :
"deletion",
3016 buf_printf(&out,
"%s %s %s p=%lu i=%lu t=%lu pr=%lu a=%lu h=%lu m=%lu/%lu/%lu/%lu/%lu",
3020 r->dwForwardIfIndex,
r->dwForwardType,
r->dwForwardProto,
3021 r->dwForwardAge,
r->dwForwardNextHopAS,
r->dwForwardMetric1,
3022 r->dwForwardMetric2,
r->dwForwardMetric3,
r->dwForwardMetric4,
3023 r->dwForwardMetric5);
3037 msg(msglevel,
"SYSTEM ROUTING TABLE");
3040 for (DWORD i = 0; i < rt->dwNumEntries; ++i)
3048#elif defined(TARGET_ANDROID)
3063 rgi->
gateway.
addr = 127 << 24 |
'd' << 16 |
'g' << 8 |
'w';
3065 strcpy(rgi->iface,
"android-gw");
3085 strcpy(rgi6->iface,
"android-gw");
3088#elif defined(TARGET_LINUX)
3095 char best_name[IFNAMSIZ];
3101 if (net_route_v4_best_gw(ctx, &dest, &rgi->
gateway.
addr, best_name) == 0)
3113 const struct ifreq *ifr;
3114 const struct ifreq *ifend;
3118 struct ifreq ifs[20];
3120 if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
3125 ifc.ifc_len =
sizeof(ifs);
3127 if (ioctl(sd, SIOCGIFCONF, &ifc) < 0)
3129 msg(
M_WARN,
"GDG: ioctl(SIOCGIFCONF) failed");
3134 ifend = ifs + (ifc.ifc_len /
sizeof(
struct ifreq));
3135 for (ifr = ifc.ifc_req; ifr < ifend; ifr++)
3137 if (ifr->ifr_addr.sa_family == AF_INET)
3140 addr = ntohl(((
struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr);
3143 strlcpy(ifreq.ifr_name, ifr->ifr_name,
sizeof(ifreq.ifr_name));
3146 if (ioctl(sd, SIOCGIFFLAGS, &ifreq) < 0)
3150 if (!(ifreq.ifr_flags & IFF_UP))
3159 if (strcmp(ifreq.ifr_name, best_name))
3165 if ((ifreq.ifr_flags & IFF_POINTOPOINT) && ioctl(sd, SIOCGIFDSTADDR, &ifreq) >= 0)
3167 rgi->
gateway.
addr = ntohl(((
struct sockaddr_in *) &ifreq.ifr_addr)->sin_addr.s_addr);
3170 rgi->
flags &= ~RGI_ON_LINK;
3178 if (ioctl(sd, SIOCGIFNETMASK, &ifreq) < 0)
3182 netmask = ntohl(((
struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr.s_addr);
3196 strlcpy(rgi->iface, ifreq.ifr_name,
sizeof(rgi->iface));
3200 memset(&ifreq.ifr_hwaddr, 0,
sizeof(
struct sockaddr));
3201 if (ioctl(sd, SIOCGIFHWADDR, &ifreq) < 0)
3203 msg(
M_WARN,
"GDG: SIOCGIFHWADDR(%s) failed", ifreq.ifr_name);
3206 memcpy(rgi->
hwaddr, &ifreq.ifr_hwaddr.sa_data, 6);
3236 if (net_route_v6_best_gw(ctx, dest, &rgi6->
gateway.
addr_ipv6, rgi6->iface) == 0)
3243 if (strlen(rgi6->iface) > 0)
3261#elif defined(TARGET_DARWIN) || defined(TARGET_SOLARIS) || defined(TARGET_FREEBSD) \
3262 || defined(TARGET_DRAGONFLY) || defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)
3264#include <sys/types.h>
3265#include <sys/socket.h>
3266#include <netinet/in.h>
3267#include <net/route.h>
3268#include <net/if_dl.h>
3269#if !defined(TARGET_SOLARIS)
3275 struct rt_msghdr m_rtm;
3295#if defined(TARGET_DARWIN)
3296#define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(uint32_t) - 1))) : sizeof(uint32_t))
3297#elif defined(TARGET_NETBSD)
3298#define ROUNDUP(a) RT_ROUNDUP(a)
3300#define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
3303#if defined(TARGET_SOLARIS)
3304#define NEXTADDR(w, u) \
3305 if (rtm_addrs & (w)) \
3307 size_t l = sizeof(u); \
3308 memmove(cp, &(u), l); \
3312#define ADVANCE(x, n) (x += ROUNDUP(sizeof(struct sockaddr_in)))
3314#define NEXTADDR(w, u) \
3315 if (rtm_addrs & (w)) \
3317 size_t l = ((struct sockaddr *)&(u))->sa_len; \
3318 memmove(cp, &(u), l); \
3322#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
3325#define max(a, b) ((a) > (b) ? (a) : (b))
3331 struct rtmsg m_rtmsg;
3334 struct sockaddr so_dst, so_mask;
3335 char *cp = m_rtmsg.m_space;
3336 struct sockaddr *gate = NULL, *ifp = NULL, *sa;
3337 struct rt_msghdr *rtm_aux;
3339#define rtm m_rtmsg.m_rtm
3344 const int pid = getpid();
3346#ifdef TARGET_OPENBSD
3347 rtm_addrs = RTA_DST | RTA_NETMASK;
3349 rtm_addrs = RTA_DST | RTA_NETMASK | RTA_IFP;
3357 rtm.rtm_type = RTM_GET;
3358 rtm.rtm_flags = RTF_UP | RTF_GATEWAY;
3359 rtm.rtm_version = RTM_VERSION;
3360 rtm.rtm_seq = ++seq;
3361#ifdef TARGET_OPENBSD
3362 rtm.rtm_tableid = (u_short)getrtable();
3364 rtm.rtm_addrs = rtm_addrs;
3366 so_dst.sa_family = AF_INET;
3367 so_mask.sa_family = AF_INET;
3369#ifndef TARGET_SOLARIS
3370 so_dst.sa_len =
sizeof(
struct sockaddr_in);
3371 so_mask.sa_len =
sizeof(
struct sockaddr_in);
3374 NEXTADDR(RTA_DST, so_dst);
3375 NEXTADDR(RTA_NETMASK, so_mask);
3378 rtm.rtm_msglen = (u_short)(cp - (
char *)&m_rtmsg);
3381 sockfd = socket(PF_ROUTE, SOCK_RAW, 0);
3387 if (
write(sockfd, (
char *)&m_rtmsg, rtm.rtm_msglen) < 0)
3395 ret =
read(sockfd, (
char *)&m_rtmsg,
sizeof(m_rtmsg));
3396 }
while (ret > 0 && (rtm.rtm_seq != seq || rtm.rtm_pid != pid));
3402 cp = (
char *)(rtm_aux + 1);
3403 if (rtm_aux->rtm_addrs)
3405 for (
unsigned int i = 1; i; i <<= 1)
3407 if (i & rtm_aux->rtm_addrs)
3409 sa = (
struct sockaddr *)cp;
3410 if (i == RTA_GATEWAY)
3414 else if (i == RTA_IFP)
3431 rgi->
gateway.
addr = ntohl(((
struct sockaddr_in *)gate)->sin_addr.s_addr);
3440 const struct sockaddr_dl *adl = (
struct sockaddr_dl *)ifp;
3441 if (adl->sdl_nlen && adl->sdl_nlen <
sizeof(rgi->iface))
3443 memcpy(rgi->iface, adl->sdl_data, adl->sdl_nlen);
3444 rgi->iface[adl->sdl_nlen] =
'\0';
3455 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
3463 ifr.ifr_addr.sa_family = AF_INET;
3464 strlcpy(ifr.ifr_name, rgi->iface, IFNAMSIZ);
3466 if (ioctl(sockfd, SIOCGIFNETMASK, (
char *)&ifr) < 0)
3474 rgi->
gateway.
netmask = ntohl(((
struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr);
3481#if defined(TARGET_SOLARIS)
3483 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
3490 struct ifreq ifreq = { 0 };
3493 strlcpy(ifreq.ifr_name, rgi->iface,
sizeof(ifreq.ifr_name));
3494 if (ioctl(sockfd, SIOCGIFHWADDR, &ifreq) < 0)
3496 msg(
M_WARN,
"GDG: SIOCGIFHWADDR(%s) failed", ifreq.ifr_name);
3500 memcpy(rgi->
hwaddr, &ifreq.ifr_addr.sa_data, 6);
3504 struct ifaddrs *ifap, *ifa;
3506 if (getifaddrs(&ifap) != 0)
3512 for (ifa = ifap; ifa; ifa = ifa->ifa_next)
3514 if (ifa->ifa_addr != NULL && ifa->ifa_addr->sa_family == AF_LINK
3515 && !strncmp(ifa->ifa_name, rgi->iface, IFNAMSIZ))
3517 struct sockaddr_dl *sdl = (
struct sockaddr_dl *)ifa->ifa_addr;
3518 memcpy(rgi->
hwaddr, LLADDR(sdl), 6);
3542#if defined(TARGET_SOLARIS)
3544#define ADVANCE(x, n) (x += ROUNDUP(sizeof(struct sockaddr_in6)))
3551 struct rtmsg m_rtmsg;
3554 struct sockaddr_in6 so_dst, so_mask;
3555 char *cp = m_rtmsg.m_space;
3556 struct sockaddr *gate = NULL, *ifp = NULL, *sa;
3557 struct rt_msghdr *rtm_aux;
3562 const int pid = getpid();
3564#ifdef TARGET_OPENBSD
3565 rtm_addrs = RTA_DST | RTA_NETMASK;
3567 rtm_addrs = RTA_DST | RTA_NETMASK | RTA_IFP;
3575 rtm.rtm_type = RTM_GET;
3576 rtm.rtm_flags = RTF_UP;
3577 rtm.rtm_version = RTM_VERSION;
3578 rtm.rtm_seq = ++seq;
3579#ifdef TARGET_OPENBSD
3580 rtm.rtm_tableid = (u_short)getrtable();
3583 so_dst.sin6_family = AF_INET6;
3584 so_mask.sin6_family = AF_INET6;
3587 && !IN6_IS_ADDR_UNSPECIFIED(dest))
3589 so_dst.sin6_addr = *dest;
3591 rtm_addrs &= ~RTA_NETMASK;
3594 rtm.rtm_addrs = rtm_addrs;
3596#ifndef TARGET_SOLARIS
3597 so_dst.sin6_len =
sizeof(
struct sockaddr_in6);
3598 so_mask.sin6_len =
sizeof(
struct sockaddr_in6);
3601 NEXTADDR(RTA_DST, so_dst);
3602 NEXTADDR(RTA_NETMASK, so_mask);
3605 rtm.rtm_msglen = (u_short)(cp - (
char *)&m_rtmsg);
3608 sockfd = socket(PF_ROUTE, SOCK_RAW, 0);
3614 if (
write(sockfd, (
char *)&m_rtmsg, rtm.rtm_msglen) < 0)
3622 ret =
read(sockfd, (
char *)&m_rtmsg,
sizeof(m_rtmsg));
3623 }
while (ret > 0 && (rtm.rtm_seq != seq || rtm.rtm_pid != pid));
3630 cp = (
char *)(rtm_aux + 1);
3631 if (rtm_aux->rtm_addrs)
3633 for (
unsigned int i = 1; i; i <<= 1)
3635 if (i & rtm_aux->rtm_addrs)
3637 sa = (
struct sockaddr *)cp;
3638 if (i == RTA_GATEWAY)
3642 else if (i == RTA_IFP)
3658 const struct sockaddr_in6 *s6 = (
struct sockaddr_in6 *)gate;
3659 struct in6_addr gw = s6->sin6_addr;
3661#ifndef TARGET_SOLARIS
3666 if (gate->sa_len ==
sizeof(
struct sockaddr_in6) && IN6_IS_ADDR_LINKLOCAL(&gw))
3668 gw.s6_addr[2] = gw.s6_addr[3] = 0;
3671 if (gate->sa_len !=
sizeof(
struct sockaddr_in6) || IN6_IS_ADDR_UNSPECIFIED(&gw))
3685 const struct sockaddr_dl *adl = (
struct sockaddr_dl *)ifp;
3686 if (adl->sdl_nlen && adl->sdl_nlen <
sizeof(rgi6->iface))
3688 memcpy(rgi6->iface, adl->sdl_data, adl->sdl_nlen);
3703#elif defined(TARGET_HAIKU)
3710 int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
3713 msg(
M_ERRNO,
"%s: Error opening socket for AF_INET", __func__);
3717 struct ifconf config;
3718 config.ifc_len =
sizeof(config.ifc_value);
3719 if (ioctl(sockfd, SIOCGRTSIZE, &config,
sizeof(
struct ifconf)) < 0)
3721 msg(
M_ERRNO,
"%s: Error getting routing table size", __func__);
3726 uint32 size = (uint32)config.ifc_value;
3733 void *
buffer = malloc(size);
3736 config.ifc_len = size;
3738 int ret = ioctl(sockfd, SIOCGRTTABLE, &config,
sizeof(
struct ifconf));
3746 struct ifreq *
interface = (struct ifreq *)
buffer;
3747 struct ifreq *end = (
struct ifreq *)((uint8 *)
buffer + size);
3749 while (interface < end)
3751 struct route_entry
route = interface->ifr_route;
3752 if ((
route.flags & RTF_GATEWAY) != 0 && (
route.flags & RTF_DEFAULT) != 0)
3754 rgi->
gateway.
addr = ntohl(((
struct sockaddr_in *)
route.gateway)->sin_addr.s_addr);
3756 strlcpy(rgi->iface, interface->ifr_name,
sizeof(rgi->iface));
3759 int32 address_size = 0;
3760 if (
route.destination != NULL)
3762 address_size +=
route.destination->sa_len;
3764 if (
route.mask != NULL)
3766 address_size +=
route.mask->sa_len;
3768 if (
route.gateway != NULL)
3770 address_size +=
route.gateway->sa_len;
3773 interface = (struct ifreq *)((addr_t)
interface +
IF_NAMESIZE + sizeof(struct route_entry)
3822 msg(
D_ROUTE,
"no support for get_default_gateway_ipv6() on this system");
3831 const int addrlen =
sizeof(
in_addr_t) * 8;
3833 if ((network & netmask) == network)
3835 for (
int i = 0; i <= addrlen; ++i)
3838 if (mask == netmask)
3862 const int addrlen =
sizeof(
in_addr_t) * 8;
3864 for (i = 0; i <= addrlen; ++i)
3867 if (mask == netmask)
3898 bool succeed =
false;
3905 iplist = iplist->Next;
3978 for (DWORD i = 0; i < rt->dwNumEntries; ++i)
3980 const MIB_IPFORWARDROW *row = &rt->table[i];
3981 const in_addr_t net = ntohl(row->dwForwardDest);
3982 const in_addr_t mask = ntohl(row->dwForwardMask);
3983 if (mask > nonlocal_netmask && (addr & mask) == net)
void argv_msg(const msglvl_t msglevel, const struct argv *a)
Write the arguments stored in a struct argv via the msg() command.
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
bool argv_printf(struct argv *argres, const char *format,...)
printf() variant which populates a struct argv.
bool argv_printf_cat(struct argv *argres, const char *format,...)
printf() inspired argv concatenation.
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
bool buf_printf(struct buffer *buf, const char *format,...)
printf-style append to a buffer with overflow check.
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Allocate memory and, optionally, zero it.
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
char * format_hex_ex(const uint8_t *data, size_t size, size_t maxoutput, unsigned int space_break_flags, const char *separator, struct gc_arena *gc)
Format a binary buffer as a hex string.
void gc_addspecial(void *addr, void(*free_function)(void *), struct gc_arena *a)
Register an address with a custom free function in a garbage collection arena.
#define BSTR(buf)
Return the buffer content pointer cast to char *.
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
Allocate and zero-initialise a garbage-collected object of the given type.
#define ALLOC_OBJ_GC(dptr, type, gc)
Allocate a garbage-collected object of the given type (uninitialised).
static void check_malloc_return(void *p)
Abort if a memory allocation returned NULL.
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
static void gc_freeaddrinfo_callback(void *addr)
Callback to free a struct addrinfo, suitable for use with gc_addspecial().
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
size_t strlcpy(char *dest, const char *src, size_t maxlen)
void setenv_int(struct env_set *es, const char *name, int value)
void setenv_str(struct env_set *es, const char *name, const char *value)
static SERVICE_STATUS status
void management_set_state(struct management *man, const int state, const char *detail, const in_addr_t *tun_local_ip, const struct in6_addr *tun_local_ip6, const struct openvpn_sockaddr *local, const struct openvpn_sockaddr *remote)
#define OPENVPN_STATE_ADD_ROUTES
static void net_ctx_reset(openvpn_net_ctx_t *ctx)
#define TUN_ADAPTER_INDEX_INVALID
#define IPV4_NETMASK_HOST
const char * strerror_win32(DWORD errnum, struct gc_arena *gc)
int openvpn_getaddrinfo(unsigned int flags, const char *hostname, const char *servname, int resolve_retry_seconds, struct signal_info *sig_info, int ai_family, struct addrinfo **res)
bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, msglvl_t msglevel)
Translate an IPv6 addr or hostname from string form to in6_addr.
in_addr_t getaddr(unsigned int flags, const char *hostname, int resolve_retry_seconds, bool *succeeded, struct signal_info *sig_info)
Translate an IPv4 addr or hostname from string form to in_addr_t.
#define GETADDR_HOST_ORDER
#define GETADDR_WARN_ON_SIGNAL
void print_route_options(const struct route_option_list *rol, msglvl_t msglevel)
static void undo_redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
static void print_route_option(const struct route_option *ro, msglvl_t msglevel)
static void add_host_route_if_nonlocal(struct route_bypass *rb, const in_addr_t addr)
bool add_routes(struct route_list *rl, struct route_ipv6_list *rl6, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
bool is_special_addr(const char *addr_str)
struct route_option_list * clone_route_option_list(const struct route_option_list *src, struct gc_arena *a)
void setenv_routes_ipv6(struct env_set *es, const struct route_ipv6_list *rl6)
static void clear_route_list(struct route_list *rl)
static void test_route_helper(bool *ret, int *count, int *good, int *ambig, const IP_ADAPTER_INFO *adapters, const in_addr_t gateway)
static bool del_route_ipapi(const struct route_ipv4 *r, const struct tuntap *tt)
static bool redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
static bool add_route3(in_addr_t network, in_addr_t netmask, in_addr_t gateway, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es, openvpn_net_ctx_t *ctx)
static void add_host_route_array(struct route_bypass *rb, const IP_ADDR_STRING *iplist)
int netmask_to_netbits2(in_addr_t netmask)
struct route_ipv6_option_list * new_route_ipv6_option_list(struct gc_arena *a)
static bool init_route(struct route_ipv4 *r, struct addrinfo **network_list, const struct route_option *ro, const struct route_list *rl)
void delete_routes_v6(struct route_ipv6_list *rl6, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
static bool get_special_addr(const struct route_list *rl, const char *string, in_addr_t *out, bool *status)
bool test_routes(const struct route_list *rl, const struct tuntap *tt)
static void add_block_local_routes(struct route_list *rl)
bool block_local_needed(const struct route_list *rl)
Get the decision whether to block traffic to local networks while the VPN is connected.
void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, const struct in6_addr *dest, openvpn_net_ctx_t *ctx)
static const MIB_IPFORWARDTABLE * get_windows_routing_table(struct gc_arena *gc)
static DWORD get_best_route(struct gc_arena *gc, SOCKADDR_INET *dest, MIB_IPFORWARD_ROW2 *best_route)
Determines the best route to a destination for both IPv4 and IPv6.
static int do_route_service(const bool add, const route_message_t *rt, const DWORD size, HANDLE pipe)
static const char * format_route_entry(const MIB_IPFORWARDROW *r, struct gc_arena *gc)
static int add_route_service(const struct route_ipv4 *, const struct tuntap *)
bool init_route_ipv6_list(struct route_ipv6_list *rl6, const struct route_ipv6_option_list *opt6, const char *remote_endpoint, int default_metric, const struct in6_addr *remote_host_ipv6, struct env_set *es, openvpn_net_ctx_t *ctx)
static void delete_route(struct route_ipv4 *r, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es, openvpn_net_ctx_t *ctx)
static bool del_route_ipv6_service(const struct route_ipv6 *, const struct tuntap *)
void route_list_add_vpn_gateway(struct route_list *rl, struct env_set *es, const in_addr_t addr)
bool ipv6_net_contains_host(const struct in6_addr *network, unsigned int bits, const struct in6_addr *host)
check whether an IPv6 host address is covered by a given network/bits
void add_route_ipv6_to_option_list(struct route_ipv6_option_list *l, const char *prefix, const char *gateway, const char *metric, int table_id)
void copy_route_option_list(struct route_option_list *dest, const struct route_option_list *src, struct gc_arena *a)
void copy_route_ipv6_option_list(struct route_ipv6_option_list *dest, const struct route_ipv6_option_list *src, struct gc_arena *a)
bool add_route(struct route_ipv4 *r, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es, openvpn_net_ctx_t *ctx)
static int test_route(const IP_ADAPTER_INFO *adapters, const in_addr_t gateway, DWORD *index)
void print_default_gateway(const msglvl_t msglevel, const struct route_gateway_info *rgi, const struct route_ipv6_gateway_info *rgi6)
bool add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
static bool del_route_service(const struct route_ipv4 *, const struct tuntap *)
static int local_route(in_addr_t network, in_addr_t netmask, in_addr_t gateway, const struct route_gateway_info *rgi)
static int add_route_ipv6_service(const struct route_ipv6 *, const struct tuntap *)
static bool is_on_link(const int is_local_route, const unsigned int flags, const struct route_gateway_info *rgi)
static const MIB_IPFORWARDROW * get_default_gateway_row(const MIB_IPFORWARDTABLE *routes)
void get_default_gateway(struct route_gateway_info *rgi, in_addr_t dest, openvpn_net_ctx_t *ctx)
Retrieves the best gateway for a given destination based on the routing table.
static int route_ipv6_ipapi(bool add, const struct route_ipv6 *, const struct tuntap *)
static void add_block_local_item(struct route_list *rl, const struct route_gateway_address *gateway, in_addr_t target)
struct route_ipv6_option_list * clone_route_ipv6_option_list(const struct route_ipv6_option_list *src, struct gc_arena *a)
static const char * show_opt(const char *option)
static bool init_route_ipv6(struct route_ipv6 *r6, const struct route_ipv6_option *r6o, const struct route_ipv6_list *rl6)
struct route_option_list * new_route_option_list(struct gc_arena *a)
int test_local_addr(const in_addr_t addr, const struct route_gateway_info *rgi)
bool init_route_list(struct route_list *rl, const struct route_option_list *opt, const char *remote_endpoint, int default_metric, in_addr_t remote_host, struct env_set *es, openvpn_net_ctx_t *ctx)
static int add_route_ipapi(const struct route_ipv4 *r, const struct tuntap *tt, DWORD adapter_index)
static bool add_bypass_routes(const struct route_bypass *rb, in_addr_t gateway, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es, openvpn_net_ctx_t *ctx)
void delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt, const struct env_set *es, openvpn_net_ctx_t *ctx)
static int do_route_ipv6_service(const bool add, const struct route_ipv6 *r, const struct tuntap *tt)
static void del_bypass_routes(const struct route_bypass *rb, in_addr_t gateway, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es, openvpn_net_ctx_t *ctx)
void route_ipv6_clear_host_bits(struct route_ipv6 *r6)
static void clear_route_ipv6_list(struct route_ipv6_list *rl6)
void delete_routes(struct route_list *rl, struct route_ipv6_list *rl6, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
void show_routes(msglvl_t msglevel)
bool netmask_to_netbits(const in_addr_t network, const in_addr_t netmask, int *netbits)
static void setenv_route_addr(struct env_set *es, const char *key, const in_addr_t addr, int i)
static DWORD windows_route_find_if_index(const struct route_ipv4 *r, const struct tuntap *tt)
static int do_route_ipv4_service(const bool add, const struct route_ipv4 *r, const struct tuntap *tt)
void setenv_routes(struct env_set *es, const struct route_list *rl)
void delete_routes_v4(struct route_list *rl, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
static void get_bypass_addresses(struct route_bypass *rb, const unsigned int flags)
static bool is_route_parm_defined(const char *parm)
static void setenv_route_ipv6(struct env_set *es, const struct route_ipv6 *r6, int i)
static bool add_bypass_address(struct route_bypass *rb, const in_addr_t a)
static void print_bypass_addresses(const struct route_bypass *rb)
static void setenv_route(struct env_set *es, const struct route_ipv4 *r, int i)
void add_route_to_option_list(struct route_option_list *l, const char *network, const char *netmask, const char *gateway, const char *metric, int table_id)
static void del_route3(in_addr_t network, in_addr_t netmask, in_addr_t gateway, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es, openvpn_net_ctx_t *ctx)
#define RL_DID_REDIRECT_DEFAULT_GATEWAY
#define RTSA_REMOTE_ENDPOINT
#define RGI_HWADDR_DEFINED
static in_addr_t netbits_to_netmask(const int netbits)
#define ROUTE_METHOD_SERVICE
#define RGI_IFACE_DEFINED
#define ROUTE_METHOD_IPAPI
#define RT_METRIC_DEFINED
#define ROUTE_DELETE_FIRST
#define TLA_NOT_IMPLEMENTED
#define ROUTE_METHOD_ADAPTIVE
#define ROUTE_METHOD_MASK
#define RTSA_DEFAULT_METRIC
#define RGI_NETMASK_DEFINED
int openvpn_execve_check(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *error_message)
#define IPV4_INVALID_ADDR
const char * print_in6_addr(struct in6_addr a6, unsigned int flags, struct gc_arena *gc)
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
Container for unidirectional cipher and HMAC key material.
in_addr_t bypass[N_ROUTE_BYPASS]
struct route_gateway_address addrs[RGI_N_ADDRESSES]
struct route_gateway_address gateway
const struct route_option * option
struct in6_addr addr_ipv6
struct route_ipv6_gateway_address gateway
struct route_ipv6_gateway_address addrs[RGI_N_ADDRESSES]
struct route_ipv6_gateway_info rgi6
struct route_ipv6 * routes_ipv6
struct route_ipv6_gateway_info ngi6
struct in6_addr remote_host_ipv6
struct in6_addr remote_endpoint_ipv6
struct route_ipv6_option * routes_ipv6
struct route_ipv6_option * next
struct route_gateway_info rgi
struct route_ipv4 * routes
struct route_special_addr spec
struct route_gateway_info ngi
struct route_option * routes
struct route_option * next
struct route_bypass bypass
in_addr_t remote_endpoint
bool did_ifconfig_ipv6_setup
if the internal variables related to ifconfig-ipv6 of this struct have been set up.
struct tuntap_options options
bool did_ifconfig_setup
if the internal variables related to ifconfig of this struct have been set up.
const IP_ADAPTER_INFO * get_tun_adapter(const struct tuntap *tt, const IP_ADAPTER_INFO *list)
bool is_adapter_up(const struct tuntap *tt, const IP_ADAPTER_INFO *list)
const IP_ADAPTER_INFO * get_adapter_info(DWORD index, struct gc_arena *gc)
const IP_PER_ADAPTER_INFO * get_per_adapter_info(const DWORD index, struct gc_arena *gc)
bool is_ip_in_adapter_subnet(const IP_ADAPTER_INFO *ai, const in_addr_t ip, in_addr_t *highest_netmask)
const IP_ADAPTER_INFO * get_adapter_info_list(struct gc_arena *gc)
const IP_ADAPTER_INFO * get_adapter(const IP_ADAPTER_INFO *ai, DWORD index)
DWORD adapter_index_of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip, int *count, in_addr_t *netmask)
WCHAR * wide_string(const char *utf8, struct gc_arena *gc)
void netcmd_semaphore_release(void)
char * get_win_sys_path(void)
void netcmd_semaphore_lock(void)
bool send_msg_iservice(HANDLE pipe, const void *data, DWORD size, ack_message_t *ack, const char *context)
Send the size bytes in buffer data to the interactive service pipe and read the result in ack.
#define WIN_ROUTE_PATH_SUFFIX