Ticket #340: openvpn-route.diff
File openvpn-route.diff, 10.4 KB (added by , 11 years ago) |
---|
-
src/openvpn/route.c
diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 19b4bfe..5efc6cf 100644
a b 49 49 #define METRIC_NOT_USED ((DWORD)-1) 50 50 #endif 51 51 52 static void delete_route (struct route *r, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es);52 static void delete_route (struct route_base *r, const struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const struct env_set *es); 53 53 54 54 static void get_bypass_addresses (struct route_bypass *rb, const unsigned int flags); 55 55 … … struct route_list * 150 150 new_route_list (const int max_routes, struct gc_arena *a) 151 151 { 152 152 struct route_list *ret; 153 ALLOC_VAR_ARRAY_CLEAR_GC (ret, struct route_list, struct route , max_routes, a);153 ALLOC_VAR_ARRAY_CLEAR_GC (ret, struct route_list, struct route_base, max_routes, a); 154 154 ret->capacity = max_routes; 155 155 return ret; 156 156 } … … new_route_ipv6_list (const int max_routes, struct gc_arena *a) 165 165 } 166 166 167 167 static const char * 168 route_string (const struct route *r, struct gc_arena *gc)168 route_string (const struct route_base *r, struct gc_arena *gc) 169 169 { 170 170 struct buffer out = alloc_buf_gc (256, gc); 171 171 buf_printf (&out, "ROUTE network %s netmask %s gateway %s", … … is_special_addr (const char *addr_str) 267 267 } 268 268 269 269 static bool 270 init_route (struct route *r,270 init_route (struct route_base *r, 271 271 struct addrinfo **network_list, 272 272 const struct route_option *ro, 273 273 const struct route_list *rl) … … void 484 484 clear_route_list (struct route_list *rl) 485 485 { 486 486 const int capacity = rl->capacity; 487 const size_t rl_size = array_mult_safe (sizeof(struct route ), capacity, sizeof(struct route_list));487 const size_t rl_size = array_mult_safe (sizeof(struct route_base), capacity, sizeof(struct route_list)); 488 488 memset(rl, 0, rl_size); 489 489 rl->capacity = capacity; 490 490 } … … add_block_local_item (struct route_list *rl, 519 519 && rl->rgi.gateway.netmask < 0xFFFFFFFF 520 520 && (rl->n)+2 <= rl->capacity) 521 521 { 522 struct route r;522 struct route_base r; 523 523 unsigned int l2; 524 524 525 525 /* split a route into two smaller blocking routes, and direct them to target */ … … init_route_list (struct route_list *rl, 649 649 for (i = 0; i < opt->n; ++i) 650 650 { 651 651 struct addrinfo* netlist; 652 struct route r;652 struct route_base r; 653 653 654 654 if (!init_route (&r, 655 655 &netlist, … … add_route3 (in_addr_t network, 760 760 const struct route_gateway_info *rgi, 761 761 const struct env_set *es) 762 762 { 763 struct route r;763 struct route_base r; 764 764 CLEAR (r); 765 765 r.flags = RT_DEFINED; 766 766 r.network = network; … … del_route3 (in_addr_t network, 778 778 const struct route_gateway_info *rgi, 779 779 const struct env_set *es) 780 780 { 781 struct route r;781 struct route_base r; 782 782 CLEAR (r); 783 783 r.flags = RT_DEFINED|RT_ADDED; 784 784 r.network = network; … … add_routes (struct route_list *rl, struct route_ipv6_list *rl6, const struct tun 1028 1028 1029 1029 for (i = 0; i < rl->n; ++i) 1030 1030 { 1031 struct route *r = &rl->routes[i];1031 struct route_base *r = &rl->routes[i]; 1032 1032 check_subnet_conflict (r->network, r->netmask, "route"); 1033 1033 if (flags & ROUTE_DELETE_FIRST) 1034 1034 delete_route (r, tt, flags, &rl->rgi, es); … … delete_routes (struct route_list *rl, struct route_ipv6_list *rl6, 1060 1060 int i; 1061 1061 for (i = rl->n - 1; i >= 0; --i) 1062 1062 { 1063 struct route * r = &rl->routes[i];1063 struct route_base * r = &rl->routes[i]; 1064 1064 delete_route (r, tt, flags, &rl->rgi, es); 1065 1065 } 1066 1066 rl->iflags &= ~RL_ROUTES_ADDED; … … print_default_gateway(const int msglevel, const struct route_gateway_info *rgi) 1154 1154 #endif 1155 1155 1156 1156 static void 1157 print_route (const struct route *r, int level)1157 print_route (const struct route_base *r, int level) 1158 1158 { 1159 1159 struct gc_arena gc = gc_new (); 1160 1160 if (r->flags & RT_DEFINED) … … print_routes (const struct route_list *rl, int level) 1171 1171 } 1172 1172 1173 1173 static void 1174 setenv_route (struct env_set *es, const struct route *r, int i)1174 setenv_route (struct env_set *es, const struct route_base *r, int i) 1175 1175 { 1176 1176 struct gc_arena gc = gc_new (); 1177 1177 if (r->flags & RT_DEFINED) … … is_on_link (const int is_local_route, const unsigned int flags, const struct rou 1288 1288 } 1289 1289 1290 1290 void 1291 add_route (struct route *r,1291 add_route (struct route_base *r, 1292 1292 const struct tuntap *tt, 1293 1293 unsigned int flags, 1294 1294 const struct route_gateway_info *rgi, /* may be NULL */ … … add_route_ipv6 (struct route_ipv6 *r6, const struct tuntap *tt, unsigned int fla 1741 1741 } 1742 1742 1743 1743 static void 1744 delete_route (struct route *r,1744 delete_route (struct route_base *r, 1745 1745 const struct tuntap *tt, 1746 1746 unsigned int flags, 1747 1747 const struct route_gateway_info *rgi, … … get_default_gateway (struct route_gateway_info *rgi) 2246 2246 } 2247 2247 2248 2248 static DWORD 2249 windows_route_find_if_index (const struct route *r, const struct tuntap *tt)2249 windows_route_find_if_index (const struct route_base *r, const struct tuntap *tt) 2250 2250 { 2251 2251 struct gc_arena gc = gc_new (); 2252 2252 DWORD ret = TUN_ADAPTER_INDEX_INVALID; … … windows_route_find_if_index (const struct route *r, const struct tuntap *tt) 2291 2291 } 2292 2292 2293 2293 bool 2294 add_route_ipapi (const struct route *r, const struct tuntap *tt, DWORD adapter_index)2294 add_route_ipapi (const struct route_base *r, const struct tuntap *tt, DWORD adapter_index) 2295 2295 { 2296 2296 struct gc_arena gc = gc_new (); 2297 2297 bool ret = false; … … add_route_ipapi (const struct route *r, const struct tuntap *tt, DWORD adapter_i 2365 2365 } 2366 2366 2367 2367 bool 2368 del_route_ipapi (const struct route *r, const struct tuntap *tt)2368 del_route_ipapi (const struct route_base *r, const struct tuntap *tt) 2369 2369 { 2370 2370 struct gc_arena gc = gc_new (); 2371 2371 bool ret = false; … … get_default_gateway (struct route_gateway_info *rgi) 2976 2976 #include <sys/types.h> 2977 2977 #include <sys/socket.h> 2978 2978 #include <netinet/in.h> 2979 2980 /* all of this is taken from <net/route.h> in OpenBSD 3.6 */ 2981 #define RTA_DST 0x1 /* destination sockaddr present */ 2982 #define RTA_GATEWAY 0x2 /* gateway sockaddr present */ 2983 #define RTA_NETMASK 0x4 /* netmask sockaddr present */ 2984 2985 #define RTM_GET 0x4 /* Report Metrics */ 2986 2987 #define RTM_VERSION 3 /* Up the ante and ignore older versions */ 2988 2989 #define RTF_UP 0x1 /* route usable */ 2990 #define RTF_GATEWAY 0x2 /* destination is a gateway */ 2991 2992 /* 2993 * Huge version for userland compatibility. 2994 */ 2995 struct rt_metrics { 2996 u_long rmx_locks; /* Kernel must leave these values alone */ 2997 u_long rmx_mtu; /* MTU for this path */ 2998 u_long rmx_hopcount; /* max hops expected */ 2999 u_long rmx_expire; /* lifetime for route, e.g. redirect */ 3000 u_long rmx_recvpipe; /* inbound delay-bandwidth product */ 3001 u_long rmx_sendpipe; /* outbound delay-bandwidth product */ 3002 u_long rmx_ssthresh; /* outbound gateway buffer limit */ 3003 u_long rmx_rtt; /* estimated round trip time */ 3004 u_long rmx_rttvar; /* estimated rtt variance */ 3005 u_long rmx_pksent; /* packets sent using this route */ 3006 }; 3007 3008 /* 3009 * Structures for routing messages. 3010 */ 3011 struct rt_msghdr { 3012 u_short rtm_msglen; /* to skip over non-understood messages */ 3013 u_char rtm_version; /* future binary compatibility */ 3014 u_char rtm_type; /* message type */ 3015 u_short rtm_index; /* index for associated ifp */ 3016 int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ 3017 int rtm_addrs; /* bitmask identifying sockaddrs in msg */ 3018 pid_t rtm_pid; /* identify sender */ 3019 int rtm_seq; /* for sender to identify action */ 3020 int rtm_errno; /* why failed */ 3021 int rtm_use; /* from rtentry */ 3022 u_long rtm_inits; /* which metrics we are initializing */ 3023 struct rt_metrics rtm_rmx; /* metrics themselves */ 3024 }; 2979 #include <net/route.h> 3025 2980 3026 2981 struct { 3027 2982 struct rt_msghdr m_rtm; -
src/openvpn/route.h
diff --git a/src/openvpn/route.h b/src/openvpn/route.h index a40de32..f12b942 100644
a b struct route_ipv6_option_list { 110 110 struct route_ipv6_option routes_ipv6[EMPTY_ARRAY_SIZE]; 111 111 }; 112 112 113 struct route {113 struct route_base { 114 114 # define RT_DEFINED (1<<0) 115 115 # define RT_ADDED (1<<1) 116 116 # define RT_METRIC_DEFINED (1<<2) … … struct route_list { 190 190 unsigned int flags; /* RG_x flags */ 191 191 int capacity; 192 192 int n; 193 struct route routes[EMPTY_ARRAY_SIZE];193 struct route_base routes[EMPTY_ARRAY_SIZE]; 194 194 }; 195 195 196 196 #if P2MP … … struct route_ipv6_list *new_route_ipv6_list (const int max_routes, struct gc_are 223 223 void add_route_ipv6 (struct route_ipv6 *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es); 224 224 void delete_route_ipv6 (const struct route_ipv6 *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es); 225 225 226 void add_route (struct route *r,226 void add_route (struct route_base *r, 227 227 const struct tuntap *tt, 228 228 unsigned int flags, 229 229 const struct route_gateway_info *rgi, … … void print_routes (const struct route_list *rl, int level); 301 301 302 302 void show_routes (int msglev); 303 303 bool test_routes (const struct route_list *rl, const struct tuntap *tt); 304 bool add_route_ipapi (const struct route *r, const struct tuntap *tt, DWORD adapter_index);305 bool del_route_ipapi (const struct route *r, const struct tuntap *tt);304 bool add_route_ipapi (const struct route_base *r, const struct tuntap *tt, DWORD adapter_index); 305 bool del_route_ipapi (const struct route_base *r, const struct tuntap *tt); 306 306 307 307 #else 308 308 static inline bool test_routes (const struct route_list *rl, const struct tuntap *tt) { return true; } -
src/openvpn/tun.c
diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 86a43f2..ea7594b 100644
a b do_ifconfig (struct tuntap *tt, 902 902 if (!tun && tt->topology == TOP_SUBNET) 903 903 { 904 904 /* Add a network route for the local tun interface */ 905 struct route r;905 struct route_base r; 906 906 CLEAR (r); 907 907 r.flags = RT_DEFINED | RT_METRIC_DEFINED; 908 908 r.network = tt->local & tt->remote_netmask; … … do_ifconfig (struct tuntap *tt, 1099 1099 /* Add a network route for the local tun interface */ 1100 1100 if (!tun && tt->topology == TOP_SUBNET) 1101 1101 { 1102 struct route r;1102 struct route_base r; 1103 1103 CLEAR (r); 1104 1104 r.flags = RT_DEFINED; 1105 1105 r.network = tt->local & tt->remote_netmask; … … do_ifconfig (struct tuntap *tt, 1165 1165 /* Add a network route for the local tun interface */ 1166 1166 if (!tun && tt->topology == TOP_SUBNET) 1167 1167 { 1168 struct route r;1168 struct route_base r; 1169 1169 CLEAR (r); 1170 1170 r.flags = RT_DEFINED; 1171 1171 r.network = tt->local & tt->remote_netmask;