48#if defined(TARGET_LINUX) || defined(TARGET_ANDROID)
49#include <linux/rtnetlink.h>
52#if defined(TARGET_NETBSD)
59#define METRIC_NOT_USED ((DWORD)-1)
237 if (!
strcmp(
string,
"vpn_gateway"))
243 *out =
rl->spec.remote_endpoint;
256 else if (!
strcmp(
string,
"net_gateway"))
262 *out =
rl->rgi.gateway.addr;
267 " ROUTE: net_gateway undefined -- unable to get default gateway from system");
276 else if (!
strcmp(
string,
"remote_host"))
282 *out =
rl->spec.remote_host;
318 struct in_addr special = { 0 };
338 special.s_addr = htonl(special.s_addr);
339 char buf[INET_ADDRSTRLEN];
340 inet_ntop(AF_INET, &special, buf,
sizeof(buf));
346 NULL, AF_INET, network_list);
396 " needs a gateway parameter for a --route option and no default was specified by either --route-gateway or --ifconfig options");
448 if (inet_pton(AF_INET6, r6o->
gateway, &
r6->gateway) != 1)
493 const char *gateway,
const char *metric,
int table_id)
556 l2 = ((~gateway->netmask) + 1) >> 1;
558 r1->gateway = target;
560 r1->netmask = ~(l2 - 1);
574#ifndef TARGET_ANDROID
605 const char *remote_endpoint,
int default_metric, in_addr_t remote_host,
631#if defined(ENABLE_DEBUG) && !defined(ENABLE_SMALL)
647 bool defined =
false;
682 struct addrinfo *netlist = NULL;
691 struct addrinfo *curele;
692 for (curele = netlist; curele; curele = curele->ai_next)
697 new->
network = ntohl(((
struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr);
720 unsigned int bits =
r6->netbits;
729 for (
i = 0; bits >= 8;
i++, bits -= 8)
731 if (
r6->network.s6_addr[
i] != host->s6_addr[
i])
742 mask = 0xff << (8 - bits);
744 if ((
r6->network.s6_addr[
i] & mask) == (host->s6_addr[
i] & mask))
754 const char *remote_endpoint,
int default_metric,
755 const struct in6_addr *remote_host_ipv6,
struct env_set *
es,
760 bool need_remote_ipv6_route;
766 if (remote_host_ipv6)
772 if (default_metric >= 0)
785#if defined(ENABLE_DEBUG) && !defined(ENABLE_SMALL)
811 need_remote_ipv6_route =
false;
828#ifndef TARGET_ANDROID
835 need_remote_ipv6_route =
true;
837 "ROUTE6: %s/%d overlaps IPv6 remote %s, adding host route to VPN endpoint",
847 if (need_remote_ipv6_route)
855 r6->network = *remote_host_ipv6;
865 r6->iface = rl6->
rgi6.iface;
875 "ROUTE6: IPv6 route overlaps with IPv6 remote address, but could not determine IPv6 gateway address + interface, expect failure\n");
949 const char err[] =
"NOTE: unable to redirect IPv4 default gateway --";
958 msg(
M_WARN,
"%s VPN gateway parameter (--route-gateway or --ifconfig) is missing", err);
969 msg(
M_WARN,
"%s Cannot read current default gateway from system", err);
974#ifndef TARGET_ANDROID
1006 dmsg(
D_ROUTE,
"ROUTE remote_host protocol differs from tunneled");
1065 rl->
iflags &= ~RL_DID_LOCAL;
1096 rl->
iflags &= ~RL_DID_REDIRECT_DEFAULT_GATEWAY;
1112 "WARNING: OpenVPN was configured to add an IPv4 "
1113 "route. However, no IPv4 has been configured for %s, "
1114 "therefore the route installation may fail or may not work "
1119#ifdef ENABLE_MANAGEMENT
1144 "WARNING: OpenVPN was configured to add an IPv6 "
1145 "route. However, no IPv6 has been configured for %s, "
1146 "therefore the route installation may fail or may not work "
1184 rl->
iflags &= ~RL_ROUTES_ADDED;
1206 rl6->
iflags &= ~RL_ROUTES_ADDED;
1222 return "default (not set)";
1243 msg(msglevel,
" [redirect_default_gateway local=%d]", (rol->
flags &
RG_LOCAL) != 0);
1287 msg(msglevel,
"%s",
BSTR(&out));
1318 msg(msglevel,
"%s",
BSTR(&out));
1444 && netmask == 0xFFFFFFFF)
1469#if defined(TARGET_LINUX) || defined(_WIN32) || defined(TARGET_DARWIN)
1495#if !defined(TARGET_LINUX)
1497#if !defined(TARGET_AIX)
1509#if defined(TARGET_LINUX)
1510 const char *
iface = NULL;
1529 msg(
D_ROUTE,
"NOTE: Linux route add command failed because route exists");
1534 msg(
M_WARN,
"ERROR: Linux route add command failed");
1538#elif defined(TARGET_ANDROID)
1543 snprintf(out,
sizeof(out),
"%s %s %s dev %s", network, netmask, gateway, rgi->iface);
1547 snprintf(out,
sizeof(out),
"%s %s %s", network, netmask, gateway);
1549 bool ret = management_android_control(
management,
"ROUTE", out);
1552#elif defined(_WIN32)
1556 network, netmask, gateway);
1569 const char *method =
"service";
1586 method =
"route.exe";
1591 method =
"ipapi [adaptive]";
1594 msg(
D_ROUTE,
"Route addition fallback to route.exe");
1597 &
argv,
es, 0,
"ERROR: Windows route add command failed [adaptive]");
1600 method =
"route.exe";
1609 msg(
D_ROUTE,
"Route addition via %s %s", method,
1614#elif defined(TARGET_SOLARIS)
1638#elif defined(TARGET_FREEBSD)
1657#elif defined(TARGET_DRAGONFLY)
1676#elif defined(TARGET_DARWIN)
1703#elif defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)
1722#elif defined(TARGET_AIX)
1732#elif defined(TARGET_HAIKU)
1743 "Sorry, but I don't know how to do 'route' commands on this operating system. Try putting your routes in a --route-up script");
1753 r->
flags &= ~RT_ADDED;
1763#if defined(__GNUC__) || defined(__clang__)
1764#pragma GCC diagnostic push
1765#pragma GCC diagnostic ignored "-Wconversion"
1776 int bits_to_clear = 128 -
r6->netbits;
1778 while (
byte >= 0 && bits_to_clear > 0)
1780 if (bits_to_clear >= 8)
1782 r6->network.s6_addr[
byte--] = 0;
1787 r6->network.s6_addr[
byte--] &= (0xff << bits_to_clear);
1798 bool gateway_needed =
false;
1810 if (
r6->iface != NULL)
1813 if (!IN6_IS_ADDR_UNSPECIFIED(&
r6->gateway))
1815 gateway_needed =
true;
1824#if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \
1825 || defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)
1831 if (
r6->iface != NULL && gateway_needed
1832 && IN6_IS_ADDR_LINKLOCAL(&
r6->gateway))
1834 int len = strlen(gateway) + 1 + strlen(
r6->iface) + 1;
1836 snprintf(tmp, len,
"%s%%%s", gateway,
r6->iface);
1842 msg(
D_ROUTE,
"add_route_ipv6(%s/%d -> %s metric %d) dev %s", network,
r6->netbits, gateway,
1843 r6->metric, device);
1845 msg(
D_ROUTE,
"add_route_ipv6(%s/%d -> %s metric %d) IF %lu", network,
r6->netbits, gateway,
1862 gateway_needed =
true;
1865 if (gateway_needed && IN6_IS_ADDR_UNSPECIFIED(&
r6->gateway))
1869 "parameter for a --route-ipv6 option and no default was set via "
1870 "--ifconfig-ipv6 or --route-ipv6-gateway option. Not installing "
1871 "IPv6 route to %s/%d.",
1872 network,
r6->netbits);
1877#if defined(TARGET_LINUX)
1881 metric =
r6->metric;
1885 int ret = net_route_v6_add(ctx, &
r6->network,
r6->netbits, gateway_needed ? &
r6->gateway : NULL,
1886 device,
r6->table_id, metric);
1889 msg(
D_ROUTE,
"NOTE: Linux route add command failed because route exists");
1894 msg(
M_WARN,
"ERROR: Linux route add command failed");
1898#elif defined(TARGET_ANDROID)
1901 snprintf(out,
sizeof(out),
"%s/%d %s", network,
r6->netbits, device);
1905#elif defined(_WIN32)
1915#elif defined(TARGET_SOLARIS)
1940#elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)
1957#elif defined(TARGET_DARWIN)
1974#elif defined(TARGET_OPENBSD)
1983#elif defined(TARGET_NETBSD)
1991#elif defined(TARGET_AIX)
1998#elif defined(TARGET_HAIKU)
2002 gateway,
r6->netbits);
2009 "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");
2019 r6->flags &= ~RT_ADDED;
2033#if !defined(TARGET_LINUX)
2034 const char *network;
2035#if !defined(TARGET_AIX)
2036 const char *netmask;
2038#if !defined(TARGET_ANDROID)
2039 const char *gateway;
2054#if !defined(TARGET_LINUX)
2056#if !defined(TARGET_AIX)
2059#if !defined(TARGET_ANDROID)
2070#if defined(TARGET_LINUX)
2081 msg(
M_WARN,
"ERROR: Linux route delete command failed");
2083#elif defined(_WIN32)
2086 network, netmask, gateway);
2093 msg(
D_ROUTE,
"Route deletion via service %s",
status ?
"succeeded" :
"failed");
2098 msg(
D_ROUTE,
"Route deletion via IPAPI %s",
status ?
"succeeded" :
"failed");
2109 msg(
D_ROUTE,
"Route deletion via IPAPI %s [adaptive]",
status ?
"succeeded" :
"failed");
2112 msg(
D_ROUTE,
"Route deletion fallback to route.exe");
2115 "ERROR: Windows route delete command failed [adaptive]");
2124#elif defined(TARGET_SOLARIS)
2131#elif defined(TARGET_FREEBSD)
2138#elif defined(TARGET_DRAGONFLY)
2145#elif defined(TARGET_DARWIN)
2150 network, netmask, rgi->iface);
2160#elif defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)
2167#elif defined(TARGET_ANDROID)
2169 "needed. The VpnService API allows routes to be set "
2170 "on connect only and will clean up automatically.");
2171#elif defined(TARGET_AIX)
2180#elif defined(TARGET_HAIKU)
2190 "Sorry, but I don't know how to do 'route' commands on this operating system. Try putting your routes in a --route-up script");
2194 r->
flags &= ~RT_ADDED;
2205 const char *network;
2213#if !defined(TARGET_LINUX)
2214 const char *gateway;
2216#if !defined(TARGET_SOLARIS)
2217 bool gateway_needed =
false;
2219 if (
r6->iface != NULL)
2222 gateway_needed =
true;
2230 gateway_needed =
true;
2239#if !defined(TARGET_LINUX) && !defined(_WIN32)
2243#if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \
2244 || defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)
2250 if (
r6->iface != NULL && gateway_needed
2251 && IN6_IS_ADDR_LINKLOCAL(&
r6->gateway))
2253 int len = strlen(gateway) + 1 + strlen(
r6->iface) + 1;
2255 snprintf(tmp, len,
"%s%%%s", gateway,
r6->iface);
2260 msg(
D_ROUTE,
"delete_route_ipv6(%s/%d)", network,
r6->netbits);
2262#if defined(TARGET_LINUX)
2266 metric =
r6->metric;
2269 if (net_route_v6_del(ctx, &
r6->network,
r6->netbits, gateway_needed ? &
r6->gateway : NULL,
2270 device,
r6->table_id, metric)
2273 msg(
M_WARN,
"ERROR: Linux route v6 delete command failed");
2276#elif defined(_WIN32)
2286#elif defined(TARGET_SOLARIS)
2295#elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)
2311#elif defined(TARGET_DARWIN)
2327#elif defined(TARGET_OPENBSD)
2335#elif defined(TARGET_NETBSD)
2342#elif defined(TARGET_AIX)
2348#elif defined(TARGET_ANDROID)
2350 "needed. The VpnService API allows routes to be set "
2351 "on connect only and will clean up automatically.");
2352#elif defined(TARGET_HAIKU)
2356 gateway,
r6->netbits);
2362 "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");
2371#if defined(__GNUC__) || defined(__clang__)
2372#pragma GCC diagnostic pop
2382static const MIB_IPFORWARDTABLE *
2386 PMIB_IPFORWARDTABLE rt = NULL;
2389 status = GetIpForwardTable(NULL, &size, TRUE);
2390 if (
status == ERROR_INSUFFICIENT_BUFFER)
2392 rt = (PMIB_IPFORWARDTABLE)
gc_malloc(size,
false,
gc);
2393 status = GetIpForwardTable(rt, &size, TRUE);
2396 msg(
D_ROUTE,
"NOTE: GetIpForwardTable returned error: %s (code=%u)",
2405test_route(
const IP_ADAPTER_INFO *adapters,
const in_addr_t gateway, DWORD *index)
2418 const in_addr_t gateway)
2451 bool adapter_up =
false;
2465 for (r = rl->
routes, len = 0; r; r = r->
next, ++len)
2477 msg(
D_ROUTE,
"TEST ROUTES: %d/%d succeeded len=%d ret=%d a=%d u/d=%s", good, count, len,
2478 (
int)ret, ambig, adapter_up ?
"up" :
"down");
2484static const MIB_IPFORWARDROW *
2488 DWORD lowest_metric = MAXDWORD;
2489 const MIB_IPFORWARDROW *ret = NULL;
2494 for (DWORD
i = 0;
i < routes->dwNumEntries; ++
i)
2496 const MIB_IPFORWARDROW *row = &routes->table[
i];
2497 const in_addr_t net = ntohl(row->dwForwardDest);
2498 const in_addr_t mask = ntohl(row->dwForwardMask);
2499 const DWORD index = row->dwForwardIfIndex;
2500 const DWORD metric = row->dwForwardMetric1;
2504 (
int)index, (
int)metric);
2506 if (!net && !mask && metric < lowest_metric)
2509 lowest_metric = metric;
2535 DWORD best_if_index;
2541 status = GetBestInterfaceEx((
struct sockaddr *)dest, &best_if_index);
2544 msg(
D_ROUTE,
"NOTE: GetBestInterfaceEx returned error: %s (code=%u)",
2549 msg(
D_ROUTE_DEBUG,
"GetBestInterfaceEx() returned if=%d", (
int)best_if_index);
2554 SOCKADDR_INET best_src;
2556 status = GetBestRoute2(&luid, best_if_index, NULL, dest, 0, best_route, &best_src);
2559 msg(
D_ROUTE,
"NOTE: GetIpForwardEntry2 returned error: %s (code=%u)",
2578 sa.si_family = AF_INET;
2579 sa.Ipv4.sin_addr.s_addr = htonl(dest);
2582 MIB_IPFORWARD_ROW2 best_route;
2591 rgi->
gateway.
addr = ntohl(best_route.NextHop.Ipv4.sin_addr.S_un.S_addr);
2604 memcpy(rgi->
hwaddr, ai->Address, 6);
2608 in_addr_t nm = inet_addr(ai->IpAddressList.IpMask.String);
2628 bool on_tun =
false;
2633 ret = tun_adapter->Index;
2644 msg(
M_WARN,
"Warning: route gateway is not reachable on any active network adapters: %s",
2650 msg(
M_WARN,
"Warning: route gateway is ambiguous: %s (%d matches)",
2654 dmsg(
D_ROUTE_DEBUG,
"DEBUG: route find if: on_tun=%d count=%d index=%d", on_tun, count,
2673 SOCKADDR_INET DestinationAddress;
2674 CLEAR(DestinationAddress);
2675 DestinationAddress.si_family = AF_INET6;
2678 DestinationAddress.Ipv6.sin6_addr = *dest;
2681 MIB_IPFORWARD_ROW2 BestRoute;
2690 msg(
D_ROUTE,
"GDG6: II=%lu DP=%s/%d NH=%s", BestRoute.InterfaceIndex,
2692 BestRoute.DestinationPrefix.PrefixLength,
2694 msg(
D_ROUTE,
"GDG6: Metric=%d, Loopback=%d, AA=%d, I=%d", (
int)BestRoute.Metric,
2695 (
int)BestRoute.Loopback, (
int)BestRoute.AutoconfigureAddress, (
int)BestRoute.Immortal);
2702 if (IN6_IS_ADDR_UNSPECIFIED(&BestRoute.NextHop.Ipv6.sin6_addr))
2724 MIB_IPFORWARDROW fr;
2726 fr.dwForwardDest = htonl(r->
network);
2727 fr.dwForwardMask = htonl(r->
netmask);
2728 fr.dwForwardPolicy = 0;
2729 fr.dwForwardNextHop = htonl(r->
gateway);
2730 fr.dwForwardIfIndex = if_index;
2731 fr.dwForwardType = 4;
2732 fr.dwForwardProto = 3;
2733 fr.dwForwardAge = 0;
2734 fr.dwForwardNextHopAS = 0;
2743 msg(
M_WARN,
"Warning: address %s is not a network address in relation to netmask %s",
2747 status = CreateIpForwardEntry(&fr);
2753 else if (
status == ERROR_OBJECT_ALREADY_EXISTS)
2760 const unsigned int forward_metric_limit =
2763 for (; fr.dwForwardMetric1 <= forward_metric_limit; ++fr.dwForwardMetric1)
2768 for (fr.dwForwardType = 4; fr.dwForwardType >= 3; --fr.dwForwardType)
2770 status = CreateIpForwardEntry(&fr);
2774 "ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=%u and dwForwardType=%u",
2775 (
unsigned int)fr.dwForwardMetric1, (
unsigned int)fr.dwForwardType);
2779 else if (
status != ERROR_BAD_ARGUMENTS)
2789 if (
status == ERROR_OBJECT_ALREADY_EXISTS)
2796 "ERROR: route addition failed using CreateIpForwardEntry: "
2797 "%s [status=%u if_index=%u]",
2818 MIB_IPFORWARDROW fr;
2821 fr.dwForwardDest = htonl(r->
network);
2822 fr.dwForwardMask = htonl(r->
netmask);
2823 fr.dwForwardPolicy = 0;
2824 fr.dwForwardNextHop = htonl(r->
gateway);
2825 fr.dwForwardIfIndex = if_index;
2827 status = DeleteIpForwardEntry(&fr);
2835 msg(
M_WARN,
"ERROR: route deletion failed using DeleteIpForwardEntry: %s",
2862 msg(
M_WARN,
"ERROR: route %s failed using service: %s [status=%u if_index=%d]",
2889 .prefix.ipv4.s_addr = htonl(r->
network),
2890 .gateway.ipv4.s_addr = htonl(r->
gateway),
2891 .iface = { .index = if_index, .name =
"" },
2895 if (
msg.prefix_len == -1)
2897 msg.prefix_len = 32;
2911 PMIB_IPFORWARD_ROW2 fwd_row;
2916 fwd_row->ValidLifetime = 0xffffffff;
2917 fwd_row->PreferredLifetime = 0xffffffff;
2918 fwd_row->Protocol = MIB_IPPROTO_NETMGMT;
2920 fwd_row->DestinationPrefix.Prefix.si_family = AF_INET6;
2921 fwd_row->DestinationPrefix.Prefix.Ipv6.sin6_addr = r->
network;
2922 fwd_row->DestinationPrefix.PrefixLength = (UINT8)r->
netbits;
2923 fwd_row->NextHop.si_family = AF_INET6;
2924 fwd_row->NextHop.Ipv6.sin6_addr = r->
gateway;
2933 inet_pton(AF_INET6,
"fe80::8", &fwd_row->NextHop.Ipv6.sin6_addr);
2941 if (err != NO_ERROR)
2945 fwd_row->InterfaceLuid = luid;
2946 fwd_row->InterfaceIndex = 0;
2951 err = CreateIpForwardEntry2(fwd_row);
2955 err = DeleteIpForwardEntry2(fwd_row);
2959 if (err != NO_ERROR)
2964 msg(
M_WARN,
"ERROR: route %s failed using ipapi: %s [status=%lu if_index=%lu]",
2966 fwd_row->InterfaceIndex);
2970 msg(
D_ROUTE,
"IPv6 route addition using ipapi failed because route exists");
2975 msg(
D_ROUTE,
"IPv6 route %s using ipapi", add ?
"added" :
"deleted");
3007 inet_pton(AF_INET6,
"fe80::8", &
msg.gateway.ipv6);
3013 msg.iface.name[
sizeof(
msg.iface.name) - 1] =
'\0';
3019 msg(
D_ROUTE,
"IPv6 route %s via service %s", add ?
"addition" :
"deletion",
3055 buf_printf(&out,
"%s %s %s p=%d i=%d t=%d pr=%d a=%d h=%d m=%d/%d/%d/%d/%d",
3059 (
int)
r->dwForwardIfIndex, (
int)
r->dwForwardType, (
int)
r->dwForwardProto,
3060 (
int)
r->dwForwardAge, (
int)
r->dwForwardNextHopAS, (
int)
r->dwForwardMetric1,
3061 (
int)
r->dwForwardMetric2, (
int)
r->dwForwardMetric3, (
int)
r->dwForwardMetric4,
3062 (
int)
r->dwForwardMetric5);
3076 msg(msglevel,
"SYSTEM ROUTING TABLE");
3079 for (DWORD
i = 0;
i < rt->dwNumEntries; ++
i)
3087#elif defined(TARGET_ANDROID)
3102 rgi->
gateway.
addr = 127 << 24 |
'd' << 16 |
'g' << 8 |
'w';
3104 strcpy(rgi->iface,
"android-gw");
3124 strcpy(rgi6->iface,
"android-gw");
3127#elif defined(TARGET_LINUX)
3134 char best_name[IFNAMSIZ];
3140 if (net_route_v4_best_gw(ctx, &dest, &rgi->
gateway.
addr, best_name) == 0)
3152 struct ifreq *ifr, *ifend;
3153 in_addr_t addr, netmask;
3156 struct ifreq ifs[20];
3158 if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
3163 ifc.ifc_len =
sizeof(ifs);
3165 if (ioctl(sd, SIOCGIFCONF, &ifc) < 0)
3167 msg(
M_WARN,
"GDG: ioctl(SIOCGIFCONF) failed");
3172 ifend = ifs + (ifc.ifc_len /
sizeof(
struct ifreq));
3173 for (ifr = ifc.ifc_req; ifr < ifend; ifr++)
3175 if (ifr->ifr_addr.sa_family == AF_INET)
3178 addr = ntohl(((
struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr);
3181 strncpynt(ifreq.ifr_name, ifr->ifr_name,
sizeof(ifreq.ifr_name));
3184 if (ioctl(sd, SIOCGIFFLAGS, &ifreq) < 0)
3188 if (!(ifreq.ifr_flags & IFF_UP))
3197 if (strcmp(ifreq.ifr_name, best_name))
3203 if ((ifreq.ifr_flags & IFF_POINTOPOINT) && ioctl(sd, SIOCGIFDSTADDR, &ifreq) >= 0)
3205 rgi->
gateway.
addr = ntohl(((
struct sockaddr_in *) &ifreq.ifr_addr)->sin_addr.s_addr);
3208 rgi->
flags &= ~RGI_ON_LINK;
3216 if (ioctl(sd, SIOCGIFNETMASK, &ifreq) < 0)
3220 netmask = ntohl(((
struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr.s_addr);
3234 strncpynt(rgi->iface, ifreq.ifr_name,
sizeof(rgi->iface));
3238 memset(&ifreq.ifr_hwaddr, 0,
sizeof(
struct sockaddr));
3239 if (ioctl(sd, SIOCGIFHWADDR, &ifreq) < 0)
3241 msg(
M_WARN,
"GDG: SIOCGIFHWADDR(%s) failed", ifreq.ifr_name);
3244 memcpy(rgi->
hwaddr, &ifreq.ifr_hwaddr.sa_data, 6);
3280 if (net_route_v6_best_gw(ctx, dest, &rgi6->
gateway.
addr_ipv6, rgi6->iface) == 0)
3287 if (strlen(rgi6->iface) > 0)
3305#elif defined(TARGET_DARWIN) || defined(TARGET_SOLARIS) || defined(TARGET_FREEBSD) \
3306 || defined(TARGET_DRAGONFLY) || defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)
3308#include <sys/types.h>
3309#include <sys/socket.h>
3310#include <netinet/in.h>
3311#include <net/route.h>
3312#include <net/if_dl.h>
3313#if !defined(TARGET_SOLARIS)
3319 struct rt_msghdr m_rtm;
3339#if defined(TARGET_DARWIN)
3340#define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(uint32_t) - 1))) : sizeof(uint32_t))
3341#elif defined(TARGET_NETBSD)
3342#define ROUNDUP(a) RT_ROUNDUP(a)
3344#define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
3347#if defined(TARGET_SOLARIS)
3348#define NEXTADDR(w, u) \
3349 if (rtm_addrs & (w)) \
3352 memmove(cp, &(u), l); \
3356#define ADVANCE(x, n) (x += ROUNDUP(sizeof(struct sockaddr_in)))
3358#define NEXTADDR(w, u) \
3359 if (rtm_addrs & (w)) \
3361 l = ((struct sockaddr *)&(u))->sa_len; \
3362 memmove(cp, &(u), l); \
3366#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
3369#define max(a, b) ((a) > (b) ? (a) : (b))
3371#if defined(__GNUC__) || defined(__clang__)
3372#pragma GCC diagnostic push
3373#pragma GCC diagnostic ignored "-Wconversion"
3380 struct rtmsg m_rtmsg;
3382 int seq, l, pid, rtm_addrs;
3384 struct sockaddr so_dst, so_mask;
3385 char *cp = m_rtmsg.m_space;
3386 struct sockaddr *gate = NULL, *ifp = NULL, *sa;
3387 struct rt_msghdr *rtm_aux;
3389#define rtm m_rtmsg.m_rtm
3396#ifdef TARGET_OPENBSD
3397 rtm_addrs = RTA_DST | RTA_NETMASK;
3399 rtm_addrs = RTA_DST | RTA_NETMASK | RTA_IFP;
3402 bzero(&m_rtmsg,
sizeof(m_rtmsg));
3403 bzero(&so_dst,
sizeof(so_dst));
3404 bzero(&so_mask,
sizeof(so_mask));
3405 bzero(&rtm,
sizeof(
struct rt_msghdr));
3407 rtm.rtm_type = RTM_GET;
3408 rtm.rtm_flags = RTF_UP | RTF_GATEWAY;
3409 rtm.rtm_version = RTM_VERSION;
3410 rtm.rtm_seq = ++seq;
3411#ifdef TARGET_OPENBSD
3412 rtm.rtm_tableid = getrtable();
3414 rtm.rtm_addrs = rtm_addrs;
3416 so_dst.sa_family = AF_INET;
3417 so_mask.sa_family = AF_INET;
3419#ifndef TARGET_SOLARIS
3420 so_dst.sa_len =
sizeof(
struct sockaddr_in);
3421 so_mask.sa_len =
sizeof(
struct sockaddr_in);
3424 NEXTADDR(RTA_DST, so_dst);
3425 NEXTADDR(RTA_NETMASK, so_mask);
3427 rtm.rtm_msglen = l = cp - (
char *)&m_rtmsg;
3430 sockfd = socket(PF_ROUTE, SOCK_RAW, 0);
3436 if (
write(sockfd, (
char *)&m_rtmsg, l) < 0)
3443 l =
read(sockfd, (
char *)&m_rtmsg,
sizeof(m_rtmsg));
3444 }
while (l > 0 && (rtm.rtm_seq != seq || rtm.rtm_pid != pid));
3450 cp = ((
char *)(rtm_aux + 1));
3451 if (rtm_aux->rtm_addrs)
3453 for (
i = 1;
i;
i <<= 1)
3455 if (
i & rtm_aux->rtm_addrs)
3457 sa = (
struct sockaddr *)cp;
3458 if (
i == RTA_GATEWAY)
3462 else if (
i == RTA_IFP)
3479 rgi->
gateway.
addr = ntohl(((
struct sockaddr_in *)gate)->sin_addr.s_addr);
3488 const struct sockaddr_dl *adl = (
struct sockaddr_dl *)ifp;
3489 if (adl->sdl_nlen && adl->sdl_nlen <
sizeof(rgi->iface))
3491 memcpy(rgi->iface, adl->sdl_data, adl->sdl_nlen);
3492 rgi->iface[adl->sdl_nlen] =
'\0';
3503 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
3511 ifr.ifr_addr.sa_family = AF_INET;
3512 strncpynt(ifr.ifr_name, rgi->iface, IFNAMSIZ);
3514 if (ioctl(sockfd, SIOCGIFNETMASK, (
char *)&ifr) < 0)
3522 rgi->
gateway.
netmask = ntohl(((
struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr);
3529#if defined(TARGET_SOLARIS)
3531 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
3538 struct ifreq ifreq = { 0 };
3541 strncpynt(ifreq.ifr_name, rgi->iface,
sizeof(ifreq.ifr_name));
3542 if (ioctl(sockfd, SIOCGIFHWADDR, &ifreq) < 0)
3544 msg(
M_WARN,
"GDG: SIOCGIFHWADDR(%s) failed", ifreq.ifr_name);
3548 memcpy(rgi->
hwaddr, &ifreq.ifr_addr.sa_data, 6);
3552 struct ifaddrs *ifap, *ifa;
3554 if (getifaddrs(&ifap) != 0)
3560 for (ifa = ifap; ifa; ifa = ifa->ifa_next)
3562 if (ifa->ifa_addr != NULL && ifa->ifa_addr->sa_family == AF_LINK
3563 && !strncmp(ifa->ifa_name, rgi->iface, IFNAMSIZ))
3565 struct sockaddr_dl *sdl = (
struct sockaddr_dl *)ifa->ifa_addr;
3566 memcpy(rgi->
hwaddr, LLADDR(sdl), 6);
3590#if defined(TARGET_SOLARIS)
3592#define ADVANCE(x, n) (x += ROUNDUP(sizeof(struct sockaddr_in6)))
3599 struct rtmsg m_rtmsg;
3601 int seq, l, pid, rtm_addrs;
3603 struct sockaddr_in6 so_dst, so_mask;
3604 char *cp = m_rtmsg.m_space;
3605 struct sockaddr *gate = NULL, *ifp = NULL, *sa;
3606 struct rt_msghdr *rtm_aux;
3613#ifdef TARGET_OPENBSD
3614 rtm_addrs = RTA_DST | RTA_NETMASK;
3616 rtm_addrs = RTA_DST | RTA_NETMASK | RTA_IFP;
3619 bzero(&m_rtmsg,
sizeof(m_rtmsg));
3620 bzero(&so_dst,
sizeof(so_dst));
3621 bzero(&so_mask,
sizeof(so_mask));
3622 bzero(&rtm,
sizeof(
struct rt_msghdr));
3624 rtm.rtm_type = RTM_GET;
3625 rtm.rtm_flags = RTF_UP;
3626 rtm.rtm_version = RTM_VERSION;
3627 rtm.rtm_seq = ++seq;
3628#ifdef TARGET_OPENBSD
3629 rtm.rtm_tableid = getrtable();
3632 so_dst.sin6_family = AF_INET6;
3633 so_mask.sin6_family = AF_INET6;
3636 && !IN6_IS_ADDR_UNSPECIFIED(dest))
3638 so_dst.sin6_addr = *dest;
3640 rtm_addrs &= ~RTA_NETMASK;
3643 rtm.rtm_addrs = rtm_addrs;
3645#ifndef TARGET_SOLARIS
3646 so_dst.sin6_len =
sizeof(
struct sockaddr_in6);
3647 so_mask.sin6_len =
sizeof(
struct sockaddr_in6);
3650 NEXTADDR(RTA_DST, so_dst);
3651 NEXTADDR(RTA_NETMASK, so_mask);
3653 rtm.rtm_msglen = l = cp - (
char *)&m_rtmsg;
3656 sockfd = socket(PF_ROUTE, SOCK_RAW, 0);
3662 if (
write(sockfd, (
char *)&m_rtmsg, l) < 0)
3670 l =
read(sockfd, (
char *)&m_rtmsg,
sizeof(m_rtmsg));
3671 }
while (l > 0 && (rtm.rtm_seq != seq || rtm.rtm_pid != pid));
3678 cp = ((
char *)(rtm_aux + 1));
3679 if (rtm_aux->rtm_addrs)
3681 for (
i = 1;
i;
i <<= 1)
3683 if (
i & rtm_aux->rtm_addrs)
3685 sa = (
struct sockaddr *)cp;
3686 if (
i == RTA_GATEWAY)
3690 else if (
i == RTA_IFP)
3706 struct sockaddr_in6 *s6 = (
struct sockaddr_in6 *)gate;
3707 struct in6_addr gw = s6->sin6_addr;
3709#ifndef TARGET_SOLARIS
3714 if (gate->sa_len ==
sizeof(
struct sockaddr_in6) && IN6_IS_ADDR_LINKLOCAL(&gw))
3716 gw.s6_addr[2] = gw.s6_addr[3] = 0;
3719 if (gate->sa_len !=
sizeof(
struct sockaddr_in6) || IN6_IS_ADDR_UNSPECIFIED(&gw))
3733 const struct sockaddr_dl *adl = (
struct sockaddr_dl *)ifp;
3734 if (adl->sdl_nlen && adl->sdl_nlen <
sizeof(rgi6->iface))
3736 memcpy(rgi6->iface, adl->sdl_data, adl->sdl_nlen);
3749#if defined(__GNUC__) || defined(__clang__)
3750#pragma GCC diagnostic pop
3755#elif defined(TARGET_HAIKU)
3762 int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
3765 msg(
M_ERRNO,
"%s: Error opening socket for AF_INET", __func__);
3769 struct ifconf config;
3770 config.ifc_len =
sizeof(config.ifc_value);
3771 if (ioctl(sockfd, SIOCGRTSIZE, &config,
sizeof(
struct ifconf)) < 0)
3773 msg(
M_ERRNO,
"%s: Error getting routing table size", __func__);
3777 uint32 size = (uint32)config.ifc_value;
3783 void *
buffer = malloc(size);
3786 config.ifc_len = size;
3788 if (ioctl(sockfd, SIOCGRTTABLE, &config,
sizeof(
struct ifconf)) < 0)
3794 struct ifreq *
interface = (struct ifreq *)
buffer;
3795 struct ifreq *end = (
struct ifreq *)((uint8 *)
buffer + size);
3797 while (interface < end)
3799 struct route_entry
route = interface->ifr_route;
3800 if ((
route.flags & RTF_GATEWAY) != 0 && (
route.flags & RTF_DEFAULT) != 0)
3802 rgi->
gateway.
addr = ntohl(((
struct sockaddr_in *)
route.gateway)->sin_addr.s_addr);
3804 strncpy(rgi->iface, interface->ifr_name,
sizeof(rgi->iface));
3807 int32 address_size = 0;
3808 if (
route.destination != NULL)
3810 address_size +=
route.destination->sa_len;
3812 if (
route.mask != NULL)
3814 address_size +=
route.mask->sa_len;
3816 if (
route.gateway != NULL)
3818 address_size +=
route.gateway->sa_len;
3821 interface = (struct ifreq *)((addr_t)
interface +
IF_NAMESIZE + sizeof(struct route_entry)
3870 msg(
D_ROUTE,
"no support for get_default_gateway_ipv6() on this system");
3880 const int addrlen =
sizeof(in_addr_t) * 8;
3882 if ((network & netmask) == network)
3884 for (
i = 0;
i <= addrlen; ++
i)
3887 if (mask == netmask)
3911 const int addrlen =
sizeof(in_addr_t) * 8;
3913 for (
i = 0;
i <= addrlen; ++
i)
3916 if (mask == netmask)
3947 bool succeed =
false;
3948 const in_addr_t ip =
3954 iplist = iplist->Next;
4018 const in_addr_t nonlocal_netmask =
4026 for (DWORD
i = 0;
i < rt->dwNumEntries; ++
i)
4028 const MIB_IPFORWARDROW *row = &rt->table[
i];
4029 const in_addr_t net = ntohl(row->dwForwardDest);
4030 const in_addr_t mask = ntohl(row->dwForwardMask);
4031 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,...)
char * format_hex_ex(const uint8_t *data, int size, int maxoutput, unsigned int space_break_flags, const char *separator, struct gc_arena *gc)
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
void gc_addspecial(void *addr, void(*free_function)(void *), struct gc_arena *a)
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
#define ALLOC_OBJ_GC(dptr, type, gc)
static void strncpynt(char *dest, const char *src, size_t maxlen)
static void check_malloc_return(void *p)
static void gc_free(struct gc_arena *a)
static void gc_freeaddrinfo_callback(void *addr)
static struct gc_arena gc_new(void)
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 IPV4_NETMASK_HOST
const char * strerror_win32(DWORD errnum, struct gc_arena *gc)
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 bool route_ipv6_match_host(const struct route_ipv6 *r6, const struct in6_addr *host)
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 void del_bypass_routes(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)
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 const char * route_string(const struct route_ipv4 *r, struct gc_arena *gc)
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 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)
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 void print_route(const struct route_ipv4 *r, msglvl_t msglevel)
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)
void print_routes(const struct route_list *rl, msglvl_t msglevel)
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)
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 int do_route_service(const bool add, const route_message_t *rt, const size_t size, HANDLE pipe)
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 bool add_bypass_routes(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)
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 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)
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 IPV4_INVALID_ADDR
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)
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)
#define GETADDR_HOST_ORDER
#define GETADDR_WARN_ON_SIGNAL
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 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_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)
#define TUN_ADAPTER_INDEX_INVALID
WCHAR * wide_string(const char *utf8, struct gc_arena *gc)
bool send_msg_iservice(HANDLE pipe, const void *data, size_t size, ack_message_t *ack, const char *context)
void netcmd_semaphore_release(void)
char * get_win_sys_path(void)
void netcmd_semaphore_lock(void)
#define WIN_ROUTE_PATH_SUFFIX