Route: add support for user defined routing table
PATCH 1/1 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).
The --route(-ipv6) directives have been extended with an additional argument (5th for --route) (4th for --route-ipv6) so that each of them can possibly use an independent routing table.
Please note: this feature is currently supported
only by Linux/SITNL.
Support for other platforms should be added in related backends.
--- doc/man-sections/vpn-network-options.rst | 16 +++- src/openvpn/helper.c | 1 + src/openvpn/init.c | 15 +++- src/openvpn/options.c | 44 +++++++++- src/openvpn/options.h | 1 + src/openvpn/route.c | 101 +++++++++++++++++++++-- src/openvpn/route.h | 17 +++- 7 files changed, 179 insertions(+), 16 deletions(-)
doc/man-sections/vpn-network-options.rst +15 -1
@@ -367,6 +367,14 @@ routing. Like ``--redirect-gateway``, but omit actually changing 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 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
@@ -379,6 +387,7 @@ routing. route network/IP netmask route network/IP netmask gateway route network/IP netmask gateway metric + route network/IP netmask gateway metric table-id This option is intended as a convenience proxy for the ``route``\(8) shell command, while at the same time providing portable semantics
@@ -394,6 +403,9 @@ routing. ``metric`` default taken from ``--route-metric`` if set, otherwise :code:`0`. + ``table-id`` (Supported on Linux only, on other platforms this is a no-op). + default taken from ``--route-table`` if set, otherwise :code:`0`. + The default can be specified by leaving an option blank or setting it to :code:`default`.
@@ -444,12 +456,14 @@ routing. Valid syntax: :: - route-ipv6 ipv6addr/bits [gateway] [metric] + route-ipv6 ipv6addr/bits [gateway] [metric] [table-id] 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. + (table-id supported on Linux only, on other platforms this is a no-op). + --route-gateway arg Specify a default *gateway* for use with ``--route``.
src/openvpn/helper.c +1 -0
@@ -120,6 +120,7 @@ helper_add_route(const in_addr_t network, const in_addr_t netmask, struct optionprint_in_addr_t (network,0 , &o->gc),print_in_addr_t (netmask,0 , &o->gc),NULL , +NULL , NULL); }
src/openvpn/init.c +14 -1
@@ -1504,6 +1504,7 @@ do_init_route_list(const struct options *options,const char *gw =NULL ;int dev =dev_type_enum (options->dev, options->dev_type);int metric =0 ; +uint32_t table_id =0 ;/* unspec table */ /* if DCO is enabled we have both regular routes and iroutes in the system * routing table, and normal routes must have a higher metric for that to
@@ -1522,6 +1523,10 @@ do_init_route_list(const struct options *options, { gw = options->route_default_gateway; } +if (options->route_default_table_id) + { + table_id = options->route_default_table_id; + }if (options->route_default_metric) { metric = options->route_default_metric;
@@ -1530,6 +1535,7 @@ do_init_route_list(const struct options *options, if (init_route_list(route_list, options->routes, gw, + table_id, metric, link_socket_current_remote(link_socket_info), es,
@@ -1549,6 +1555,7 @@ do_init_route_ipv6_list(const struct options *options, {const char *gw =NULL ;int metric =-1 ;/* no metric set */ +uint32_t table_id =0 ;/* unspec table */ /* see explanation in do_init_route_list() */ if (dco_enabled (options))
@@ -1567,6 +1574,11 @@ do_init_route_ipv6_list(const struct options *options, metric = options->route_default_metric; } +if (options->route_default_table_id) + { + table_id = options->route_default_table_id; + } +/* redirect (IPv6) gateway to VPN? if yes, add a few more specifics */ if (options->routes_ipv6->flags &RG_REROUTE_GW )
@@ -1578,7 +1590,7 @@ do_init_route_ipv6_list(const struct options *options, {add_route_ipv6_to_option_list ( options->routes_ipv6,string_alloc (opt_list[i], options->routes_ipv6->gc), -NULL ,NULL ); +NULL ,NULL ,NULL ); } }
@@ -1586,6 +1598,7 @@ do_init_route_ipv6_list(const struct options *options, options->routes_ipv6, gw, metric, + table_id,link_socket_current_remote_ipv6 (link_socket_info), es, ctx))
src/openvpn/options.c +40 -4
63 lines not on this page · raw message
src/openvpn/options.h +1 -0
@@ -411,6 +411,7 @@ struct optionsconst char *route_predown_script;const char *route_default_gateway;const char *route_ipv6_default_gateway; +uint32_t route_default_table_id;int route_default_metric;bool route_noexec;int route_delay;
src/openvpn/route.c +93 -8
204 lines not on this page · raw message
src/openvpn/route.h +15 -2
@@ -63,12 +63,14 @@ struct route_special_addr#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; +uint32_t table_id;int default_metric; };
@@ -77,6 +79,7 @@ struct route_option {const char *network;const char *netmask;const char *gateway; +const char *table_id;const char *metric; };
@@ -92,6 +95,7 @@ struct route_option {struct route_option_list {unsigned int flags;/* RG_x flags */ +struct route_option *routes;struct gc_arena *gc; };
@@ -101,6 +105,7 @@ struct route_ipv6_option {const char *prefix;/* e.g. "2001:db8:1::/64" */ const char *gateway;/* e.g. "2001:db8:0::2" */ const char *metric;/* e.g. "5" */ +const char *table_id; };struct route_ipv6_option_list {
@@ -113,12 +118,14 @@ struct route_ipv4 {#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; +uint32_t table_id;int metric; };
@@ -129,6 +136,7 @@ struct route_ipv6 {unsigned int netbits;struct in6_addr gateway;int metric; +uint32_t table_id;/* gateway interface */ #ifdef _WIN32DWORD adapter_index;/* interface or ~0 if undefined */
@@ -223,6 +231,7 @@ struct route_ipv6_list {struct in6_addr remote_endpoint_ipv6;/* inside tun */ struct in6_addr remote_host_ipv6;/* --remote address */ int default_metric; +uint32_t default_route_table_id;struct route_ipv6_gateway_info rgi6;unsigned int flags;/* RG_x flags, see route_option_list */
@@ -271,17 +280,20 @@ void add_route_to_option_list(struct route_option_list *l,const char *network, const char *netmask, const char *gateway, - const char *metric); + const char *metric, + const char *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, +const char *table_id);bool init_route_list (struct route_list *rl,const struct route_option_list *opt,const char *remote_endpoint,int default_metric, +uint32_t table_id,in_addr_t remote_host,struct env_set *es,openvpn_net_ctx_t *ctx);
@@ -290,6 +302,7 @@ bool init_route_ipv6_list(struct route_ipv6_list *rl6,const struct route_ipv6_option_list *opt6, const char *remote_endpoint, int default_metric, + uint32_t table_id, const struct in6_addr *remote_host, struct env_set *es, openvpn_net_ctx_t *ctx);
Signature · 1 line
2.37.2
PATCH v2 1/1 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).
The --route(-ipv6) directives have been extended with an additional argument (5th for --route) (4th for --route-ipv6) so that each of them can possibly use an independent routing table.
Please note: this feature is currently supported
only by Linux/SITNL.
Support for other platforms should be added in related backends.
---
Changes from v1:
* fixed parameters (metric and table_id) order in init_route_list() call in init.c : 1535.
doc/man-sections/vpn-network-options.rst | 16 +++- src/openvpn/helper.c | 1 + src/openvpn/init.c | 15 +++- src/openvpn/options.c | 44 +++++++++- src/openvpn/options.h | 1 + src/openvpn/route.c | 101 +++++++++++++++++++++-- src/openvpn/route.h | 17 +++- 7 files changed, 179 insertions(+), 16 deletions(-)
doc/man-sections/vpn-network-options.rst +15 -1
@@ -367,6 +367,14 @@ routing. Like ``--redirect-gateway``, but omit actually changing 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 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
@@ -379,6 +387,7 @@ routing. route network/IP netmask route network/IP netmask gateway route network/IP netmask gateway metric + route network/IP netmask gateway metric table-id This option is intended as a convenience proxy for the ``route``\(8) shell command, while at the same time providing portable semantics
@@ -394,6 +403,9 @@ routing. ``metric`` default taken from ``--route-metric`` if set, otherwise :code:`0`. + ``table-id`` (Supported on Linux only, on other platforms this is a no-op). + default taken from ``--route-table`` if set, otherwise :code:`0`. + The default can be specified by leaving an option blank or setting it to :code:`default`.
@@ -444,12 +456,14 @@ routing. Valid syntax: :: - route-ipv6 ipv6addr/bits [gateway] [metric] + route-ipv6 ipv6addr/bits [gateway] [metric] [table-id] 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. + (table-id supported on Linux only, on other platforms this is a no-op). + --route-gateway arg Specify a default *gateway* for use with ``--route``.
src/openvpn/helper.c +1 -0
@@ -120,6 +120,7 @@ helper_add_route(const in_addr_t network, const in_addr_t netmask, struct optionprint_in_addr_t (network,0 , &o->gc),print_in_addr_t (netmask,0 , &o->gc),NULL , +NULL , NULL); }
src/openvpn/init.c +14 -1
@@ -1504,6 +1504,7 @@ do_init_route_list(const struct options *options,const char *gw =NULL ;int dev =dev_type_enum (options->dev, options->dev_type);int metric =0 ; +uint32_t table_id =0 ;/* unspec table */ /* if DCO is enabled we have both regular routes and iroutes in the system * routing table, and normal routes must have a higher metric for that to
@@ -1522,6 +1523,10 @@ do_init_route_list(const struct options *options, { gw = options->route_default_gateway; } +if (options->route_default_table_id) + { + table_id = options->route_default_table_id; + }if (options->route_default_metric) { metric = options->route_default_metric;
@@ -1531,6 +1536,7 @@ do_init_route_list(const struct options *options, options->routes, gw, metric, + table_id,link_socket_current_remote (link_socket_info), es, ctx))
@@ -1549,6 +1555,7 @@ do_init_route_ipv6_list(const struct options *options, {const char *gw =NULL ;int metric =-1 ;/* no metric set */ +uint32_t table_id =0 ;/* unspec table */ /* see explanation in do_init_route_list() */ if (dco_enabled (options))
@@ -1567,6 +1574,11 @@ do_init_route_ipv6_list(const struct options *options, metric = options->route_default_metric; } +if (options->route_default_table_id) + { + table_id = options->route_default_table_id; + } +/* redirect (IPv6) gateway to VPN? if yes, add a few more specifics */ if (options->routes_ipv6->flags &RG_REROUTE_GW )
@@ -1578,7 +1590,7 @@ do_init_route_ipv6_list(const struct options *options, {add_route_ipv6_to_option_list ( options->routes_ipv6,string_alloc (opt_list[i], options->routes_ipv6->gc), -NULL ,NULL ); +NULL ,NULL ,NULL ); } }
@@ -1586,6 +1598,7 @@ do_init_route_ipv6_list(const struct options *options, options->routes_ipv6, gw, metric, + table_id,link_socket_current_remote_ipv6 (link_socket_info), es, ctx))
src/openvpn/options.c +40 -4
63 lines not on this page · raw message
src/openvpn/options.h +1 -0
@@ -411,6 +411,7 @@ struct optionsconst char *route_predown_script;const char *route_default_gateway;const char *route_ipv6_default_gateway; +uint32_t route_default_table_id;int route_default_metric;bool route_noexec;int route_delay;
src/openvpn/route.c +93 -8
204 lines not on this page · raw message
src/openvpn/route.h +15 -2
@@ -63,12 +63,14 @@ struct route_special_addr#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; +uint32_t table_id;int default_metric; };
@@ -77,6 +79,7 @@ struct route_option {const char *network;const char *netmask;const char *gateway; +const char *table_id;const char *metric; };
@@ -92,6 +95,7 @@ struct route_option {struct route_option_list {unsigned int flags;/* RG_x flags */ +struct route_option *routes;struct gc_arena *gc; };
@@ -101,6 +105,7 @@ struct route_ipv6_option {const char *prefix;/* e.g. "2001:db8:1::/64" */ const char *gateway;/* e.g. "2001:db8:0::2" */ const char *metric;/* e.g. "5" */ +const char *table_id; };struct route_ipv6_option_list {
@@ -113,12 +118,14 @@ struct route_ipv4 {#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; +uint32_t table_id;int metric; };
@@ -129,6 +136,7 @@ struct route_ipv6 {unsigned int netbits;struct in6_addr gateway;int metric; +uint32_t table_id;/* gateway interface */ #ifdef _WIN32DWORD adapter_index;/* interface or ~0 if undefined */
@@ -223,6 +231,7 @@ struct route_ipv6_list {struct in6_addr remote_endpoint_ipv6;/* inside tun */ struct in6_addr remote_host_ipv6;/* --remote address */ int default_metric; +uint32_t default_route_table_id;struct route_ipv6_gateway_info rgi6;unsigned int flags;/* RG_x flags, see route_option_list */
@@ -271,17 +280,20 @@ void add_route_to_option_list(struct route_option_list *l,const char *network, const char *netmask, const char *gateway, - const char *metric); + const char *metric, + const char *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, +const char *table_id);bool init_route_list (struct route_list *rl,const struct route_option_list *opt,const char *remote_endpoint,int default_metric, +uint32_t table_id,in_addr_t remote_host,struct env_set *es,openvpn_net_ctx_t *ctx);
@@ -290,6 +302,7 @@ bool init_route_ipv6_list(struct route_ipv6_list *rl6,const struct route_ipv6_option_list *opt6, const char *remote_endpoint, int default_metric, + uint32_t table_id, const struct in6_addr *remote_host, struct env_set *es, openvpn_net_ctx_t *ctx);
Signature · 1 line
2.37.2
PATCH v3 1/1 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).
The --route(-ipv6) directives have been extended with an additional argument (5th for --route) (4th for --route-ipv6) so that each of them can possibly use an independent routing table.
Please note: this feature is currently supported
only by Linux/SITNL.
Support for other platforms should be added in related backends.
---
Changes from v1:
* Fixed parameters (metric and table_id) order in init_route_list() call in init.c : 1535.
Changes from v2:
* Add route_default_table_id to show_settings() in options.c : 1800.
doc/man-sections/vpn-network-options.rst | 16 +++- src/openvpn/helper.c | 1 + src/openvpn/init.c | 15 +++- src/openvpn/options.c | 45 +++++++++- src/openvpn/options.h | 1 + src/openvpn/route.c | 101 +++++++++++++++++++++-- src/openvpn/route.h | 17 +++- 7 files changed, 180 insertions(+), 16 deletions(-)
doc/man-sections/vpn-network-options.rst +15 -1
@@ -367,6 +367,14 @@ routing. Like ``--redirect-gateway``, but omit actually changing 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 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
@@ -379,6 +387,7 @@ routing. route network/IP netmask route network/IP netmask gateway route network/IP netmask gateway metric + route network/IP netmask gateway metric table-id This option is intended as a convenience proxy for the ``route``\(8) shell command, while at the same time providing portable semantics
@@ -394,6 +403,9 @@ routing. ``metric`` default taken from ``--route-metric`` if set, otherwise :code:`0`. + ``table-id`` (Supported on Linux only, on other platforms this is a no-op). + default taken from ``--route-table`` if set, otherwise :code:`0`. + The default can be specified by leaving an option blank or setting it to :code:`default`.
@@ -444,12 +456,14 @@ routing. Valid syntax: :: - route-ipv6 ipv6addr/bits [gateway] [metric] + route-ipv6 ipv6addr/bits [gateway] [metric] [table-id] 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. + (table-id supported on Linux only, on other platforms this is a no-op). + --route-gateway arg Specify a default *gateway* for use with ``--route``.
src/openvpn/helper.c +1 -0
@@ -120,6 +120,7 @@ helper_add_route(const in_addr_t network, const in_addr_t netmask, struct optionprint_in_addr_t (network,0 , &o->gc),print_in_addr_t (netmask,0 , &o->gc),NULL , +NULL , NULL); }
src/openvpn/init.c +14 -1
@@ -1504,6 +1504,7 @@ do_init_route_list(const struct options *options,const char *gw =NULL ;int dev =dev_type_enum (options->dev, options->dev_type);int metric =0 ; +uint32_t table_id =0 ;/* unspec table */ /* if DCO is enabled we have both regular routes and iroutes in the system * routing table, and normal routes must have a higher metric for that to
@@ -1522,6 +1523,10 @@ do_init_route_list(const struct options *options, { gw = options->route_default_gateway; } +if (options->route_default_table_id) + { + table_id = options->route_default_table_id; + }if (options->route_default_metric) { metric = options->route_default_metric;
@@ -1531,6 +1536,7 @@ do_init_route_list(const struct options *options, options->routes, gw, metric, + table_id,link_socket_current_remote (link_socket_info), es, ctx))
@@ -1549,6 +1555,7 @@ do_init_route_ipv6_list(const struct options *options, {const char *gw =NULL ;int metric =-1 ;/* no metric set */ +uint32_t table_id =0 ;/* unspec table */ /* see explanation in do_init_route_list() */ if (dco_enabled (options))
@@ -1567,6 +1574,11 @@ do_init_route_ipv6_list(const struct options *options, metric = options->route_default_metric; } +if (options->route_default_table_id) + { + table_id = options->route_default_table_id; + } +/* redirect (IPv6) gateway to VPN? if yes, add a few more specifics */ if (options->routes_ipv6->flags &RG_REROUTE_GW )
@@ -1578,7 +1590,7 @@ do_init_route_ipv6_list(const struct options *options, {add_route_ipv6_to_option_list ( options->routes_ipv6,string_alloc (opt_list[i], options->routes_ipv6->gc), -NULL ,NULL ); +NULL ,NULL ,NULL ); } }
@@ -1586,6 +1598,7 @@ do_init_route_ipv6_list(const struct options *options, options->routes_ipv6, gw, metric, + table_id,link_socket_current_remote_ipv6 (link_socket_info), es, ctx))
src/openvpn/options.c +41 -4
70 lines not on this page · raw message
src/openvpn/options.h +1 -0
@@ -411,6 +411,7 @@ struct optionsconst char *route_predown_script;const char *route_default_gateway;const char *route_ipv6_default_gateway; +uint32_t route_default_table_id;int route_default_metric;bool route_noexec;int route_delay;
src/openvpn/route.c +93 -8
204 lines not on this page · raw message
src/openvpn/route.h +15 -2
@@ -63,12 +63,14 @@ struct route_special_addr#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; +uint32_t table_id;int default_metric; };
@@ -77,6 +79,7 @@ struct route_option {const char *network;const char *netmask;const char *gateway; +const char *table_id;const char *metric; };
@@ -92,6 +95,7 @@ struct route_option {struct route_option_list {unsigned int flags;/* RG_x flags */ +struct route_option *routes;struct gc_arena *gc; };
@@ -101,6 +105,7 @@ struct route_ipv6_option {const char *prefix;/* e.g. "2001:db8:1::/64" */ const char *gateway;/* e.g. "2001:db8:0::2" */ const char *metric;/* e.g. "5" */ +const char *table_id; };struct route_ipv6_option_list {
@@ -113,12 +118,14 @@ struct route_ipv4 {#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; +uint32_t table_id;int metric; };
@@ -129,6 +136,7 @@ struct route_ipv6 {unsigned int netbits;struct in6_addr gateway;int metric; +uint32_t table_id;/* gateway interface */ #ifdef _WIN32DWORD adapter_index;/* interface or ~0 if undefined */
@@ -223,6 +231,7 @@ struct route_ipv6_list {struct in6_addr remote_endpoint_ipv6;/* inside tun */ struct in6_addr remote_host_ipv6;/* --remote address */ int default_metric; +uint32_t default_route_table_id;struct route_ipv6_gateway_info rgi6;unsigned int flags;/* RG_x flags, see route_option_list */
@@ -271,17 +280,20 @@ void add_route_to_option_list(struct route_option_list *l,const char *network, const char *netmask, const char *gateway, - const char *metric); + const char *metric, + const char *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, +const char *table_id);bool init_route_list (struct route_list *rl,const struct route_option_list *opt,const char *remote_endpoint,int default_metric, +uint32_t table_id,in_addr_t remote_host,struct env_set *es,openvpn_net_ctx_t *ctx);
@@ -290,6 +302,7 @@ bool init_route_ipv6_list(struct route_ipv6_list *rl6,const struct route_ipv6_option_list *opt6, const char *remote_endpoint, int default_metric, + uint32_t table_id, const struct in6_addr *remote_host, struct env_set *es, openvpn_net_ctx_t *ctx);
Signature · 1 line
2.37.2
Quoted 19 lines · Gianmarco De Gregori
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).
The --route(-ipv6) directives have been extended with an additional argument (5th for --route) (4th for --route-ipv6) so that each of them can possibly use an independent routing table.
Please note: this feature is currently supported
only by Linux/SITNL.
Support for other platforms should be added in related backends.Signed-off-by Gianmarco De Gregori <[email protected]...>---
[...]
Quoted 4 lines
src/openvpn/options.c +0
-0
[...]
src/openvpn/options.c add_option(struct options *options, · line 7026
Quoted 9 lines
src/openvpn/options.c +4
-1@@ -6998,7 +7020,22 @@ add_option(struct options *options, }/* p[3] is metric, if present */ } -add_route_ipv6_to_option_list (options->routes_ipv6, p[1 ], p[2 ], p[3 ]); + +/* at the moment the routing table id is supported only by Linux/SITNL */ +#ifndef ENABLE_SITNL +if (p[5 ])
p[4]
Quoted 15 lines
src/openvpn/options.c +12
-0+ { +static bool route6_table_warned = false; + +if (!route6_table_warned) + { +msg (M_WARN ,"NOTE: table specified for --route-ipv6, but not supported on this platform" ); + route6_table_warned = true; + } + } +#endif + +add_route_ipv6_to_option_list (options->routes_ipv6, p[1 ], p[2 ], p[3 ], p[4 ]); }else if (streq (p[0 ],"max-routes" ) && !p[2 ]) {
[...]
Quoted 4 lines
src/openvpn/route.c +0
-0
[...]
src/openvpn/route.c init_route(struct route_ipv4 *r, · line 445
Quoted 11 lines
src/openvpn/route.c +7
-0@@ -437,6 +436,27 @@ init_route(struct route_ipv4 *r, r->flags |=RT_DEFINED ; +/* routing table id */ + + r->table_id =0 ; +if (ro->table_id) + { + r->table_id =atoi (ro->table_id); +if (r->table_id <0 )
Isn't r->table_id an uint32 ?
Quoted 18 lines
src/openvpn/route.c +14
-0+ { +msg (M_WARN ,PACKAGE_NAME "ROUTE: routing table id for network %s (%s) must be >= 0" , + ro->network, + ro->table_id); + goto fail; + } + r->flags |=RT_TABLE_DEFINED ; + } +else if (rl->spec.flags &RTSA_DEFAULT_TABLE_ID ) + { + r->table_id = rl->spec.table_id; + r->flags |=RT_TABLE_DEFINED ; + } +return true; fail:
src/openvpn/route.c init_route_ipv6(struct route_ipv6 *r6, · line 522
Quoted 10 lines
src/openvpn/route.c +7
-0@@ -493,6 +513,27 @@ init_route_ipv6(struct route_ipv6 *r6, r6->flags |=RT_DEFINED ; +/* routing table id */ + + r6->table_id =0 ; +if (r6o->table_id) + { + r6->table_id =atoi (r6o->table_id); +if (r6->table_id <0 )
Isn't r6->table_id an uint32 ?
Quoted 17 lines
src/openvpn/route.c +14
-0+ { +msg (M_WARN ,PACKAGE_NAME "ROUTE: routing table id for network %s (%s) must be >= 0" , + r6o->prefix, + r6o->table_id); + goto fail; + } + r6->flags |=RT_TABLE_DEFINED ; + } +else if (rl6->spec_flags &RTSA_DEFAULT_TABLE_ID ) + { + r6->table_id = rl6->default_route_table_id; + r6->flags |=RT_TABLE_DEFINED ; + } +return true; fail:
[...]
src/openvpn/route.c add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, · line 2047
Quoted 6 lines
src/openvpn/route.c +2
-0@@ -1978,10 +2043,16 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, metric = r6->metric; } +uint32_t table_id =0 ; +if ((r6->flags &RT_TABLE_DEFINED ) && (r6->table_id >0 ))
Isn't r6->table_id an uint32 ?
src/openvpn/route.c add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, · line 2058
Quoted 12 lines
src/openvpn/route.c +5
-1+ { + table_id = r6->table_id; + } + status =RTA_SUCCESS ;int ret =net_route_v6_add (ctx, &r6->network, r6->netbits, gateway_needed ? &r6->gateway :NULL , - device,0 , metric); + device, table_id, metric);if (ret == -EEXIST ) {msg (D_ROUTE ,"NOTE: Linux route add command failed because route exists" );
[...]
Regards,
Signature · 1 line
Frank Lichtenheld
Hi,
Quoted 15 lines · Gianmarco De Gregori
src/openvpn/route.c +0
-1@@ -325,7 +325,6 @@ init_route(struct route_ipv4 *r,CLEAR (*r); r->option = ro; -/* network */ if (!is_route_parm_defined (ro->network))@@ -437,6 +436,27 @@ init_route(struct route_ipv4 *r, r->flags |=RT_DEFINED ;
src/openvpn/route.c init_route(struct route_ipv4 *r, · line 447
Quoted 10 lines
src/openvpn/route.c +9
-0+/* routing table id */ + + r->table_id =0 ; +if (ro->table_id) + { + r->table_id =atoi (ro->table_id); +if (r->table_id <0 ) + { + msg(M_WARN, PACKAGE_NAME "ROUTE: routing table id for network %s (%s) must be >= 0",
Frank's comments alerted me to this, and this certainly is not the way to approach it. Syntax checking of the routing table ID must happen during option parsing (options.c), not in init_route() - so, this function should be able to rely on ro->table_id being an *int*, and properly sanitized - "if set, the content is valid".
Same for IPv6, of course.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Quoted 35 lines · Gert Doering
Hi,
Quoted 15 lines · Gianmarco De Gregori
src/openvpn/route.c +0
-1@@ -325,7 +325,6 @@ init_route(struct route_ipv4 *r,CLEAR (*r); r->option = ro; -/* network */ if (!is_route_parm_defined (ro->network))@@ -437,6 +436,27 @@ init_route(struct route_ipv4 *r, r->flags |=RT_DEFINED ;src/openvpn/route.c init_route(struct route_ipv4 *r, · line 447
Quoted 10 lines
src/openvpn/route.c +9
-0+/* routing table id */ + + r->table_id =0 ; +if (ro->table_id) + { + r->table_id =atoi (ro->table_id); +if (r->table_id <0 ) + { + msg(M_WARN, PACKAGE_NAME "ROUTE: routing table id for network %s (%s) must be >= 0",Frank's comments alerted me to this, and this certainly is not the way to approach it. Syntax checking of the routing table ID must happen during option parsing (
options.c), not ininit_route()- so, this function should be able to rely onro->table_idbeing an *int*, and properly sanitized - "if set, the content is valid".
Quoted 1 line
Same for IPv6, of course.
To be fair, he implemented it in the same way all the other parameters are implemented. That is why I did not complain about that (e.g. compare ro->metric, which is treated exactly the same way). However, I agree with your general sentiment.
Regards,
Signature · 1 line
Frank Lichtenheld
Hi,
-----Original Message-----
From: Frank Lichtenheld <[email protected]...>
Sent: giovedì 13 aprile 2023 16:19
To: Gert Doering <[email protected]...>
Cc: Gianmarco De Gregori <[email protected]...>; [email protected]
Subject: Re: [Openvpn-devel] [PATCH v3] Route: add support for user defined routing table
Quoted 36 lines · Gert Doering
Hi,
Quoted 16 lines · Gianmarco De Gregori
src/openvpn/route.c index renamed from src/openvpn/route.c +0
-0
3798bc65..00419dce100644src/openvpn/route.c +0
-1@@ -325,7 +325,6 @@ init_route(struct route_ipv4 *r,CLEAR (*r); r->option = ro; -/* network */ if (!is_route_parm_defined (ro->network))@@ -437,6 +436,27 @@ init_route(struct route_ipv4 *r, r->flags |=RT_DEFINED ;src/openvpn/route.c init_route(struct route_ipv4 *r, · line 448
Quoted 10 lines
src/openvpn/route.c +10
-0+/* routing table id */ + + r->table_id =0 ; +if (ro->table_id) + { + r->table_id =atoi (ro->table_id); +if (r->table_id <0 ) + { + msg(M_WARN, PACKAGE_NAME "ROUTE: routing table id for + network %s (%s) must be >= 0",Frank's comments alerted me to this, and this certainly is not the way to approach it. Syntax checking of the routing table ID must happen during option parsing (
options.c), not ininit_route()- so, this function should be able to rely onro->table_idbeing an *int*, and properly sanitized - "if set, the content is valid".
Quoted 1 line
Same for IPv6, of course.
To be fair, he implemented it in the same way all the other parameters are implemented. That is why I did not complain about that (e.g. compare ro->metric, which is treated exactly the same way).
However, I agree with your general sentiment.
I completely agree with switching from uint32_t to *int* as I notice that those muliple checks doesn't make any sense.
As Frank said, I chose this approach of following how options->route_default_metric and ro->metric are implemented to be consistent with the overall data flow, anyway, in a follow-up patch I could perform a clean-up of all those parameters to be sanitized and managed through options.c .
Regards,
Gianmarco De Gregori
PATCH v4 1/1 Route: add support for user defined routing table
In reply to Gianmarco De GregoriAdd 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).
The --route(-ipv6) directives have been extended with an additional argument (5th for --route) (4th for --route-ipv6) so that each of them can possibly use an independent routing table.
Please note: this feature is currently supported
only by Linux/SITNL.
Support for other platforms should be added in related backends.
---
Changes from v1:
* Fixed parameters (metric and table_id) order in init_route_list() call in init.c : 1535.
Changes from v2:
* Add route_default_table_id to show_settings() in options.c : 1800.
Changes from v3:
* Switched table_id data type from uint32_t to int.
* Added discard to pulled routing table_id from server in case of pull mode.
doc/man-sections/vpn-network-options.rst | 16 +++- src/openvpn/helper.c | 1 + src/openvpn/init.c | 15 +++- src/openvpn/options.c | 62 ++++++++++++-- src/openvpn/options.h | 1 + src/openvpn/route.c | 101 +++++++++++++++++++++-- src/openvpn/route.h | 17 +++- 7 files changed, 196 insertions(+), 17 deletions(-)
doc/man-sections/vpn-network-options.rst +15 -1
@@ -367,6 +367,14 @@ routing. Like ``--redirect-gateway``, but omit actually changing 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 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
@@ -379,6 +387,7 @@ routing. route network/IP netmask route network/IP netmask gateway route network/IP netmask gateway metric + route network/IP netmask gateway metric table-id This option is intended as a convenience proxy for the ``route``\(8) shell command, while at the same time providing portable semantics
@@ -394,6 +403,9 @@ routing. ``metric`` default taken from ``--route-metric`` if set, otherwise :code:`0`. + ``table-id`` (Supported on Linux only, on other platforms this is a no-op). + default taken from ``--route-table`` if set, otherwise :code:`0`. + The default can be specified by leaving an option blank or setting it to :code:`default`.
@@ -444,12 +456,14 @@ routing. Valid syntax: :: - route-ipv6 ipv6addr/bits [gateway] [metric] + route-ipv6 ipv6addr/bits [gateway] [metric] [table-id] 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. + (table-id supported on Linux only, on other platforms this is a no-op). + --route-gateway arg Specify a default *gateway* for use with ``--route``.
src/openvpn/helper.c +1 -0
@@ -120,6 +120,7 @@ helper_add_route(const in_addr_t network, const in_addr_t netmask, struct optionprint_in_addr_t (network,0 , &o->gc),print_in_addr_t (netmask,0 , &o->gc),NULL , +NULL , NULL); }
src/openvpn/init.c +14 -1
@@ -1504,6 +1504,7 @@ do_init_route_list(const struct options *options,const char *gw =NULL ;int dev =dev_type_enum (options->dev, options->dev_type);int metric =0 ; +int table_id =0 ;/* unspec table */ /* if DCO is enabled we have both regular routes and iroutes in the system * routing table, and normal routes must have a higher metric for that to
@@ -1522,6 +1523,10 @@ do_init_route_list(const struct options *options, { gw = options->route_default_gateway; } +if (options->route_default_table_id) + { + table_id = options->route_default_table_id; + }if (options->route_default_metric) { metric = options->route_default_metric;
@@ -1531,6 +1536,7 @@ do_init_route_list(const struct options *options, options->routes, gw, metric, + table_id,link_socket_current_remote (link_socket_info), es, ctx))
@@ -1549,6 +1555,7 @@ do_init_route_ipv6_list(const struct options *options, {const char *gw =NULL ;int metric =-1 ;/* no metric set */ +int table_id =0 ;/* unspec table */ /* see explanation in do_init_route_list() */ if (dco_enabled (options))
@@ -1567,6 +1574,11 @@ do_init_route_ipv6_list(const struct options *options, metric = options->route_default_metric; } +if (options->route_default_table_id) + { + table_id = options->route_default_table_id; + } +/* redirect (IPv6) gateway to VPN? if yes, add a few more specifics */ if (options->routes_ipv6->flags &RG_REROUTE_GW )
@@ -1578,7 +1590,7 @@ do_init_route_ipv6_list(const struct options *options, {add_route_ipv6_to_option_list ( options->routes_ipv6,string_alloc (opt_list[i], options->routes_ipv6->gc), -NULL ,NULL ); +NULL ,NULL ,NULL ); } }
@@ -1586,6 +1598,7 @@ do_init_route_ipv6_list(const struct options *options, options->routes_ipv6, gw, metric, + table_id,link_socket_current_remote_ipv6 (link_socket_info), es, ctx))
src/openvpn/options.c +57 -5
89 lines not on this page · raw message
src/openvpn/options.h +1 -0
@@ -411,6 +411,7 @@ struct optionsconst 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;
src/openvpn/route.c +93 -8
204 lines not on this page · raw message
src/openvpn/route.h +15 -2
@@ -63,12 +63,14 @@ struct route_special_addr#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 @@ struct route_option {const char *network;const char *netmask;const char *gateway; +const char *table_id;const char *metric; };
@@ -92,6 +95,7 @@ struct route_option {struct route_option_list {unsigned int flags;/* RG_x flags */ +struct route_option *routes;struct gc_arena *gc; };
@@ -101,6 +105,7 @@ struct route_ipv6_option {const char *prefix;/* e.g. "2001:db8:1::/64" */ const char *gateway;/* e.g. "2001:db8:0::2" */ const char *metric;/* e.g. "5" */ +const char *table_id; };struct route_ipv6_option_list {
@@ -113,12 +118,14 @@ struct route_ipv4 {#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 +136,7 @@ struct route_ipv6 {unsigned int netbits;struct in6_addr gateway;int metric; +int table_id;/* gateway interface */ #ifdef _WIN32DWORD adapter_index;/* interface or ~0 if undefined */
@@ -223,6 +231,7 @@ struct route_ipv6_list {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_list */
@@ -271,17 +280,20 @@ void add_route_to_option_list(struct route_option_list *l,const char *network, const char *netmask, const char *gateway, - const char *metric); + const char *metric, + const char *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, +const char *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);
@@ -290,6 +302,7 @@ bool init_route_ipv6_list(struct route_ipv6_list *rl6,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);
Signature · 1 line
2.37.2
Quoted 23 lines · Gianmarco De Gregori
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).
The --route(-ipv6) directives have been extended with an additional argument (5th for --route) (4th for --route-ipv6) so that each of them can possibly use an independent routing table.
Please note: this feature is currently supported
only by Linux/SITNL.
Support for other platforms should be added in related backends.Fixes Trac #1399Signed-off-by Gianmarco De Gregori <[email protected]...>---
Changes from v1:
* Fixed parameters (metric andtable_id) order ininit_route_list()call ininit.c: 1535.
Quoted 6 lines
Changes from v2:
* Addroute_default_table_idtoshow_settings()inoptions.c: 1800.Changes from v3:
* Switchedtable_iddata type fromuint32_tto int.
* Added discard to pulled routingtable_idfrom server in case of pull mode.
One question about that, see below.
[...]
src/openvpn/options.c
Quoted 4 lines
src/openvpn/options.c +0
-0
side-note: --route-table missing in usage_message.
Quoted 26 lines
src/openvpn/options.c +10
-1@@ -1912,6 +1912,7 @@ show_settings(const struct options *o)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);@@ -6956,7 +6957,15 @@ add_option(struct options *options,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" ) && p[1 ] && !p[5 ]) +else if (streq (p[0 ],"route-table" ) && p[1 ] && !p[2 ]) + { +#ifndef ENABLE_SITNL +msg (M_WARN ,"NOTE: --route-table specified, but not supported on this platform" ); +#endif +VERIFY_PERMISSION (OPT_P_ROUTE ); + options->route_default_table_id =positive_atoi (p[1 ]); + } +else if (streq (p[0 ],"route" ) && p[1 ] && !p[6 ]) {VERIFY_PERMISSION (OPT_P_ROUTE );rol_check_alloc (options);
src/openvpn/options.c add_option(struct options *options, · line 6992
Quoted 7 lines
src/openvpn/options.c +4
-0@@ -6977,10 +6986,31 @@ add_option(struct options *options,msg (msglevel,"route parameter gateway '%s' must be a valid address" , p[3 ]); goto err; } +/* p[4] is metric, if specified */ + +/* discard pulled routing table_id from server +* since this must be an entirely local choice */
Don't you need that check for --route-table as well?
Quoted 16 lines
src/openvpn/options.c +16
-0+if (p[5 ]) + { + p[5 ] =NULL ; + } + } +/* at the moment the routing table id is supported only by Linux/SITNL */ +#ifndef ENABLE_SITNL +if (p[5 ]) + { +static bool route_table_warned = false; + +if (!route_table_warned) + { +msg (M_WARN ,"NOTE: table specified for --route, but not supported on this platform" ); + route_table_warned = true; + }
src/openvpn/options.c add_option(struct options *options, · line 7016
Quoted 10 lines
src/openvpn/options.c +3
-2} -add_route_to_option_list (options->routes, p[1 ], p[2 ], p[3 ], p[4 ]); +#endif +add_route_to_option_list (options->routes, p[1 ], p[2 ], p[3 ], p[4 ], p[5 ]); } -else if (streq (p[0 ],"route-ipv6" ) && p[1 ] && !p[4 ]) +else if (streq (p[0 ],"route-ipv6" ) && p[1 ] && !p[5 ]) {VERIFY_PERMISSION (OPT_P_ROUTE );rol6_check_alloc (options);
Regards,
Signature · 1 line
Frank Lichtenheld
Hi,
Quoted 6 lines
-----Original Message-----
From: Frank Lichtenheld <[email protected]...>
Sent: mercoledì 19 aprile 2023 11:56
To: Gianmarco De Gregori <[email protected]...>
Cc: [email protected]
Subject: Re: [Openvpn-devel] [PATCH v4] Route: add support for user
defined
Quoted 22 lines
routing table
Quoted 19 lines · Gianmarco De Gregori
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).The --route(-ipv6) directives have been extended with an additional argument (5th for --route) (4th for --route-ipv6) so that each of them can possibly use an independent routing table.
Please note: this feature is currently supported only by Linux/SITNL. Support for other platforms should be added in related backends.
Fixes Trac #1399Signed-off-by Gianmarco De Gregori <[email protected]...>---
Changes from v1:
* Fixed parameters (metric andtable_id) order ininit_route_list()call
in init.c
Quoted 8 lines
: 1535.
Quoted 7 lines
Changes from v2:
* Addroute_default_table_idtoshow_settings()inoptions.c: 1800.Changes from v3:
* Switchedtable_iddata type fromuint32_tto int.
* Added discard to pulled routingtable_idfrom server in case of pull
mode.
Quoted 10 lines
One question about that, see below.
[...]
src/openvpn/options.c
Quoted 4 lines
src/openvpn/options.c index renamed from src/openvpn/options.c +0
-0
2680f268..a908566a100644src/openvpn/options.c +0
-0side-note: --route-table missing in
usage_message.
Gonna add it soon, thanks for reminding.
Quoted 12 lines
src/openvpn/options.c add_option(struct options *options, · line 6958
Quoted 12 lines
src/openvpn/options.c +1
-0@@ -1912,6 +1912,7 @@ show_settings(const struct options *o)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);@@ -6956,7 +6957,15 @@ add_option(struct options *options,cnol_check_alloc (options); add_client_nat_to_option_list(options->client_nat, p[1], p[2],
p[3],
Quoted 17 lines
p[4], msglevel);
Quoted 15 lines
src/openvpn/options.c +9
-1} -else if (streq (p[0 ],"route" ) && p[1 ] && !p[5 ]) +else if (streq (p[0 ],"route-table" ) && p[1 ] && !p[2 ]) + { +#ifndef ENABLE_SITNL + msg(M_WARN, "NOTE: --route-table specified, but not supported +on this platform"); #endif + VERIFY_PERMISSION(OPT_P_ROUTE); + options->route_default_table_id = positive_atoi(p[1]); + } +else if (streq (p[0 ],"route" ) && p[1 ] && !p[6 ]) {VERIFY_PERMISSION (OPT_P_ROUTE );rol_check_alloc (options);src/openvpn/options.c add_option(struct options *options, · line 6986
Quoted 1 line
src/openvpn/options.c +0
-0@@ -6977,10 +6986,31 @@ add_option(struct options *options, msg(msglevel, "route parameter gateway '%s' must be a
valid
Quoted 10 lines
address", p[3]);
src/openvpn/options.c add_option(struct options *options, · line 6992
Quoted 6 lines
src/openvpn/options.c +4
-0goto err; } +/* p[4] is metric, if specified */ + +/* discard pulled routing table_id from server +* since this must be an entirely local choice */ Don't you need that check for --route-table as well?
There is no need since if the table_id is specified via --route-table that will be used regardless, otherwise the main table with id 0 will be used.
Quoted 20 lines
Quoted 5 lines
src/openvpn/options.c +4
-0+if (p[5 ]) + { + p[5 ] =NULL ; + }src/openvpn/options.c add_option(struct options *options,
Quoted 10 lines
src/openvpn/options.c +10
-0+ } +/* at the moment the routing table id is supported only by +Linux/SITNL */ #ifndef ENABLE_SITNL +if (p[5 ]) + { +static bool route_table_warned = false; + +if (!route_table_warned) + { + msg(M_WARN, "NOTE: table specified for --route, but notsupported on this platform");
Quoted 4 lines
src/openvpn/options.c +2
-1+ route_table_warned = true; + } } - add_route_to_option_list(options->routes, p[1], p[2], p[3],
p[4]);
Quoted 10 lines
src/openvpn/options.c add_option(struct options *options, · line 7016
Quoted 9 lines
src/openvpn/options.c +4
-1+#endif +add_route_to_option_list (options->routes, p[1 ], p[2 ], p[3 ], +p[4 ], p[5 ]); } -else if (streq (p[0 ],"route-ipv6" ) && p[1 ] && !p[4 ]) +else if (streq (p[0 ],"route-ipv6" ) && p[1 ] && !p[5 ]) {VERIFY_PERMISSION (OPT_P_ROUTE );rol6_check_alloc (options);
Regards,
Gianmarco De Gregori
Hi,
Quoted 6 lines
-----Original Message-----
From: [email protected]... <[email protected]...>
Sent: mercoledì 19 aprile 2023 12:28
To: 'Frank Lichtenheld' <[email protected]...>
Cc: [email protected]
Subject: Re: [Openvpn-devel] [PATCH v4] Route: add support for user
defined
Quoted 101 lines
routing table
Hi,
Quoted 6 lines
-----Original Message-----
From: Frank Lichtenheld <[email protected]...>
Sent: mercoledì 19 aprile 2023 11:56
To: Gianmarco De Gregori <[email protected]...>
Cc: [email protected]
Subject: Re: [Openvpn-devel] [PATCH v4] Route: add support for userdefined
Quoted 23 lines
routing table
Quoted 20 lines · Gianmarco De Gregori
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).The --route(-ipv6) directives have been extended with an additional argument (5th for --route) (4th for --route-ipv6) so that each of them can possibly use an independent routing table.
Please note: this feature is currently supported only by Linux/SITNL. Support for other platforms should be added in related backends.
Fixes Trac #1399Signed-off-by Gianmarco De Gregori <[email protected]...>---
Changes from v1:
* Fixed parameters (metric andtable_id) order ininit_route_list()callin
init.cQuoted 9 lines
: 1535.
Quoted 8 lines
Changes from v2:
* Addroute_default_table_idtoshow_settings()inoptions.c: 1800.Changes from v3:
* Switchedtable_iddata type fromuint32_tto int.
* Added discard to pulled routingtable_idfrom server in case of pullmode.
Quoted 10 lines
One question about that, see below.
[...]
src/openvpn/options.c
Quoted 4 lines
src/openvpn/options.c index renamed from src/openvpn/options.c +0
-0
2680f268..a908566a100644src/openvpn/options.c +0
-0side-note: --route-table missing in
usage_message.Gonna add it soon, thanks for reminding.
Quoted 13 lines
src/openvpn/options.c add_option(struct options *options, · line 6959
Quoted 13 lines
src/openvpn/options.c +1
-0@@ -1912,6 +1912,7 @@ show_settings(const struct options *o)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);@@ -6956,7 +6957,15 @@ add_option(struct options *options,cnol_check_alloc (options); add_client_nat_to_option_list(options->client_nat, p[1], p[2],p[3],
Quoted 10 lines
p[4], msglevel);
Quoted 9 lines
src/openvpn/options.c +7
-1} -else if (streq (p[0 ],"route" ) && p[1 ] && !p[5 ]) +else if (streq (p[0 ],"route-table" ) && p[1 ] && !p[2 ]) + { +#ifndef ENABLE_SITNL + msg(M_WARN, "NOTE: --route-table specified, but not +supported on this platform"); #endif + VERIFY_PERMISSION(OPT_P_ROUTE); + options->route_default_table_id =positive_atoi (p[1 ]);Quoted 8 lines
Quoted 8 lines
src/openvpn/options.c +2
-0+ } +else if (streq (p[0 ],"route" ) && p[1 ] && !p[6 ]) {VERIFY_PERMISSION (OPT_P_ROUTE );rol_check_alloc(options);src/openvpn/options.c +0
-0@@ -6977,10 +6986,31 @@ add_option(struct options *options, msg(msglevel, "route parameter gateway '%s' must bea
valid
Quoted 9 lines
address", p[3]);
Quoted 6 lines
goto err; }src/openvpn/options.c +4
-0+/* p[4] is metric, if specified */ + +/* discard pulled routing table_id from server +* since this must be an entirely local choice */
Quoted 3 lines
Quoted 1 line
Don't you need that check for --route-table as well?
There is no need since if the
table_idis specified via --route-table that
will be
Quoted 1 line
used regardless, otherwise the main table with id 0 will be used.
Sure, I had not considered the case of pulling the route-table from server. My bad, gonna add it soon also.
Quoted 18 lines
Quoted 18 lines
Quoted 7 lines
src/openvpn/options.c +5
-0+if (p[5 ]) + { + p[5 ] =NULL ; + } + }src/openvpn/options.c add_option(struct options *options,
Quoted 10 lines
src/openvpn/options.c +10
-0+/* at the moment the routing table id is supported only by +Linux/SITNL */ #ifndef ENABLE_SITNL +if (p[5 ]) + { +static bool route_table_warned = false; + +if (!route_table_warned) + { + msg(M_WARN, "NOTE: table specified for --route, but + notsupported on this platform");
Quoted 16 lines
Quoted 4 lines
src/openvpn/options.c add_option(struct options *options,
Quoted 4 lines
src/openvpn/options.c +2
-1+ route_table_warned = true; + } } - add_route_to_option_list(options->routes, p[1], p[2], p[3],p[4]);
Quoted 10 lines
Quoted 9 lines
src/openvpn/options.c +4
-1+#endif +add_route_to_option_list (options->routes, p[1 ], p[2 ], p[3 ], +p[4 ], p[5 ]); } -else if (streq (p[0 ],"route-ipv6" ) && p[1 ] && !p[4 ]) +else if (streq (p[0 ],"route-ipv6" ) && p[1 ] && !p[5 ]) {VERIFY_PERMISSION (OPT_P_ROUTE );rol6_check_alloc (options);
Regards,
Gianmarco De Gregori
PATCH v5 1/1 Route: add support for user defined routing table
In reply to Gianmarco De GregoriAdd 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).
The --route(-ipv6) directives have been extended with an additional argument (5th for --route) (4th for --route-ipv6) so that each of them can possibly use an independent routing table.
Please note: this feature is currently supported
only by Linux/SITNL.
Support for other platforms should be added in related backends.
---
Changes from v1:
* Fixed parameters (metric and table_id) order in init_route_list() call in init.c : 1535.
Changes from v2:
* Add route_default_table_id to show_settings() in options.c : 1800.
Changes from v3:
* Switched table_id data type from uint32_t to int.
* Added discard to pulled routing table_id from server in case of pull mode.
Changes from v4:
* The --route-table option has been made non-pullable.
* A short description of --route-table has been added to usage_message.
doc/man-sections/vpn-network-options.rst | 16 +++- src/openvpn/helper.c | 1 + src/openvpn/init.c | 15 +++- src/openvpn/options.c | 67 +++++++++++++-- src/openvpn/options.h | 2 + src/openvpn/route.c | 101 +++++++++++++++++++++-- src/openvpn/route.h | 17 +++- 7 files changed, 202 insertions(+), 17 deletions(-)
doc/man-sections/vpn-network-options.rst +15 -1
@@ -367,6 +367,14 @@ routing. Like ``--redirect-gateway``, but omit actually changing 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 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
@@ -379,6 +387,7 @@ routing. route network/IP netmask route network/IP netmask gateway route network/IP netmask gateway metric + route network/IP netmask gateway metric table-id This option is intended as a convenience proxy for the ``route``\(8) shell command, while at the same time providing portable semantics
@@ -394,6 +403,9 @@ routing. ``metric`` default taken from ``--route-metric`` if set, otherwise :code:`0`. + ``table-id`` (Supported on Linux only, on other platforms this is a no-op). + default taken from ``--route-table`` if set, otherwise :code:`0`. + The default can be specified by leaving an option blank or setting it to :code:`default`.
@@ -444,12 +456,14 @@ routing. Valid syntax: :: - route-ipv6 ipv6addr/bits [gateway] [metric] + route-ipv6 ipv6addr/bits [gateway] [metric] [table-id] 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. + (table-id supported on Linux only, on other platforms this is a no-op). + --route-gateway arg Specify a default *gateway* for use with ``--route``.
src/openvpn/helper.c +1 -0
@@ -120,6 +120,7 @@ helper_add_route(const in_addr_t network, const in_addr_t netmask, struct optionprint_in_addr_t (network,0 , &o->gc),print_in_addr_t (netmask,0 , &o->gc),NULL , +NULL , NULL); }
src/openvpn/init.c +14 -1
@@ -1504,6 +1504,7 @@ do_init_route_list(const struct options *options,const char *gw =NULL ;int dev =dev_type_enum (options->dev, options->dev_type);int metric =0 ; +int table_id =0 ;/* unspec table */ /* if DCO is enabled we have both regular routes and iroutes in the system * routing table, and normal routes must have a higher metric for that to
@@ -1522,6 +1523,10 @@ do_init_route_list(const struct options *options, { gw = options->route_default_gateway; } +if (options->route_default_table_id) + { + table_id = options->route_default_table_id; + }if (options->route_default_metric) { metric = options->route_default_metric;
@@ -1531,6 +1536,7 @@ do_init_route_list(const struct options *options, options->routes, gw, metric, + table_id,link_socket_current_remote (link_socket_info), es, ctx))
@@ -1549,6 +1555,7 @@ do_init_route_ipv6_list(const struct options *options, {const char *gw =NULL ;int metric =-1 ;/* no metric set */ +int table_id =0 ;/* unspec table */ /* see explanation in do_init_route_list() */ if (dco_enabled (options))
@@ -1567,6 +1574,11 @@ do_init_route_ipv6_list(const struct options *options, metric = options->route_default_metric; } +if (options->route_default_table_id) + { + table_id = options->route_default_table_id; + } +/* redirect (IPv6) gateway to VPN? if yes, add a few more specifics */ if (options->routes_ipv6->flags &RG_REROUTE_GW )
@@ -1578,7 +1590,7 @@ do_init_route_ipv6_list(const struct options *options, {add_route_ipv6_to_option_list ( options->routes_ipv6,string_alloc (opt_list[i], options->routes_ipv6->gc), -NULL ,NULL ); +NULL ,NULL ,NULL ); } }
@@ -1586,6 +1598,7 @@ do_init_route_ipv6_list(const struct options *options, options->routes_ipv6, gw, metric, + table_id,link_socket_current_remote_ipv6 (link_socket_info), es, ctx))
src/openvpn/options.c +62 -5
100 lines not on this page · raw message
src/openvpn/options.h +2 -0
@@ -411,6 +411,7 @@ struct optionsconst 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;
@@ -739,6 +740,7 @@ struct options#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))
src/openvpn/route.c +93 -8
204 lines not on this page · raw message
src/openvpn/route.h +15 -2
@@ -63,12 +63,14 @@ struct route_special_addr#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 @@ struct route_option {const char *network;const char *netmask;const char *gateway; +const char *table_id;const char *metric; };
@@ -92,6 +95,7 @@ struct route_option {struct route_option_list {unsigned int flags;/* RG_x flags */ +struct route_option *routes;struct gc_arena *gc; };
@@ -101,6 +105,7 @@ struct route_ipv6_option {const char *prefix;/* e.g. "2001:db8:1::/64" */ const char *gateway;/* e.g. "2001:db8:0::2" */ const char *metric;/* e.g. "5" */ +const char *table_id; };struct route_ipv6_option_list {
@@ -113,12 +118,14 @@ struct route_ipv4 {#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 +136,7 @@ struct route_ipv6 {unsigned int netbits;struct in6_addr gateway;int metric; +int table_id;/* gateway interface */ #ifdef _WIN32DWORD adapter_index;/* interface or ~0 if undefined */
@@ -223,6 +231,7 @@ struct route_ipv6_list {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_list */
@@ -271,17 +280,20 @@ void add_route_to_option_list(struct route_option_list *l,const char *network, const char *netmask, const char *gateway, - const char *metric); + const char *metric, + const char *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, +const char *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);
@@ -290,6 +302,7 @@ bool init_route_ipv6_list(struct route_ipv6_list *rl6,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);
Signature · 1 line
2.37.2