OpenVPN
Data Structures | Macros | Functions
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_listnew_route_option_list (struct gc_arena *a)
 
struct route_ipv6_option_listnew_route_ipv6_option_list (struct gc_arena *a)
 
struct route_option_listclone_route_option_list (const struct route_option_list *src, struct gc_arena *a)
 
struct route_ipv6_option_listclone_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 print_routes (const struct route_list *rl, 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 bool route_list_vpn_gateway_needed (const struct route_list *rl)
 
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.

◆ RG_AUTO_LOCAL

#define RG_AUTO_LOCAL   (1u << 6)

Definition at line 92 of file route.h.

◆ RG_BLOCK_LOCAL

#define RG_BLOCK_LOCAL   (1u << 7)

Definition at line 93 of file route.h.

◆ RG_BYPASS_DHCP

#define RG_BYPASS_DHCP   (1u << 3)

Definition at line 89 of file route.h.

◆ RG_BYPASS_DNS

#define RG_BYPASS_DNS   (1u << 4)

Definition at line 90 of file route.h.

◆ RG_DEF1

#define RG_DEF1   (1u << 2)

Definition at line 88 of file route.h.

◆ RG_ENABLE

#define RG_ENABLE   (1u << 0)

Definition at line 86 of file route.h.

◆ RG_LOCAL

#define RG_LOCAL   (1u << 1)

Definition at line 87 of file route.h.

◆ RG_REROUTE_GW

#define RG_REROUTE_GW   (1u << 5)

Definition at line 91 of file route.h.

◆ RGI_ADDR_DEFINED

#define RGI_ADDR_DEFINED   (1 << 0) /* set if gateway.addr defined */

Definition at line 159 of file route.h.

◆ RGI_HWADDR_DEFINED

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

Definition at line 161 of file route.h.

◆ RGI_IFACE_DEFINED

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

Definition at line 162 of file route.h.

◆ 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 */

Definition at line 160 of file route.h.

◆ RGI_ON_LINK

#define RGI_ON_LINK   (1 << 5)

Definition at line 164 of file route.h.

◆ 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.

◆ RL_DID_REDIRECT_DEFAULT_GATEWAY

#define RL_DID_REDIRECT_DEFAULT_GATEWAY   (1u << 0)

Definition at line 230 of file route.h.

◆ RL_ROUTES_ADDED

#define RL_ROUTES_ADDED   (1u << 2)

Definition at line 232 of file route.h.

◆ ROUTE_DELETE_FIRST

#define ROUTE_DELETE_FIRST   (1 << 2)

Definition at line 49 of file route.h.

◆ ROUTE_METHOD_ADAPTIVE

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

Definition at line 39 of file route.h.

◆ ROUTE_METHOD_EXE

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

Definition at line 41 of file route.h.

◆ ROUTE_METHOD_IPAPI

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

Definition at line 40 of file route.h.

◆ ROUTE_METHOD_MASK

#define ROUTE_METHOD_MASK   3

Definition at line 43 of file route.h.

◆ ROUTE_METHOD_SERVICE

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

Definition at line 42 of file route.h.

◆ ROUTE_REF_GW

#define ROUTE_REF_GW   (1 << 3)

Definition at line 50 of file route.h.

◆ RT_ADDED

#define RT_ADDED   (1u << 1)

Definition at line 121 of file route.h.

◆ RT_DEFINED

#define RT_DEFINED   (1u << 0)

Definition at line 120 of file route.h.

◆ RT_METRIC_DEFINED

#define RT_METRIC_DEFINED   (1u << 2)

Definition at line 122 of file route.h.

◆ RTSA_DEFAULT_METRIC

#define RTSA_DEFAULT_METRIC   (1 << 2)

Definition at line 64 of file route.h.

◆ RTSA_REMOTE_ENDPOINT

#define RTSA_REMOTE_ENDPOINT   (1 << 0)

Definition at line 62 of file route.h.

◆ RTSA_REMOTE_HOST

#define RTSA_REMOTE_HOST   (1 << 1)

Definition at line 63 of file route.h.

◆ TLA_LOCAL

#define TLA_LOCAL   2

Definition at line 370 of file route.h.

◆ TLA_NONLOCAL

#define TLA_NONLOCAL   1

Definition at line 369 of file route.h.

◆ TLA_NOT_IMPLEMENTED

#define TLA_NOT_IMPLEMENTED   0

Definition at line 368 of file route.h.

Function Documentation

◆ add_route()

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 
)

◆ add_route_ipv6()

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 
)

◆ 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()

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 
)

◆ 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 596 of file route.c.

References route_special_addr::flags, route_gateway_info::flags, route_list::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 162 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 153 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 179 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 171 of file route.c.

References route_option_list::gc.

Referenced by pre_connect_restore().

◆ delete_route_ipv6()

void delete_route_ipv6 ( const struct route_ipv6 r,
const struct tuntap tt,
const struct env_set es,
openvpn_net_ctx_t ctx 
)

◆ 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 1162 of file route.c.

References delete_routes_v4(), delete_routes_v6(), es, 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 2566 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()

void get_default_gateway_ipv6 ( struct route_ipv6_gateway_info rgi,
const struct in6_addr *  dest,
openvpn_net_ctx_t ctx 
)

◆ init_route_ipv6_list()

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 
)

◆ init_route_list()

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 
)

◆ 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 714 of file route.c.

References i, and route_ipv4::network.

Referenced by init_route_ipv6_list().

◆ is_special_addr()

bool is_special_addr ( const char *  addr_str)

Definition at line 299 of file route.c.

References get_special_addr(), and buffer::len.

Referenced by add_option(), and check_route_option().

◆ netbits_to_netmask()

static 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 3874 of file route.c.

References i, and 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 137 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 128 of file route.c.

References ALLOC_OBJ_CLEAR_GC, and route_option_list::gc.

Referenced by rol_check_alloc().

◆ print_default_gateway()

void print_default_gateway ( const msglvl_t  msglevel,
const struct route_gateway_info rgi,
const struct route_ipv6_gateway_info rgi6 
)

◆ print_route_options()

void print_route_options ( const struct route_option_list rol,
msglvl_t  msglevel 
)

◆ print_routes()

void print_routes ( const struct route_list rl,
msglvl_t  msglevel 
)

Definition at line 1333 of file route.c.

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

◆ route_did_redirect_default_gateway()

static int route_did_redirect_default_gateway ( const struct route_list rl)
inlinestatic

Definition at line 424 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 1765 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 
)

◆ route_list_vpn_gateway_needed()

static bool route_list_vpn_gateway_needed ( const struct route_list rl)
inlinestatic

Definition at line 411 of file route.h.

References route_special_addr::flags, RTSA_REMOTE_ENDPOINT, and route_list::spec.

◆ setenv_routes()

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

Definition at line 1363 of file route.c.

References es, i, 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 1400 of file route.c.

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

Referenced by do_init_route_ipv6_list().

◆ show_routes()

void show_routes ( msglvl_t  msglevel)

◆ test_local_addr()

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

◆ test_routes()

bool test_routes ( const struct route_list rl,
const struct tuntap tt 
)