Use the following constants:
- METRIC_NOT_USED
- TUN_ADAPTER_INDEX_INVALID
Modified: Use MAXDWORD for route loop.
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Signed-off-by: David Sommerseth <davids@redhat.com>
... | ... |
@@ -45,6 +45,10 @@ |
45 | 45 |
|
46 | 46 |
#include "memdbg.h" |
47 | 47 |
|
48 |
+#ifdef WIN32 |
|
49 |
+#define METRIC_NOT_USED ((DWORD)-1) |
|
50 |
+#endif |
|
51 |
+ |
|
48 | 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); |
49 | 53 |
|
50 | 54 |
static void get_bypass_addresses (struct route_bypass *rb, const unsigned int flags); |
... | ... |
@@ -1342,7 +1346,7 @@ add_route (struct route *r, |
1342 | 1342 |
|
1343 | 1343 |
#elif defined (WIN32) |
1344 | 1344 |
{ |
1345 |
- DWORD ai = ~0; |
|
1345 |
+ DWORD ai = TUN_ADAPTER_INDEX_INVALID; |
|
1346 | 1346 |
argv_printf (&argv, "%s%sc ADD %s MASK %s %s", |
1347 | 1347 |
get_win_sys_path(), |
1348 | 1348 |
WIN_ROUTE_PATH_SUFFIX, |
... | ... |
@@ -2098,7 +2102,7 @@ static const MIB_IPFORWARDROW * |
2098 | 2098 |
get_default_gateway_row (const MIB_IPFORWARDTABLE *routes) |
2099 | 2099 |
{ |
2100 | 2100 |
struct gc_arena gc = gc_new (); |
2101 |
- DWORD lowest_metric = ~0; |
|
2101 |
+ DWORD lowest_metric = MAXDWORD; |
|
2102 | 2102 |
const MIB_IPFORWARDROW *ret = NULL; |
2103 | 2103 |
int i; |
2104 | 2104 |
int best = -1; |
... | ... |
@@ -2155,7 +2159,7 @@ get_default_gateway (struct route_gateway_info *rgi) |
2155 | 2155 |
{ |
2156 | 2156 |
rgi->flags |= RGI_ADDR_DEFINED; |
2157 | 2157 |
a_index = adapter_index_of_ip (adapters, rgi->gateway.addr, NULL, &rgi->gateway.netmask); |
2158 |
- if (a_index != ~0) |
|
2158 |
+ if (a_index != TUN_ADAPTER_INDEX_INVALID) |
|
2159 | 2159 |
{ |
2160 | 2160 |
rgi->adapter_index = a_index; |
2161 | 2161 |
rgi->flags |= (RGI_IFACE_DEFINED|RGI_NETMASK_DEFINED); |
... | ... |
@@ -2176,7 +2180,7 @@ static DWORD |
2176 | 2176 |
windows_route_find_if_index (const struct route *r, const struct tuntap *tt) |
2177 | 2177 |
{ |
2178 | 2178 |
struct gc_arena gc = gc_new (); |
2179 |
- DWORD ret = ~0; |
|
2179 |
+ DWORD ret = TUN_ADAPTER_INDEX_INVALID; |
|
2180 | 2180 |
int count = 0; |
2181 | 2181 |
const IP_ADAPTER_INFO *adapters = get_adapter_info_list (&gc); |
2182 | 2182 |
const IP_ADAPTER_INFO *tun_adapter = get_tun_adapter (tt, adapters); |
... | ... |
@@ -2198,14 +2202,14 @@ windows_route_find_if_index (const struct route *r, const struct tuntap *tt) |
2198 | 2198 |
{ |
2199 | 2199 |
msg (M_WARN, "Warning: route gateway is not reachable on any active network adapters: %s", |
2200 | 2200 |
print_in_addr_t (r->gateway, 0, &gc)); |
2201 |
- ret = ~0; |
|
2201 |
+ ret = TUN_ADAPTER_INDEX_INVALID; |
|
2202 | 2202 |
} |
2203 | 2203 |
else if (count > 1) |
2204 | 2204 |
{ |
2205 | 2205 |
msg (M_WARN, "Warning: route gateway is ambiguous: %s (%d matches)", |
2206 | 2206 |
print_in_addr_t (r->gateway, 0, &gc), |
2207 | 2207 |
count); |
2208 |
- ret = ~0; |
|
2208 |
+ ret = TUN_ADAPTER_INDEX_INVALID; |
|
2209 | 2209 |
} |
2210 | 2210 |
|
2211 | 2211 |
dmsg (D_ROUTE_DEBUG, "DEBUG: route find if: on_tun=%d count=%d index=%d", |
... | ... |
@@ -2223,9 +2227,9 @@ add_route_ipapi (const struct route *r, const struct tuntap *tt, DWORD adapter_i |
2223 | 2223 |
struct gc_arena gc = gc_new (); |
2224 | 2224 |
bool ret = false; |
2225 | 2225 |
DWORD status; |
2226 |
- const DWORD if_index = (adapter_index == ~0) ? windows_route_find_if_index (r, tt) : adapter_index; |
|
2226 |
+ const DWORD if_index = (adapter_index == TUN_ADAPTER_INDEX_INVALID) ? windows_route_find_if_index (r, tt) : adapter_index; |
|
2227 | 2227 |
|
2228 |
- if (if_index != ~0) |
|
2228 |
+ if (if_index != TUN_ADAPTER_INDEX_INVALID) |
|
2229 | 2229 |
{ |
2230 | 2230 |
MIB_IPFORWARDROW fr; |
2231 | 2231 |
CLEAR (fr); |
... | ... |
@@ -2239,10 +2243,10 @@ add_route_ipapi (const struct route *r, const struct tuntap *tt, DWORD adapter_i |
2239 | 2239 |
fr.dwForwardAge = 0; |
2240 | 2240 |
fr.dwForwardNextHopAS = 0; |
2241 | 2241 |
fr.dwForwardMetric1 = (r->flags & RT_METRIC_DEFINED) ? r->metric : 1; |
2242 |
- fr.dwForwardMetric2 = ~0; |
|
2243 |
- fr.dwForwardMetric3 = ~0; |
|
2244 |
- fr.dwForwardMetric4 = ~0; |
|
2245 |
- fr.dwForwardMetric5 = ~0; |
|
2242 |
+ fr.dwForwardMetric2 = METRIC_NOT_USED; |
|
2243 |
+ fr.dwForwardMetric3 = METRIC_NOT_USED; |
|
2244 |
+ fr.dwForwardMetric4 = METRIC_NOT_USED; |
|
2245 |
+ fr.dwForwardMetric5 = METRIC_NOT_USED; |
|
2246 | 2246 |
|
2247 | 2247 |
if ((r->network & r->netmask) != r->network) |
2248 | 2248 |
msg (M_WARN, "Warning: address %s is not a network address in relation to netmask %s", |
... | ... |
@@ -2299,7 +2303,7 @@ del_route_ipapi (const struct route *r, const struct tuntap *tt) |
2299 | 2299 |
DWORD status; |
2300 | 2300 |
const DWORD if_index = windows_route_find_if_index (r, tt); |
2301 | 2301 |
|
2302 |
- if (if_index != ~0) |
|
2302 |
+ if (if_index != TUN_ADAPTER_INDEX_INVALID) |
|
2303 | 2303 |
{ |
2304 | 2304 |
MIB_IPFORWARDROW fr; |
2305 | 2305 |
CLEAR (fr); |
... | ... |
@@ -579,7 +579,7 @@ init_tun_post (struct tuntap *tt, |
579 | 579 |
overlapped_io_init (&tt->writes, frame, TRUE, true); |
580 | 580 |
tt->rw_handle.read = tt->reads.overlapped.hEvent; |
581 | 581 |
tt->rw_handle.write = tt->writes.overlapped.hEvent; |
582 |
- tt->adapter_index = ~0; |
|
582 |
+ tt->adapter_index = TUN_ADAPTER_INDEX_INVALID; |
|
583 | 583 |
#endif |
584 | 584 |
} |
585 | 585 |
|
... | ... |
@@ -3250,7 +3250,7 @@ get_per_adapter_info (const DWORD index, struct gc_arena *gc) |
3250 | 3250 |
IP_PER_ADAPTER_INFO *pi = NULL; |
3251 | 3251 |
DWORD status; |
3252 | 3252 |
|
3253 |
- if (index != ~0) |
|
3253 |
+ if (index != TUN_ADAPTER_INDEX_INVALID) |
|
3254 | 3254 |
{ |
3255 | 3255 |
if ((status = GetPerAdapterInfo (index, NULL, &size)) != ERROR_BUFFER_OVERFLOW) |
3256 | 3256 |
{ |
... | ... |
@@ -3327,7 +3327,7 @@ get_interface_info (DWORD index, struct gc_arena *gc) |
3327 | 3327 |
const IP_ADAPTER_INFO * |
3328 | 3328 |
get_adapter (const IP_ADAPTER_INFO *ai, DWORD index) |
3329 | 3329 |
{ |
3330 |
- if (ai && index != (DWORD)~0) |
|
3330 |
+ if (ai && index != TUN_ADAPTER_INDEX_INVALID) |
|
3331 | 3331 |
{ |
3332 | 3332 |
const IP_ADAPTER_INFO *a; |
3333 | 3333 |
|
... | ... |
@@ -3504,7 +3504,7 @@ adapter_index_of_ip (const IP_ADAPTER_INFO *list, |
3504 | 3504 |
in_addr_t *netmask) |
3505 | 3505 |
{ |
3506 | 3506 |
struct gc_arena gc = gc_new (); |
3507 |
- DWORD ret = ~0; |
|
3507 |
+ DWORD ret = TUN_ADAPTER_INDEX_INVALID; |
|
3508 | 3508 |
in_addr_t highest_netmask = 0; |
3509 | 3509 |
bool first = true; |
3510 | 3510 |
|
... | ... |
@@ -3540,7 +3540,7 @@ adapter_index_of_ip (const IP_ADAPTER_INFO *list, |
3540 | 3540 |
(int)ret, |
3541 | 3541 |
count ? *count : -1); |
3542 | 3542 |
|
3543 |
- if (ret == ~0 && count) |
|
3543 |
+ if (ret == TUN_ADAPTER_INDEX_INVALID && count) |
|
3544 | 3544 |
*count = 0; |
3545 | 3545 |
|
3546 | 3546 |
if (netmask) |
... | ... |
@@ -3564,7 +3564,7 @@ dhcp_status (DWORD index) |
3564 | 3564 |
{ |
3565 | 3565 |
struct gc_arena gc = gc_new (); |
3566 | 3566 |
int ret = DHCP_STATUS_UNDEF; |
3567 |
- if (index != ~0) |
|
3567 |
+ if (index != TUN_ADAPTER_INDEX_INVALID) |
|
3568 | 3568 |
{ |
3569 | 3569 |
const IP_ADAPTER_INFO *ai = get_adapter_info (index, &gc); |
3570 | 3570 |
|
... | ... |
@@ -3626,15 +3626,15 @@ delete_temp_addresses (DWORD index) |
3626 | 3626 |
static DWORD |
3627 | 3627 |
get_adapter_index_method_1 (const char *guid) |
3628 | 3628 |
{ |
3629 |
- struct gc_arena gc = gc_new (); |
|
3630 |
- ULONG index = ~0; |
|
3631 |
- DWORD status; |
|
3629 |
+ DWORD index; |
|
3630 |
+ ULONG aindex; |
|
3632 | 3631 |
wchar_t wbuf[256]; |
3633 | 3632 |
_snwprintf (wbuf, SIZE (wbuf), L"\\DEVICE\\TCPIP_%S", guid); |
3634 | 3633 |
wbuf [SIZE(wbuf) - 1] = 0; |
3635 |
- if ((status = GetAdapterIndex (wbuf, &index)) != NO_ERROR) |
|
3636 |
- index = ~0; |
|
3637 |
- gc_free (&gc); |
|
3634 |
+ if (GetAdapterIndex (wbuf, &aindex) != NO_ERROR) |
|
3635 |
+ index = TUN_ADAPTER_INDEX_INVALID; |
|
3636 |
+ else |
|
3637 |
+ index = (DWORD)aindex; |
|
3638 | 3638 |
return index; |
3639 | 3639 |
} |
3640 | 3640 |
|
... | ... |
@@ -3642,7 +3642,7 @@ static DWORD |
3642 | 3642 |
get_adapter_index_method_2 (const char *guid) |
3643 | 3643 |
{ |
3644 | 3644 |
struct gc_arena gc = gc_new (); |
3645 |
- DWORD index = ~0; |
|
3645 |
+ DWORD index = TUN_ADAPTER_INDEX_INVALID; |
|
3646 | 3646 |
|
3647 | 3647 |
const IP_ADAPTER_INFO *list = get_adapter_info_list (&gc); |
3648 | 3648 |
|
... | ... |
@@ -3665,9 +3665,9 @@ get_adapter_index (const char *guid) |
3665 | 3665 |
{ |
3666 | 3666 |
DWORD index; |
3667 | 3667 |
index = get_adapter_index_method_1 (guid); |
3668 |
- if (index == ~0) |
|
3668 |
+ if (index == TUN_ADAPTER_INDEX_INVALID) |
|
3669 | 3669 |
index = get_adapter_index_method_2 (guid); |
3670 |
- if (index == ~0) |
|
3670 |
+ if (index == TUN_ADAPTER_INDEX_INVALID) |
|
3671 | 3671 |
msg (M_INFO, "NOTE: could not get adapter index for %s", guid); |
3672 | 3672 |
return index; |
3673 | 3673 |
} |
... | ... |
@@ -3678,18 +3678,18 @@ get_adapter_index_flexible (const char *name) /* actual name or GUID */ |
3678 | 3678 |
struct gc_arena gc = gc_new (); |
3679 | 3679 |
DWORD index; |
3680 | 3680 |
index = get_adapter_index_method_1 (name); |
3681 |
- if (index == ~0) |
|
3681 |
+ if (index == TUN_ADAPTER_INDEX_INVALID) |
|
3682 | 3682 |
index = get_adapter_index_method_2 (name); |
3683 |
- if (index == ~0) |
|
3683 |
+ if (index == TUN_ADAPTER_INDEX_INVALID) |
|
3684 | 3684 |
{ |
3685 | 3685 |
const struct tap_reg *tap_reg = get_tap_reg (&gc); |
3686 | 3686 |
const struct panel_reg *panel_reg = get_panel_reg (&gc); |
3687 | 3687 |
const char *guid = name_to_guid (name, tap_reg, panel_reg); |
3688 | 3688 |
index = get_adapter_index_method_1 (guid); |
3689 |
- if (index == ~0) |
|
3689 |
+ if (index == TUN_ADAPTER_INDEX_INVALID) |
|
3690 | 3690 |
index = get_adapter_index_method_2 (guid); |
3691 | 3691 |
} |
3692 |
- if (index == ~0) |
|
3692 |
+ if (index == TUN_ADAPTER_INDEX_INVALID) |
|
3693 | 3693 |
msg (M_INFO, "NOTE: could not get adapter index for name/GUID '%s'", name); |
3694 | 3694 |
gc_free (&gc); |
3695 | 3695 |
return index; |
... | ... |
@@ -3920,7 +3920,7 @@ dhcp_release_by_adapter_index(const DWORD adapter_index) |
3920 | 3920 |
static bool |
3921 | 3921 |
dhcp_release (const struct tuntap *tt) |
3922 | 3922 |
{ |
3923 |
- if (tt && tt->options.ip_win32_type == IPW32_SET_DHCP_MASQ && tt->adapter_index != ~0) |
|
3923 |
+ if (tt && tt->options.ip_win32_type == IPW32_SET_DHCP_MASQ && tt->adapter_index != TUN_ADAPTER_INDEX_INVALID) |
|
3924 | 3924 |
return dhcp_release_by_adapter_index (tt->adapter_index); |
3925 | 3925 |
else |
3926 | 3926 |
return false; |
... | ... |
@@ -3953,7 +3953,7 @@ dhcp_renew_by_adapter_index (const DWORD adapter_index) |
3953 | 3953 |
static bool |
3954 | 3954 |
dhcp_renew (const struct tuntap *tt) |
3955 | 3955 |
{ |
3956 |
- if (tt && tt->options.ip_win32_type == IPW32_SET_DHCP_MASQ && tt->adapter_index != ~0) |
|
3956 |
+ if (tt && tt->options.ip_win32_type == IPW32_SET_DHCP_MASQ && tt->adapter_index != TUN_ADAPTER_INDEX_INVALID) |
|
3957 | 3957 |
return dhcp_renew_by_adapter_index (tt->adapter_index); |
3958 | 3958 |
else |
3959 | 3959 |
return false; |
... | ... |
@@ -4838,7 +4838,7 @@ open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tu |
4838 | 4838 |
const DWORD index = tt->adapter_index; |
4839 | 4839 |
|
4840 | 4840 |
/* flush arp cache */ |
4841 |
- if (index != (DWORD)~0) |
|
4841 |
+ if (index != TUN_ADAPTER_INDEX_INVALID) |
|
4842 | 4842 |
{ |
4843 | 4843 |
DWORD status; |
4844 | 4844 |
|
... | ... |
@@ -4880,7 +4880,7 @@ open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tu |
4880 | 4880 |
const char *error_suffix = "I am having trouble using the Windows 'IP helper API' to automatically set the IP address -- consider using other --ip-win32 methods (not 'ipapi')"; |
4881 | 4881 |
|
4882 | 4882 |
/* couldn't get adapter index */ |
4883 |
- if (index == (DWORD)~0) |
|
4883 |
+ if (index == TUN_ADAPTER_INDEX_INVALID) |
|
4884 | 4884 |
{ |
4885 | 4885 |
msg (M_FATAL, "ERROR: unable to get adapter index for interface %s -- %s", |
4886 | 4886 |
device_guid, |