OpenVPN
Macros | Functions
route.c File Reference
#include "syshead.h"
#include "common.h"
#include "error.h"
#include "route.h"
#include "run_command.h"
#include "socket.h"
#include "manage.h"
#include "win32.h"
#include "options.h"
#include "memdbg.h"
#include "openvpn-msg.h"
Include dependency graph for route.c:

Go to the source code of this file.

Macros

#define METRIC_NOT_USED   ((DWORD)-1)
 
#define LR_NOMATCH   0 /* route is not local */
 
#define LR_MATCH   1 /* route is local */
 
#define LR_ERROR   2 /* caller should abort adding route */
 

Functions

static bool add_route_service (const struct route_ipv4 *, const struct tuntap *)
 
static bool del_route_service (const struct route_ipv4 *, const struct tuntap *)
 
static bool add_route_ipv6_service (const struct route_ipv6 *, const struct tuntap *)
 
static bool del_route_ipv6_service (const struct route_ipv6 *, const struct tuntap *)
 
static void delete_route (struct route_ipv4 *r, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es)
 
static void get_bypass_addresses (struct route_bypass *rb, const unsigned int flags)
 
static bool add_bypass_address (struct route_bypass *rb, const in_addr_t a)
 
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)
 
static const char * route_string (const struct route_ipv4 *r, struct gc_arena *gc)
 
static bool is_route_parm_defined (const char *parm)
 
static void setenv_route_addr (struct env_set *es, const char *key, const in_addr_t addr, int i)
 
static bool get_special_addr (const struct route_list *rl, const char *string, in_addr_t *out, bool *status)
 
bool is_special_addr (const char *addr_str)
 
static bool init_route (struct route_ipv4 *r, struct addrinfo **network_list, const struct route_option *ro, const struct route_list *rl)
 
static bool init_route_ipv6 (struct route_ipv6 *r6, const struct route_ipv6_option *r6o, const struct route_ipv6_list *rl6)
 
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)
 
static void clear_route_list (struct route_list *rl)
 
static void clear_route_ipv6_list (struct route_ipv6_list *rl6)
 
void route_list_add_vpn_gateway (struct route_list *rl, struct env_set *es, const in_addr_t addr)
 
static void add_block_local_item (struct route_list *rl, const struct route_gateway_address *gateway, in_addr_t target)
 
static void add_block_local (struct route_list *rl)
 
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)
 
static bool route_ipv6_match_host (const struct route_ipv6 *r6, const struct in6_addr *host)
 
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_ipv6, struct env_set *es)
 
static void add_route3 (in_addr_t network, in_addr_t netmask, in_addr_t gateway, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es)
 
static void del_route3 (in_addr_t network, in_addr_t netmask, in_addr_t gateway, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es)
 
static void add_bypass_routes (struct route_bypass *rb, in_addr_t gateway, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es)
 
static void del_bypass_routes (struct route_bypass *rb, in_addr_t gateway, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es)
 
static void redirect_default_route_to_vpn (struct route_list *rl, const struct tuntap *tt, unsigned int flags, const struct env_set *es)
 
static void undo_redirect_default_route_to_vpn (struct route_list *rl, const struct tuntap *tt, unsigned int flags, const struct env_set *es)
 
void add_routes (struct route_list *rl, struct route_ipv6_list *rl6, const struct tuntap *tt, unsigned int flags, const struct env_set *es)
 
void delete_routes (struct route_list *rl, struct route_ipv6_list *rl6, const struct tuntap *tt, unsigned int flags, const struct env_set *es)
 
static const char * show_opt (const char *option)
 
static void print_route_option (const struct route_option *ro, int level)
 
void print_route_options (const struct route_option_list *rol, int level)
 
void print_default_gateway (const int msglevel, const struct route_gateway_info *rgi, const struct route_ipv6_gateway_info *rgi6)
 
static void print_route (const struct route_ipv4 *r, int level)
 
void print_routes (const struct route_list *rl, int level)
 
static void setenv_route (struct env_set *es, const struct route_ipv4 *r, int i)
 
void setenv_routes (struct env_set *es, const struct route_list *rl)
 
static void setenv_route_ipv6 (struct env_set *es, const struct route_ipv6 *r6, int i)
 
void setenv_routes_ipv6 (struct env_set *es, const struct route_ipv6_list *rl6)
 
static int local_route (in_addr_t network, in_addr_t netmask, in_addr_t gateway, const struct route_gateway_info *rgi)
 
static bool is_on_link (const int is_local_route, const unsigned int flags, const struct route_gateway_info *rgi)
 
void add_route (struct route_ipv4 *r, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es)
 
void route_ipv6_clear_host_bits (struct route_ipv6 *r6)
 
void add_route_ipv6 (struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flags, const struct env_set *es)
 
void delete_route_ipv6 (const struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flags, const struct env_set *es)
 
static const MIB_IPFORWARDTABLE * get_windows_routing_table (struct gc_arena *gc)
 
static int test_route (const IP_ADAPTER_INFO *adapters, const in_addr_t gateway, DWORD *index)
 
static void test_route_helper (bool *ret, int *count, int *good, int *ambig, const IP_ADAPTER_INFO *adapters, const in_addr_t gateway)
 
bool test_routes (const struct route_list *rl, const struct tuntap *tt)
 
static const MIB_IPFORWARDROW * get_default_gateway_row (const MIB_IPFORWARDTABLE *routes)
 
void get_default_gateway (struct route_gateway_info *rgi)
 
static DWORD windows_route_find_if_index (const struct route_ipv4 *r, const struct tuntap *tt)
 
void get_default_gateway_ipv6 (struct route_ipv6_gateway_info *rgi6, const struct in6_addr *dest)
 
bool add_route_ipapi (const struct route_ipv4 *r, const struct tuntap *tt, DWORD adapter_index)
 
bool del_route_ipapi (const struct route_ipv4 *r, const struct tuntap *tt)
 
static bool do_route_service (const bool add, const route_message_t *rt, const size_t size, HANDLE pipe)
 
static bool do_route_ipv4_service (const bool add, const struct route_ipv4 *r, const struct tuntap *tt)
 
static bool do_route_ipv6_service (const bool add, const struct route_ipv6 *r, const struct tuntap *tt)
 
static const char * format_route_entry (const MIB_IPFORWARDROW *r, struct gc_arena *gc)
 
void show_routes (int msglev)
 
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 void add_host_route_if_nonlocal (struct route_bypass *rb, const in_addr_t addr)
 
static void add_host_route_array (struct route_bypass *rb, const IP_ADDR_STRING *iplist)
 
int test_local_addr (const in_addr_t addr, const struct route_gateway_info *rgi)
 

Macro Definition Documentation

◆ LR_ERROR

#define LR_ERROR   2 /* caller should abort adding route */

Definition at line 1474 of file route.c.

Referenced by add_route(), and delete_route().

◆ LR_MATCH

#define LR_MATCH   1 /* route is local */

Definition at line 1473 of file route.c.

Referenced by is_on_link(), and local_route().

◆ LR_NOMATCH

#define LR_NOMATCH   0 /* route is not local */

Definition at line 1472 of file route.c.

Referenced by local_route().

◆ METRIC_NOT_USED

#define METRIC_NOT_USED   ((DWORD)-1)

Definition at line 54 of file route.c.

Referenced by add_route_ipapi().

Function Documentation

◆ add_block_local()

static void add_block_local ( struct route_list rl)
static

◆ add_block_local_item()

static void add_block_local_item ( struct route_list rl,
const struct route_gateway_address gateway,
in_addr_t  target 
)
static

◆ add_bypass_address()

static bool add_bypass_address ( struct route_bypass rb,
const in_addr_t  a 
)
static

Definition at line 88 of file route.c.

References route_bypass::bypass, route_bypass::n_bypass, and N_ROUTE_BYPASS.

Referenced by add_block_local(), and add_host_route_if_nonlocal().

◆ add_bypass_routes()

static void add_bypass_routes ( struct route_bypass rb,
in_addr_t  gateway,
const struct tuntap tt,
unsigned int  flags,
const struct route_gateway_info rgi,
const struct env_set es 
)
static

◆ add_host_route_array()

static void add_host_route_array ( struct route_bypass rb,
const IP_ADDR_STRING *  iplist 
)
static

Definition at line 4080 of file route.c.

References add_host_route_if_nonlocal(), getaddr(), GETADDR_HOST_ORDER, and in_addr_t.

Referenced by get_bypass_addresses().

◆ add_host_route_if_nonlocal()

static void add_host_route_if_nonlocal ( struct route_bypass rb,
const in_addr_t  addr 
)
static

Definition at line 4071 of file route.c.

References add_bypass_address(), IPV4_NETMASK_HOST, test_local_addr(), and TLA_NONLOCAL.

Referenced by add_host_route_array().

◆ add_route()

void add_route ( struct route_ipv4 r,
const struct tuntap tt,
unsigned int  flags,
const struct route_gateway_info rgi,
const struct env_set es 
)

◆ add_route3()

static void add_route3 ( in_addr_t  network,
in_addr_t  netmask,
in_addr_t  gateway,
const struct tuntap tt,
unsigned int  flags,
const struct route_gateway_info rgi,
const struct env_set es 
)
static

◆ add_route_ipapi()

bool add_route_ipapi ( const struct route_ipv4 r,
const struct tuntap tt,
DWORD  adapter_index 
)

◆ add_route_ipv6()

void add_route_ipv6 ( struct route_ipv6 r6,
const struct tuntap tt,
unsigned int  flags,
const struct env_set es 
)

◆ add_route_ipv6_service()

static bool add_route_ipv6_service ( const struct route_ipv6 r,
const struct tuntap tt 
)
static

Definition at line 3114 of file route.c.

References do_route_ipv6_service().

Referenced by 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 
)

◆ add_route_service()

static bool add_route_service ( const struct route_ipv4 r,
const struct tuntap tt 
)
static

Definition at line 3102 of file route.c.

References do_route_ipv4_service().

Referenced by add_route().

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

void add_routes ( struct route_list rl,
struct route_ipv6_list rl6,
const struct tuntap tt,
unsigned int  flags,
const struct env_set es 
)

◆ clear_route_ipv6_list()

static void clear_route_ipv6_list ( struct route_ipv6_list rl6)
static

Definition at line 524 of file route.c.

References CLEAR, route_ipv6_list::gc, and gc_free().

Referenced by delete_routes(), and init_route_ipv6_list().

◆ clear_route_list()

static void clear_route_list ( struct route_list rl)
static

Definition at line 517 of file route.c.

References CLEAR, route_list::gc, and gc_free().

Referenced by delete_routes(), 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 144 of file route.c.

References ALLOC_OBJ_GC.

Referenced by pre_pull_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 135 of file route.c.

References ALLOC_OBJ_GC.

Referenced by pre_pull_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 160 of file route.c.

References route_ipv6_option_list::gc.

Referenced by pre_pull_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 153 of file route.c.

References route_option_list::gc.

Referenced by pre_pull_restore().

◆ del_bypass_routes()

static void del_bypass_routes ( struct route_bypass rb,
in_addr_t  gateway,
const struct tuntap tt,
unsigned int  flags,
const struct route_gateway_info rgi,
const struct env_set es 
)
static

◆ del_route3()

static void del_route3 ( in_addr_t  network,
in_addr_t  netmask,
in_addr_t  gateway,
const struct tuntap tt,
unsigned int  flags,
const struct route_gateway_info rgi,
const struct env_set es 
)
static

◆ del_route_ipapi()

bool del_route_ipapi ( const struct route_ipv4 r,
const struct tuntap tt 
)

◆ del_route_ipv6_service()

static bool del_route_ipv6_service ( const struct route_ipv6 r,
const struct tuntap tt 
)
static

Definition at line 3120 of file route.c.

References do_route_ipv6_service().

Referenced by delete_route_ipv6().

◆ del_route_service()

static bool del_route_service ( const struct route_ipv4 r,
const struct tuntap tt 
)
static

Definition at line 3108 of file route.c.

References do_route_ipv4_service().

Referenced by delete_route().

◆ delete_route()

static void delete_route ( struct route_ipv4 r,
const struct tuntap tt,
unsigned int  flags,
const struct route_gateway_info rgi,
const struct env_set es 
)
static

◆ delete_route_ipv6()

void delete_route_ipv6 ( const struct route_ipv6 r6,
const struct tuntap tt,
unsigned int  flags,
const struct env_set es 
)

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

◆ do_route_ipv4_service()

static bool do_route_ipv4_service ( const bool  add,
const struct route_ipv4 r,
const struct tuntap tt 
)
static

◆ do_route_ipv6_service()

static bool do_route_ipv6_service ( const bool  add,
const struct route_ipv6 r,
const struct tuntap tt 
)
static

◆ do_route_service()

static bool do_route_service ( const bool  add,
const route_message_t rt,
const size_t  size,
HANDLE  pipe 
)
static

◆ format_route_entry()

static const char* format_route_entry ( const MIB_IPFORWARDROW *  r,
struct gc_arena gc 
)
static

Definition at line 3126 of file route.c.

References alloc_buf_gc(), BSTR, buf_printf(), IA_NET_ORDER, and print_in_addr_t().

Referenced by show_routes().

◆ get_bypass_addresses()

static void get_bypass_addresses ( struct route_bypass rb,
const unsigned int  flags 
)
static

◆ get_default_gateway()

void get_default_gateway ( struct route_gateway_info rgi)

◆ get_default_gateway_ipv6()

void get_default_gateway_ipv6 ( struct route_ipv6_gateway_info rgi6,
const struct in6_addr *  dest 
)

◆ get_default_gateway_row()

static const MIB_IPFORWARDROW* get_default_gateway_row ( const MIB_IPFORWARDTABLE *  routes)
static

Definition at line 2683 of file route.c.

References D_ROUTE_DEBUG, dmsg, gc_free(), gc_new(), in_addr_t, and print_in_addr_t().

Referenced by get_bypass_addresses(), and get_default_gateway().

◆ get_special_addr()

static bool get_special_addr ( const struct route_list rl,
const char *  string,
in_addr_t out,
bool status 
)
static

◆ get_windows_routing_table()

static const MIB_IPFORWARDTABLE* get_windows_routing_table ( struct gc_arena gc)
static

◆ init_route()

static bool init_route ( struct route_ipv4 r,
struct addrinfo **  network_list,
const struct route_option ro,
const struct route_list rl 
)
static

◆ init_route_ipv6()

static bool init_route_ipv6 ( struct route_ipv6 r6,
const struct route_ipv6_option r6o,
const struct route_ipv6_list rl6 
)
static

◆ 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_ipv6,
struct env_set es 
)

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

◆ is_on_link()

static bool is_on_link ( const int  is_local_route,
const unsigned int  flags,
const struct route_gateway_info rgi 
)
inlinestatic

Definition at line 1513 of file route.c.

References route_gateway_info::flags, LR_MATCH, RGI_ON_LINK, and ROUTE_REF_GW.

Referenced by add_route(), and delete_route().

◆ is_route_parm_defined()

static bool is_route_parm_defined ( const char *  parm)
static

Definition at line 185 of file route.c.

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

◆ is_special_addr()

bool is_special_addr ( const char *  addr_str)

Definition at line 286 of file route.c.

References get_special_addr().

Referenced by add_option().

◆ local_route()

static int local_route ( in_addr_t  network,
in_addr_t  netmask,
in_addr_t  gateway,
const struct route_gateway_info rgi 
)
static

◆ netmask_to_netbits()

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

Definition at line 4014 of file route.c.

References in_addr_t, and netbits_to_netmask().

Referenced by do_route_ipv4_service(), helper_client_server(), and option_iroute().

◆ netmask_to_netbits2()

int netmask_to_netbits2 ( in_addr_t  netmask)

Definition at line 4045 of file route.c.

References in_addr_t, and netbits_to_netmask().

Referenced by add_route(), delete_route(), do_ifconfig_ipv4(), and open_null().

◆ new_route_ipv6_option_list()

struct route_ipv6_option_list* new_route_ipv6_option_list ( struct gc_arena a)

Definition at line 119 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 110 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()

static void print_route ( const struct route_ipv4 r,
int  level 
)
static

Definition at line 1371 of file route.c.

References route_ipv4::flags, gc_free(), gc_new(), msg, route_string(), and RT_DEFINED.

Referenced by print_routes().

◆ print_route_option()

static void print_route_option ( const struct route_option ro,
int  level 
)
static

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

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

◆ redirect_default_route_to_vpn()

static void redirect_default_route_to_vpn ( struct route_list rl,
const struct tuntap tt,
unsigned int  flags,
const struct env_set es 
)
static

◆ route_ipv6_clear_host_bits()

void route_ipv6_clear_host_bits ( struct route_ipv6 r6)

Definition at line 1819 of file route.c.

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

Referenced by add_route_ipv6(), and delete_route_connected_v6_net().

◆ route_ipv6_match_host()

static bool route_ipv6_match_host ( const struct route_ipv6 r6,
const struct in6_addr *  host 
)
static

Definition at line 725 of file route.c.

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

Referenced by init_route_ipv6_list().

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

static const char* route_string ( const struct route_ipv4 r,
struct gc_arena gc 
)
static

◆ setenv_route()

static void setenv_route ( struct env_set es,
const struct route_ipv4 r,
int  i 
)
static

◆ setenv_route_addr()

static void setenv_route_addr ( struct env_set es,
const char *  key,
const in_addr_t  addr,
int  i 
)
static

◆ setenv_route_ipv6()

static void setenv_route_ipv6 ( struct env_set es,
const struct route_ipv6 r6,
int  i 
)
static

◆ setenv_routes()

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

Definition at line 1412 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 1443 of file route.c.

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

Referenced by do_init_route_ipv6_list().

◆ show_opt()

static const char* show_opt ( const char *  option)
static

Definition at line 1257 of file route.c.

Referenced by print_route_option().

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

static int test_route ( const IP_ADAPTER_INFO *  adapters,
const in_addr_t  gateway,
DWORD *  index 
)
static

Definition at line 2592 of file route.c.

References adapter_index_of_ip().

Referenced by test_route_helper(), and windows_route_find_if_index().

◆ test_route_helper()

static void test_route_helper ( bool ret,
int *  count,
int *  good,
int *  ambig,
const IP_ADAPTER_INFO *  adapters,
const in_addr_t  gateway 
)
static

Definition at line 2606 of file route.c.

References test_route().

Referenced by test_routes().

◆ test_routes()

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

◆ undo_redirect_default_route_to_vpn()

static void undo_redirect_default_route_to_vpn ( struct route_list rl,
const struct tuntap tt,
unsigned int  flags,
const struct env_set es 
)
static

◆ windows_route_find_if_index()

static DWORD windows_route_find_if_index ( const struct route_ipv4 r,
const struct tuntap tt 
)
static