From: "its_Giaan (Code Review)" Date: Tue, 2 Jul 2024 13:50:20 +0000 In-Reply-To: References: Reply-To: gianmarco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., gert@...1296... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="31E8QLscdhM="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Route: add support for user defined routing table List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , cron2 , flichtenheld Cc: openvpn-devel --31E8QLscdhM= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, flichtenheld, its_Giaan, plais= thos. Hello cron2, flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/524?usp=3Demail to look at the new patch set (#5). The following approvals got outdated and were removed: Code-Review+2 by flichtenheld, Code-Review-1 by cron2 The change is no longer submittable: Code-Review and checks~ChecksSubmitRul= e are unsatisfied now. Change subject: Route: add support for user defined routing table ...................................................................... Route: add support for user defined routing table Add the ability for users to specify a custom routing table where routes should be installed in. As of now routes are always installed in the main routing table of the operating system, however, with the new --route-table option it is possibile to specify the ID of the default routing table to be used by --route(-ipv6). Please note: this feature is currently supported only by Linux/SITNL. Support for other platforms should be added in related backends. Fixes: Trac #1399 Change-Id: I3e4ebef484d2a04a383a65ede5617ee98bf218a7 Signed-off-by: Gianmarco De Gregori --- M doc/man-sections/vpn-network-options.rst M src/openvpn/helper.c M src/openvpn/init.c M src/openvpn/options.c M src/openvpn/options.h M src/openvpn/route.c M src/openvpn/route.h 7 files changed, 153 insertions(+), 19 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/24/524/5 diff --git a/doc/man-sections/vpn-network-options.rst b/doc/man-sections/vp= n-network-options.rst index 84d4273..9d4235b 100644 --- a/doc/man-sections/vpn-network-options.rst +++ b/doc/man-sections/vpn-network-options.rst @@ -371,6 +371,14 @@ Like ``--redirect-gateway``, but omit actually changing the default gate= way. Useful when pushing private subnets. +--route-table id + Specify a default table id for use with --route. + By default, OpenVPN installs routes in the main routing + table of the operating system, but with this option, + a user defined routing table can be used instead. + + (Supported on Linux only, on other platforms this is a no-op). + --route args Add route to routing table after connection is established. Multiple routes can be specified. Routes will be automatically torn down in @@ -445,14 +453,20 @@ Setup IPv6 routing in the system to send the specified IPv6 network into OpenVPN's *tun*. - Valid syntax: + Valid syntaxes: :: - route-ipv6 ipv6addr/bits [gateway] [metric] + route-ipv6 ipv6addr/bits + route-ipv6 ipv6addr/bits gateway + route-ipv6 ipv6addr/bits gateway metric - The gateway parameter is only used for IPv6 routes across *tap* devices, - and if missing, the ``ipv6remote`` field from ``--ifconfig-ipv6`` or - ``--route-ipv6-gateway`` is used. + ``gateway`` + Only used for IPv6 routes across *tap* devices, + and if missing, the ``ipv6remote`` field from ``--ifconfig-ipv6`` = or + ``--route-ipv6-gateway`` is used. + + ``metric`` + default taken from ``--route-metric`` if set, otherwise :code:`0`. --route-gateway arg Specify a default *gateway* for use with ``--route``. diff --git a/src/openvpn/helper.c b/src/openvpn/helper.c index bbdbc04..2306760 100644 --- a/src/openvpn/helper.c +++ b/src/openvpn/helper.c @@ -118,7 +118,8 @@ print_in_addr_t(network, 0, &o->gc), print_in_addr_t(netmask, 0, &o->gc), NULL, - NULL); + NULL, + o->route_default_table_id); } static void diff --git a/src/openvpn/init.c b/src/openvpn/init.c index a49e563..8a1038b 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -1499,6 +1499,7 @@ options->routes, gw, metric, + options->route_default_table_id, link_socket_current_remote(link_socket_info), es, ctx)) @@ -1546,7 +1547,7 @@ { add_route_ipv6_to_option_list( options->routes_ipv6, string_alloc(opt_list[i], optio= ns->routes_ipv6->gc), - NULL, NULL ); + NULL, NULL, options->route_defa= ult_table_id); } } @@ -1554,6 +1555,7 @@ options->routes_ipv6, gw, metric, + options->route_default_table_id, link_socket_current_remote_ipv6(link_socket_i= nfo), es, ctx)) diff --git a/src/openvpn/options.c b/src/openvpn/options.c index dbe1425..0214735 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -201,6 +201,10 @@ " pass --ifconfig parms by environment to scripts.\= n" "--ifconfig-nowarn : Don't warn if the --ifconfig option on this side = of the\n" " connection doesn't match the remote side.\n" +#ifdef TARGET_LINUX + "--route-table table_id : Specify a custom routing table for use with = --route(-ipv6).\n" + " If not specified, the id of the default ro= uting table will be used.\n" +#endif "--route network [netmask] [gateway] [metric] :\n" " Add route to routing table after connection\n" " is established. Multiple routes can be specified.\= n" @@ -817,6 +821,7 @@ o->ce.mssfix =3D 0; o->ce.mssfix_default =3D true; o->ce.mssfix_encap =3D true; + o->route_default_table_id =3D 0; o->route_delay_window =3D 30; o->resolve_retry_seconds =3D RESOLV_RETRY_INFINITE; o->resolve_in_advance =3D false; @@ -1908,6 +1913,7 @@ SHOW_STR(route_script); SHOW_STR(route_default_gateway); SHOW_INT(route_default_metric); + SHOW_INT(route_default_table_id); SHOW_BOOL(route_noexec); SHOW_INT(route_delay); SHOW_INT(route_delay_window); @@ -6987,6 +6993,15 @@ cnol_check_alloc(options); add_client_nat_to_option_list(options->client_nat, p[1], p[2], p[3= ], p[4], msglevel); } + else if (streq(p[0], "route-table") && p[1] && !p[2]) + { +#ifndef ENABLE_SITNL + msg(M_WARN, "NOTE: --route-table is supported only on Linux when S= ITNL is built-in"); +#endif + VERIFY_PERMISSION(OPT_P_ROUTE_TABLE); + options->route_default_table_id =3D positive_atoi(p[1]); + + } else if (streq(p[0], "route") && p[1] && !p[5]) { VERIFY_PERMISSION(OPT_P_ROUTE); @@ -7008,8 +7023,10 @@ msg(msglevel, "route parameter gateway '%s' must be a vali= d address", p[3]); goto err; } + /* p[4] is metric, if specified */ } - add_route_to_option_list(options->routes, p[1], p[2], p[3], p[4]); + + add_route_to_option_list(options->routes, p[1], p[2], p[3], p[4], = options->route_default_table_id); } else if (streq(p[0], "route-ipv6") && p[1] && !p[4]) { @@ -7027,9 +7044,10 @@ msg(msglevel, "route-ipv6 parameter gateway '%s' must be a= valid address", p[2]); goto err; } - /* p[3] is metric, if present */ + /* p[3] is metric, if specified */ } - add_route_ipv6_to_option_list(options->routes_ipv6, p[1], p[2], p[= 3]); + + add_route_ipv6_to_option_list(options->routes_ipv6, p[1], p[2], p[= 3], options->route_default_table_id); } else if (streq(p[0], "max-routes") && !p[2]) { diff --git a/src/openvpn/options.h b/src/openvpn/options.h index f608cb8..d3a8141 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -410,6 +410,7 @@ const char *route_predown_script; const char *route_default_gateway; const char *route_ipv6_default_gateway; + int route_default_table_id; int route_default_metric; bool route_noexec; int route_delay; @@ -740,6 +741,7 @@ #define OPT_P_PEER_ID (1<<28) #define OPT_P_INLINE (1<<29) #define OPT_P_PUSH_MTU (1<<30) +#define OPT_P_ROUTE_TABLE (1<<31) #define OPT_P_DEFAULT (~(OPT_P_INSTANCE|OPT_P_PULL_MODE)) diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 91f2032..4b61ea1 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -328,7 +328,6 @@ CLEAR(*r); r->option =3D ro; - /* network */ if (!is_route_parm_defined(ro->network)) @@ -442,6 +441,27 @@ r->flags |=3D RT_DEFINED; + /* routing table id */ + + r->table_id =3D 0; + if (ro->table_id) + { + r->table_id =3D ro->table_id; + if (r->table_id < 0) + { + msg(M_WARN, PACKAGE_NAME "ROUTE: routing table id for network = %s (%d) must be >=3D 0", + ro->network, + ro->table_id); + goto fail; + } + r->flags |=3D RT_TABLE_DEFINED; + } + else if (rl->spec.flags & RTSA_DEFAULT_TABLE_ID) + { + r->table_id =3D rl->spec.table_id; + r->flags |=3D RT_TABLE_DEFINED; + } + return true; fail: @@ -498,6 +518,27 @@ r6->flags |=3D RT_DEFINED; + /* routing table id */ + + r6->table_id =3D 0; + if (r6o->table_id) + { + r6->table_id =3D r6o->table_id; + if (r6->table_id < 0) + { + msg(M_WARN, PACKAGE_NAME "ROUTE: routing table id for network = %s (%d) must be >=3D 0", + r6o->prefix, + r6o->table_id); + goto fail; + } + r6->flags |=3D RT_TABLE_DEFINED; + } + else if (rl6->spec_flags & RTSA_DEFAULT_TABLE_ID) + { + r6->table_id =3D rl6->default_route_table_id; + r6->flags |=3D RT_TABLE_DEFINED; + } + return true; fail: @@ -511,7 +552,8 @@ const char *network, const char *netmask, const char *gateway, - const char *metric) + const char *metric, + int table_id) { struct route_option *ro; ALLOC_OBJ_GC(ro, struct route_option, l->gc); @@ -519,6 +561,7 @@ ro->netmask =3D netmask; ro->gateway =3D gateway; ro->metric =3D metric; + ro->table_id =3D table_id; ro->next =3D l->routes; l->routes =3D ro; @@ -528,13 +571,15 @@ add_route_ipv6_to_option_list(struct route_ipv6_option_list *l, const char *prefix, const char *gateway, - const char *metric) + const char *metric, + int table_id) { struct route_ipv6_option *ro; ALLOC_OBJ_GC(ro, struct route_ipv6_option, l->gc); ro->prefix =3D prefix; ro->gateway =3D gateway; ro->metric =3D metric; + ro->table_id =3D table_id; ro->next =3D l->routes_ipv6; l->routes_ipv6 =3D ro; } @@ -632,6 +677,7 @@ const struct route_option_list *opt, const char *remote_endpoint, int default_metric, + int table_id, in_addr_t remote_host, struct env_set *es, openvpn_net_ctx_t *ctx) @@ -655,6 +701,12 @@ rl->spec.flags |=3D RTSA_DEFAULT_METRIC; } + if (table_id) + { + rl->spec.table_id =3D table_id; + rl->spec.flags |=3D RTSA_DEFAULT_TABLE_ID; + } + get_default_gateway(&rl->rgi, ctx); if (rl->rgi.flags & RGI_ADDR_DEFINED) { @@ -791,6 +843,7 @@ const struct route_ipv6_option_list *opt6, const char *remote_endpoint, int default_metric, + int table_id, const struct in6_addr *remote_host_ipv6, struct env_set *es, openvpn_net_ctx_t *ctx) @@ -815,6 +868,12 @@ rl6->spec_flags |=3D RTSA_DEFAULT_METRIC; } + if (table_id) + { + rl6->default_route_table_id =3D table_id; + rl6->spec_flags |=3D RTSA_DEFAULT_TABLE_ID; + } + msg(D_ROUTE, "GDG6: remote_host_ipv6=3D%s", remote_host_ipv6 ? print_in6_addr(*remote_host_ipv6, 0, &gc) : "n= /a" ); @@ -1608,9 +1667,15 @@ metric =3D r->metric; } + int table_id =3D 0; + if (r->flags & RT_TABLE_DEFINED) + { + table_id =3D r->table_id; + } + status =3D RTA_SUCCESS; int ret =3D net_route_v4_add(ctx, &r->network, netmask_to_netbits2(r->= netmask), - &r->gateway, iface, 0, metric); + &r->gateway, iface, table_id, metric); if (ret =3D=3D -EEXIST) { msg(D_ROUTE, "NOTE: Linux route add command failed because route e= xists"); @@ -1988,10 +2053,16 @@ metric =3D r6->metric; } + int table_id =3D 0; + if ((r6->flags & RT_TABLE_DEFINED) && (r6->table_id > 0)) + { + table_id =3D r6->table_id; + } + status =3D RTA_SUCCESS; int ret =3D net_route_v6_add(ctx, &r6->network, r6->netbits, gateway_needed ? &r6->gateway : NULL, - device, 0, metric); + device, table_id, metric); if (ret =3D=3D -EEXIST) { msg(D_ROUTE, "NOTE: Linux route add command failed because route e= xists"); @@ -2196,8 +2267,14 @@ metric =3D r->metric; } + int table_id =3D 0; + if (r->flags & RT_TABLE_DEFINED) + { + table_id =3D r->table_id; + } + if (net_route_v4_del(ctx, &r->network, netmask_to_netbits2(r->netmask), - &r->gateway, NULL, 0, metric) < 0) + &r->gateway, NULL, table_id, metric) < 0) { msg(M_WARN, "ERROR: Linux route delete command failed"); } @@ -2409,8 +2486,16 @@ metric =3D r6->metric; } + int table_id =3D 0; + if (r6->flags & RT_TABLE_DEFINED) + { + table_id =3D r6->table_id; + } + + + if (net_route_v6_del(ctx, &r6->network, r6->netbits, - gateway_needed ? &r6->gateway : NULL, device, 0, + gateway_needed ? &r6->gateway : NULL, device, tab= le_id, metric) < 0) { msg(M_WARN, "ERROR: Linux route v6 delete command failed"); diff --git a/src/openvpn/route.h b/src/openvpn/route.h index 421e7d2..815aea6 100644 --- a/src/openvpn/route.h +++ b/src/openvpn/route.h @@ -63,12 +63,14 @@ #define RTSA_REMOTE_ENDPOINT (1<<0) #define RTSA_REMOTE_HOST (1<<1) #define RTSA_DEFAULT_METRIC (1<<2) +#define RTSA_DEFAULT_TABLE_ID (1<<3) unsigned int flags; in_addr_t remote_endpoint; in_addr_t remote_host; int remote_host_local; /* TLA_x value */ struct route_bypass bypass; + int table_id; int default_metric; }; @@ -77,6 +79,7 @@ const char *network; const char *netmask; const char *gateway; + int table_id; const char *metric; }; @@ -101,6 +104,7 @@ const char *prefix; /* e.g. "2001:db8:1::/64" */ const char *gateway; /* e.g. "2001:db8:0::2" */ const char *metric; /* e.g. "5" */ + int table_id; }; struct route_ipv6_option_list { @@ -113,12 +117,14 @@ #define RT_DEFINED (1<<0) #define RT_ADDED (1<<1) #define RT_METRIC_DEFINED (1<<2) +#define RT_TABLE_DEFINED (1<<3) struct route_ipv4 *next; unsigned int flags; const struct route_option *option; in_addr_t network; in_addr_t netmask; in_addr_t gateway; + int table_id; int metric; }; @@ -129,6 +135,7 @@ unsigned int netbits; struct in6_addr gateway; int metric; + int table_id; /* gateway interface */ #ifdef _WIN32 DWORD adapter_index; /* interface or ~0 if undefined */ @@ -223,6 +230,7 @@ struct in6_addr remote_endpoint_ipv6; /* inside tun */ struct in6_addr remote_host_ipv6; /* --remote address */ int default_metric; + int default_route_table_id; struct route_ipv6_gateway_info rgi6; unsigned int flags; /* RG_x flags, see route_option_li= st */ @@ -283,17 +291,20 @@ const char *network, const char *netmask, const char *gateway, - const char *metric); + const char *metric, + int table_id); void add_route_ipv6_to_option_list(struct route_ipv6_option_list *l, const char *prefix, const char *gateway, - const char *metric); + const char *metric, + int table_id); bool init_route_list(struct route_list *rl, const struct route_option_list *opt, const char *remote_endpoint, int default_metric, + int table_id, in_addr_t remote_host, struct env_set *es, openvpn_net_ctx_t *ctx); @@ -302,6 +313,7 @@ const struct route_ipv6_option_list *opt6, const char *remote_endpoint, int default_metric, + int table_id, const struct in6_addr *remote_host, struct env_set *es, openvpn_net_ctx_t *ctx); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/524?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I3e4ebef484d2a04a383a65ede5617ee98bf218a7 Gerrit-Change-Number: 524 Gerrit-PatchSet: 5 Gerrit-Owner: its_Giaan Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: its_Giaan Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --31E8QLscdhM= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: cron2, flichtenheld, its_Giaan, p= laisthos.

its_Giaan uploaded patch set #5 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/524?usp=3Demail">View Chang= e

The following approvals got outdated and were removed: Code-Review+2 by flichtenheld, Code-Review-1 by cron2

The change is n= o longer submittable: Code-Review and checks~ChecksSubmitRule are unsatisfi= ed now.

Route: add support for user defined routing table

Add the ab= ility for users to specify a custom
routing table where routes should be= installed in.
As of now routes are always installed in the main
rout= ing table of the operating system, however,
with the new --route-table o= ption it is possibile
to specify the ID of the default routing table
= to be used by --route(-ipv6).

Please note: this feature is currently= supported
only by Linux/SITNL.
Support for other platforms should be= added in related backends.

Fixes: Trac #1399
Change-Id: I3e4ebef= 484d2a04a383a65ede5617ee98bf218a7
Signed-off-by: Gianmarco De Gregori &l= t;gianmarco@...2726...>
---
M doc/man-sections/vpn-network-options= .rst
M src/openvpn/helper.c
M src/openvpn/init.c
M src/openvpn/opt= ions.c
M src/openvpn/options.h
M src/openvpn/route.c
M src/openvpn= /route.h
7 files changed, 153 insertions(+), 19 deletions(-)

g=
it pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/24/524/5
<= pre style=3D"font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/doc/man-sections/vpn-network-options.rst b/doc/man-sections/= vpn-network-options.rst
index 84d4273..9d4235b 100644
--- a/doc/man-sections/vpn-network-options.rst
+= ++ b/doc/man-sections/vpn-network-options.rst
@@ -371,6 +37= 1,14 @@
Like ``--redirect-gateway``, but omit actually c= hanging the default gateway.
Useful when pushing private= subnets.

+--route-table id
+ Specify a default table id for use with --route.
+ By default, OpenVPN installs routes i= n the main routing
+ = table of the operating system, but with this option,
+ a user defined routing table can be use= d instead.
++ (Supported on Linux only, = on other platforms this is a no-op).
+
--route args
Add rout= e to routing table after connection is established. Multiple
routes can be specified. Routes will be automatically torn down in
@@ -445,14 +453,20 @@
Setup IPv6 routing in= the system to send the specified IPv6 network into
Open= VPN's *tun*.

- Valid syntax:
+ Valid syntaxes:
::
- route-ipv6 ipv6addr/bits = [gateway] [metric]
+ = route-ipv6 ipv6addr/bits
+ route-ipv6 ipv6addr/bits gateway
+ route-ipv6 ipv6addr/bits gateway metric

- The g= ateway parameter is only used for IPv6 routes across *tap* devices,<= br>- and if missing, the ``ipv6r= emote`` field from ``--ifconfig-ipv6`` or
- ``--route-ipv6-gateway`` is used.
+ ``gateway``
+ Only used for IPv6 routes across *tap= * devices,
+ a= nd if missing, the ``ipv6remote`` field from ``--ifconfig-ipv6`` or<= br>+ ``--route-ipv6-gate= way`` is used.
+

+ ``metric``
<= span style=3D"color: hsl(120, 100%, 40%);">+ default taken from ``--= route-metric`` if set, otherwise :code:`0`.


--route-gateway arg
Specify a default *gateway* for = use with ``--route``.
diff --git a/src/openvpn/helper.c b/s= rc/openvpn/helper.c
index bbdbc04..2306760 100644--- a/src/openvpn/helper.c
+++ b/src/openvpn/helper.= c
@@ -118,7 +118,8 @@
= print_in_addr_t(network, 0, &o->gc),
= print_in_addr_t(netmask, 0, &o->gc),<= br> NULL,
- NULL);
+ NULL,
+ = o->route_default_table_id);
}
=
static void
diff --git a/src/openvpn/init= .c b/src/openvpn/init.c
index a49e563..8a1038b 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.= c
@@ -1499,6 +1499,7 @@
= options->routes,
gw,

metric,
+ options->route_default_= table_id,
link_socket_current_remo= te(link_socket_info),
es, ctx))
@@ -1546,7 +1547,7 @= @
{
add_route_ipv6_to= _option_list( options->routes_ipv6,
= string_alloc(opt_list[i], options->routes_ipv6-&= gt;gc),
- = NULL, NULL );
+ NULL, NUL= L, options->route_default_table_id);
} }

@@ -1554,6 +1555,7 @@
options->routes_ipv6, gw,
= metric,
= + options->route_default_table_id, link_socket_current_remote_ipv6(link_s= ocket_info),
es,
ctx))

diff --git a/src/op= envpn/options.c b/src/openvpn/options.c
index dbe1425..0214= 735 100644
--- a/src/openvpn/options.c
+++ = b/src/openvpn/options.c
@@ -201,6 +201,10 @@
" pass --ifconfig parms by environment to sc= ripts.\n"
"--ifconfig-nowarn : Don't war= n if the --ifconfig option on this side of the\n"
= " connection doesn't match the remote side.\n&= quot;
+#ifdef TARGET_= LINUX
+ "--ro= ute-table table_id : Specify a custom routing table for use with --route(-i= pv6).\n"
+ &q= uot; If not specified, the id of the default rout= ing table will be used.\n"
+#endif
"--route network [netmask] [ga= teway] [metric] :\n"
" Add = route to routing table after connection\n"
"= is established. Multiple routes can be specified.\n"= ;
@@ -817,6 +821,7 @@
o->ce.mssfix = =3D 0;
o->ce.mssfix_default =3D true;
o->ce.mssfix_encap =3D true;
+ o->route_default_table_id =3D 0;
o->route_delay_window =3D 30;
o->resolve_r= etry_seconds =3D RESOLV_RETRY_INFINITE;
o->resolve_= in_advance =3D false;
@@ -1908,6 +1913,7 @@
SHOW_STR(route_script);
SHOW_STR(route_default_g= ateway);
SHOW_INT(route_default_metric);
+ SHOW_INT(route_default_table_= id);
SHOW_BOOL(route_noexec);
SHO= W_INT(route_delay);
SHOW_INT(route_delay_window);

@@ -6987,6 +6993,15 @@
cnol_check_allo= c(options);
add_client_nat_to_option_list(options-= >client_nat, p[1], p[2], p[3], p[4], msglevel);
}
+ else if (streq(p[= 0], "route-table") && p[1] && !p[2])
+ {

+#ifndef ENABLE_SITNL
+ msg(M_WARN, "NOTE: --route-table= is supported only on Linux when SITNL is built-in");
+#endif
+ VERIFY_PERMISSION(OPT_P_ROUTE_TABLE);
+ options->rou= te_default_table_id =3D positive_atoi(p[1]);
+
+ }
else if (streq(p[0], "route") &a= mp;& p[1] && !p[5])
{
= VERIFY_PERMISSION(OPT_P_ROUTE);
@@ -7008,8 +7023,10 @@=
msg(msglevel, "route parameter gatew= ay '%s' must be a valid address", p[3]);
= goto err;
}
+ /* p[4] is metric, if specifi= ed */
}
- add_route_to_option_list(options->routes, p[1], p[2],= p[3], p[4]);
+
+ add_route_to_opti= on_list(options->routes, p[1], p[2], p[3], p[4], options->route_defau= lt_table_id);
}
else if (streq(p[= 0], "route-ipv6") && p[1] && !p[4])
{

@@ -7027,9 +7044,10 @@
= msg(msglevel, "route-ipv6 parameter gateway '%s' must b= e a valid address", p[2]);
goto err;<= /span>
}
- /* p[3] is metric, if present */
+ /* p[3] is metric, if specifi= ed */
}
- add_route_ipv6_to_option_list(options->routes_ipv6, p= [1], p[2], p[3]);
+
+ add_route_ipv= 6_to_option_list(options->routes_ipv6, p[1], p[2], p[3], options->rou= te_default_table_id);
}
else if (= streq(p[0], "max-routes") && !p[2])
= {
diff --git a/src/openvpn/options.h b/src/openvpn/options.= h
index f608cb8..d3a8141 100644
--- a/src/o= penvpn/options.h
+++ b/src/openvpn/options.h
@@ -410,6 +410,7 @@

const char *route_predown_script= ;
const char *route_default_gateway;
= const char *route_ipv6_default_gateway;
+ int route_default_table_id;
= int route_default_metric;
bool route_noexec;<= br> int route_delay;
@@ -740,6 +741,7 @@ #define OPT_P_PEER_ID (1<<28)
#defi= ne OPT_P_INLINE (1<<29)
#define OPT_P_PUSH_= MTU (1<<30)
+#define OPT_P_ROUTE_TABLE (1<<31)
#define OPT_P_DEFAULT (~(OPT_P_INSTANCE|OPT_P_PULL_MODE))=

diff --git a/src/openvpn/route.c b/src/openvpn/= route.c
index 91f2032..4b61ea1 100644
--- a= /src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -328,7 +328,6 @@


CLEAR(*r);
r->option =3D ro;
-
/* network */

if (!is_route_parm_defined(ro->network))
@@ -442,6 +441,27 @@


r->flags= |=3D RT_DEFINED;

+ /* routing table id */
+
+ r->table_id =3D 0;
+ if (ro->table_id)
+ {
= + r->table_id =3D ro->table_id;
+ if (r->table_id < 0)
+ {

+ msg(M_WARN, PACKAGE_NAME "RO= UTE: routing table id for network %s (%d) must be >=3D 0",+ ro->netwo= rk,
+ = ro->table_id);
+ = goto fail;
= + }
+ r= ->flags |=3D RT_TABLE_DEFINED;
+ }
+= else if (rl->spec.flags & RTSA_DEFAULT_TABLE_ID)
+ {

+ r->table_id =3D rl->spec.table_id;<= /span>
+ r->flags = |=3D RT_TABLE_DEFINED;
+
= return true;

fail:
= @@ -498,6 +518,27 @@

r6->fl= ags |=3D RT_DEFINED;

+ /* routing table id */
+
+ r6->table_id =3D 0;
+ if (r6o->table_id)
+ {
+ r6->table_id =3D r6o->table_id;
+ if (r6->table_id < 0)
+ {
+ msg(M_WARN, PACKAGE_NAM= E "ROUTE: routing table id for network %s (%d) must be >=3D 0"= ,

+ r6= o->prefix,
+ = r6o->table_id);
+ goto fail;
+ }
+ r6->flags |=3D RT_TABLE_DEFINED;
+ }
+ else if (rl6->spec_flags & RTSA_DEFAULT_TABLE_ID)
+ {
+ r6->table_id =3D rl6->= default_route_table_id;
+ r6->flags |=3D RT_TABLE_DEFINED;
+ }
+
return true;
fail:
@@ -511,7 +552,8 @@
= const char *network,
= const char *netmask,
const = char *gateway,
- = const char *metric)
+ const char *metric,
+ int tab= le_id)

{
struct route_option *ro;
ALLOC_OBJ_GC(ro, struct route_option, l->gc);@@ -519,6 +561,7 @@
ro->netmask =3D netmask= ;
ro->gateway =3D gateway;
ro-= >metric =3D metric;
- const char *metric)
+ const char= *metric,
+ = int table_id)
{
s= truct route_ipv6_option *ro;
ALLOC_OBJ_GC(ro, struct r= oute_ipv6_option, l->gc);
ro->prefix =3D prefix;=
ro->gateway =3D gateway;
ro-&= gt;metric =3D metric;
+ ro->table_id =3D table_id;
ro->next =3D l-= >routes_ipv6;
l->routes_ipv6 =3D ro;
<= span> }

@@ -632,6 +677,7 @@
= const struct route_option_list *opt,
con= st char *remote_endpoint,
int default_metr= ic,
+ = int table_id,
in_addr_t remote_host,
struct env_set *es,
= openvpn_net_ctx_t *ctx)
@@ -655,6 +701,12 @@ rl->spec.flags |=3D RTSA_DEFAULT_METRIC;
}


+ if (table_id)
+ {
+ r= l->spec.table_id =3D table_id;
+ rl->spec.flags |=3D RTSA_DEFAULT_TABLE_ID;<= br>+ }
+
get_default_gateway= (&rl->rgi, ctx);
if (rl->rgi.flags & RGI= _ADDR_DEFINED)
{
@@ -791,6 +843,7 @@
const struct route_ipv6_option_list *o= pt6,
const char *remote_endpoint,
int default_metric,
+ int table_id,
const struct in6_addr *remote_host_ipv6,
struct env_set *es,
= openvpn_net_ctx_t *ctx)
@@ -815,6 +868,= 12 @@
rl6->spec_flags |=3D RTSA_DEFAULT_METRIC;=
}

+ if (table_id)
+ {
+ rl6->default_route_table_id =3D table_id;
+ rl6->spec_flags |=3D RTSA= _DEFAULT_TABLE_ID;
+ = }
+
msg(D_ROUTE, "GDG6: remote_host_ipv6=3D%s",

remote_host_ipv6 ? print_in6_addr(*remote_host_ipv6, 0, &gc= ) : "n/a" );


@@ -1608,9 +1667,1= 5 @@
metric =3D r->metric;
= }

= + int table_id =3D 0;
+ if (r->flags & RT_TABLE_DEFINED)
+ {
+ table_id =3D r->table_id;
+ }
+
status =3D RTA_SUCCESS; int ret =3D net_route_v4_add(ctx, &r->network, netmask_t= o_netbits2(r->netmask),
- &r->gateway, iface, 0, metric);<= /span>
+ = &r->gateway, iface, table_id, metric);
= if (ret =3D=3D -EEXIST)
{
= msg(D_ROUTE, "NOTE: Linux route add command failed because route exist= s");
@@ -1988,10 +2053,16 @@
= metric =3D r6->metric;
}
+ int table_id =3D 0;
+ if ((r6->flags &a= mp; RT_TABLE_DEFINED) && (r6->table_id > 0))
+ {
+ table_id =3D r6->table_id;
+ }

+
status =3D RTA_SUCCESS;<= /span>
int ret =3D net_route_v6_add(ctx, &r6->network,= r6->netbits,
gateway_ne= eded ? &r6->gateway : NULL,
- device, 0, metric);
<= span style=3D"color: hsl(120, 100%, 40%);">+ = device, table_id, metric);

if (ret =3D=3D -EEXIST)
{
msg(D_ROUTE, "NOTE: Linux= route add command failed because route exists");
@@ -= 2196,8 +2267,14 @@
metric =3D r->metric;=
}

+ int table_id =3D 0;
+ if (r->flags & RT_TABLE_DEFINED)
+ {

+ table_id =3D r->table_id;+ }
+
if (net_route_v4_de= l(ctx, &r->network, netmask_to_netbits2(r->netmask),
- &r-&g= t;gateway, NULL, 0, metric) < 0)

+ &r->gateway, NULL, table_id= , metric) < 0)
{
msg(M_WAR= N, "ERROR: Linux route delete command failed");
= }
@@ -2409,8 +2486,16 @@
metri= c =3D r6->metric;
}

+ int table_id =3D 0;
+ if (r6->flags & RT= _TABLE_DEFINED)
+ = {
+ table_id = =3D r6->table_id;
= + }
+
+

+
if (net_route_v6_del(ctx, &am= p;r6->network, r6->netbits,
- gateway_needed ? &r6->gateway := NULL, device, 0,
+ = gateway_needed ? &r6->gateway : NULL, device,= table_id,
metric) < 0)=
{
msg(M_WARN, "ERROR: Linux ro= ute v6 delete command failed");
diff --git a/src/openv= pn/route.h b/src/openvpn/route.h
index 421e7d2..815aea6 100= 644
--- a/src/openvpn/route.h
+++ b/src/ope= nvpn/route.h
@@ -63,12 +63,14 @@
#define R= TSA_REMOTE_ENDPOINT (1<<0)
#define RTSA_REMOTE_HOST= (1<<1)
#define RTSA_DEFAULT_METRIC (1<<= ;2)
+#define RTSA_DEF= AULT_TABLE_ID (1<<3)
unsigned int flags;<= br>
in_addr_t remote_endpoint;
= in_addr_t remote_host;
int remote_host_local; /* = TLA_x value */
struct route_bypass bypass;
<= span style=3D"color: hsl(120, 100%, 40%);">+ int table_id;

int default_metric;
};
@@ -77,6 +79,7 @@
const char *network; const char *netmask;
const char *gateway;=
+ int table_id;
const char *metric;
};

@@ -101,6 +104,7 @@
const char *pre= fix; /* e.g. "2001:db8:1::/64" */
co= nst char *gateway; /* e.g. "2001:db8:0::2" */
const char *metric; /* e.g. "5" */
+ int table_id;
};

struct route_ipv6_option_list {

@@ -113,12 +117,14 @@
#define RT_DEFINED = (1<<0)
#define RT_ADDED (1<<1)

#define RT_METRIC_DEFINED (1<<2)
+#define RT_TABLE_DEFINED (1<<3)
struct route_ipv4 *next;
unsigned i= nt flags;
const struct route_option *option; in_addr_t network;
in_addr_t netmask;
in_addr_t gateway;
+ int table_id;
int metric; };

@@ -129,6 +135,7 @@ unsigned int netbits;
struct in6_addr gate= way;
int metric;
+ int table_id;
/* gateway interfa= ce */
#ifdef _WIN32
DWORD adapter_ind= ex; /* interface or ~0 if undefined */
@@ -223,6 +23= 0,7 @@
struct in6_addr remote_endpoint_ipv6; /* inside= tun */
struct in6_addr remote_host_ipv6; /* --remot= e address */
int default_metric;
+ int default_route_table_id;
struct route_ipv6_gateway_info rgi6; unsigned int flags; /* RG_x flags, see route_o= ption_list */
@@ -283,17 +291,20 @@
= const char *network,
= const char *netmask,
= const char *gateway,
- const char *metric);
+ const= char *metric,

+ = int table_id);

= void add_route_ipv6_to_option_list(struct route_ipv6_option_list *l,=
const char *prefix, const char *gateway,
<= span style=3D"color: hsl(0, 100%, 40%);">- = const char *metric);

+ in= t table_id);

bool init_route_list(struct= route_list *rl,
const struct route_o= ption_list *opt,
const char *remote_e= ndpoint,
int default_metric,+ int tab= le_id,
in_addr_t remote_host,<= br> struct env_set *es,
= openvpn_net_ctx_t *ctx);
@@ -302,6 +313,7 @@<= /span>
const struct route_ipv6_option_l= ist *opt6,
const char *remote_en= dpoint,
int default_metric,
+ = int table_id,
const struct in6= _addr *remote_host,
struct env_s= et *es,
openvpn_net_ctx_t *ctx);=

To view, visit change 524. To unsubscribe, = or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I3e4ebef484d2a04a383a65ede56= 17ee98bf218a7
Gerrit-Change-Number: 524
Gerrit-PatchSet: 5
Gerrit-Owner: its_Giaan <gianmarco@...2786...= ..>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: cron2 <gert@...1296...>= ;
Gerrit-Attention: its_Giaan <gianmarco@...1665...= 726...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newpatchset
--31E8QLscdhM=--