Skip to content

Commit 2777cdd

Browse files
mrbffcron2
authored andcommitted
route: handle default gateway (net_gateway) and nexthop towards VPN server separately
Right now there is the assumption that the gateway used for net_gateway is the same used to reach the VPN server. However, these two gateways may be different (i.e. when there is a specific hostroute for the VPN server using a different nexthop). For this reason we must adapt init_route_list() to fetch the two gateways separately. Github: fixes #890 Change-Id: I16d90221d0a75193035253817ff195f6da9dc0b3 Signed-off-by: Marco Baffo <[email protected]> Acked-by: Gert Doering <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1222 Message-Id: <[email protected]> URL: https://www.mail-archive.com/[email protected]/msg34529.html Signed-off-by: Gert Doering <[email protected]>
1 parent 3d0d4b1 commit 2777cdd

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/openvpn/route.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ get_special_addr(const struct route_list *rl, const char *string, in_addr_t *out
257257
{
258258
if (rl)
259259
{
260-
if (rl->rgi.flags & RGI_ADDR_DEFINED)
260+
if (rl->ngi.flags & RGI_ADDR_DEFINED)
261261
{
262-
*out = rl->rgi.gateway.addr;
262+
*out = rl->ngi.gateway.addr;
263263
}
264264
else
265265
{
@@ -624,10 +624,10 @@ init_route_list(struct route_list *rl, const struct route_option_list *opt,
624624
rl->spec.flags |= RTSA_DEFAULT_METRIC;
625625
}
626626

627-
get_default_gateway(&rl->rgi, remote_host != IPV4_INVALID_ADDR ? remote_host : INADDR_ANY, ctx);
628-
if (rl->rgi.flags & RGI_ADDR_DEFINED)
627+
get_default_gateway(&rl->ngi, INADDR_ANY, ctx);
628+
if (rl->ngi.flags & RGI_ADDR_DEFINED)
629629
{
630-
setenv_route_addr(es, "net_gateway", rl->rgi.gateway.addr, -1);
630+
setenv_route_addr(es, "net_gateway", rl->ngi.gateway.addr, -1);
631631
#if defined(ENABLE_DEBUG) && !defined(ENABLE_SMALL)
632632
print_default_gateway(D_ROUTE, &rl->rgi, NULL);
633633
#endif
@@ -637,6 +637,8 @@ init_route_list(struct route_list *rl, const struct route_option_list *opt,
637637
dmsg(D_ROUTE, "ROUTE: default_gateway=UNDEF");
638638
}
639639

640+
get_default_gateway(&rl->rgi, remote_host != IPV4_INVALID_ADDR ? remote_host : INADDR_ANY, ctx);
641+
640642
if (rl->spec.flags & RTSA_REMOTE_HOST)
641643
{
642644
rl->spec.remote_host_local = test_local_addr(remote_host, &rl->rgi);
@@ -773,10 +775,10 @@ init_route_ipv6_list(struct route_ipv6_list *rl6, const struct route_ipv6_option
773775
msg(D_ROUTE, "GDG6: remote_host_ipv6=%s",
774776
remote_host_ipv6 ? print_in6_addr(*remote_host_ipv6, 0, &gc) : "n/a");
775777

776-
get_default_gateway_ipv6(&rl6->rgi6, remote_host_ipv6, ctx);
777-
if (rl6->rgi6.flags & RGI_ADDR_DEFINED)
778+
get_default_gateway_ipv6(&rl6->ngi6, NULL, ctx);
779+
if (rl6->ngi6.flags & RGI_ADDR_DEFINED)
778780
{
779-
setenv_str(es, "net_gateway_ipv6", print_in6_addr(rl6->rgi6.gateway.addr_ipv6, 0, &gc));
781+
setenv_str(es, "net_gateway_ipv6", print_in6_addr(rl6->ngi6.gateway.addr_ipv6, 0, &gc));
780782
#if defined(ENABLE_DEBUG) && !defined(ENABLE_SMALL)
781783
print_default_gateway(D_ROUTE, NULL, &rl6->rgi6);
782784
#endif
@@ -786,6 +788,8 @@ init_route_ipv6_list(struct route_ipv6_list *rl6, const struct route_ipv6_option
786788
dmsg(D_ROUTE, "ROUTE6: default_gateway=UNDEF");
787789
}
788790

791+
get_default_gateway_ipv6(&rl6->rgi6, remote_host_ipv6, ctx);
792+
789793
if (is_route_parm_defined(remote_endpoint))
790794
{
791795
if (inet_pton(AF_INET6, remote_endpoint, &rl6->remote_endpoint_ipv6) == 1)

src/openvpn/route.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ struct route_list
234234

235235
struct route_special_addr spec;
236236
struct route_gateway_info rgi;
237-
unsigned int flags; /* RG_x flags */
237+
struct route_gateway_info ngi; /* net_gateway */
238+
unsigned int flags; /* RG_x flags */
238239
struct route_ipv4 *routes;
239240
struct gc_arena gc;
240241
};
@@ -249,7 +250,8 @@ struct route_ipv6_list
249250
int default_metric;
250251

251252
struct route_ipv6_gateway_info rgi6;
252-
unsigned int flags; /* RG_x flags, see route_option_list */
253+
struct route_ipv6_gateway_info ngi6; /* net_gateway_ipv6 */
254+
unsigned int flags; /* RG_x flags, see route_option_list */
253255
struct route_ipv6 *routes_ipv6;
254256
struct gc_arena gc;
255257
};

0 commit comments

Comments
 (0)