From: "cron2 (Code Review)" Date: Wed, 11 Mar 2026 16:43:29 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <2f751fc272a039f4f636a83c184db09f1e82cc2d-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="IbVBcuAZuNc="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Win32: Make interface index DWORD consistently List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos Cc: openvpn-devel --IbVBcuAZuNc= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, flichtenheld, plaisthos. cron2 has uploaded a new patch set (#7) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1519?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 The change is no longer submittable: Code-Review and checks~ChecksSubmitRul= e are unsatisfied now. Change subject: Win32: Make interface index DWORD consistently ...................................................................... Win32: Make interface index DWORD consistently Previously we had a weird mix of int and DWORD. But the Win32 APIs seem to be consistent (they have different names, but NET_IFINDEX is ULONG is DWORD). So use that. Note that this fixes some smaller issues in surrounding code that are not strictly related but were found while scanning the code. Mostly about needlessly converting all DWORD values to int for printf(). Change-Id: I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1519 Message-Id: <20260311163852.21387-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36= 021.html Signed-off-by: Gert Doering --- M include/openvpn-msg.h M src/openvpn/dns.c M src/openvpn/route.c M src/openvpn/tun.c M src/openvpn/tun.h M src/openvpn/win32.c M src/openvpnserv/interactive.c 7 files changed, 78 insertions(+), 87 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/19/1519/7 diff --git a/include/openvpn-msg.h b/include/openvpn-msg.h index a0cec53..34f50c8 100644 --- a/include/openvpn-msg.h +++ b/include/openvpn-msg.h @@ -66,7 +66,8 @@ typedef struct { - int index; +#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1) + DWORD index; char name[256]; } interface_t; diff --git a/src/openvpn/dns.c b/src/openvpn/dns.c index 4a4bb0c..a42d032 100644 --- a/src/openvpn/dns.c +++ b/src/openvpn/dns.c @@ -468,9 +468,10 @@ make_domain_list("dns search domains", search_domains, false, nrpt.sea= rch_domains, sizeof(nrpt.search_domains)); - msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index =3D %d) using service", + msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index =3D %lu) using service", (add ? "Setting" : "Deleting"), nrpt.resolve_domains[0] !=3D 0 ? "= , resolve domains" : "", - nrpt.search_domains[0] !=3D 0 ? ", search domains" : "", nrpt.ifac= e.name, nrpt.iface.index); + nrpt.search_domains[0] !=3D 0 ? ", search domains" : "", + nrpt.iface.name, nrpt.iface.index); send_msg_iservice(o->msg_channel, &nrpt, sizeof(nrpt), &ack, "DNS"); } diff --git a/src/openvpn/route.c b/src/openvpn/route.c index b196713..1cfbf80 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -2389,8 +2389,8 @@ status =3D GetIpForwardTable(rt, &size, TRUE); if (status !=3D NO_ERROR) { - msg(D_ROUTE, "NOTE: GetIpForwardTable returned error: %s (code= =3D%u)", - strerror_win32(status, gc), (unsigned int)status); + msg(D_ROUTE, "NOTE: GetIpForwardTable returned error: %s (code= =3D%lu)", + strerror_win32(status, gc), status); rt =3D NULL; } } @@ -2470,8 +2470,8 @@ } } - msg(D_ROUTE, "TEST ROUTES: %d/%d succeeded len=3D%d ret=3D%d a=3D%d u/= d=3D%s", good, count, len, - (int)ret, ambig, adapter_up ? "up" : "down"); + msg(D_ROUTE, "TEST ROUTES: %d/%d succeeded len=3D%d ret=3D%u a=3D%d u/= d=3D%s", + good, count, len, ret, ambig, adapter_up ? "up" : "down"); gc_free(&gc); return ret; @@ -2495,9 +2495,9 @@ const DWORD index =3D row->dwForwardIfIndex; const DWORD metric =3D row->dwForwardMetric1; - dmsg(D_ROUTE_DEBUG, "GDGR: route[%lu] %s/%s i=3D%d m=3D%d", i, + dmsg(D_ROUTE_DEBUG, "GDGR: route[%lu] %s/%s i=3D%lu m=3D%lu", = i, print_in_addr_t((in_addr_t)net, 0, &gc), print_in_addr_t(= (in_addr_t)mask, 0, &gc), - (int)index, (int)metric); + index, metric); if (!net && !mask && metric < lowest_metric) { @@ -2508,7 +2508,7 @@ } } - dmsg(D_ROUTE_DEBUG, "GDGR: best=3D%d lm=3D%u", best, (unsigned int)low= est_metric); + dmsg(D_ROUTE_DEBUG, "GDGR: best=3D%d lm=3D%lu", best, lowest_metric); gc_free(&gc); return ret; @@ -2537,12 +2537,12 @@ status =3D GetBestInterfaceEx((struct sockaddr *)dest, &best_if_index); if (status !=3D NO_ERROR) { - msg(D_ROUTE, "NOTE: GetBestInterfaceEx returned error: %s (code=3D= %u)", - strerror_win32(status, gc), (unsigned int)status); + msg(D_ROUTE, "NOTE: GetBestInterfaceEx returned error: %s (code=3D= %lu)", + strerror_win32(status, gc), status); goto done; } - msg(D_ROUTE_DEBUG, "GetBestInterfaceEx() returned if=3D%d", (int)best_= if_index); + msg(D_ROUTE_DEBUG, "GetBestInterfaceEx() returned if=3D%lu", best_if_i= ndex); /* get the routing information (such as NextHop) for the destination a= nd interface */ NET_LUID luid; @@ -2552,8 +2552,8 @@ status =3D GetBestRoute2(&luid, best_if_index, NULL, dest, 0, best_rou= te, &best_src); if (status !=3D NO_ERROR) { - msg(D_ROUTE, "NOTE: GetIpForwardEntry2 returned error: %s (code=3D= %u)", - strerror_win32(status, gc), (unsigned int)status); + msg(D_ROUTE, "NOTE: GetIpForwardEntry2 returned error: %s (code=3D= %lu)", + strerror_win32(status, gc), status); goto done; } @@ -2647,15 +2647,14 @@ print_in_addr_t(r->gateway, 0, &gc), count); } - dmsg(D_ROUTE_DEBUG, "DEBUG: route find if: on_tun=3D%d count=3D%d inde= x=3D%d", on_tun, count, - (int)ret); + dmsg(D_ROUTE_DEBUG, "DEBUG: route find if: on_tun=3D%d count=3D%d inde= x=3D%lu", + on_tun, count, ret); gc_free(&gc); return ret; } /* IPv6 implementation using GetBestRoute2() - * (TBD: dynamic linking so the binary can still run on XP?) * https://msdn.microsoft.com/en-us/library/windows/desktop/aa365922(v=3Dv= s.85).aspx * https://msdn.microsoft.com/en-us/library/windows/desktop/aa814411(v=3Dv= s.85).aspx */ @@ -2687,8 +2686,8 @@ print_in6_addr(BestRoute.DestinationPrefix.Prefix.Ipv6.sin6_addr, = 0, &gc), BestRoute.DestinationPrefix.PrefixLength, print_in6_addr(BestRoute.NextHop.Ipv6.sin6_addr, 0, &gc)); - msg(D_ROUTE, "GDG6: Metric=3D%d, Loopback=3D%d, AA=3D%d, I=3D%d", (int= )BestRoute.Metric, - (int)BestRoute.Loopback, (int)BestRoute.AutoconfigureAddress, (int= )BestRoute.Immortal); + msg(D_ROUTE, "GDG6: Metric=3D%lu, Loopback=3D%u, AA=3D%u, I=3D%u", Bes= tRoute.Metric, + BestRoute.Loopback, BestRoute.AutoconfigureAddress, BestRoute.Immo= rtal); rgi6->gateway.addr_ipv6 =3D BestRoute.NextHop.Ipv6.sin6_addr; rgi6->adapter_index =3D BestRoute.InterfaceIndex; @@ -2753,8 +2752,8 @@ else { /* failed, try increasing the metric to work around Vista issu= e */ - const unsigned int forward_metric_limit =3D - 2048; /* iteratively retry higher metrics up to this limit= */ + /* iteratively retry higher metrics up to this limit */ + const DWORD forward_metric_limit =3D 2048; for (; fr.dwForwardMetric1 <=3D forward_metric_limit; ++fr.dwF= orwardMetric1) { @@ -2767,8 +2766,8 @@ if (status =3D=3D NO_ERROR) { msg(D_ROUTE, - "ROUTE: CreateIpForwardEntry succeeded with dw= ForwardMetric1=3D%u and dwForwardType=3D%u", - (unsigned int)fr.dwForwardMetric1, (unsigned i= nt)fr.dwForwardType); + "ROUTE: CreateIpForwardEntry succeeded with dw= ForwardMetric1=3D%lu and dwForwardType=3D%lu", + fr.dwForwardMetric1, fr.dwForwardType); ret =3D RTA_SUCCESS; goto doublebreak; } @@ -2790,8 +2789,8 @@ { msg(M_WARN, "ERROR: route addition failed using CreateIpForwar= dEntry: " - "%s [status=3D%u if_index=3D%u]", - strerror_win32(status, &gc), (unsigned int)status,= (unsigned int)if_index); + "%s [status=3D%lu if_index=3D%lu]", + strerror_win32(status, &gc), status, if_index); } } } @@ -2855,7 +2854,7 @@ ret =3D (ack.error_number =3D=3D ERROR_OBJECT_ALREADY_EXISTS) ? RT= A_EEXIST : RTA_ERROR; if (ret =3D=3D RTA_ERROR) { - msg(M_WARN, "ERROR: route %s failed using service: %s [status= =3D%u if_index=3D%d]", + msg(M_WARN, "ERROR: route %s failed using service: %s [status= =3D%u if_index=3D%lu]", (add ? "addition" : "deletion"), strerror_win32(ack.error_= number, &gc), ack.error_number, rt->iface.index); } @@ -2869,17 +2868,12 @@ return ret; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsign-compare" -#endif - /* Returns RTA_SUCCESS on success, RTA_EEXIST if route exists, RTA_ERROR o= n error */ static int do_route_ipv4_service(const bool add, const struct route_ipv4 *r, const st= ruct tuntap *tt) { DWORD if_index =3D windows_route_find_if_index(r, tt); - if (if_index =3D=3D ~0) + if (if_index =3D=3D TUN_ADAPTER_INDEX_INVALID) { return RTA_ERROR; } @@ -3023,10 +3017,6 @@ return status; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - /* Returns RTA_SUCCESS on success, RTA_EEXIST if route exists, RTA_ERROR o= n error */ static int add_route_service(const struct route_ipv4 *r, const struct tuntap *tt) @@ -3057,14 +3047,14 @@ format_route_entry(const MIB_IPFORWARDROW *r, struct gc_arena *gc) { struct buffer out =3D alloc_buf_gc(256, gc); - buf_printf(&out, "%s %s %s p=3D%d i=3D%d t=3D%d pr=3D%d a=3D%d h=3D%d = m=3D%d/%d/%d/%d/%d", + buf_printf(&out, "%s %s %s p=3D%lu i=3D%lu t=3D%lu pr=3D%lu a=3D%lu h= =3D%lu m=3D%lu/%lu/%lu/%lu/%lu", print_in_addr_t(r->dwForwardDest, IA_NET_ORDER, gc), print_in_addr_t(r->dwForwardMask, IA_NET_ORDER, gc), - print_in_addr_t(r->dwForwardNextHop, IA_NET_ORDER, gc), (in= t)r->dwForwardPolicy, - (int)r->dwForwardIfIndex, (int)r->dwForwardType, (int)r->dw= ForwardProto, - (int)r->dwForwardAge, (int)r->dwForwardNextHopAS, (int)r->d= wForwardMetric1, - (int)r->dwForwardMetric2, (int)r->dwForwardMetric3, (int)r-= >dwForwardMetric4, - (int)r->dwForwardMetric5); + print_in_addr_t(r->dwForwardNextHop, IA_NET_ORDER, gc), r->= dwForwardPolicy, + r->dwForwardIfIndex, r->dwForwardType, r->dwForwardProto, + r->dwForwardAge, r->dwForwardNextHopAS, r->dwForwardMetric1, + r->dwForwardMetric2, r->dwForwardMetric3, r->dwForwardMetri= c4, + r->dwForwardMetric5); return BSTR(&out); } diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 7a173c5..b37a2ea 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -158,7 +158,7 @@ if (ack.error_number !=3D NO_ERROR) { - msg(M_WARN, "TUN: %s address failed using service: %s [status=3D%u= if_index=3D%d]", + msg(M_WARN, "TUN: %s address failed using service: %s [status=3D%u= if_index=3D%lu]", (add ? "adding" : "deleting"), strerror_win32(ack.error_number= , &gc), ack.error_number, addr.iface.index); goto out; @@ -220,7 +220,7 @@ strncpy(dns.domains + dstlen, o->domain_search_list[i], srclen + 1= ); } - msg(D_LOW, "%s DNS domains on '%s' (if_index =3D %d) using service", + msg(D_LOW, "%s DNS domains on '%s' (if_index =3D %lu) using service", (add ? "Setting" : "Deleting"), dns.iface.name, dns.iface.index); if (!send_msg_iservice(o->msg_channel, &dns, sizeof(dns), &ack, "TUN")) { @@ -289,7 +289,7 @@ } } - msg(D_LOW, "%s %s dns servers on '%s' (if_index =3D %d) using service", + msg(D_LOW, "%s %s dns servers on '%s' (if_index =3D %lu) using service= ", (add ? "Setting" : "Deleting"), ip_proto_name, dns.iface.name, dns= .iface.index); if (!send_msg_iservice(pipe, &dns, sizeof(dns), &ack, "TUN")) @@ -346,7 +346,7 @@ wins.addr[i].ipv4.s_addr =3D htonl(tt->options.wins[i]); } - msg(D_LOW, "%s WINS servers on '%s' (if_index =3D %d) using service", + msg(D_LOW, "%s WINS servers on '%s' (if_index =3D %lu) using service", (add ? "Setting" : "Deleting"), wins.iface.name, wins.iface.index); if (!send_msg_iservice(pipe, &wins, sizeof(wins), &ack, "TUN")) @@ -357,8 +357,8 @@ if (ack.error_number !=3D NO_ERROR) { msg(M_WARN, "TUN: %s WINS failed using service: %s [status=3D%u if= _name=3D%s]", - (add ? "adding" : "deleting"), strerror_win32(ack.error_number= , &gc), ack.error_number, - wins.iface.name); + (add ? "adding" : "deleting"), strerror_win32(ack.error_number= , &gc), + ack.error_number, wins.iface.name); goto out; } @@ -398,13 +398,13 @@ if (ack.error_number !=3D NO_ERROR) { - msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s [sta= tus=3D%u if_index=3D%d]", + msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s [sta= tus=3D%u if_index=3D%lu]", family_name, strerror_win32(ack.error_number, &gc), ack.error_= number, mtu_msg.iface.index); } else { - msg(M_INFO, "%s MTU set to %d on interface %d using service", fami= ly_name, mtu, + msg(M_INFO, "%s MTU set to %d on interface %lu using service", fam= ily_name, mtu, mtu_msg.iface.index); ret =3D true; } @@ -3422,7 +3422,7 @@ if (dev_info_set =3D=3D INVALID_HANDLE_VALUE) { err =3D GetLastError(); - msg(M_FATAL, "Error [%u] opening device information set key: %s", = (unsigned int)err, + msg(M_FATAL, "Error [%lu] opening device information set key: %s",= err, strerror_win32(err, gc)); } @@ -4105,7 +4105,7 @@ if ((status =3D GetAdaptersInfo(NULL, &size)) !=3D ERROR_BUFFER_OVERFL= OW) { - msg(M_INFO, "GetAdaptersInfo #1 failed (status=3D%u) : %s", (unsig= ned int)status, + msg(M_INFO, "GetAdaptersInfo #1 failed (status=3D%lu) : %s", statu= s, strerror_win32(status, gc)); } else @@ -4113,7 +4113,7 @@ pi =3D (PIP_ADAPTER_INFO)gc_malloc(size, false, gc); if ((status =3D GetAdaptersInfo(pi, &size)) !=3D NO_ERROR) { - msg(M_INFO, "GetAdaptersInfo #2 failed (status=3D%u) : %s", (u= nsigned int)status, + msg(M_INFO, "GetAdaptersInfo #2 failed (status=3D%lu) : %s", s= tatus, strerror_win32(status, gc)); pi =3D NULL; } @@ -4132,19 +4132,19 @@ { if ((status =3D GetPerAdapterInfo(index, NULL, &size)) !=3D ERROR_= BUFFER_OVERFLOW) { - msg(M_INFO, "GetPerAdapterInfo #1 failed (status=3D%u) : %s", = (unsigned int)status, + msg(M_INFO, "GetPerAdapterInfo #1 failed (status=3D%lu) : %s",= status, strerror_win32(status, gc)); } else { pi =3D (PIP_PER_ADAPTER_INFO)gc_malloc(size, false, gc); - if ((status =3D GetPerAdapterInfo((ULONG)index, pi, &size)) = =3D=3D ERROR_SUCCESS) + if ((status =3D GetPerAdapterInfo(index, pi, &size)) =3D=3D ER= ROR_SUCCESS) { return pi; } else { - msg(M_INFO, "GetPerAdapterInfo #2 failed (status=3D%u) : %= s", (unsigned int)status, + msg(M_INFO, "GetPerAdapterInfo #2 failed (status=3D%lu) : = %s", status, strerror_win32(status, gc)); } } @@ -4161,7 +4161,7 @@ if ((status =3D GetInterfaceInfo(NULL, &size)) !=3D ERROR_INSUFFICIENT= _BUFFER) { - msg(M_INFO, "GetInterfaceInfo #1 failed (status=3D%u) : %s", (unsi= gned int)status, + msg(M_INFO, "GetInterfaceInfo #1 failed (status=3D%lu) : %s", stat= us, strerror_win32(status, gc)); } else @@ -4173,7 +4173,7 @@ } else { - msg(M_INFO, "GetInterfaceInfo #2 failed (status=3D%u) : %s", (= unsigned int)status, + msg(M_INFO, "GetInterfaceInfo #2 failed (status=3D%lu) : %s", = status, strerror_win32(status, gc)); } } @@ -4450,8 +4450,8 @@ list =3D list->Next; } - dmsg(D_ROUTE_DEBUG, "DEBUG: IP Locate: ip=3D%s nm=3D%s index=3D%d coun= t=3D%d metric=3D%d", - print_in_addr_t(ip, 0, &gc), print_in_addr_t(highest_netmask, 0, = &gc), (int)ret, + dmsg(D_ROUTE_DEBUG, "DEBUG: IP Locate: ip=3D%s nm=3D%s index=3D%lu cou= nt=3D%d metric=3D%d", + print_in_addr_t(ip, 0, &gc), print_in_addr_t(highest_netmask, 0, = &gc), ret, count ? *count : -1, lowest_metric); if (ret =3D=3D TUN_ADAPTER_INDEX_INVALID && count) @@ -4520,7 +4520,7 @@ DWORD status; const DWORD context =3D ip->Context; - if ((status =3D DeleteIPAddress((ULONG)context)) =3D=3D NO_ERR= OR) + if ((status =3D DeleteIPAddress(context)) =3D=3D NO_ERROR) { msg(M_INFO, "Successfully deleted previously set dynamic I= P/netmask: %s/%s", ip->IpAddress.String, ip->IpMask.String); @@ -4531,8 +4531,8 @@ if (strcmp(ip->IpAddress.String, empty) || strcmp(ip->IpMa= sk.String, empty)) { msg(M_INFO, - "NOTE: could not delete previously set dynamic IP/= netmask: %s/%s (status=3D%u)", - ip->IpAddress.String, ip->IpMask.String, (unsigned= int)status); + "NOTE: could not delete previously set dynamic IP/= netmask: %s/%s (status=3D%lu)", + ip->IpAddress.String, ip->IpMask.String, status); } } ip =3D ip->Next; @@ -4628,7 +4628,7 @@ show_adapter(msglvl_t msglevel, const IP_ADAPTER_INFO *a, struct gc_arena = *gc) { msg(msglevel, "%s", a->Description); - msg(msglevel, " Index =3D %d", (int)a->Index); + msg(msglevel, " Index =3D %lu", a->Index); msg(msglevel, " GUID =3D %s", a->AdapterName); msg(msglevel, " IP =3D %s", format_ip_addr_string(&a->IpAddressList, = gc)); msg(msglevel, " MAC =3D %s", format_hex_ex(a->Address, a->AddressLeng= th, 0, 1, ":", gc)); @@ -4804,8 +4804,8 @@ else { msg(M_WARN, - "NOTE: Release of DHCP-assigned IP address lease on TAP-Wi= ndows adapter failed: %s (code=3D%u)", - strerror_win32(status, &gc), (unsigned int)status); + "NOTE: Release of DHCP-assigned IP address lease on TAP-Wi= ndows adapter failed: %s (code=3D%lu)", + strerror_win32(status, &gc), status); } } @@ -4845,8 +4845,8 @@ else { msg(M_WARN, - "WARNING: Failed to renew DHCP IP address lease on TAP-Win= dows adapter: %s (code=3D%u)", - strerror_win32(status, &gc), (unsigned int)status); + "WARNING: Failed to renew DHCP IP address lease on TAP-Win= dows adapter: %s (code=3D%lu)", + strerror_win32(status, &gc), status); } } gc_free(&gc); @@ -5209,12 +5209,12 @@ if (ack.error_number !=3D NO_ERROR) { - msg(M_NONFATAL, "TUN: enabling dhcp using service failed: %s [stat= us=3D%u if_index=3D%d]", + msg(M_NONFATAL, "TUN: enabling dhcp using service failed: %s [stat= us=3D%u if_index=3D%lu]", strerror_win32(ack.error_number, &gc), ack.error_number, dhcp.= iface.index); } else { - msg(M_INFO, "DHCP enabled on interface %d using service", dhcp.ifa= ce.index); + msg(M_INFO, "DHCP enabled on interface %lu using service", dhcp.if= ace.index); ret =3D true; } @@ -5503,7 +5503,7 @@ /* flush arp cache */ if (tt->backend_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6 && index != =3D TUN_ADAPTER_INDEX_INVALID) { - DWORD status =3D -1; + DWORD status =3D (DWORD)-1; if (tt->options.msg_channel) { @@ -5527,7 +5527,7 @@ { msg(M_INFO, "Successful ARP Flush on interface [%lu] %s", inde= x, device_guid); } - else if (status !=3D -1) + else if (status !=3D (DWORD)-1) { msg(D_TUNTAP_INFO, "NOTE: FlushIpNetTable failed on interface [%lu] %s (statu= s=3D%lu) : %s", index, @@ -6221,11 +6221,12 @@ if (tt->ipapi_context_defined) { DWORD status; + if ((status =3D DeleteIPAddress(tt->ipapi_context)) !=3D NO_ERROR) { msg(M_WARN, - "Warning: DeleteIPAddress[%u] failed on TAP-Windows adapte= r, status=3D%u : %s", - (unsigned int)tt->ipapi_context, (unsigned int)status, str= error_win32(status, &gc)); + "Warning: DeleteIPAddress[%lu] failed on TAP-Windows adapt= er, status=3D%lu : %s", + tt->ipapi_context, status, strerror_win32(status, &gc)); } } diff --git a/src/openvpn/tun.h b/src/openvpn/tun.h index 4d6dfbb..ecb5e88 100644 --- a/src/openvpn/tun.h +++ b/src/openvpn/tun.h @@ -61,8 +61,6 @@ #if defined(_WIN32) || defined(TARGET_ANDROID) || defined(DHCP_UNIT_TEST) -#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1) - /* time constants for --ip-win32 adaptive */ #define IPW32_SET_ADAPTIVE_DELAY_WINDOW 300 #define IPW32_SET_ADAPTIVE_TRY_NETSH 20 @@ -230,7 +228,7 @@ in_addr_t adapter_netmask; /* Windows adapter index for TAP-Windows adapter, - * ~0 if undefined */ + * TUN_ADAPTER_INDEX_INVALID if undefined */ DWORD adapter_index; int standby_iter; diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c index ac449fd..b2a7331 100644 --- a/src/openvpn/win32.c +++ b/src/openvpn/win32.c @@ -1185,7 +1185,7 @@ if (ack.error_number !=3D NO_ERROR) { msg(M_WARN, - "WFP block: %s block filters using service failed: %s [status= =3D0x%x if_index=3D%d]", + "WFP block: %s block filters using service failed: %s [status= =3D0x%x if_index=3D%lu]", (add ? "adding" : "deleting"), strerror_win32(ack.error_number= , &gc), ack.error_number, data.iface.index); goto out; diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index 09c709e..b50aeb3 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -96,7 +96,7 @@ typedef struct { HANDLE engine; - int index; + DWORD index; int metric_v4; int metric_v6; } wfp_block_data_t; @@ -584,7 +584,7 @@ addr_row->Address =3D sockaddr_inet(msg->family, &msg->address); addr_row->OnLinkPrefixLength =3D (UINT8)msg->prefix_len; - if (msg->iface.index !=3D -1) + if (msg->iface.index !=3D TUN_ADAPTER_INDEX_INVALID) { addr_row->InterfaceIndex =3D msg->iface.index; } @@ -667,7 +667,7 @@ fwd_row->DestinationPrefix.PrefixLength =3D (UINT8)msg->prefix_len; fwd_row->NextHop =3D sockaddr_inet(msg->family, &msg->gateway); - if (msg->iface.index !=3D -1) + if (msg->iface.index !=3D TUN_ADAPTER_INDEX_INVALID) { fwd_row->InterfaceIndex =3D msg->iface.index; } @@ -1010,7 +1010,7 @@ * if action =3D "set" then "static" is added before $addr */ static DWORD -netsh_wins_cmd(const wchar_t *action, int if_index, const wchar_t *addr) +netsh_wins_cmd(const wchar_t *action, DWORD if_index, const wchar_t *addr) { DWORD err =3D 0; int timeout =3D 30000; /* in msec */ @@ -1036,7 +1036,7 @@ /* cmd template: * netsh interface ip $action wins $if_name $static $addr */ - const wchar_t *fmt =3D L"netsh interface ip %ls wins %d %ls %ls"; + const wchar_t *fmt =3D L"netsh interface ip %ls wins %lu %ls %ls"; /* max cmdline length in wchars -- include room for worst case and som= e */ size_t ncmdline =3D wcslen(fmt) + 11 /*if_index*/ + wcslen(action) + w= cslen(addr) @@ -2984,7 +2984,7 @@ */ } - int *if_index =3D malloc(sizeof(msg->iface.index)); + PDWORD if_index =3D malloc(sizeof(msg->iface.index)); if (if_index) { *if_index =3D msg->iface.index; @@ -3017,7 +3017,7 @@ /* cmd template: * netsh interface ipv4 set address name=3D$if_index source=3Ddhcp */ - const wchar_t *fmt =3D L"netsh interface ipv4 set address name=3D\"%d\= " source=3Ddhcp"; + const wchar_t *fmt =3D L"netsh interface ipv4 set address name=3D\"%lu= \" source=3Ddhcp"; /* max cmdline length in wchars -- include room for if index: * 10 chars for 32 bit int in decimal and +1 for NUL @@ -3250,7 +3250,7 @@ break; case undo_wins: - netsh_wins_cmd(L"delete", *(int *)item->data, NULL); + netsh_wins_cmd(L"delete", *(PDWORD)item->data, NULL); break; case wfp_block: -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1519?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81 Gerrit-Change-Number: 1519 Gerrit-PatchSet: 7 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: flichtenheld --IbVBcuAZuNc= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: cron2, flichtenheld, plaisthos.

cron2 uploaded patch set #7 to the change originally cr= eated by flichtenheld.

View Change

The following approvals got outd= ated and were removed: Code-Review+2 by cron2

The change is no longer submittable: Code-Revi= ew and checks~ChecksSubmitRule are unsatisfied now.

Win32:=
 Make interface index DWORD consistently

Previously we had a weird m= ix of int and DWORD. But the
Win32 APIs seem to be consistent (they have= different names,
but NET_IFINDEX is ULONG is DWORD). So use that.
Note that this fixes some smaller issues in surrounding
code that are = not strictly related but were found while
scanning the code. Mostly abou= t needlessly converting
all DWORD values to int for printf().

Cha= nge-Id: I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81
Signed-off-by: Frank L= ichtenheld <frank@...2641...>
Acked-by: Gert Doering <gert@...1386...= 296...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1519
Me= ssage-Id: <20260311163852.21387-1-gert@...1296...>
URL: https://ww= w.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36021.html
Sig= ned-off-by: Gert Doering <gert@...1296...>
---
M include/openvp= n-msg.h
M src/openvpn/dns.c
M src/openvpn/route.c
M src/openvpn/tu= n.c
M src/openvpn/tun.h
M src/openvpn/win32.c
M src/openvpnserv/in= teractive.c
7 files changed, 78 insertions(+), 87 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/chan=
ges/19/1519/7
diff --git a/include/openvpn-msg.h b/include/openvpn-=
msg.h
index a0cec53..34f50c8 100644
--- a/i= nclude/openvpn-msg.h
+++ b/include/openvpn-msg.h
= @@ -66,7 +66,8 @@

typedef struct
{
- = int index;
+#define T= UN_ADAPTER_INDEX_INVALID ((DWORD)-1)
+ DWORD index;
char name[256];
} interface_t;

diff --git a/= src/openvpn/dns.c b/src/openvpn/dns.c
index 4a4bb0c..a42d03= 2 100644
--- a/src/openvpn/dns.c
+++ b/src/= openvpn/dns.c
@@ -468,9 +468,10 @@
mak= e_domain_list("dns search domains", search_domains, false, nrpt.s= earch_domains,
sizeof(nrpt.search_dom= ains));

- msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index =3D %d) = using service",
= + msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index =3D %lu) us= ing service",
(add ? "Setting" : &q= uot;Deleting"), nrpt.resolve_domains[0] !=3D 0 ? ", resolve domai= ns" : "",
+ nrpt.search_domains[0] !=3D 0 ? "= , search domains" : "",
+ nrpt.iface.name, nrpt.iface.index);

send_msg_iservice(o->msg_channel, &nrpt, = sizeof(nrpt), &ack, "DNS");
}
diff --git a/src/openvpn/route.c b/src/openvpn/route.c

in= dex b196713..1cfbf80 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -2389,8 +2389,8 @@<= /span>
status =3D GetIpForwardTable(rt, &size, TRUE);=
if (status !=3D NO_ERROR)
= {
- msg(D_= ROUTE, "NOTE: GetIpForwardTable returned error: %s (code=3D%u)",<= /span>
- strerr= or_win32(status, gc), (unsigned int)status);
+ msg(D_ROUTE, "NOTE: GetIpForwardT= able returned error: %s (code=3D%lu)",
+ strerror_win32(status, gc), status)= ;
rt =3D NULL;
}
}
@@ -2470,8 +2470,8 @@
= }
}

- msg(D_ROUTE, "TEST ROUTES: %d/%d succe= eded len=3D%d ret=3D%d a=3D%d u/d=3D%s", good, count, len,
<= span style=3D"color: hsl(0, 100%, 40%);">- (int)ret, ambig, adapter_= up ? "up" : "down");

+ msg(D_ROUTE, "TEST ROUTES: %d/%d succeeded le= n=3D%d ret=3D%u a=3D%d u/d=3D%s",
+ good, count, len, ret, ambig, adapter_up ? "= ;up" : "down");

gc_fr= ee(&gc);
return ret;
@@ -2495,9 +2= 495,9 @@
const DWORD index =3D row->dwForwa= rdIfIndex;
const DWORD metric =3D row->dwFo= rwardMetric1;

- dmsg(D_ROUTE_DEBUG, "GDGR: route[%lu] %s/%s i=3D= %d m=3D%d", i,
+= dmsg(D_ROUTE_DEBUG, "GDGR: route[%lu] %s/%s i=3D%lu m=3D%l= u", i,
print_in_addr_t((in_addr_t)ne= t, 0, &gc), print_in_addr_t((in_addr_t)mask, 0, &gc),
- (int)index, (int)m= etric);

+ = index, metric);

if (!ne= t && !mask && metric < lowest_metric)
= {
@@ -2508,7 +2508,7 @@
= }
}

- dmsg(D_ROUTE_DEBUG, "GDGR: best=3D%d lm=3D%u= ", best, (unsigned int)lowest_metric);
+ dmsg(D_ROUTE_DEBUG, "GDGR: best=3D%d lm=3D= %lu", best, lowest_metric);

gc_= free(&gc);
return ret;
@@ -2537,12= +2537,12 @@
status =3D GetBestInterfaceEx((struct soc= kaddr *)dest, &best_if_index);
if (status !=3D NO_= ERROR)
{
- msg(D_ROUTE, "NOTE: GetBestInterfaceEx returned error:= %s (code=3D%u)",
= - strerror_win32(status, gc), (unsigned int)status);
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg(D_ROUTE, "NOTE= : GetBestInterfaceEx returned error: %s (code=3D%lu)",

+ strerror_win32(status, = gc), status);

goto done;
}

- ms= g(D_ROUTE_DEBUG, "GetBestInterfaceEx() returned if=3D%d", (int)be= st_if_index);
+ ms= g(D_ROUTE_DEBUG, "GetBestInterfaceEx() returned if=3D%lu", best_i= f_index);

/* get the routing informa= tion (such as NextHop) for the destination and interface */
NET_LUID luid;

@@ -2552,8 +2552,8 @@
= status =3D GetBestRoute2(&luid, best_if_index, NULL, dest, 0, best= _route, &best_src);
if (status !=3D NO_ERROR)
{
- = msg(D_ROUTE, "NOTE: GetIpForwardEntry2 returned error: %s (code= =3D%u)",
- = strerror_win32(status, gc), (unsigned int)status);
+ msg(D_ROUTE, "NOTE: GetIpFo= rwardEntry2 returned error: %s (code=3D%lu)",
+ strerror_win32(status, gc), stat= us);
goto done;
}
<= span>

@@ -2647,15 +2647,14 @@
= print_in_addr_t(r->gateway, 0, &gc), count);
}=

- = dmsg(D_ROUTE_DEBUG, "DEBUG: route find if: on_tun=3D%d count=3D%d ind= ex=3D%d", on_tun, count,
- (int)ret);
+ dmsg(D_ROUTE_DEBUG, "DEBUG: route find if: on_tun=3D%d cou= nt=3D%d index=3D%lu",
+ on_tun, count, ret);

= gc_free(&gc);
return ret;
}

/* IPv6 implementation using GetBestRoute2()=
- * (TBD: dynamic li= nking so the binary can still run on XP?)
* https://msdn.= microsoft.com/en-us/library/windows/desktop/aa365922(v=3Dvs.85).aspx=
* https://msdn.microsoft.com/en-us/library/windows/desktop/aa81= 4411(v=3Dvs.85).aspx
*/
@@ -2687,8 +2686,= 8 @@
print_in6_addr(BestRoute.DestinationPrefix.Pr= efix.Ipv6.sin6_addr, 0, &gc),
BestRoute.Destin= ationPrefix.PrefixLength,
print_in6_addr(BestRoute= .NextHop.Ipv6.sin6_addr, 0, &gc));
- msg(D_ROUTE, "GDG6: Metric=3D%d, Loopback=3D%d, A= A=3D%d, I=3D%d", (int)BestRoute.Metric,
- (int)BestRoute.Loopback, (int)BestRoute.Auto= configureAddress, (int)BestRoute.Immortal);
+ msg(D_ROUTE, "GDG6: Metric=3D%lu, Loopback= =3D%u, AA=3D%u, I=3D%u", BestRoute.Metric,
+ BestRoute.Loopback, BestRoute.Autoconfi= gureAddress, BestRoute.Immortal);

rg= i6->gateway.addr_ipv6 =3D BestRoute.NextHop.Ipv6.sin6_addr;
rgi6->adapter_index =3D BestRoute.InterfaceIndex;

@@ -2753,8 +2752,8 @@
else
= {
/* failed, try increasing the metric to= work around Vista issue */
- const unsigned int forward_metric_limit =3D
- 2048; /* iterativel= y retry higher metrics up to this limit */
+ /* iteratively retry higher metrics up t= o this limit */
+ = const DWORD forward_metric_limit =3D 2048;
=
for (; fr.dwForwardMetric1 <=3D forward_metric_li= mit; ++fr.dwForwardMetric1)
{
= @@ -2767,8 +2766,8 @@
if (status =3D= =3D NO_ERROR)
{
= msg(D_ROUTE,
- "ROUTE: CreateIpForwardEntry suc= ceeded with dwForwardMetric1=3D%u and dwForwardType=3D%u",
<= span style=3D"color: hsl(0, 100%, 40%);">- (unsi= gned int)fr.dwForwardMetric1, (unsigned int)fr.dwForwardType);
+ &quo= t;ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=3D%lu and dwF= orwardType=3D%lu",
+ fr.dwForwardMetric1, fr.dwForwardType);

ret =3D RTA_SUCCESS;
= goto doublebreak;
= }
@@ -2790,8 +2789,8 @@
= {
msg(M_WARN,
= "ERROR: route addition failed using CreateIpForwar= dEntry: "
- = "%s [status=3D%u if_index=3D%u]",
- strerror_win= 32(status, &gc), (unsigned int)status, (unsigned int)if_index);<= br>+ &qu= ot;%s [status=3D%lu if_index=3D%lu]",
+ strerror_win32(status, &= gc), status, if_index);
}
= }
}
@@ -2855,7 +2854,= 7 @@
ret =3D (ack.error_number =3D=3D ERROR_OBJECT= _ALREADY_EXISTS) ? RTA_EEXIST : RTA_ERROR;
if (ret= =3D=3D RTA_ERROR)
{
- msg(M_WARN, "ERROR: route %s faile= d using service: %s [status=3D%u if_index=3D%d]",
+ msg(M_WARN, "ERROR: rou= te %s failed using service: %s [status=3D%u if_index=3D%lu]", (add ? "addition" : "deletion"= ), strerror_win32(ack.error_number, &gc),
= ack.error_number, rt->iface.index);
}
@@ -2869,17 +2868,12 @@
return ret;<= br> }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "= -Wsign-compare"

-#= endif
-
/* Returns RTA_SUCCESS on success, RTA_EEXIST if route exists, RTA_ERROR = on error */
static int
do_route_ipv4_serv= ice(const bool add, const struct route_ipv4 *r, const struct tuntap *tt)
{
DWORD if_index =3D windows_route_find= _if_index(r, tt);
- = if (if_index =3D=3D ~0)
+ if (if_index =3D=3D TUN_ADAPTER_INDEX_INVALID)
= {
return RTA_ERROR;
}=
@@ -3023,10 +3017,6 @@
return status;=
}

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
/* Returns RTA_SUCCESS on success, = RTA_EEXIST if route exists, RTA_ERROR on error */
static i= nt
add_route_service(const struct route_ipv4 *r, const str= uct tuntap *tt)
@@ -3057,14 +3047,14 @@
fo= rmat_route_entry(const MIB_IPFORWARDROW *r, struct gc_arena *gc)
= {
struct buffer out =3D alloc_buf_gc(256, gc);<= /span>
- buf_printf(&ou= t, "%s %s %s p=3D%d i=3D%d t=3D%d pr=3D%d a=3D%d h=3D%d m=3D%d/%d/%d/%= d/%d",
+ buf_= printf(&out, "%s %s %s p=3D%lu i=3D%lu t=3D%lu pr=3D%lu a=3D%lu h= =3D%lu m=3D%lu/%lu/%lu/%lu/%lu",
print= _in_addr_t(r->dwForwardDest, IA_NET_ORDER, gc),
= print_in_addr_t(r->dwForwardMask, IA_NET_ORDER, gc),
<= span style=3D"color: hsl(0, 100%, 40%);">- print_in_addr_t(r-= >dwForwardNextHop, IA_NET_ORDER, gc), (int)r->dwForwardPolicy,
=
- (int)r->dw= ForwardIfIndex, (int)r->dwForwardType, (int)r->dwForwardProto,=
- (int)r->dw= ForwardAge, (int)r->dwForwardNextHopAS, (int)r->dwForwardMetric1,

- (int)r->= ;dwForwardMetric2, (int)r->dwForwardMetric3, (int)r->dwForwardMetric4= ,
- (int)= r->dwForwardMetric5);
+ print_in_addr_t(r->dwForwardNextHop, IA_NET_ORDER, g= c), r->dwForwardPolicy,
+ r->dwForwardIfIndex, r->dwForwardType, r->dw= ForwardProto,
+ = r->dwForwardAge, r->dwForwardNextHopAS, r->dwForwardMetri= c1,
+ r= ->dwForwardMetric2, r->dwForwardMetric3, r->dwForwardMetric4,
+ r->dwF= orwardMetric5);
return BSTR(&out);
}


diff --git a/src/openvpn/tun.c b/src/= openvpn/tun.c
index 7a173c5..b37a2ea 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
= @@ -158,7 +158,7 @@

if (ack.er= ror_number !=3D NO_ERROR)
{
- msg(M_WARN, "TUN: %s address failed= using service: %s [status=3D%u if_index=3D%d]",
+ msg(M_WARN, "TUN: %s address= failed using service: %s [status=3D%u if_index=3D%lu]",
(add ? "adding" : "deleting"), strerror= _win32(ack.error_number, &gc), ack.error_number,
= addr.iface.index);
goto out;
@@ -220,7 +220,7 @@
strncpy(dns.domains + dstlen= , o->domain_search_list[i], srclen + 1);
}
- msg(D_LO= W, "%s DNS domains on '%s' (if_index =3D %d) using service&quo= t;,
+ msg(D_LOW, &= quot;%s DNS domains on '%s' (if_index =3D %lu) using service",=
(add ? "Setting" : "Deleting"= ), dns.iface.name, dns.iface.index);
if (!send_msg_ise= rvice(o->msg_channel, &dns, sizeof(dns), &ack, "TUN"))=
{
@@ -289,7 +289,7 @@
}
}

- msg(D_LOW, "%s %s dns servers on &= #39;%s' (if_index =3D %d) using service",
+ msg(D_LOW, "%s %s dns servers on &#= 39;%s' (if_index =3D %lu) using service",
= (add ? "Setting" : "Deleting"), ip_proto_name, dns.ifa= ce.name, dns.iface.index);

if (!send= _msg_iservice(pipe, &dns, sizeof(dns), &ack, "TUN"))

@@ -346,7 +346,7 @@
wins.addr[i].ipv4.= s_addr =3D htonl(tt->options.wins[i]);
}
=
- msg(D_LOW,= "%s WINS servers on '%s' (if_index =3D %d) using service"= ;,
+ msg(D_LOW, &q= uot;%s WINS servers on '%s' (if_index =3D %lu) using service",=
(add ? "Setting" : "Deleting"= ), wins.iface.name, wins.iface.index);

= if (!send_msg_iservice(pipe, &wins, sizeof(wins), &ack, "TU= N"))
@@ -357,8 +357,8 @@
if (ack.= error_number !=3D NO_ERROR)
{
= msg(M_WARN, "TUN: %s WINS failed using service: %s [status=3D%u if_na= me=3D%s]",
- = (add ? "adding" : "deleting"), strerror_win32(ack= .error_number, &gc), ack.error_number,
- wins.iface.name);
+ (add ? "adding" : &quo= t;deleting"), strerror_win32(ack.error_number, &gc),
+ ack.error_number, win= s.iface.name);
goto out;
}

@@ -398,13 +398,13 @@

if (ack.error_number !=3D NO_ERROR)
= {
- msg(M_NONFAT= AL, "TUN: setting %s mtu using service failed: %s [status=3D%u if_inde= x=3D%d]",
+ = msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s [stat= us=3D%u if_index=3D%lu]",
family_name, st= rerror_win32(ack.error_number, &gc), ack.error_number,
= mtu_msg.iface.index);
}
= else
{
- msg(M_INFO, "%s MTU set to %d on interface %d using = service", family_name, mtu,
+ msg(M_INFO, "%s MTU set to %d on interface %lu us= ing service", family_name, mtu,
mtu_msg.i= face.index);
ret =3D true;
}<= /span>
@@ -3422,7 +3422,7 @@
if (dev_info_set= =3D=3D INVALID_HANDLE_VALUE)
{
= err =3D GetLastError();
- msg(M_FATAL, "Error [%u] opening device information set k= ey: %s", (unsigned int)err,
+ msg(M_FATAL, "Error [%lu] opening device informat= ion set key: %s", err,
strerror_win32(err= , gc));
}

@@ -4105,7= +4105,7 @@

if ((status =3D GetAdapt= ersInfo(NULL, &size)) !=3D ERROR_BUFFER_OVERFLOW)
= {
- msg(M_INFO, = "GetAdaptersInfo #1 failed (status=3D%u) : %s", (unsigned int)sta= tus,
+ msg(M_I= NFO, "GetAdaptersInfo #1 failed (status=3D%lu) : %s", status,

strerror_win32(status, gc));
= }
else
@@ -4113,7 +4113,7 @@ pi =3D (PIP_ADAPTER_INFO)gc_malloc(size, false, gc);

if ((status =3D GetAdaptersInfo(pi, &size)) !=3D NO= _ERROR)
{
- msg(M_INFO, "GetAdaptersInfo #2 failed (statu= s=3D%u) : %s", (unsigned int)status,
+ msg(M_INFO, "GetAdaptersInfo #2 fail= ed (status=3D%lu) : %s", status,
stre= rror_win32(status, gc));
pi =3D NULL; }
@@ -4132,19 +4132,19 @@
= {
if ((status =3D GetPerAdapterInfo(index, NU= LL, &size)) !=3D ERROR_BUFFER_OVERFLOW)
{
- msg(M_INFO, &q= uot;GetPerAdapterInfo #1 failed (status=3D%u) : %s", (unsigned int)sta= tus,
+ msg= (M_INFO, "GetPerAdapterInfo #1 failed (status=3D%lu) : %s", statu= s,
strerror_win32(status, gc));
= }
else
{
pi =3D (PIP_PER_ADAPTER_INFO)gc_malloc(size, fa= lse, gc);
- = if ((status =3D GetPerAdapterInfo((ULONG)index, pi, &size)) =3D=3D ERRO= R_SUCCESS)
+ = if ((status =3D GetPerAdapterInfo(index, pi, &size)) =3D=3D ERROR_SU= CCESS)
{
retu= rn pi;
}
else
{
- msg(M_INFO, "GetPerAdapterInfo #2 failed (status= =3D%u) : %s", (unsigned int)status,
+ msg(M_INFO, "GetPerAdapterInfo #2= failed (status=3D%lu) : %s", status,
= strerror_win32(status, gc));
}
= }
@@ -4161,7 +4161,7 @@

if ((status =3D GetInterfaceInfo(NULL, &size)) !=3D = ERROR_INSUFFICIENT_BUFFER)
{
- msg(M_INFO, "GetInterfaceInfo #1 f= ailed (status=3D%u) : %s", (unsigned int)status,
+ msg(M_INFO, "GetInterfaceInf= o #1 failed (status=3D%lu) : %s", status,
= strerror_win32(status, gc));
}
e= lse
@@ -4173,7 +4173,7 @@
}=
else
{
- msg(M_INFO, "GetInterfaceInfo= #2 failed (status=3D%u) : %s", (unsigned int)status,
+ msg(M_INFO, "GetInt= erfaceInfo #2 failed (status=3D%lu) : %s", status,
= strerror_win32(status, gc));
}
}
@@ -4450,8 +4450,8 @@
= list =3D list->Next;
}

- dmsg(D_ROUTE_DEBUG, &q= uot;DEBUG: IP Locate: ip=3D%s nm=3D%s index=3D%d count=3D%d metric=3D%d&quo= t;,
- print_in_= addr_t(ip, 0, &gc), print_in_addr_t(highest_netmask, 0, &gc), (int)= ret,
+ dmsg(D_ROUT= E_DEBUG, "DEBUG: IP Locate: ip=3D%s nm=3D%s index=3D%lu count=3D%d met= ric=3D%d",
+ = print_in_addr_t(ip, 0, &gc), print_in_addr_t(highest_netmask, 0, &= amp;gc), ret,
count ? *count : -1, lowest_metric)= ;

if (ret =3D=3D TUN_ADAPTER_INDEX_I= NVALID && count)
@@ -4520,7 +4520,7 @@
DWORD status;

const DWORD con= text =3D ip->Context;

- if ((status =3D DeleteIPAddress((ULONG)con= text)) =3D=3D NO_ERROR)
+ if ((status =3D DeleteIPAddress(context)) =3D=3D NO_ERROR)<= /span>
{
msg(M_INFO,= "Successfully deleted previously set dynamic IP/netmask: %s/%s",=
ip->IpAddress.String, ip->IpMas= k.String);
@@ -4531,8 +4531,8 @@
= if (strcmp(ip->IpAddress.String, empty) || strcmp(ip->IpMask.S= tring, empty))
{
= msg(M_INFO,
- "NOTE: could not delete previously set dynam= ic IP/netmask: %s/%s (status=3D%u)",
- ip->IpAddress.String, ip->= ;IpMask.String, (unsigned int)status);
+ "NOTE: could not delete pre= viously set dynamic IP/netmask: %s/%s (status=3D%lu)",
+ ip->IpAd= dress.String, ip->IpMask.String, status);

= }
}
ip =3D ip-= >Next;
@@ -4628,7 +4628,7 @@
show_adapt= er(msglvl_t msglevel, const IP_ADAPTER_INFO *a, struct gc_arena *gc)=
{
msg(msglevel, "%s", a->Descr= iption);
- msg(msgle= vel, " Index =3D %d", (int)a->Index);
+ msg(msglevel, " Index =3D %lu&q= uot;, a->Index);
msg(msglevel, " GUID =3D %s&= quot;, a->AdapterName);
msg(msglevel, " IP = =3D %s", format_ip_addr_string(&a->IpAddressList, gc));<= br> msg(msglevel, " MAC =3D %s", format_hex_ex(a->A= ddress, a->AddressLength, 0, 1, ":", gc));
@@ = -4804,8 +4804,8 @@
else
{=
msg(M_WARN,
- "NOTE: Release of DHCP-assigned IP= address lease on TAP-Windows adapter failed: %s (code=3D%u)",<= br>- strerror_win3= 2(status, &gc), (unsigned int)status);
+ "NOTE: Release of DHCP-assigned= IP address lease on TAP-Windows adapter failed: %s (code=3D%lu)",
+ strerro= r_win32(status, &gc), status);
}
}


@@ -4845,8 +4845,8 @@ else
{
= msg(M_WARN,
- = "WARNING: Failed to renew DHCP IP address lease on TAP-Windows= adapter: %s (code=3D%u)",
- strerror_win32(status, &gc), (unsigned int)st= atus);
+ = "WARNING: Failed to renew DHCP IP address lease on TAP-Windows adap= ter: %s (code=3D%lu)",
+ strerror_win32(status, &gc), status); }
}
gc_free(&= gc);
@@ -5209,12 +5209,12 @@

if (ack.error_number !=3D NO_ERROR)

{<= br>- msg(M_NONFATAL, "= ;TUN: enabling dhcp using service failed: %s [status=3D%u if_index=3D%d]&qu= ot;,
+ msg(M_N= ONFATAL, "TUN: enabling dhcp using service failed: %s [status=3D%u if_= index=3D%lu]",
strerror_win32(ack.error_n= umber, &gc), ack.error_number, dhcp.iface.index);
= }
else
{
- msg(M_INFO, "DHCP enabled on inte= rface %d using service", dhcp.iface.index);
+ msg(M_INFO, "DHCP enabled on inte= rface %lu using service", dhcp.iface.index);
= ret =3D true;
}

@@ -= 5503,7 +5503,7 @@
/* flush arp cache */
if (tt->backend_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6 &&a= mp; index !=3D TUN_ADAPTER_INDEX_INVALID)

{
= - DWORD status =3D -1;
+ DWORD status = =3D (DWORD)-1;

if (tt->option= s.msg_channel)
{
@@ -5527,7 +5527,= 7 @@
{
msg(M_INFO, &q= uot;Successful ARP Flush on interface [%lu] %s", index, device_guid);<= /span>
}
- else if (status !=3D -1)
+ else if (status !=3D (DWORD)-1)
= {
msg(D_TUNTAP_INFO,
= "NOTE: FlushIpNetTable failed on interface [%lu] %s (s= tatus=3D%lu) : %s", index,
@@ -6221,11 +6221,12 @@
if (tt->ipapi_context_defined)
{<= /span>
DWORD status;
+
if ((status =3D DeleteIPAddres= s(tt->ipapi_context)) !=3D NO_ERROR)
{ msg(M_WARN,
- "Warning: DeleteIPAddress[%u] failed on TAP= -Windows adapter, status=3D%u : %s",
- (unsigned int)tt->ipapi_context, (un= signed int)status, strerror_win32(status, &gc));
+ "Warning: DeleteIPAd= dress[%lu] failed on TAP-Windows adapter, status=3D%lu : %s",+ tt->ipapi= _context, status, strerror_win32(status, &gc));
= }
}

diff --git a/s= rc/openvpn/tun.h b/src/openvpn/tun.h
index 4d6dfbb..ecb5e88= 100644
--- a/src/openvpn/tun.h
+++ b/src/o= penvpn/tun.h
@@ -61,8 +61,6 @@

= #if defined(_WIN32) || defined(TARGET_ANDROID) || defined(DHCP_UNIT_= TEST)

-#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
-
/* time constants for --ip-win3= 2 adaptive */
#define IPW32_SET_ADAPTIVE_DELAY_WINDOW 300<= /span>
#define IPW32_SET_ADAPTIVE_TRY_NETSH 20
@@ -230,7 +228,7 @@

in_addr_t adapter_netmask;=

/* Windows adapter index for TAP-Windows a= dapter,
- * ~0 if u= ndefined */
+ * T= UN_ADAPTER_INDEX_INVALID if undefined */
DWORD adapter= _index;

int standby_iter;
= diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c
index ac449fd..b2a7331 100644

--- a/src/openvpn/win32.c
+++ b/src/openvpn/win32.c
@@ -1185,7 +1185,7= @@
if (ack.error_number !=3D NO_ERROR)
{

msg(M_WARN,
- "WFP block: %s block filters using= service failed: %s [status=3D0x%x if_index=3D%d]",
+ "WFP block: %s block = filters using service failed: %s [status=3D0x%x if_index=3D%lu]",
(add ? "adding" : "deleting"),= strerror_win32(ack.error_number, &gc), ack.error_number,
data.iface.index);

goto out;
diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/int= eractive.c
index 09c709e..b50aeb3 100644
--= - a/src/openvpnserv/interactive.c
+++ b/src/openvpnserv/int= eractive.c
@@ -96,7 +96,7 @@
typedef struc= t
{
HANDLE engine;
- int index;
+ DWORD index;
int met= ric_v4;
int metric_v6;
} wfp_block_da= ta_t;
@@ -584,7 +584,7 @@
addr_row->= ;Address =3D sockaddr_inet(msg->family, &msg->address); addr_row->OnLinkPrefixLength =3D (UINT8)msg->prefix_len;<= /span>

- = if (msg->iface.index !=3D -1)
+ if (msg->iface.index !=3D TUN_ADAPTER_INDEX_INVALID)
{
addr_row->InterfaceIndex = =3D msg->iface.index;
}
@@ -667,7 += 667,7 @@
fwd_row->DestinationPrefix.PrefixLength = =3D (UINT8)msg->prefix_len;
fwd_row->NextHop =3D= sockaddr_inet(msg->family, &msg->gateway);

- if (msg->iface.ind= ex !=3D -1)
+ if (= msg->iface.index !=3D TUN_ADAPTER_INDEX_INVALID)
{<= /span>
fwd_row->InterfaceIndex =3D msg->iface.index= ;
}
@@ -1010,7 +1010,7 @@
* if action =3D "set" then "static" is added befo= re $addr

*/
static DWORD
-netsh_wins_cmd(const wchar_t *action,= int if_index, const wchar_t *addr)

+netsh_wins_cmd(const wchar_t *action, DWORD if_index, const= wchar_t *addr)
{
DWORD err =3D 0;
int timeout =3D 30000; /* in msec */
@@ = -1036,7 +1036,7 @@
/* cmd template:
= * netsh interface ip $action wins $if_name $static $addr
*/

- const w= char_t *fmt =3D L"netsh interface ip %ls wins %d %ls %ls";=
+ const wchar_t *fmt =3D= L"netsh interface ip %ls wins %lu %ls %ls";

/* max cmdline length in wchars -- include room for wors= t case and some */
size_t ncmdline =3D wcslen(fmt) + 1= 1 /*if_index*/ + wcslen(action) + wcslen(addr)
@@ -2984,7 += 2984,7 @@
*/
}

- int *if_index= =3D malloc(sizeof(msg->iface.index));
+ PDWORD if_index =3D malloc(sizeof(msg->iface.i= ndex));
if (if_index)
{ *if_index =3D msg->iface.index;
@@ -3017= ,7 +3017,7 @@
/* cmd template:
*= netsh interface ipv4 set address name=3D$if_index source=3Ddhcp
= */
- con= st wchar_t *fmt =3D L"netsh interface ipv4 set address name=3D\"%= d\" source=3Ddhcp";
+ const wchar_t *fmt =3D L"netsh interface ipv4 set addres= s name=3D\"%lu\" source=3Ddhcp";
/* max cmdline length in wchars -- include room for if index:
* 10 chars for 32 bit int in decimal and +1 for NUL
@@ -3250,7 +3250,7 @@
br= eak;

case undo_wins:
- netsh= _wins_cmd(L"delete", *(int *)item->data, NULL);
+ netsh_wins_cmd= (L"delete", *(PDWORD)item->data, NULL);

= break;

ca= se wfp_block:

To view, visit change 1519. T= o unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I38bb2d1fa66c543e8bcf47b7d77= b6154d1895f81
Gerrit-Change-Number: 1519
Gerrit-PatchSet: 7
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: cron2 <gert@...1296...>= ;
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
= --IbVBcuAZuNc=--