OpenVPN
route.h File Reference
#include "basic.h"
#include "tun.h"
#include "misc.h"
#include "networking.h"
Include dependency graph for route.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  route_bypass
struct  route_special_addr
struct  route_option
struct  route_option_list
struct  route_ipv6_option
struct  route_ipv6_option_list
struct  route_ipv4
struct  route_ipv6
struct  route_gateway_address
struct  route_gateway_info
struct  route_ipv6_gateway_address
struct  route_ipv6_gateway_info
struct  route_list
struct  route_ipv6_list
struct  iroute
struct  iroute_ipv6

Macros

#define ROUTE_METHOD_ADAPTIVE   0 /* try IP helper first then route.exe */
#define ROUTE_METHOD_IPAPI   1 /* use IP helper API */
#define ROUTE_METHOD_EXE   2 /* use route.exe */
#define ROUTE_METHOD_SERVICE   3 /* use the privileged Windows service */
#define ROUTE_METHOD_MASK   3
#define ROUTE_DELETE_FIRST   (1 << 2)
#define ROUTE_REF_GW   (1 << 3)
#define N_ROUTE_BYPASS   8
#define RTSA_REMOTE_ENDPOINT   (1 << 0)
#define RTSA_REMOTE_HOST   (1 << 1)
#define RTSA_DEFAULT_METRIC   (1 << 2)
#define RG_ENABLE   (1u << 0)
#define RG_LOCAL   (1u << 1)
#define RG_DEF1   (1u << 2)
#define RG_BYPASS_DHCP   (1u << 3)
#define RG_BYPASS_DNS   (1u << 4)
#define RG_REROUTE_GW   (1u << 5)
#define RG_AUTO_LOCAL   (1u << 6)
#define RG_BLOCK_LOCAL   (1u << 7)
#define RT_DEFINED   (1u << 0)
#define RT_ADDED   (1u << 1)
#define RT_METRIC_DEFINED   (1u << 2)
#define RGI_ADDR_DEFINED   (1 << 0) /* set if gateway.addr defined */
#define RGI_NETMASK_DEFINED   (1 << 1) /* set if gateway.netmask defined */
#define RGI_HWADDR_DEFINED   (1 << 2) /* set if hwaddr is defined */
#define RGI_IFACE_DEFINED   (1 << 3) /* set if iface is defined */
#define RGI_OVERFLOW   (1 << 4) /* set if more interface addresses than will fit in addrs */
#define RGI_ON_LINK   (1 << 5)
#define RGI_N_ADDRESSES   8
#define RGI_N_ADDRESSES   8
#define RL_DID_REDIRECT_DEFAULT_GATEWAY   (1u << 0)
#define RL_DID_LOCAL   (1u << 1)
#define RL_ROUTES_ADDED   (1u << 2)
#define TLA_NOT_IMPLEMENTED   0
#define TLA_NONLOCAL   1
#define TLA_LOCAL   2

Functions

bool block_local_needed (const struct route_list *rl)
 Get the decision whether to block traffic to local networks while the VPN is connected.
struct route_option_list * new_route_option_list (struct gc_arena *a)
struct route_ipv6_option_list * new_route_ipv6_option_list (struct gc_arena *a)
struct route_option_list * clone_route_option_list (const struct route_option_list *src, struct gc_arena *a)
struct route_ipv6_option_list * clone_route_ipv6_option_list (const struct route_ipv6_option_list *src, struct gc_arena *a)
void copy_route_option_list (struct route_option_list *dest, const struct route_option_list *src, struct gc_arena *a)
void copy_route_ipv6_option_list (struct route_ipv6_option_list *dest, const struct route_ipv6_option_list *src, struct gc_arena *a)
void route_ipv6_clear_host_bits (struct route_ipv6 *r6)
bool add_route_ipv6 (struct route_ipv6 *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
void delete_route_ipv6 (const struct route_ipv6 *r, const struct tuntap *tt, const struct env_set *es, openvpn_net_ctx_t *ctx)
bool add_route (struct route_ipv4 *r, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es, openvpn_net_ctx_t *ctx)
void add_route_to_option_list (struct route_option_list *l, const char *network, const char *netmask, const char *gateway, const char *metric, int table_id)
void add_route_ipv6_to_option_list (struct route_ipv6_option_list *l, const char *prefix, const char *gateway, const char *metric, int table_id)
bool init_route_list (struct route_list *rl, const struct route_option_list *opt, const char *remote_endpoint, int default_metric, in_addr_t remote_host, struct env_set *es, openvpn_net_ctx_t *ctx)
bool init_route_ipv6_list (struct route_ipv6_list *rl6, const struct route_ipv6_option_list *opt6, const char *remote_endpoint, int default_metric, const struct in6_addr *remote_host, struct env_set *es, openvpn_net_ctx_t *ctx)
void route_list_add_vpn_gateway (struct route_list *rl, struct env_set *es, const in_addr_t addr)
bool add_routes (struct route_list *rl, struct route_ipv6_list *rl6, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
void delete_routes (struct route_list *rl, struct route_ipv6_list *rl6, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
void delete_routes_v4 (struct route_list *rl, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
void delete_routes_v6 (struct route_ipv6_list *rl6, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
void setenv_routes (struct env_set *es, const struct route_list *rl)
void setenv_routes_ipv6 (struct env_set *es, const struct route_ipv6_list *rl6)
bool is_special_addr (const char *addr_str)
void get_default_gateway (struct route_gateway_info *rgi, in_addr_t dest, openvpn_net_ctx_t *ctx)
 Retrieves the best gateway for a given destination based on the routing table.
void get_default_gateway_ipv6 (struct route_ipv6_gateway_info *rgi, const struct in6_addr *dest, openvpn_net_ctx_t *ctx)
void print_default_gateway (const msglvl_t msglevel, const struct route_gateway_info *rgi, const struct route_ipv6_gateway_info *rgi6)
int test_local_addr (const in_addr_t addr, const struct route_gateway_info *rgi)
void print_route_options (const struct route_option_list *rol, msglvl_t msglevel)
void show_routes (msglvl_t msglevel)
bool test_routes (const struct route_list *rl, const struct tuntap *tt)
bool netmask_to_netbits (const in_addr_t network, const in_addr_t netmask, int *netbits)
int netmask_to_netbits2 (in_addr_t netmask)
static in_addr_t netbits_to_netmask (const int netbits)
static int route_did_redirect_default_gateway (const struct route_list *rl)
bool ipv6_net_contains_host (const struct in6_addr *network, unsigned int bits, const struct in6_addr *host)
 check whether an IPv6 host address is covered by a given network/bits

Macro Definition Documentation

◆ N_ROUTE_BYPASS

#define N_ROUTE_BYPASS   8

Definition at line 54 of file route.h.

Referenced by add_bypass_address().

◆ RG_AUTO_LOCAL

#define RG_AUTO_LOCAL   (1u << 6)

Definition at line 92 of file route.h.

Referenced by add_option(), and redirect_default_route_to_vpn().

◆ RG_BLOCK_LOCAL

#define RG_BLOCK_LOCAL   (1u << 7)

Definition at line 93 of file route.h.

Referenced by add_option(), and block_local_needed().

◆ RG_BYPASS_DHCP

#define RG_BYPASS_DHCP   (1u << 3)

Definition at line 89 of file route.h.

Referenced by add_option(), and get_bypass_addresses().

◆ RG_BYPASS_DNS

#define RG_BYPASS_DNS   (1u << 4)

Definition at line 90 of file route.h.

Referenced by add_option(), and get_bypass_addresses().

◆ RG_DEF1

#define RG_DEF1   (1u << 2)

◆ RG_ENABLE

#define RG_ENABLE   (1u << 0)

◆ RG_LOCAL

#define RG_LOCAL   (1u << 1)

Definition at line 87 of file route.h.

Referenced by add_option(), print_route_options(), and redirect_default_route_to_vpn().

◆ RG_REROUTE_GW

#define RG_REROUTE_GW   (1u << 5)

◆ RGI_ADDR_DEFINED

◆ RGI_HWADDR_DEFINED

#define RGI_HWADDR_DEFINED   (1 << 2) /* set if hwaddr is defined */

Definition at line 161 of file route.h.

Referenced by get_default_gateway(), print_default_gateway(), and push_peer_info().

◆ RGI_IFACE_DEFINED

#define RGI_IFACE_DEFINED   (1 << 3) /* set if iface is defined */

◆ RGI_N_ADDRESSES [1/2]

#define RGI_N_ADDRESSES   8

Definition at line 183 of file route.h.

◆ RGI_N_ADDRESSES [2/2]

#define RGI_N_ADDRESSES   8

Definition at line 183 of file route.h.

◆ RGI_NETMASK_DEFINED

#define RGI_NETMASK_DEFINED   (1 << 1) /* set if gateway.netmask defined */

◆ RGI_ON_LINK

#define RGI_ON_LINK   (1 << 5)

◆ RGI_OVERFLOW

#define RGI_OVERFLOW   (1 << 4) /* set if more interface addresses than will fit in addrs */

Definition at line 163 of file route.h.

◆ RL_DID_LOCAL

#define RL_DID_LOCAL   (1u << 1)

Definition at line 231 of file route.h.

Referenced by redirect_default_route_to_vpn(), and undo_redirect_default_route_to_vpn().

◆ RL_DID_REDIRECT_DEFAULT_GATEWAY

#define RL_DID_REDIRECT_DEFAULT_GATEWAY   (1u << 0)

◆ RL_ROUTES_ADDED

#define RL_ROUTES_ADDED   (1u << 2)

Definition at line 232 of file route.h.

Referenced by add_routes(), delete_routes_v4(), and delete_routes_v6().

◆ ROUTE_DELETE_FIRST

#define ROUTE_DELETE_FIRST   (1 << 2)

Definition at line 49 of file route.h.

Referenced by add_routes().

◆ ROUTE_METHOD_ADAPTIVE

#define ROUTE_METHOD_ADAPTIVE   0 /* try IP helper first then route.exe */

Definition at line 39 of file route.h.

Referenced by add_option(), add_route(), delete_route(), and init_options().

◆ ROUTE_METHOD_EXE

#define ROUTE_METHOD_EXE   2 /* use route.exe */

Definition at line 41 of file route.h.

Referenced by add_option(), add_route(), and delete_route().

◆ ROUTE_METHOD_IPAPI

#define ROUTE_METHOD_IPAPI   1 /* use IP helper API */

Definition at line 40 of file route.h.

Referenced by add_option(), add_route(), and delete_route().

◆ ROUTE_METHOD_MASK

#define ROUTE_METHOD_MASK   3

Definition at line 43 of file route.h.

Referenced by add_route(), and delete_route().

◆ ROUTE_METHOD_SERVICE

#define ROUTE_METHOD_SERVICE   3 /* use the privileged Windows service */

Definition at line 42 of file route.h.

Referenced by add_option(), add_route(), delete_route(), and remap_redirect_gateway_flags().

◆ ROUTE_REF_GW

#define ROUTE_REF_GW   (1 << 3)

◆ RT_ADDED

#define RT_ADDED   (1u << 1)

◆ RT_DEFINED

◆ RT_METRIC_DEFINED

◆ RTSA_DEFAULT_METRIC

#define RTSA_DEFAULT_METRIC   (1 << 2)

Definition at line 64 of file route.h.

Referenced by init_route(), init_route_ipv6(), init_route_ipv6_list(), and init_route_list().

◆ RTSA_REMOTE_ENDPOINT

◆ RTSA_REMOTE_HOST

#define RTSA_REMOTE_HOST   (1 << 1)

◆ TLA_LOCAL

#define TLA_LOCAL   2

Definition at line 372 of file route.h.

Referenced by block_local_needed(), redirect_default_route_to_vpn(), and test_local_addr().

◆ TLA_NONLOCAL

#define TLA_NONLOCAL   1

◆ TLA_NOT_IMPLEMENTED

#define TLA_NOT_IMPLEMENTED   0

Definition at line 370 of file route.h.

Function Documentation

◆ add_route()

◆ add_route_ipv6()

◆ add_route_ipv6_to_option_list()

void add_route_ipv6_to_option_list ( struct route_ipv6_option_list * l,
const char * prefix,
const char * gateway,
const char * metric,
int table_id )

◆ add_route_to_option_list()

void add_route_to_option_list ( struct route_option_list * l,
const char * network,
const char * netmask,
const char * gateway,
const char * metric,
int table_id )

◆ add_routes()

◆ block_local_needed()

bool block_local_needed ( const struct route_list * rl)

Get the decision whether to block traffic to local networks while the VPN is connected.

This definitely returns false when not redirecting the gateway or when the 'block-local' flag is not set. Also checks for other prerequisites to redirect local networks into the tunnel.

Parameters
rlconst pointer to the struct route_list to base the decision on.
Returns
boolean indicating whether local traffic should be blocked.

Definition at line 586 of file route.c.

References route_gateway_info::flags, route_list::flags, route_special_addr::flags, route_special_addr::remote_host_local, RG_BLOCK_LOCAL, route_list::rgi, RGI_ADDR_DEFINED, RGI_NETMASK_DEFINED, RTSA_REMOTE_ENDPOINT, route_list::spec, and TLA_LOCAL.

Referenced by add_wfp_block(), del_wfp_block(), and init_route_list().

◆ clone_route_ipv6_option_list()

struct route_ipv6_option_list * clone_route_ipv6_option_list ( const struct route_ipv6_option_list * src,
struct gc_arena * a )

Definition at line 165 of file route.c.

References ALLOC_OBJ_GC.

Referenced by pre_connect_save().

◆ clone_route_option_list()

struct route_option_list * clone_route_option_list ( const struct route_option_list * src,
struct gc_arena * a )

Definition at line 156 of file route.c.

References ALLOC_OBJ_GC.

Referenced by pre_connect_save().

◆ copy_route_ipv6_option_list()

void copy_route_ipv6_option_list ( struct route_ipv6_option_list * dest,
const struct route_ipv6_option_list * src,
struct gc_arena * a )

Definition at line 182 of file route.c.

References route_ipv6_option_list::gc.

Referenced by pre_connect_restore().

◆ copy_route_option_list()

void copy_route_option_list ( struct route_option_list * dest,
const struct route_option_list * src,
struct gc_arena * a )

Definition at line 174 of file route.c.

References route_option_list::gc.

Referenced by pre_connect_restore().

◆ delete_route_ipv6()

◆ delete_routes()

void delete_routes ( struct route_list * rl,
struct route_ipv6_list * rl6,
const struct tuntap * tt,
unsigned int flags,
const struct env_set * es,
openvpn_net_ctx_t * ctx )

Definition at line 1158 of file route.c.

References delete_routes_v4(), delete_routes_v6(), and route_ipv6::flags.

Referenced by do_close_tun().

◆ delete_routes_v4()

void delete_routes_v4 ( struct route_list * rl,
const struct tuntap * tt,
unsigned int flags,
const struct env_set * es,
openvpn_net_ctx_t * ctx )

◆ delete_routes_v6()

void delete_routes_v6 ( struct route_ipv6_list * rl6,
const struct tuntap * tt,
unsigned int flags,
const struct env_set * es,
openvpn_net_ctx_t * ctx )

◆ get_default_gateway()

void get_default_gateway ( struct route_gateway_info * rgi,
in_addr_t dest,
openvpn_net_ctx_t * ctx )

Retrieves the best gateway for a given destination based on the routing table.

Parameters
rgiPointer to a struct to store the gateway information.
destDestination IP address in host byte order.
ctxPointer to a platform-specific network context struct.

Definition at line 2534 of file route.c.

References route_gateway_info::adapter_index, route_gateway_address::addr, CLEAR, route_gateway_info::flags, route_gateway_info::gateway, gc, gc_free(), gc_new(), get_adapter(), get_adapter_info_list(), get_best_route(), route_gateway_info::hwaddr, route_gateway_address::netmask, RGI_ADDR_DEFINED, RGI_HWADDR_DEFINED, RGI_IFACE_DEFINED, RGI_NETMASK_DEFINED, RGI_ON_LINK, and status.

Referenced by add_option(), init_route_list(), push_peer_info(), and warn_on_use_of_common_subnets().

◆ get_default_gateway_ipv6()

◆ init_route_ipv6_list()

◆ init_route_list()

◆ ipv6_net_contains_host()

bool ipv6_net_contains_host ( const struct in6_addr * network,
unsigned int bits,
const struct in6_addr * host )

check whether an IPv6 host address is covered by a given network/bits

Parameters
networkthe network address
bitsthe network mask
hostthe host address to be checked if it is contained by the network
Returns
true if the host address is covered by the network with the given network mask by bits

Definition at line 706 of file route.c.

References route_ipv4::network.

Referenced by init_route_ipv6_list(), and multi_check_push_ifconfig_ipv6_extra_route().

◆ is_special_addr()

bool is_special_addr ( const char * addr_str)

Definition at line 289 of file route.c.

References get_special_addr().

Referenced by add_option(), and check_route_option().

◆ netbits_to_netmask()

in_addr_t netbits_to_netmask ( const int netbits)
inlinestatic

◆ netmask_to_netbits()

bool netmask_to_netbits ( const in_addr_t network,
const in_addr_t netmask,
int * netbits )

Definition at line 3829 of file route.c.

References netbits_to_netmask().

Referenced by do_route_ipv4_service(), and helper_client_server().

◆ netmask_to_netbits2()

int netmask_to_netbits2 ( in_addr_t netmask)

◆ new_route_ipv6_option_list()

struct route_ipv6_option_list * new_route_ipv6_option_list ( struct gc_arena * a)

Definition at line 140 of file route.c.

References ALLOC_OBJ_CLEAR_GC, and route_ipv6_option_list::gc.

Referenced by rol6_check_alloc().

◆ new_route_option_list()

struct route_option_list * new_route_option_list ( struct gc_arena * a)

Definition at line 131 of file route.c.

References ALLOC_OBJ_CLEAR_GC, and route_option_list::gc.

Referenced by rol_check_alloc().

◆ print_default_gateway()

◆ print_route_options()

void print_route_options ( const struct route_option_list * rol,
msglvl_t msglevel )

◆ route_did_redirect_default_gateway()

int route_did_redirect_default_gateway ( const struct route_list * rl)
inlinestatic

Definition at line 411 of file route.h.

References BOOL_CAST, route_list::iflags, and RL_DID_REDIRECT_DEFAULT_GATEWAY.

Referenced by do_route().

◆ route_ipv6_clear_host_bits()

void route_ipv6_clear_host_bits ( struct route_ipv6 * r6)

Definition at line 1734 of file route.c.

References r6.

Referenced by add_route_ipv6(), and delete_route_connected_v6_net().

◆ route_list_add_vpn_gateway()

void route_list_add_vpn_gateway ( struct route_list * rl,
struct env_set * es,
const in_addr_t addr )

◆ setenv_routes()

void setenv_routes ( struct env_set * es,
const struct route_list * rl )

Definition at line 1338 of file route.c.

References route_ipv4::next, route_list::routes, and setenv_route().

Referenced by do_init_route_list().

◆ setenv_routes_ipv6()

void setenv_routes_ipv6 ( struct env_set * es,
const struct route_ipv6_list * rl6 )

Definition at line 1375 of file route.c.

References r6, route_ipv6_list::routes_ipv6, and setenv_route_ipv6().

Referenced by do_init_route_ipv6_list().

◆ show_routes()

◆ test_local_addr()

int test_local_addr ( const in_addr_t addr,
const struct route_gateway_info * rgi )

◆ test_routes()