By switching to the networking API (for Linux) openvpn will
now use any of the available implementations to handle the
routing table.
At the moment only iproute2 is implemented.
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20181219050118.6568-5-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18029.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
... | ... |
@@ -511,7 +511,7 @@ static void |
511 | 511 |
check_add_routes_action(struct context *c, const bool errors) |
512 | 512 |
{ |
513 | 513 |
do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, |
514 |
- c->c1.tuntap, c->plugins, c->c2.es); |
|
514 |
+ c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); |
|
515 | 515 |
update_time(); |
516 | 516 |
event_timeout_clear(&c->c2.route_wakeup); |
517 | 517 |
event_timeout_clear(&c->c2.route_wakeup_expire); |
... | ... |
@@ -1426,7 +1426,8 @@ static void |
1426 | 1426 |
do_init_route_list(const struct options *options, |
1427 | 1427 |
struct route_list *route_list, |
1428 | 1428 |
const struct link_socket_info *link_socket_info, |
1429 |
- struct env_set *es) |
|
1429 |
+ struct env_set *es, |
|
1430 |
+ openvpn_net_ctx_t *ctx) |
|
1430 | 1431 |
{ |
1431 | 1432 |
const char *gw = NULL; |
1432 | 1433 |
int dev = dev_type_enum(options->dev, options->dev_type); |
... | ... |
@@ -1450,7 +1451,8 @@ do_init_route_list(const struct options *options, |
1450 | 1450 |
gw, |
1451 | 1451 |
metric, |
1452 | 1452 |
link_socket_current_remote(link_socket_info), |
1453 |
- es)) |
|
1453 |
+ es, |
|
1454 |
+ ctx)) |
|
1454 | 1455 |
{ |
1455 | 1456 |
/* copy routes to environment */ |
1456 | 1457 |
setenv_routes(es, route_list); |
... | ... |
@@ -1633,11 +1635,13 @@ do_route(const struct options *options, |
1633 | 1633 |
struct route_ipv6_list *route_ipv6_list, |
1634 | 1634 |
const struct tuntap *tt, |
1635 | 1635 |
const struct plugin_list *plugins, |
1636 |
- struct env_set *es) |
|
1636 |
+ struct env_set *es, |
|
1637 |
+ openvpn_net_ctx_t *ctx) |
|
1637 | 1638 |
{ |
1638 | 1639 |
if (!options->route_noexec && ( route_list || route_ipv6_list ) ) |
1639 | 1640 |
{ |
1640 |
- add_routes(route_list, route_ipv6_list, tt, ROUTE_OPTION_FLAGS(options), es); |
|
1641 |
+ add_routes(route_list, route_ipv6_list, tt, ROUTE_OPTION_FLAGS(options), |
|
1642 |
+ es, ctx); |
|
1641 | 1643 |
setenv_int(es, "redirect_gateway", route_did_redirect_default_gateway(route_list)); |
1642 | 1644 |
} |
1643 | 1645 |
#ifdef ENABLE_MANAGEMENT |
... | ... |
@@ -1750,7 +1754,7 @@ do_open_tun(struct context *c) |
1750 | 1750 |
if (c->options.routes && c->c1.route_list) |
1751 | 1751 |
{ |
1752 | 1752 |
do_init_route_list(&c->options, c->c1.route_list, |
1753 |
- &c->c2.link_socket->info, c->c2.es); |
|
1753 |
+ &c->c2.link_socket->info, c->c2.es, &c->net_ctx); |
|
1754 | 1754 |
} |
1755 | 1755 |
if (c->options.routes_ipv6 && c->c1.route_ipv6_list) |
1756 | 1756 |
{ |
... | ... |
@@ -1777,7 +1781,7 @@ do_open_tun(struct context *c) |
1777 | 1777 |
{ |
1778 | 1778 |
/* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */ |
1779 | 1779 |
do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, |
1780 |
- c->c1.tuntap, c->plugins, c->c2.es); |
|
1780 |
+ c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); |
|
1781 | 1781 |
} |
1782 | 1782 |
#ifdef TARGET_ANDROID |
1783 | 1783 |
/* Store the old fd inside the fd so open_tun can use it */ |
... | ... |
@@ -1834,7 +1838,7 @@ do_open_tun(struct context *c) |
1834 | 1834 |
if ((route_order() == ROUTE_AFTER_TUN) && (!c->options.route_delay_defined)) |
1835 | 1835 |
{ |
1836 | 1836 |
do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list, |
1837 |
- c->c1.tuntap, c->plugins, c->c2.es); |
|
1837 |
+ c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); |
|
1838 | 1838 |
} |
1839 | 1839 |
|
1840 | 1840 |
/* |
... | ... |
@@ -1963,7 +1967,8 @@ do_close_tun(struct context *c, bool force) |
1963 | 1963 |
c->c2.es); |
1964 | 1964 |
|
1965 | 1965 |
delete_routes(c->c1.route_list, c->c1.route_ipv6_list, |
1966 |
- c->c1.tuntap, ROUTE_OPTION_FLAGS(&c->options), c->c2.es); |
|
1966 |
+ c->c1.tuntap, ROUTE_OPTION_FLAGS(&c->options), |
|
1967 |
+ c->c2.es, &c->net_ctx); |
|
1967 | 1968 |
} |
1968 | 1969 |
|
1969 | 1970 |
/* actually close tun/tap device based on --down-pre flag */ |
... | ... |
@@ -2820,6 +2825,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) |
2820 | 2820 |
to.x509_username_field = X509_USERNAME_FIELD_DEFAULT; |
2821 | 2821 |
#endif |
2822 | 2822 |
to.es = c->c2.es; |
2823 |
+ to.net_ctx = &c->net_ctx; |
|
2823 | 2824 |
|
2824 | 2825 |
#ifdef ENABLE_DEBUG |
2825 | 2826 |
to.gremlin = c->options.gremlin; |
... | ... |
@@ -3182,7 +3188,7 @@ do_option_warnings(struct context *c) |
3182 | 3182 |
|
3183 | 3183 |
if (o->tls_server) |
3184 | 3184 |
{ |
3185 |
- warn_on_use_of_common_subnets(); |
|
3185 |
+ warn_on_use_of_common_subnets(&c->net_ctx); |
|
3186 | 3186 |
} |
3187 | 3187 |
if (o->tls_client |
3188 | 3188 |
&& !o->tls_verify |
... | ... |
@@ -76,7 +76,8 @@ void do_route(const struct options *options, |
76 | 76 |
struct route_ipv6_list *route_ipv6_list, |
77 | 77 |
const struct tuntap *tt, |
78 | 78 |
const struct plugin_list *plugins, |
79 |
- struct env_set *es); |
|
79 |
+ struct env_set *es, |
|
80 |
+ openvpn_net_ctx_t *ctx); |
|
80 | 81 |
|
81 | 82 |
void close_instance(struct context *c); |
82 | 83 |
|
... | ... |
@@ -5006,12 +5006,14 @@ add_option(struct options *options, |
5006 | 5006 |
struct route_gateway_info rgi; |
5007 | 5007 |
struct route_ipv6_gateway_info rgi6; |
5008 | 5008 |
struct in6_addr remote = IN6ADDR_ANY_INIT; |
5009 |
+ openvpn_net_ctx_t net_ctx; |
|
5009 | 5010 |
VERIFY_PERMISSION(OPT_P_GENERAL); |
5010 | 5011 |
if (p[1]) |
5011 | 5012 |
{ |
5012 | 5013 |
get_ipv6_addr(p[1], &remote, NULL, M_WARN); |
5013 | 5014 |
} |
5014 |
- get_default_gateway(&rgi); |
|
5015 |
+ net_ctx_init(NULL, &net_ctx); |
|
5016 |
+ get_default_gateway(&rgi, &net_ctx); |
|
5015 | 5017 |
get_default_gateway_ipv6(&rgi6, &remote); |
5016 | 5018 |
print_default_gateway(M_INFO, &rgi, &rgi6); |
5017 | 5019 |
openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */ |
... | ... |
@@ -41,6 +41,7 @@ |
41 | 41 |
#include "manage.h" |
42 | 42 |
#include "win32.h" |
43 | 43 |
#include "options.h" |
44 |
+#include "networking.h" |
|
44 | 45 |
|
45 | 46 |
#include "memdbg.h" |
46 | 47 |
|
... | ... |
@@ -62,7 +63,7 @@ static bool del_route_ipv6_service(const struct route_ipv6 *, const struct tunta |
62 | 62 |
|
63 | 63 |
#endif |
64 | 64 |
|
65 |
-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); |
|
65 |
+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); |
|
66 | 66 |
|
67 | 67 |
static void get_bypass_addresses(struct route_bypass *rb, const unsigned int flags); |
68 | 68 |
|
... | ... |
@@ -608,7 +609,8 @@ init_route_list(struct route_list *rl, |
608 | 608 |
const char *remote_endpoint, |
609 | 609 |
int default_metric, |
610 | 610 |
in_addr_t remote_host, |
611 |
- struct env_set *es) |
|
611 |
+ struct env_set *es, |
|
612 |
+ openvpn_net_ctx_t *ctx) |
|
612 | 613 |
{ |
613 | 614 |
struct gc_arena gc = gc_new(); |
614 | 615 |
bool ret = true; |
... | ... |
@@ -629,7 +631,7 @@ init_route_list(struct route_list *rl, |
629 | 629 |
rl->spec.flags |= RTSA_DEFAULT_METRIC; |
630 | 630 |
} |
631 | 631 |
|
632 |
- get_default_gateway(&rl->rgi); |
|
632 |
+ get_default_gateway(&rl->rgi, ctx); |
|
633 | 633 |
if (rl->rgi.flags & RGI_ADDR_DEFINED) |
634 | 634 |
{ |
635 | 635 |
setenv_route_addr(es, "net_gateway", rl->rgi.gateway.addr, -1); |
... | ... |
@@ -896,7 +898,8 @@ add_route3(in_addr_t network, |
896 | 896 |
const struct tuntap *tt, |
897 | 897 |
unsigned int flags, |
898 | 898 |
const struct route_gateway_info *rgi, |
899 |
- const struct env_set *es) |
|
899 |
+ const struct env_set *es, |
|
900 |
+ openvpn_net_ctx_t *ctx) |
|
900 | 901 |
{ |
901 | 902 |
struct route_ipv4 r; |
902 | 903 |
CLEAR(r); |
... | ... |
@@ -904,7 +907,7 @@ add_route3(in_addr_t network, |
904 | 904 |
r.network = network; |
905 | 905 |
r.netmask = netmask; |
906 | 906 |
r.gateway = gateway; |
907 |
- add_route(&r, tt, flags, rgi, es); |
|
907 |
+ add_route(&r, tt, flags, rgi, es, ctx); |
|
908 | 908 |
} |
909 | 909 |
|
910 | 910 |
static void |
... | ... |
@@ -914,7 +917,8 @@ del_route3(in_addr_t network, |
914 | 914 |
const struct tuntap *tt, |
915 | 915 |
unsigned int flags, |
916 | 916 |
const struct route_gateway_info *rgi, |
917 |
- const struct env_set *es) |
|
917 |
+ const struct env_set *es, |
|
918 |
+ openvpn_net_ctx_t *ctx) |
|
918 | 919 |
{ |
919 | 920 |
struct route_ipv4 r; |
920 | 921 |
CLEAR(r); |
... | ... |
@@ -922,7 +926,7 @@ del_route3(in_addr_t network, |
922 | 922 |
r.network = network; |
923 | 923 |
r.netmask = netmask; |
924 | 924 |
r.gateway = gateway; |
925 |
- delete_route(&r, tt, flags, rgi, es); |
|
925 |
+ delete_route(&r, tt, flags, rgi, es, ctx); |
|
926 | 926 |
} |
927 | 927 |
|
928 | 928 |
static void |
... | ... |
@@ -931,7 +935,8 @@ add_bypass_routes(struct route_bypass *rb, |
931 | 931 |
const struct tuntap *tt, |
932 | 932 |
unsigned int flags, |
933 | 933 |
const struct route_gateway_info *rgi, |
934 |
- const struct env_set *es) |
|
934 |
+ const struct env_set *es, |
|
935 |
+ openvpn_net_ctx_t *ctx) |
|
935 | 936 |
{ |
936 | 937 |
int i; |
937 | 938 |
for (i = 0; i < rb->n_bypass; ++i) |
... | ... |
@@ -944,7 +949,8 @@ add_bypass_routes(struct route_bypass *rb, |
944 | 944 |
tt, |
945 | 945 |
flags | ROUTE_REF_GW, |
946 | 946 |
rgi, |
947 |
- es); |
|
947 |
+ es, |
|
948 |
+ ctx); |
|
948 | 949 |
} |
949 | 950 |
} |
950 | 951 |
} |
... | ... |
@@ -955,7 +961,8 @@ del_bypass_routes(struct route_bypass *rb, |
955 | 955 |
const struct tuntap *tt, |
956 | 956 |
unsigned int flags, |
957 | 957 |
const struct route_gateway_info *rgi, |
958 |
- const struct env_set *es) |
|
958 |
+ const struct env_set *es, |
|
959 |
+ openvpn_net_ctx_t *ctx) |
|
959 | 960 |
{ |
960 | 961 |
int i; |
961 | 962 |
for (i = 0; i < rb->n_bypass; ++i) |
... | ... |
@@ -968,13 +975,16 @@ del_bypass_routes(struct route_bypass *rb, |
968 | 968 |
tt, |
969 | 969 |
flags | ROUTE_REF_GW, |
970 | 970 |
rgi, |
971 |
- es); |
|
971 |
+ es, |
|
972 |
+ ctx); |
|
972 | 973 |
} |
973 | 974 |
} |
974 | 975 |
} |
975 | 976 |
|
976 | 977 |
static void |
977 |
-redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, unsigned int flags, const struct env_set *es) |
|
978 |
+redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, |
|
979 |
+ unsigned int flags, const struct env_set *es, |
|
980 |
+ openvpn_net_ctx_t *ctx) |
|
978 | 981 |
{ |
979 | 982 |
const char err[] = "NOTE: unable to redirect default gateway --"; |
980 | 983 |
|
... | ... |
@@ -1030,7 +1040,8 @@ redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, un |
1030 | 1030 |
tt, |
1031 | 1031 |
flags | ROUTE_REF_GW, |
1032 | 1032 |
&rl->rgi, |
1033 |
- es); |
|
1033 |
+ es, |
|
1034 |
+ ctx); |
|
1034 | 1035 |
rl->iflags |= RL_DID_LOCAL; |
1035 | 1036 |
} |
1036 | 1037 |
else |
... | ... |
@@ -1041,7 +1052,8 @@ redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, un |
1041 | 1041 |
#endif /* ifndef TARGET_ANDROID */ |
1042 | 1042 |
|
1043 | 1043 |
/* route DHCP/DNS server traffic through original default gateway */ |
1044 |
- add_bypass_routes(&rl->spec.bypass, rl->rgi.gateway.addr, tt, flags, &rl->rgi, es); |
|
1044 |
+ add_bypass_routes(&rl->spec.bypass, rl->rgi.gateway.addr, tt, flags, |
|
1045 |
+ &rl->rgi, es, ctx); |
|
1045 | 1046 |
|
1046 | 1047 |
if (rl->flags & RG_REROUTE_GW) |
1047 | 1048 |
{ |
... | ... |
@@ -1054,7 +1066,8 @@ redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, un |
1054 | 1054 |
tt, |
1055 | 1055 |
flags, |
1056 | 1056 |
&rl->rgi, |
1057 |
- es); |
|
1057 |
+ es, |
|
1058 |
+ ctx); |
|
1058 | 1059 |
|
1059 | 1060 |
/* add new default route (2nd component) */ |
1060 | 1061 |
add_route3(0x80000000, |
... | ... |
@@ -1063,7 +1076,8 @@ redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, un |
1063 | 1063 |
tt, |
1064 | 1064 |
flags, |
1065 | 1065 |
&rl->rgi, |
1066 |
- es); |
|
1066 |
+ es, |
|
1067 |
+ ctx); |
|
1067 | 1068 |
} |
1068 | 1069 |
else |
1069 | 1070 |
{ |
... | ... |
@@ -1072,7 +1086,7 @@ redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, un |
1072 | 1072 |
{ |
1073 | 1073 |
/* delete default route */ |
1074 | 1074 |
del_route3(0, 0, rl->rgi.gateway.addr, tt, |
1075 |
- flags | ROUTE_REF_GW, &rl->rgi, es); |
|
1075 |
+ flags | ROUTE_REF_GW, &rl->rgi, es, ctx); |
|
1076 | 1076 |
} |
1077 | 1077 |
|
1078 | 1078 |
/* add new default route */ |
... | ... |
@@ -1082,7 +1096,8 @@ redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, un |
1082 | 1082 |
tt, |
1083 | 1083 |
flags, |
1084 | 1084 |
&rl->rgi, |
1085 |
- es); |
|
1085 |
+ es, |
|
1086 |
+ ctx); |
|
1086 | 1087 |
} |
1087 | 1088 |
} |
1088 | 1089 |
|
... | ... |
@@ -1093,7 +1108,10 @@ redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, un |
1093 | 1093 |
} |
1094 | 1094 |
|
1095 | 1095 |
static void |
1096 |
-undo_redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, unsigned int flags, const struct env_set *es) |
|
1096 |
+undo_redirect_default_route_to_vpn(struct route_list *rl, |
|
1097 |
+ const struct tuntap *tt, unsigned int flags, |
|
1098 |
+ const struct env_set *es, |
|
1099 |
+ openvpn_net_ctx_t *ctx) |
|
1097 | 1100 |
{ |
1098 | 1101 |
if (rl && rl->iflags & RL_DID_REDIRECT_DEFAULT_GATEWAY) |
1099 | 1102 |
{ |
... | ... |
@@ -1106,12 +1124,14 @@ undo_redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *t |
1106 | 1106 |
tt, |
1107 | 1107 |
flags | ROUTE_REF_GW, |
1108 | 1108 |
&rl->rgi, |
1109 |
- es); |
|
1109 |
+ es, |
|
1110 |
+ ctx); |
|
1110 | 1111 |
rl->iflags &= ~RL_DID_LOCAL; |
1111 | 1112 |
} |
1112 | 1113 |
|
1113 | 1114 |
/* delete special DHCP/DNS bypass route */ |
1114 |
- del_bypass_routes(&rl->spec.bypass, rl->rgi.gateway.addr, tt, flags, &rl->rgi, es); |
|
1115 |
+ del_bypass_routes(&rl->spec.bypass, rl->rgi.gateway.addr, tt, flags, |
|
1116 |
+ &rl->rgi, es, ctx); |
|
1115 | 1117 |
|
1116 | 1118 |
if (rl->flags & RG_REROUTE_GW) |
1117 | 1119 |
{ |
... | ... |
@@ -1124,7 +1144,8 @@ undo_redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *t |
1124 | 1124 |
tt, |
1125 | 1125 |
flags, |
1126 | 1126 |
&rl->rgi, |
1127 |
- es); |
|
1127 |
+ es, |
|
1128 |
+ ctx); |
|
1128 | 1129 |
|
1129 | 1130 |
/* delete default route (2nd component) */ |
1130 | 1131 |
del_route3(0x80000000, |
... | ... |
@@ -1133,7 +1154,8 @@ undo_redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *t |
1133 | 1133 |
tt, |
1134 | 1134 |
flags, |
1135 | 1135 |
&rl->rgi, |
1136 |
- es); |
|
1136 |
+ es, |
|
1137 |
+ ctx); |
|
1137 | 1138 |
} |
1138 | 1139 |
else |
1139 | 1140 |
{ |
... | ... |
@@ -1144,12 +1166,13 @@ undo_redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *t |
1144 | 1144 |
tt, |
1145 | 1145 |
flags, |
1146 | 1146 |
&rl->rgi, |
1147 |
- es); |
|
1147 |
+ es, |
|
1148 |
+ ctx); |
|
1148 | 1149 |
/* restore original default route if there was any */ |
1149 | 1150 |
if (rl->rgi.flags & RGI_ADDR_DEFINED) |
1150 | 1151 |
{ |
1151 | 1152 |
add_route3(0, 0, rl->rgi.gateway.addr, tt, |
1152 |
- flags | ROUTE_REF_GW, &rl->rgi, es); |
|
1153 |
+ flags | ROUTE_REF_GW, &rl->rgi, es, ctx); |
|
1153 | 1154 |
} |
1154 | 1155 |
} |
1155 | 1156 |
} |
... | ... |
@@ -1159,9 +1182,11 @@ undo_redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *t |
1159 | 1159 |
} |
1160 | 1160 |
|
1161 | 1161 |
void |
1162 |
-add_routes(struct route_list *rl, struct route_ipv6_list *rl6, const struct tuntap *tt, unsigned int flags, const struct env_set *es) |
|
1162 |
+add_routes(struct route_list *rl, struct route_ipv6_list *rl6, |
|
1163 |
+ const struct tuntap *tt, unsigned int flags, |
|
1164 |
+ const struct env_set *es, openvpn_net_ctx_t *ctx) |
|
1163 | 1165 |
{ |
1164 |
- redirect_default_route_to_vpn(rl, tt, flags, es); |
|
1166 |
+ redirect_default_route_to_vpn(rl, tt, flags, es, ctx); |
|
1165 | 1167 |
if (rl && !(rl->iflags & RL_ROUTES_ADDED) ) |
1166 | 1168 |
{ |
1167 | 1169 |
struct route_ipv4 *r; |
... | ... |
@@ -1184,9 +1209,9 @@ add_routes(struct route_list *rl, struct route_ipv6_list *rl6, const struct tunt |
1184 | 1184 |
check_subnet_conflict(r->network, r->netmask, "route"); |
1185 | 1185 |
if (flags & ROUTE_DELETE_FIRST) |
1186 | 1186 |
{ |
1187 |
- delete_route(r, tt, flags, &rl->rgi, es); |
|
1187 |
+ delete_route(r, tt, flags, &rl->rgi, es, ctx); |
|
1188 | 1188 |
} |
1189 |
- add_route(r, tt, flags, &rl->rgi, es); |
|
1189 |
+ add_route(r, tt, flags, &rl->rgi, es, ctx); |
|
1190 | 1190 |
} |
1191 | 1191 |
rl->iflags |= RL_ROUTES_ADDED; |
1192 | 1192 |
} |
... | ... |
@@ -1206,9 +1231,9 @@ add_routes(struct route_list *rl, struct route_ipv6_list *rl6, const struct tunt |
1206 | 1206 |
{ |
1207 | 1207 |
if (flags & ROUTE_DELETE_FIRST) |
1208 | 1208 |
{ |
1209 |
- delete_route_ipv6(r, tt, flags, es); |
|
1209 |
+ delete_route_ipv6(r, tt, flags, es, ctx); |
|
1210 | 1210 |
} |
1211 |
- add_route_ipv6(r, tt, flags, es); |
|
1211 |
+ add_route_ipv6(r, tt, flags, es, ctx); |
|
1212 | 1212 |
} |
1213 | 1213 |
rl6->iflags |= RL_ROUTES_ADDED; |
1214 | 1214 |
} |
... | ... |
@@ -1216,19 +1241,20 @@ add_routes(struct route_list *rl, struct route_ipv6_list *rl6, const struct tunt |
1216 | 1216 |
|
1217 | 1217 |
void |
1218 | 1218 |
delete_routes(struct route_list *rl, struct route_ipv6_list *rl6, |
1219 |
- const struct tuntap *tt, unsigned int flags, const struct env_set *es) |
|
1219 |
+ const struct tuntap *tt, unsigned int flags, |
|
1220 |
+ const struct env_set *es, openvpn_net_ctx_t *ctx) |
|
1220 | 1221 |
{ |
1221 | 1222 |
if (rl && rl->iflags & RL_ROUTES_ADDED) |
1222 | 1223 |
{ |
1223 | 1224 |
struct route_ipv4 *r; |
1224 | 1225 |
for (r = rl->routes; r; r = r->next) |
1225 | 1226 |
{ |
1226 |
- delete_route(r, tt, flags, &rl->rgi, es); |
|
1227 |
+ delete_route(r, tt, flags, &rl->rgi, es, ctx); |
|
1227 | 1228 |
} |
1228 | 1229 |
rl->iflags &= ~RL_ROUTES_ADDED; |
1229 | 1230 |
} |
1230 | 1231 |
|
1231 |
- undo_redirect_default_route_to_vpn(rl, tt, flags, es); |
|
1232 |
+ undo_redirect_default_route_to_vpn(rl, tt, flags, es, ctx); |
|
1232 | 1233 |
|
1233 | 1234 |
if (rl) |
1234 | 1235 |
{ |
... | ... |
@@ -1240,7 +1266,7 @@ delete_routes(struct route_list *rl, struct route_ipv6_list *rl6, |
1240 | 1240 |
struct route_ipv6 *r6; |
1241 | 1241 |
for (r6 = rl6->routes_ipv6; r6; r6 = r6->next) |
1242 | 1242 |
{ |
1243 |
- delete_route_ipv6(r6, tt, flags, es); |
|
1243 |
+ delete_route_ipv6(r6, tt, flags, es, ctx); |
|
1244 | 1244 |
} |
1245 | 1245 |
rl6->iflags &= ~RL_ROUTES_ADDED; |
1246 | 1246 |
} |
... | ... |
@@ -1520,15 +1546,21 @@ add_route(struct route_ipv4 *r, |
1520 | 1520 |
const struct tuntap *tt, |
1521 | 1521 |
unsigned int flags, |
1522 | 1522 |
const struct route_gateway_info *rgi, /* may be NULL */ |
1523 |
- const struct env_set *es) |
|
1523 |
+ const struct env_set *es, |
|
1524 |
+ openvpn_net_ctx_t *ctx) |
|
1524 | 1525 |
{ |
1525 | 1526 |
struct gc_arena gc; |
1526 | 1527 |
struct argv argv = argv_new(); |
1528 |
+#if !defined(TARGET_LINUX) |
|
1527 | 1529 |
const char *network; |
1528 | 1530 |
#if !defined(ENABLE_IPROUTE) && !defined(TARGET_AIX) |
1529 | 1531 |
const char *netmask; |
1530 | 1532 |
#endif |
1531 | 1533 |
const char *gateway; |
1534 |
+#else |
|
1535 |
+ const char *iface; |
|
1536 |
+ int metric; |
|
1537 |
+#endif |
|
1532 | 1538 |
bool status = false; |
1533 | 1539 |
int is_local_route; |
1534 | 1540 |
|
... | ... |
@@ -1539,11 +1571,13 @@ add_route(struct route_ipv4 *r, |
1539 | 1539 |
|
1540 | 1540 |
gc_init(&gc); |
1541 | 1541 |
|
1542 |
+#if !defined(TARGET_LINUX) |
|
1542 | 1543 |
network = print_in_addr_t(r->network, 0, &gc); |
1543 | 1544 |
#if !defined(ENABLE_IPROUTE) && !defined(TARGET_AIX) |
1544 | 1545 |
netmask = print_in_addr_t(r->netmask, 0, &gc); |
1545 | 1546 |
#endif |
1546 | 1547 |
gateway = print_in_addr_t(r->gateway, 0, &gc); |
1548 |
+#endif |
|
1547 | 1549 |
|
1548 | 1550 |
is_local_route = local_route(r->network, r->netmask, r->gateway, rgi); |
1549 | 1551 |
if (is_local_route == LR_ERROR) |
... | ... |
@@ -1552,47 +1586,26 @@ add_route(struct route_ipv4 *r, |
1552 | 1552 |
} |
1553 | 1553 |
|
1554 | 1554 |
#if defined(TARGET_LINUX) |
1555 |
-#ifdef ENABLE_IPROUTE |
|
1556 |
- argv_printf(&argv, "%s route add %s/%d", |
|
1557 |
- iproute_path, |
|
1558 |
- network, |
|
1559 |
- netmask_to_netbits2(r->netmask)); |
|
1560 |
- |
|
1561 |
- if (r->flags & RT_METRIC_DEFINED) |
|
1562 |
- { |
|
1563 |
- argv_printf_cat(&argv, "metric %d", r->metric); |
|
1564 |
- } |
|
1565 |
- |
|
1555 |
+ iface = NULL; |
|
1566 | 1556 |
if (is_on_link(is_local_route, flags, rgi)) |
1567 | 1557 |
{ |
1568 |
- argv_printf_cat(&argv, "dev %s", rgi->iface); |
|
1558 |
+ iface = rgi->iface; |
|
1569 | 1559 |
} |
1570 |
- else |
|
1571 |
- { |
|
1572 |
- argv_printf_cat(&argv, "via %s", gateway); |
|
1573 |
- } |
|
1574 |
-#else /* ifdef ENABLE_IPROUTE */ |
|
1575 |
- argv_printf(&argv, "%s add -net %s netmask %s", |
|
1576 |
- ROUTE_PATH, |
|
1577 |
- network, |
|
1578 |
- netmask); |
|
1560 |
+ |
|
1561 |
+ metric = -1; |
|
1579 | 1562 |
if (r->flags & RT_METRIC_DEFINED) |
1580 | 1563 |
{ |
1581 |
- argv_printf_cat(&argv, "metric %d", r->metric); |
|
1564 |
+ metric = r->metric; |
|
1582 | 1565 |
} |
1583 |
- if (is_on_link(is_local_route, flags, rgi)) |
|
1584 |
- { |
|
1585 |
- argv_printf_cat(&argv, "dev %s", rgi->iface); |
|
1586 |
- } |
|
1587 |
- else |
|
1566 |
+ |
|
1567 |
+ status = true; |
|
1568 |
+ if (net_route_v4_add(ctx, &r->network, netmask_to_netbits2(r->netmask), |
|
1569 |
+ &r->gateway, iface, 0, metric) < 0) |
|
1588 | 1570 |
{ |
1589 |
- argv_printf_cat(&argv, "gw %s", gateway); |
|
1571 |
+ msg(M_WARN, "ERROR: Linux route add command failed"); |
|
1572 |
+ status = false; |
|
1590 | 1573 |
} |
1591 | 1574 |
|
1592 |
-#endif /*ENABLE_IPROUTE*/ |
|
1593 |
- argv_msg(D_ROUTE, &argv); |
|
1594 |
- status = openvpn_execve_check(&argv, es, 0, "ERROR: Linux route add command failed"); |
|
1595 |
- |
|
1596 | 1575 |
#elif defined (TARGET_ANDROID) |
1597 | 1576 |
char out[128]; |
1598 | 1577 |
|
... | ... |
@@ -1839,7 +1852,9 @@ route_ipv6_clear_host_bits( struct route_ipv6 *r6 ) |
1839 | 1839 |
} |
1840 | 1840 |
|
1841 | 1841 |
void |
1842 |
-add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flags, const struct env_set *es) |
|
1842 |
+add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, |
|
1843 |
+ unsigned int flags, const struct env_set *es, |
|
1844 |
+ openvpn_net_ctx_t *ctx) |
|
1843 | 1845 |
{ |
1844 | 1846 |
struct gc_arena gc; |
1845 | 1847 |
struct argv argv = argv_new(); |
... | ... |
@@ -1848,7 +1863,9 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flag |
1848 | 1848 |
const char *gateway; |
1849 | 1849 |
bool status = false; |
1850 | 1850 |
const char *device = tt->actual_name; |
1851 |
- |
|
1851 |
+#if defined(TARGET_LINUX) |
|
1852 |
+ int metric; |
|
1853 |
+#endif |
|
1852 | 1854 |
bool gateway_needed = false; |
1853 | 1855 |
|
1854 | 1856 |
if (!(r6->flags & RT_DEFINED) ) |
... | ... |
@@ -1923,38 +1940,20 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flag |
1923 | 1923 |
} |
1924 | 1924 |
|
1925 | 1925 |
#if defined(TARGET_LINUX) |
1926 |
-#ifdef ENABLE_IPROUTE |
|
1927 |
- argv_printf(&argv, "%s -6 route add %s/%d dev %s", |
|
1928 |
- iproute_path, |
|
1929 |
- network, |
|
1930 |
- r6->netbits, |
|
1931 |
- device); |
|
1932 |
- if (gateway_needed) |
|
1933 |
- { |
|
1934 |
- argv_printf_cat(&argv, "via %s", gateway); |
|
1935 |
- } |
|
1936 |
- if ( (r6->flags & RT_METRIC_DEFINED) && r6->metric > 0) |
|
1926 |
+ metric = -1; |
|
1927 |
+ if ((r6->flags & RT_METRIC_DEFINED) && (r6->metric > 0)) |
|
1937 | 1928 |
{ |
1938 |
- argv_printf_cat(&argv, " metric %d", r6->metric); |
|
1929 |
+ metric = r6->metric; |
|
1939 | 1930 |
} |
1940 | 1931 |
|
1941 |
-#else /* ifdef ENABLE_IPROUTE */ |
|
1942 |
- argv_printf(&argv, "%s -A inet6 add %s/%d dev %s", |
|
1943 |
- ROUTE_PATH, |
|
1944 |
- network, |
|
1945 |
- r6->netbits, |
|
1946 |
- device); |
|
1947 |
- if (gateway_needed) |
|
1932 |
+ status = true; |
|
1933 |
+ if (net_route_v6_add(ctx, &r6->network, r6->netbits, |
|
1934 |
+ gateway_needed ? &r6->gateway : NULL, device, 0, |
|
1935 |
+ metric) < 0) |
|
1948 | 1936 |
{ |
1949 |
- argv_printf_cat(&argv, "gw %s", gateway); |
|
1950 |
- } |
|
1951 |
- if ( (r6->flags & RT_METRIC_DEFINED) && r6->metric > 0) |
|
1952 |
- { |
|
1953 |
- argv_printf_cat(&argv, " metric %d", r6->metric); |
|
1937 |
+ msg(M_WARN, "ERROR: Linux IPv6 route can't be added"); |
|
1938 |
+ status = false; |
|
1954 | 1939 |
} |
1955 |
-#endif /*ENABLE_IPROUTE*/ |
|
1956 |
- argv_msg(D_ROUTE, &argv); |
|
1957 |
- status = openvpn_execve_check(&argv, es, 0, "ERROR: Linux route -6/-A inet6 add command failed"); |
|
1958 | 1940 |
|
1959 | 1941 |
#elif defined (TARGET_ANDROID) |
1960 | 1942 |
char out[64]; |
... | ... |
@@ -2137,10 +2136,12 @@ delete_route(struct route_ipv4 *r, |
2137 | 2137 |
const struct tuntap *tt, |
2138 | 2138 |
unsigned int flags, |
2139 | 2139 |
const struct route_gateway_info *rgi, |
2140 |
- const struct env_set *es) |
|
2140 |
+ const struct env_set *es, |
|
2141 |
+ openvpn_net_ctx_t *ctx) |
|
2141 | 2142 |
{ |
2142 | 2143 |
struct gc_arena gc; |
2143 | 2144 |
struct argv argv = argv_new(); |
2145 |
+#if !defined(TARGET_LINUX) |
|
2144 | 2146 |
const char *network; |
2145 | 2147 |
#if !defined(ENABLE_IPROUTE) && !defined(TARGET_AIX) |
2146 | 2148 |
const char *netmask; |
... | ... |
@@ -2148,6 +2149,9 @@ delete_route(struct route_ipv4 *r, |
2148 | 2148 |
#if !defined(TARGET_LINUX) && !defined(TARGET_ANDROID) |
2149 | 2149 |
const char *gateway; |
2150 | 2150 |
#endif |
2151 |
+#else |
|
2152 |
+ int metric; |
|
2153 |
+#endif |
|
2151 | 2154 |
int is_local_route; |
2152 | 2155 |
|
2153 | 2156 |
if ((r->flags & (RT_DEFINED|RT_ADDED)) != (RT_DEFINED|RT_ADDED)) |
... | ... |
@@ -2157,6 +2161,7 @@ delete_route(struct route_ipv4 *r, |
2157 | 2157 |
|
2158 | 2158 |
gc_init(&gc); |
2159 | 2159 |
|
2160 |
+#if !defined(TARGET_LINUX) |
|
2160 | 2161 |
network = print_in_addr_t(r->network, 0, &gc); |
2161 | 2162 |
#if !defined(ENABLE_IPROUTE) && !defined(TARGET_AIX) |
2162 | 2163 |
netmask = print_in_addr_t(r->netmask, 0, &gc); |
... | ... |
@@ -2164,6 +2169,7 @@ delete_route(struct route_ipv4 *r, |
2164 | 2164 |
#if !defined(TARGET_LINUX) && !defined(TARGET_ANDROID) |
2165 | 2165 |
gateway = print_in_addr_t(r->gateway, 0, &gc); |
2166 | 2166 |
#endif |
2167 |
+#endif |
|
2167 | 2168 |
|
2168 | 2169 |
is_local_route = local_route(r->network, r->netmask, r->gateway, rgi); |
2169 | 2170 |
if (is_local_route == LR_ERROR) |
... | ... |
@@ -2172,24 +2178,17 @@ delete_route(struct route_ipv4 *r, |
2172 | 2172 |
} |
2173 | 2173 |
|
2174 | 2174 |
#if defined(TARGET_LINUX) |
2175 |
-#ifdef ENABLE_IPROUTE |
|
2176 |
- argv_printf(&argv, "%s route del %s/%d", |
|
2177 |
- iproute_path, |
|
2178 |
- network, |
|
2179 |
- netmask_to_netbits2(r->netmask)); |
|
2180 |
-#else |
|
2181 |
- argv_printf(&argv, "%s del -net %s netmask %s", |
|
2182 |
- ROUTE_PATH, |
|
2183 |
- network, |
|
2184 |
- netmask); |
|
2185 |
-#endif /*ENABLE_IPROUTE*/ |
|
2175 |
+ metric = -1; |
|
2186 | 2176 |
if (r->flags & RT_METRIC_DEFINED) |
2187 | 2177 |
{ |
2188 |
- argv_printf_cat(&argv, "metric %d", r->metric); |
|
2178 |
+ metric = r->metric; |
|
2189 | 2179 |
} |
2190 |
- argv_msg(D_ROUTE, &argv); |
|
2191 |
- openvpn_execve_check(&argv, es, 0, "ERROR: Linux route delete command failed"); |
|
2192 | 2180 |
|
2181 |
+ if (net_route_v4_del(ctx, &r->network, netmask_to_netbits2(r->netmask), |
|
2182 |
+ &r->gateway, NULL, 0, metric) < 0) |
|
2183 |
+ { |
|
2184 |
+ msg(M_WARN, "ERROR: Linux route delete command failed"); |
|
2185 |
+ } |
|
2193 | 2186 |
#elif defined (_WIN32) |
2194 | 2187 |
|
2195 | 2188 |
argv_printf(&argv, "%s%sc DELETE %s MASK %s %s", |
... | ... |
@@ -2325,12 +2324,18 @@ done: |
2325 | 2325 |
} |
2326 | 2326 |
|
2327 | 2327 |
void |
2328 |
-delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flags, const struct env_set *es) |
|
2328 |
+delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt, |
|
2329 |
+ unsigned int flags, const struct env_set *es, |
|
2330 |
+ openvpn_net_ctx_t *ctx) |
|
2329 | 2331 |
{ |
2330 | 2332 |
struct gc_arena gc; |
2331 | 2333 |
struct argv argv = argv_new(); |
2332 | 2334 |
const char *network; |
2335 |
+#if !defined(TARGET_LINUX) |
|
2333 | 2336 |
const char *gateway; |
2337 |
+#else |
|
2338 |
+ int metric; |
|
2339 |
+#endif |
|
2334 | 2340 |
const char *device = tt->actual_name; |
2335 | 2341 |
bool gateway_needed = false; |
2336 | 2342 |
|
... | ... |
@@ -2350,7 +2355,9 @@ delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt, unsigned |
2350 | 2350 |
gc_init(&gc); |
2351 | 2351 |
|
2352 | 2352 |
network = print_in6_addr( r6->network, 0, &gc); |
2353 |
+#if !defined(TARGET_LINUX) |
|
2353 | 2354 |
gateway = print_in6_addr( r6->gateway, 0, &gc); |
2355 |
+#endif |
|
2354 | 2356 |
|
2355 | 2357 |
#if defined(TARGET_DARWIN) \ |
2356 | 2358 |
|| defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \ |
... | ... |
@@ -2381,35 +2388,19 @@ delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt, unsigned |
2381 | 2381 |
gateway_needed = true; |
2382 | 2382 |
} |
2383 | 2383 |
|
2384 |
- |
|
2385 | 2384 |
#if defined(TARGET_LINUX) |
2386 |
-#ifdef ENABLE_IPROUTE |
|
2387 |
- argv_printf(&argv, "%s -6 route del %s/%d dev %s", |
|
2388 |
- iproute_path, |
|
2389 |
- network, |
|
2390 |
- r6->netbits, |
|
2391 |
- device); |
|
2392 |
- if (gateway_needed) |
|
2393 |
- { |
|
2394 |
- argv_printf_cat(&argv, "via %s", gateway); |
|
2395 |
- } |
|
2396 |
-#else /* ifdef ENABLE_IPROUTE */ |
|
2397 |
- argv_printf(&argv, "%s -A inet6 del %s/%d dev %s", |
|
2398 |
- ROUTE_PATH, |
|
2399 |
- network, |
|
2400 |
- r6->netbits, |
|
2401 |
- device); |
|
2402 |
- if (gateway_needed) |
|
2385 |
+ metric = -1; |
|
2386 |
+ if ((r6->flags & RT_METRIC_DEFINED) && (r6->metric > 0)) |
|
2403 | 2387 |
{ |
2404 |
- argv_printf_cat(&argv, "gw %s", gateway); |
|
2388 |
+ metric = r6->metric; |
|
2405 | 2389 |
} |
2406 |
- if ( (r6->flags & RT_METRIC_DEFINED) && r6->metric > 0) |
|
2390 |
+ |
|
2391 |
+ if (net_route_v6_del(ctx, &r6->network, r6->netbits, |
|
2392 |
+ gateway_needed ? &r6->gateway : NULL, device, 0, |
|
2393 |
+ metric) < 0) |
|
2407 | 2394 |
{ |
2408 |
- argv_printf_cat(&argv, " metric %d", r6->metric); |
|
2395 |
+ msg(M_WARN, "ERROR: Linux route v6 delete command failed"); |
|
2409 | 2396 |
} |
2410 |
-#endif /*ENABLE_IPROUTE*/ |
|
2411 |
- argv_msg(D_ROUTE, &argv); |
|
2412 |
- openvpn_execve_check(&argv, es, 0, "ERROR: Linux route -6/-A inet6 del command failed"); |
|
2413 | 2397 |
|
2414 | 2398 |
#elif defined (_WIN32) |
2415 | 2399 |
|
... | ... |
@@ -2721,7 +2712,7 @@ get_default_gateway_row(const MIB_IPFORWARDTABLE *routes) |
2721 | 2721 |
} |
2722 | 2722 |
|
2723 | 2723 |
void |
2724 |
-get_default_gateway(struct route_gateway_info *rgi) |
|
2724 |
+get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) |
|
2725 | 2725 |
{ |
2726 | 2726 |
struct gc_arena gc = gc_new(); |
2727 | 2727 |
|
... | ... |
@@ -2808,7 +2799,7 @@ windows_route_find_if_index(const struct route_ipv4 *r, const struct tuntap *tt) |
2808 | 2808 |
*/ |
2809 | 2809 |
void |
2810 | 2810 |
get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, |
2811 |
- const struct in6_addr *dest) |
|
2811 |
+ const struct in6_addr *dest, openvpn_net_ctx_t *ctx) |
|
2812 | 2812 |
{ |
2813 | 2813 |
struct gc_arena gc = gc_new(); |
2814 | 2814 |
MIB_IPFORWARD_ROW2 BestRoute; |
... | ... |
@@ -3169,72 +3160,23 @@ show_routes(int msglev) |
3169 | 3169 |
#elif defined(TARGET_LINUX) || defined(TARGET_ANDROID) |
3170 | 3170 |
|
3171 | 3171 |
void |
3172 |
-get_default_gateway(struct route_gateway_info *rgi) |
|
3172 |
+get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) |
|
3173 | 3173 |
{ |
3174 | 3174 |
struct gc_arena gc = gc_new(); |
3175 | 3175 |
int sd = -1; |
3176 |
- char best_name[16]; |
|
3177 |
- best_name[0] = 0; |
|
3176 |
+ char best_name[IFNAMSIZ]; |
|
3178 | 3177 |
|
3179 | 3178 |
CLEAR(*rgi); |
3179 |
+ CLEAR(best_name); |
|
3180 | 3180 |
|
3181 | 3181 |
#ifndef TARGET_ANDROID |
3182 | 3182 |
/* get default gateway IP addr */ |
3183 |
+ if (net_route_v4_best_gw(ctx, NULL, 0, &rgi->gateway.addr, best_name) == 0) |
|
3183 | 3184 |
{ |
3184 |
- FILE *fp = fopen("/proc/net/route", "r"); |
|
3185 |
- if (fp) |
|
3185 |
+ rgi->flags |= RGI_ADDR_DEFINED; |
|
3186 |
+ if (!rgi->gateway.addr && best_name[0]) |
|
3186 | 3187 |
{ |
3187 |
- char line[256]; |
|
3188 |
- int count = 0; |
|
3189 |
- unsigned int lowest_metric = UINT_MAX; |
|
3190 |
- in_addr_t best_gw = 0; |
|
3191 |
- bool found = false; |
|
3192 |
- while (fgets(line, sizeof(line), fp) != NULL) |
|
3193 |
- { |
|
3194 |
- if (count) |
|
3195 |
- { |
|
3196 |
- unsigned int net_x = 0; |
|
3197 |
- unsigned int mask_x = 0; |
|
3198 |
- unsigned int gw_x = 0; |
|
3199 |
- unsigned int metric = 0; |
|
3200 |
- unsigned int flags = 0; |
|
3201 |
- char name[16]; |
|
3202 |
- name[0] = 0; |
|
3203 |
- const int np = sscanf(line, "%15s\t%x\t%x\t%x\t%*s\t%*s\t%d\t%x", |
|
3204 |
- name, |
|
3205 |
- &net_x, |
|
3206 |
- &gw_x, |
|
3207 |
- &flags, |
|
3208 |
- &metric, |
|
3209 |
- &mask_x); |
|
3210 |
- if (np == 6 && (flags & IFF_UP)) |
|
3211 |
- { |
|
3212 |
- const in_addr_t net = ntohl(net_x); |
|
3213 |
- const in_addr_t mask = ntohl(mask_x); |
|
3214 |
- const in_addr_t gw = ntohl(gw_x); |
|
3215 |
- |
|
3216 |
- if (!net && !mask && metric < lowest_metric) |
|
3217 |
- { |
|
3218 |
- found = true; |
|
3219 |
- best_gw = gw; |
|
3220 |
- strcpy(best_name, name); |
|
3221 |
- lowest_metric = metric; |
|
3222 |
- } |
|
3223 |
- } |
|
3224 |
- } |
|
3225 |
- ++count; |
|
3226 |
- } |
|
3227 |
- fclose(fp); |
|
3228 |
- |
|
3229 |
- if (found) |
|
3230 |
- { |
|
3231 |
- rgi->gateway.addr = best_gw; |
|
3232 |
- rgi->flags |= RGI_ADDR_DEFINED; |
|
3233 |
- if (!rgi->gateway.addr && best_name[0]) |
|
3234 |
- { |
|
3235 |
- rgi->flags |= RGI_ON_LINK; |
|
3236 |
- } |
|
3237 |
- } |
|
3188 |
+ rgi->flags |= RGI_ON_LINK; |
|
3238 | 3189 |
} |
3239 | 3190 |
} |
3240 | 3191 |
#else /* ifndef TARGET_ANDROID */ |
... | ... |
@@ -3596,7 +3538,7 @@ struct rtmsg { |
3596 | 3596 |
#define max(a,b) ((a) > (b) ? (a) : (b)) |
3597 | 3597 |
|
3598 | 3598 |
void |
3599 |
-get_default_gateway(struct route_gateway_info *rgi) |
|
3599 |
+get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) |
|
3600 | 3600 |
{ |
3601 | 3601 |
struct gc_arena gc = gc_new(); |
3602 | 3602 |
struct rtmsg m_rtmsg; |
... | ... |
@@ -3996,7 +3938,7 @@ done: |
3996 | 3996 |
* may be disabled by missing items. |
3997 | 3997 |
*/ |
3998 | 3998 |
void |
3999 |
-get_default_gateway(struct route_gateway_info *rgi) |
|
3999 |
+get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) |
|
4000 | 4000 |
{ |
4001 | 4001 |
CLEAR(*rgi); |
4002 | 4002 |
} |
... | ... |
@@ -256,15 +256,16 @@ void copy_route_ipv6_option_list(struct route_ipv6_option_list *dest, |
256 | 256 |
|
257 | 257 |
void route_ipv6_clear_host_bits( struct route_ipv6 *r6 ); |
258 | 258 |
|
259 |
-void add_route_ipv6(struct route_ipv6 *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es); |
|
259 |
+void add_route_ipv6(struct route_ipv6 *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx); |
|
260 | 260 |
|
261 |
-void delete_route_ipv6(const struct route_ipv6 *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es); |
|
261 |
+void delete_route_ipv6(const struct route_ipv6 *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx); |
|
262 | 262 |
|
263 | 263 |
void add_route(struct route_ipv4 *r, |
264 | 264 |
const struct tuntap *tt, |
265 | 265 |
unsigned int flags, |
266 | 266 |
const struct route_gateway_info *rgi, |
267 |
- const struct env_set *es); |
|
267 |
+ const struct env_set *es, |
|
268 |
+ openvpn_net_ctx_t *ctx); |
|
268 | 269 |
|
269 | 270 |
void add_route_to_option_list(struct route_option_list *l, |
270 | 271 |
const char *network, |
... | ... |
@@ -282,7 +283,8 @@ bool init_route_list(struct route_list *rl, |
282 | 282 |
const char *remote_endpoint, |
283 | 283 |
int default_metric, |
284 | 284 |
in_addr_t remote_host, |
285 |
- struct env_set *es); |
|
285 |
+ struct env_set *es, |
|
286 |
+ openvpn_net_ctx_t *ctx); |
|
286 | 287 |
|
287 | 288 |
bool init_route_ipv6_list(struct route_ipv6_list *rl6, |
288 | 289 |
const struct route_ipv6_option_list *opt6, |
... | ... |
@@ -299,13 +301,15 @@ void add_routes(struct route_list *rl, |
299 | 299 |
struct route_ipv6_list *rl6, |
300 | 300 |
const struct tuntap *tt, |
301 | 301 |
unsigned int flags, |
302 |
- const struct env_set *es); |
|
302 |
+ const struct env_set *es, |
|
303 |
+ openvpn_net_ctx_t *ctx); |
|
303 | 304 |
|
304 | 305 |
void delete_routes(struct route_list *rl, |
305 | 306 |
struct route_ipv6_list *rl6, |
306 | 307 |
const struct tuntap *tt, |
307 | 308 |
unsigned int flags, |
308 |
- const struct env_set *es); |
|
309 |
+ const struct env_set *es, |
|
310 |
+ openvpn_net_ctx_t *ctx); |
|
309 | 311 |
|
310 | 312 |
void setenv_routes(struct env_set *es, const struct route_list *rl); |
311 | 313 |
|
... | ... |
@@ -315,7 +319,8 @@ void setenv_routes_ipv6(struct env_set *es, const struct route_ipv6_list *rl6); |
315 | 315 |
|
316 | 316 |
bool is_special_addr(const char *addr_str); |
317 | 317 |
|
318 |
-void get_default_gateway(struct route_gateway_info *rgi); |
|
318 |
+void get_default_gateway(struct route_gateway_info *rgi, |
|
319 |
+ openvpn_net_ctx_t *ctx); |
|
319 | 320 |
|
320 | 321 |
void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi, |
321 | 322 |
const struct in6_addr *dest); |
... | ... |
@@ -2324,7 +2324,7 @@ push_peer_info(struct buffer *buf, struct tls_session *session) |
2324 | 2324 |
{ |
2325 | 2325 |
/* push mac addr */ |
2326 | 2326 |
struct route_gateway_info rgi; |
2327 |
- get_default_gateway(&rgi); |
|
2327 |
+ get_default_gateway(&rgi, session->opt->net_ctx); |
|
2328 | 2328 |
if (rgi.flags & RGI_HWADDR_DEFINED) |
2329 | 2329 |
{ |
2330 | 2330 |
buf_printf(&out, "IV_HWADDR=%s\n", format_hex_ex(rgi.hwaddr, 6, 0, 1, ":", &gc)); |
... | ... |
@@ -453,13 +453,13 @@ check_subnet_conflict(const in_addr_t ip, |
453 | 453 |
} |
454 | 454 |
|
455 | 455 |
void |
456 |
-warn_on_use_of_common_subnets(void) |
|
456 |
+warn_on_use_of_common_subnets(openvpn_net_ctx_t *ctx) |
|
457 | 457 |
{ |
458 | 458 |
struct gc_arena gc = gc_new(); |
459 | 459 |
struct route_gateway_info rgi; |
460 | 460 |
const int needed = (RGI_ADDR_DEFINED|RGI_NETMASK_DEFINED); |
461 | 461 |
|
462 |
- get_default_gateway(&rgi); |
|
462 |
+ get_default_gateway(&rgi, ctx); |
|
463 | 463 |
if ((rgi.flags & needed) == needed) |
464 | 464 |
{ |
465 | 465 |
const in_addr_t lan_network = rgi.gateway.addr & rgi.gateway.netmask; |
... | ... |
@@ -818,7 +818,7 @@ add_route_connected_v6_net(struct tuntap *tt, |
818 | 818 |
r6.gateway = tt->local_ipv6; |
819 | 819 |
r6.metric = 0; /* connected route */ |
820 | 820 |
r6.flags = RT_DEFINED | RT_METRIC_DEFINED; |
821 |
- add_route_ipv6(&r6, tt, 0, es); |
|
821 |
+ add_route_ipv6(&r6, tt, 0, es, NULL); |
|
822 | 822 |
} |
823 | 823 |
|
824 | 824 |
void |
... | ... |
@@ -834,7 +834,7 @@ delete_route_connected_v6_net(struct tuntap *tt, |
834 | 834 |
r6.metric = 0; /* connected route */ |
835 | 835 |
r6.flags = RT_DEFINED | RT_ADDED | RT_METRIC_DEFINED; |
836 | 836 |
route_ipv6_clear_host_bits(&r6); |
837 |
- delete_route_ipv6(&r6, tt, 0, es); |
|
837 |
+ delete_route_ipv6(&r6, tt, 0, es, NULL); |
|
838 | 838 |
} |
839 | 839 |
#endif /* if defined(_WIN32) || defined(TARGET_DARWIN) || defined(TARGET_NETBSD) || defined(TARGET_OPENBSD) */ |
840 | 840 |
|
... | ... |
@@ -1170,7 +1170,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, |
1170 | 1170 |
r.netmask = tt->remote_netmask; |
1171 | 1171 |
r.gateway = tt->local; |
1172 | 1172 |
r.metric = 0; |
1173 |
- add_route(&r, tt, 0, NULL, es); |
|
1173 |
+ add_route(&r, tt, 0, NULL, es, NULL); |
|
1174 | 1174 |
} |
1175 | 1175 |
|
1176 | 1176 |
#elif defined(TARGET_OPENBSD) |
... | ... |
@@ -1217,7 +1217,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, |
1217 | 1217 |
r.network = tt->local & tt->remote_netmask; |
1218 | 1218 |
r.netmask = tt->remote_netmask; |
1219 | 1219 |
r.gateway = remote_end; |
1220 |
- add_route(&r, tt, 0, NULL, es); |
|
1220 |
+ add_route(&r, tt, 0, NULL, es, NULL); |
|
1221 | 1221 |
} |
1222 | 1222 |
|
1223 | 1223 |
#elif defined(TARGET_NETBSD) |
... | ... |
@@ -1259,7 +1259,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, |
1259 | 1259 |
r.network = tt->local & tt->remote_netmask; |
1260 | 1260 |
r.netmask = tt->remote_netmask; |
1261 | 1261 |
r.gateway = remote_end; |
1262 |
- add_route(&r, tt, 0, NULL, es); |
|
1262 |
+ add_route(&r, tt, 0, NULL, es, NULL); |
|
1263 | 1263 |
} |
1264 | 1264 |
|
1265 | 1265 |
#elif defined(TARGET_DARWIN) |
... | ... |
@@ -1309,7 +1309,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, |
1309 | 1309 |
r.network = tt->local & tt->remote_netmask; |
1310 | 1310 |
r.netmask = tt->remote_netmask; |
1311 | 1311 |
r.gateway = tt->local; |
1312 |
- add_route(&r, tt, 0, NULL, es); |
|
1312 |
+ add_route(&r, tt, 0, NULL, es, NULL); |
|
1313 | 1313 |
} |
1314 | 1314 |
|
1315 | 1315 |
#elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) |
... | ... |
@@ -1348,7 +1348,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, |
1348 | 1348 |
r.network = tt->local & tt->remote_netmask; |
1349 | 1349 |
r.netmask = tt->remote_netmask; |
1350 | 1350 |
r.gateway = remote_end; |
1351 |
- add_route(&r, tt, 0, NULL, es); |
|
1351 |
+ add_route(&r, tt, 0, NULL, es, NULL); |
|
1352 | 1352 |
} |
1353 | 1353 |
|
1354 | 1354 |
#elif defined(TARGET_AIX) |
... | ... |
@@ -275,7 +275,7 @@ void check_subnet_conflict(const in_addr_t ip, |
275 | 275 |
const in_addr_t netmask, |
276 | 276 |
const char *prefix); |
277 | 277 |
|
278 |
-void warn_on_use_of_common_subnets(void); |
|
278 |
+void warn_on_use_of_common_subnets(openvpn_net_ctx_t *ctx); |
|
279 | 279 |
|
280 | 280 |
/* |
281 | 281 |
* Inline functions |