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   (1<<0)
 
#define RG_LOCAL   (1<<1)
 
#define RG_DEF1   (1<<2)
 
#define RG_BYPASS_DHCP   (1<<3)
 
#define RG_BYPASS_DNS   (1<<4)
 
#define RG_REROUTE_GW   (1<<5)
 
#define RG_AUTO_LOCAL   (1<<6)
 
#define RG_BLOCK_LOCAL   (1<<7)
 
#define RT_DEFINED   (1<<0)
 
#define RT_ADDED   (1<<1)
 
#define RT_METRIC_DEFINED   (1<<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   (1<<0)
 
#define RL_DID_LOCAL   (1<<1)
 
#define RL_ROUTES_ADDED   (1<<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. More...
 
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, unsigned int flags, 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)
 
void add_route_ipv6_to_option_list (struct route_ipv6_option_list *l, const char *prefix, const char *gateway, const char *metric)
 
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 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, openvpn_net_ctx_t *ctx)
 
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 int 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, int level)
 
void print_routes (const struct route_list *rl, int level)
 
void show_routes (int msglev)
 
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)
 

Macro Definition Documentation

◆ N_ROUTE_BYPASS

#define N_ROUTE_BYPASS   8

Definition at line 55 of file route.h.

◆ RG_AUTO_LOCAL

#define RG_AUTO_LOCAL   (1<<6)

Definition at line 90 of file route.h.

◆ RG_BLOCK_LOCAL

#define RG_BLOCK_LOCAL   (1<<7)

Definition at line 91 of file route.h.

◆ RG_BYPASS_DHCP

#define RG_BYPASS_DHCP   (1<<3)

Definition at line 87 of file route.h.

◆ RG_BYPASS_DNS

#define RG_BYPASS_DNS   (1<<4)

Definition at line 88 of file route.h.

◆ RG_DEF1

#define RG_DEF1   (1<<2)

Definition at line 86 of file route.h.

◆ RG_ENABLE

#define RG_ENABLE   (1<<0)

Definition at line 84 of file route.h.

◆ RG_LOCAL

#define RG_LOCAL   (1<<1)

Definition at line 85 of file route.h.

◆ RG_REROUTE_GW

#define RG_REROUTE_GW   (1<<5)

Definition at line 89 of file route.h.

◆ RGI_ADDR_DEFINED

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

Definition at line 147 of file route.h.

◆ RGI_HWADDR_DEFINED

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

Definition at line 149 of file route.h.

◆ RGI_IFACE_DEFINED

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

Definition at line 150 of file route.h.

◆ RGI_N_ADDRESSES [1/2]

#define RGI_N_ADDRESSES   8

Definition at line 201 of file route.h.

◆ RGI_N_ADDRESSES [2/2]

#define RGI_N_ADDRESSES   8

Definition at line 201 of file route.h.

◆ RGI_NETMASK_DEFINED

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

Definition at line 148 of file route.h.

◆ RGI_ON_LINK

#define RGI_ON_LINK   (1<<5)

Definition at line 152 of file route.h.

◆ RGI_OVERFLOW

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

Definition at line 151 of file route.h.

◆ RL_DID_LOCAL

#define RL_DID_LOCAL   (1<<1)

Definition at line 208 of file route.h.

◆ RL_DID_REDIRECT_DEFAULT_GATEWAY

#define RL_DID_REDIRECT_DEFAULT_GATEWAY   (1<<0)

Definition at line 207 of file route.h.

◆ RL_ROUTES_ADDED

#define RL_ROUTES_ADDED   (1<<2)

Definition at line 209 of file route.h.

◆ ROUTE_DELETE_FIRST

#define ROUTE_DELETE_FIRST   (1<<2)

Definition at line 50 of file route.h.

◆ ROUTE_METHOD_ADAPTIVE

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

Definition at line 40 of file route.h.

◆ ROUTE_METHOD_EXE

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

Definition at line 42 of file route.h.

◆ ROUTE_METHOD_IPAPI

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

Definition at line 41 of file route.h.

◆ ROUTE_METHOD_MASK

#define ROUTE_METHOD_MASK   3

Definition at line 44 of file route.h.

◆ ROUTE_METHOD_SERVICE

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

Definition at line 43 of file route.h.

◆ ROUTE_REF_GW

#define ROUTE_REF_GW   (1<<3)

Definition at line 51 of file route.h.

◆ RT_ADDED

#define RT_ADDED   (1<<1)

Definition at line 114 of file route.h.

◆ RT_DEFINED

#define RT_DEFINED   (1<<0)

Definition at line 113 of file route.h.

◆ RT_METRIC_DEFINED

#define RT_METRIC_DEFINED   (1<<2)

Definition at line 115 of file route.h.

◆ RTSA_DEFAULT_METRIC

#define RTSA_DEFAULT_METRIC   (1<<2)

Definition at line 65 of file route.h.

◆ RTSA_REMOTE_ENDPOINT

#define RTSA_REMOTE_ENDPOINT   (1<<0)

Definition at line 63 of file route.h.

◆ RTSA_REMOTE_HOST

#define RTSA_REMOTE_HOST   (1<<1)

Definition at line 64 of file route.h.

◆ TLA_LOCAL

#define TLA_LOCAL   2

Definition at line 349 of file route.h.

◆ TLA_NONLOCAL

#define TLA_NONLOCAL   1

Definition at line 348 of file route.h.

◆ TLA_NOT_IMPLEMENTED

#define TLA_NOT_IMPLEMENTED   0

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

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

◆ 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 621 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 164 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 155 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 180 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 173 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,
unsigned int  flags,
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 
)

◆ get_default_gateway()

void get_default_gateway ( struct route_gateway_info rgi,
openvpn_net_ctx_t ctx 
)

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

◆ is_special_addr()

bool is_special_addr ( const char *  addr_str)

Definition at line 306 of file route.c.

References get_special_addr().

Referenced by add_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 3928 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 139 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 130 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 int  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,
int  level 
)

◆ print_routes()

void print_routes ( const struct route_list rl,
int  level 
)

Definition at line 1419 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 404 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 1876 of file route.c.

References route_ipv6::netbits, and route_ipv6::network.

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 391 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 1449 of file route.c.

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

References es, route_ipv6::next, route_ipv6_list::routes_ipv6, and setenv_route_ipv6().

Referenced by do_init_route_ipv6_list().

◆ show_routes()

void show_routes ( int  msglev)

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