From: "d12fk (Code Review)" Date: Tue, 4 Jun 2024 00:14:20 +0000 In-Reply-To: References: Reply-To: heiko@...515..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., gert@...1296..., lstipakov@...277... Message-ID: <8a8596beba3525163e40974c8c25ebd631fca704-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Fs4w2dJgzi0="; charset=UTF-8 Subject: [Openvpn-devel] [L] Change in openvpn[master]: Windows: enforce 'block-local' with WFP filters List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , cron2 , flichtenheld , stipa Cc: openvpn-devel --Fs4w2dJgzi0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, flichtenheld, plaisthos, stipa. Hello cron2, flichtenheld, plaisthos, stipa, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/489?usp=3Demail to look at the new patch set (#6). The following approvals got outdated and were removed: Code-Review+1 by flichtenheld, Code-Review+2 by stipa, Code-Review-1 by cro= n2 The change is no longer submittable: Code-Review and checks~ChecksSubmitRul= e are unsatisfied now. Change subject: Windows: enforce 'block-local' with WFP filters ...................................................................... Windows: enforce 'block-local' with WFP filters In an attempt to better defend against the TunnelCrack attacks, enforce that no traffic can pass to anything else than the VPN interface when the 'block-local' flags is given with either --redirect-gateway or --redirect-private. Reuse much of the existing --block-outside-dns code, but make it more general, so that it can also block any traffic, not just port 53. Uses the Windows Filtering Platform for enforcement in addition to the routes redirecting the networks into the tunnel. Change-Id: Ic9bf797bfc7e2d471998a84cb0f071db3e4832ba Signed-off-by: Heiko Hund --- M CMakeLists.txt M doc/man-sections/vpn-network-options.rst M include/openvpn-msg.h M src/openvpn/Makefile.am M src/openvpn/init.c M src/openvpn/route.c M src/openvpn/route.h M src/openvpn/tun.c R src/openvpn/wfp_block.c R src/openvpn/wfp_block.h M src/openvpn/win32.c M src/openvpn/win32.h M src/openvpnserv/CMakeLists.txt M src/openvpnserv/Makefile.am M src/openvpnserv/interactive.c 15 files changed, 365 insertions(+), 243 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/89/489/6 diff --git a/CMakeLists.txt b/CMakeLists.txt index f8b37a9..096837d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -369,8 +369,6 @@ src/openvpn/base64.c src/openvpn/base64.h src/openvpn/basic.h - src/openvpn/block_dns.h - src/openvpn/block_dns.c src/openvpn/buffer.c src/openvpn/buffer.h src/openvpn/circ_list.h @@ -550,6 +548,8 @@ src/openvpn/ssl_util.h src/openvpn/vlan.c src/openvpn/vlan.h + src/openvpn/wfp_block.c + src/openvpn/wfp_block.h src/openvpn/win32.c src/openvpn/win32-util.c src/openvpn/win32.h diff --git a/doc/man-sections/vpn-network-options.rst b/doc/man-sections/vp= n-network-options.rst index 98b4971..84d4273 100644 --- a/doc/man-sections/vpn-network-options.rst +++ b/doc/man-sections/vpn-network-options.rst @@ -352,6 +352,10 @@ Block access to local LAN when the tunnel is active, except for the LAN gateway itself. This is accomplished by routing the local LAN (except for the LAN gateway address) into the tunnel. + On Windows WFP filters are added in addition to the routes which + block access to resources not routed through the VPN adapter. + Push this flag to protect against TunnelCrack type of attacks + (see: https://tunnelcrack.mathyvanhoef.com/). :code:`ipv6` Redirect IPv6 routing into the tunnel. This works similar to diff --git a/include/openvpn-msg.h b/include/openvpn-msg.h index 657eb5e..7a99335 100644 --- a/include/openvpn-msg.h +++ b/include/openvpn-msg.h @@ -24,6 +24,9 @@ #ifndef OPENVPN_MSG_H_ #define OPENVPN_MSG_H_ +#include +#include + typedef enum { msg_acknowledgement, msg_add_address, @@ -35,8 +38,8 @@ msg_add_nbt_cfg, msg_del_nbt_cfg, msg_flush_neighbors, - msg_add_block_dns, - msg_del_block_dns, + msg_add_wfp_block, + msg_del_wfp_block, msg_register_dns, msg_enable_dhcp, msg_register_ring_buffers, @@ -61,6 +64,11 @@ char name[256]; } interface_t; +typedef enum { + wfp_block_local =3D 1<<0, + wfp_block_dns =3D 1<<1 +} wfp_block_flags_t; + typedef struct { message_header_t header; short family; @@ -120,8 +128,9 @@ typedef struct { message_header_t header; + wfp_block_flags_t flags; interface_t iface; -} block_dns_message_t; +} wfp_block_message_t; typedef struct { message_header_t header; diff --git a/src/openvpn/Makefile.am b/src/openvpn/Makefile.am index 7ceec0c..56cce9d 100644 --- a/src/openvpn/Makefile.am +++ b/src/openvpn/Makefile.am @@ -156,6 +156,6 @@ $(OPTIONAL_DL_LIBS) \ $(OPTIONAL_INOTIFY_LIBS) if WIN32 -openvpn_SOURCES +=3D openvpn_win32_resources.rc block_dns.c block_dns.h ri= ng_buffer.h +openvpn_SOURCES +=3D openvpn_win32_resources.rc wfp_block.c wfp_block.h ri= ng_buffer.h openvpn_LDADD +=3D -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm= -lfwpuclnt -lrpcrt4 -lncrypt -lsetupapi -lbcrypt endif diff --git a/src/openvpn/init.c b/src/openvpn/init.c index ec0c309..b081b2f 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -1782,6 +1782,54 @@ #endif } +/** + * Add WFP filters to block traffic to local networks. + * Depending on the configuration all or just DNS is filtered. + * This functionality is only available on Windows on all other + * systems this function is a noop. + * + * @param c pointer to the connection context + */ +static void +add_wfp_block(struct context *c) +{ +#if defined(_WIN32) + /* Fortify 'redirect-gateway block-local' with firewall rules? */ + bool block_local =3D block_local_needed(c->c1.route_list); + + if (c->options.block_outside_dns || block_local) + { + BOOL dns_only =3D !block_local; + if (!win_wfp_block(c->c1.tuntap->adapter_index, c->options.msg_cha= nnel, dns_only)) + { + msg(M_FATAL, "WFP: initialization failed"); + } + } +#endif +} + +/** + * Remove any WFP block filters previously added. + * This functionality is only available on Windows on all other + * systems the function is a noop. + * + * @param c pointer to the connection context + * @param adapter_index the VPN adapter index + */ +static void +del_wfp_block(struct context *c, unsigned long adapter_index) +{ +#if defined(_WIN32) + if (c->options.block_outside_dns || block_local_needed(c->c1.route_lis= t)) + { + if (!win_wfp_uninit(adapter_index, c->options.msg_channel)) + { + msg(M_FATAL, "WFP: deinitialization failed"); + } + } +#endif +} + static bool do_open_tun(struct context *c, int *error_flags) { @@ -1904,16 +1952,7 @@ "up", c->c2.es); -#if defined(_WIN32) - if (c->options.block_outside_dns) - { - dmsg(D_LOW, "Blocking outside DNS"); - if (!win_wfp_block_dns(c->c1.tuntap->adapter_index, c->options= .msg_channel)) - { - msg(M_FATAL, "Blocking DNS failed!"); - } - } -#endif + add_wfp_block(c); /* possibly add routes */ if ((route_order() =3D=3D ROUTE_AFTER_TUN) && (!c->options.route_d= elay_defined)) @@ -1953,17 +1992,8 @@ "up", c->c2.es); } -#if defined(_WIN32) - if (c->options.block_outside_dns) - { - dmsg(D_LOW, "Blocking outside DNS"); - if (!win_wfp_block_dns(c->c1.tuntap->adapter_index, c->options= .msg_channel)) - { - msg(M_FATAL, "Blocking DNS failed!"); - } - } -#endif + add_wfp_block(c); } gc_free(&gc); return ret; @@ -2012,11 +2042,12 @@ struct gc_arena gc =3D gc_new(); const char *tuntap_actual =3D string_alloc(c->c1.tuntap->actual_name, = &gc); -#ifdef _WIN32 - DWORD adapter_index =3D c->c1.tuntap->adapter_index; -#endif const in_addr_t local =3D c->c1.tuntap->local; const in_addr_t remote_netmask =3D c->c1.tuntap->remote_netmask; + unsigned long adapter_index =3D 0; +#ifdef _WIN32 + adapter_index =3D c->c1.tuntap->adapter_index; +#endif if (force || !(c->sig->signal_received =3D=3D SIGUSR1 && c->options.pe= rsist_tun)) { @@ -2081,15 +2112,7 @@ "down", c->c2.es); -#if defined(_WIN32) - if (c->options.block_outside_dns) - { - if (!win_wfp_uninit(adapter_index, c->options.msg_channel)) - { - msg(M_FATAL, "Uninitialising WFP failed!"); - } - } -#endif + del_wfp_block(c, adapter_index); /* actually close tun/tap device based on --down-pre flag */ if (c->options.down_pre) @@ -2120,16 +2143,7 @@ c->c2.es); } -#if defined(_WIN32) - if (c->options.block_outside_dns) - { - if (!win_wfp_uninit(adapter_index, c->options.msg_channel)) - { - msg(M_FATAL, "Uninitialising WFP failed!"); - } - } -#endif - + del_wfp_block(c, adapter_index); } gc_free(&gc); } diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 68bbcfd..91f2032 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -25,6 +25,7 @@ * Support routines for adding/deleting network routes. */ #include +#include #ifdef HAVE_CONFIG_H #include "config.h" @@ -74,7 +75,9 @@ #endif -static void delete_route(struct route_ipv4 *r, const struct tuntap *tt, un= signed int flags, const struct route_gateway_info *rgi, const struct env_se= t *es, openvpn_net_ctx_t *ctx); +static void delete_route(struct route_ipv4 *r, const struct tuntap *tt, un= signed int flags, + const struct route_gateway_info *rgi, const struc= t env_set *es, + openvpn_net_ctx_t *ctx); static void get_bypass_addresses(struct route_bypass *rb, const unsigned i= nt flags); @@ -566,9 +569,7 @@ const struct route_gateway_address *gateway, in_addr_t target) { - const int rgi_needed =3D (RGI_ADDR_DEFINED|RGI_NETMASK_DEFINED); - if ((rl->rgi.flags & rgi_needed) =3D=3D rgi_needed - && rl->rgi.gateway.netmask < 0xFFFFFFFF) + if (rl->rgi.gateway.netmask < 0xFFFFFFFF) { struct route_ipv4 *r1, *r2; unsigned int l2; @@ -593,39 +594,40 @@ } static void -add_block_local(struct route_list *rl) +add_block_local_routes(struct route_list *rl) { - const int rgi_needed =3D (RGI_ADDR_DEFINED|RGI_NETMASK_DEFINED); - if ((rl->flags & RG_BLOCK_LOCAL) - && (rl->rgi.flags & rgi_needed) =3D=3D rgi_needed - && (rl->spec.flags & RTSA_REMOTE_ENDPOINT) - && rl->spec.remote_host_local !=3D TLA_LOCAL) - { - size_t i; - #ifndef TARGET_ANDROID - /* add bypass for gateway addr */ - add_bypass_address(&rl->spec.bypass, rl->rgi.gateway.addr); + /* add bypass for gateway addr */ + add_bypass_address(&rl->spec.bypass, rl->rgi.gateway.addr); #endif - /* block access to local subnet */ - add_block_local_item(rl, &rl->rgi.gateway, rl->spec.remote_endpoin= t); + /* block access to local subnet */ + add_block_local_item(rl, &rl->rgi.gateway, rl->spec.remote_endpoint); - /* process additional subnets on gateway interface */ - for (i =3D 0; i < rl->rgi.n_addrs; ++i) + /* process additional subnets on gateway interface */ + for (size_t i =3D 0; i < rl->rgi.n_addrs; ++i) + { + const struct route_gateway_address *gwa =3D &rl->rgi.addrs[i]; + /* omit the add/subnet in &rl->rgi which we processed above */ + if (!((rl->rgi.gateway.addr & rl->rgi.gateway.netmask) =3D=3D (gwa= ->addr & gwa->netmask) + && rl->rgi.gateway.netmask =3D=3D gwa->netmask)) { - const struct route_gateway_address *gwa =3D &rl->rgi.addrs[i]; - /* omit the add/subnet in &rl->rgi which we processed above */ - if (!((rl->rgi.gateway.addr & rl->rgi.gateway.netmask) =3D=3D = (gwa->addr & gwa->netmask) - && rl->rgi.gateway.netmask =3D=3D gwa->netmask)) - { - add_block_local_item(rl, gwa, rl->spec.remote_endpoint); - } + add_block_local_item(rl, gwa, rl->spec.remote_endpoint); } } } bool +block_local_needed(const struct route_list *rl) +{ + const int rgi_needed =3D (RGI_ADDR_DEFINED|RGI_NETMASK_DEFINED); + return (rl->flags & RG_BLOCK_LOCAL) + && (rl->rgi.flags & rgi_needed) =3D=3D rgi_needed + && (rl->spec.flags & RTSA_REMOTE_ENDPOINT) + && rl->spec.remote_host_local !=3D TLA_LOCAL; +} + +bool init_route_list(struct route_list *rl, const struct route_option_list *opt, const char *remote_endpoint, @@ -698,7 +700,10 @@ if (rl->flags & RG_ENABLE) { - add_block_local(rl); + if (block_local_needed(rl)) + { + add_block_local_routes(rl); + } get_bypass_addresses(&rl->spec.bypass, rl->flags); #ifdef ENABLE_DEBUG print_bypass_addresses(&rl->spec.bypass); @@ -1241,6 +1246,7 @@ } rl6->iflags |=3D RL_ROUTES_ADDED; } + return ret; } diff --git a/src/openvpn/route.h b/src/openvpn/route.h index eb98c71..421e7d2 100644 --- a/src/openvpn/route.h +++ b/src/openvpn/route.h @@ -243,6 +243,18 @@ struct iroute_ipv6 *next; }; +/** + * Get the decision whether to block traffic to local networks while the V= PN + * is connected. This definitely returns false when not redirecting the ga= teway + * or when the 'block-local' flag is not set. Also checks for other + * prerequisites to redirect local networks into the tunnel. + * + * @param rl const pointer to the struct route_list to base the decision o= n. + * + * @return boolean indicating whether local traffic should be blocked. + */ +bool block_local_needed(const struct route_list *rl); + struct route_option_list *new_route_option_list(struct gc_arena *a); struct route_ipv6_option_list *new_route_ipv6_option_list(struct gc_arena = *a); diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index d01515d..ce3d882 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -44,7 +44,7 @@ #include "manage.h" #include "route.h" #include "win32.h" -#include "block_dns.h" +#include "wfp_block.h" #include "networking.h" #include "memdbg.h" diff --git a/src/openvpn/block_dns.c b/src/openvpn/wfp_block.c similarity index 63% rename from src/openvpn/block_dns.c rename to src/openvpn/wfp_block.c index 5f4925f..cf5b39c 100644 --- a/src/openvpn/block_dns.c +++ b/src/openvpn/wfp_block.c @@ -37,7 +37,8 @@ #include #include #include -#include "block_dns.h" + +#include "wfp_block.h" /* * WFP-related defines and GUIDs not in mingw32 @@ -92,10 +93,19 @@ 0xb7, 0xf3, 0xbd, 0xa5, 0xd3, 0x28, 0x90, 0xa4 ); +/* 632ce23b-5167-435c-86d7-e903684aa80c */ +DEFINE_GUID( + FWPM_CONDITION_FLAGS, + 0x632ce23b, + 0x5167, + 0x435c, + 0x86, 0xd7, 0xe9, 0x03, 0x68, 0x4a, 0xa8, 0x0c + ); + /* UUID of WFP sublayer used by all instances of openvpn * 2f660d7e-6a37-11e6-a181-001e8c6e04a2 */ DEFINE_GUID( - OPENVPN_BLOCK_OUTSIDE_DNS_SUBLAYER, + OPENVPN_WFP_BLOCK_SUBLAYER, 0x2f660d7e, 0x6a37, 0x11e6, @@ -113,7 +123,7 @@ return; } -#define CHECK_ERROR(err, msg) \ +#define OUT_ON_ERROR(err, msg) \ if (err) { msg_handler(err, msg); goto out; } /* @@ -154,36 +164,42 @@ } /* - * Block outgoing port 53 traffic except for - * (i) adapter with the specified index + * Block outgoing local traffic, possibly DNS only, except for + * (i) adapter with the specified index (and loopback, if all is blocked) * OR * (ii) processes with the specified executable path * The firewall filters added here are automatically removed when the proc= ess exits or - * on calling delete_block_dns_filters(). + * on calling delete_wfp_block_filters(). * Arguments: * engine_handle : On successful return contains the handle for a newly = opened fwp session * in which the filters are added. - * May be closed by passing to delete_block_dns_filters = to remove the filters. + * May be closed by passing to delete_wfp_block_filters = to remove the filters. * index : The index of adapter for which traffic is permitted. * exe_path : Path of executable for which traffic is permitted. * msg_handler : An optional callback function for error reporting. + * dns_only : Whether the blocking filters should apply for DNS onl= y. * Returns 0 on success, a non-zero status code of the last failed action = on failure. */ DWORD -add_block_dns_filters(HANDLE *engine_handle, +add_wfp_block_filters(HANDLE *engine_handle, int index, const WCHAR *exe_path, - block_dns_msg_handler_t msg_handler - ) + wfp_block_msg_handler_t msg_handler, + BOOL dns_only) { FWPM_SESSION0 session =3D {0}; FWPM_SUBLAYER0 *sublayer_ptr =3D NULL; - NET_LUID tapluid; + NET_LUID itf_luid; UINT64 filterid; FWP_BYTE_BLOB *openvpnblob =3D NULL; FWPM_FILTER0 Filter =3D {0}; - FWPM_FILTER_CONDITION0 Condition[2] =3D {0}; + FWPM_FILTER_CONDITION0 Condition[2]; + FWPM_FILTER_CONDITION0 match_openvpn =3D {0}; + FWPM_FILTER_CONDITION0 match_port_53 =3D {0}; + FWPM_FILTER_CONDITION0 match_interface =3D {0}; + FWPM_FILTER_CONDITION0 match_loopback =3D {0}; + FWPM_FILTER_CONDITION0 match_not_loopback =3D {0}; DWORD err =3D 0; if (!msg_handler) @@ -197,116 +213,154 @@ *engine_handle =3D NULL; err =3D FwpmEngineOpen0(NULL, RPC_C_AUTHN_WINNT, NULL, &session, engin= e_handle); - CHECK_ERROR(err, "FwpEngineOpen: open fwp session failed"); - msg_handler(0, "Block_DNS: WFP engine opened"); + OUT_ON_ERROR(err, "FwpEngineOpen: open fwp session failed"); + msg_handler(0, "WFP Block: WFP engine opened"); /* Check sublayer exists and add one if it does not. */ - if (FwpmSubLayerGetByKey0(*engine_handle, &OPENVPN_BLOCK_OUTSIDE_DNS_S= UBLAYER, &sublayer_ptr) + if (FwpmSubLayerGetByKey0(*engine_handle, &OPENVPN_WFP_BLOCK_SUBLAYER,= &sublayer_ptr) =3D=3D ERROR_SUCCESS) { - msg_handler(0, "Block_DNS: Using existing sublayer"); + msg_handler(0, "WFP Block: Using existing sublayer"); FwpmFreeMemory0((void **)&sublayer_ptr); } else { /* Add a new sublayer -- as another process may add it in the meant= ime, * do not treat "already exists" as an error */ - err =3D add_sublayer(OPENVPN_BLOCK_OUTSIDE_DNS_SUBLAYER); + err =3D add_sublayer(OPENVPN_WFP_BLOCK_SUBLAYER); if (err =3D=3D FWP_E_ALREADY_EXISTS || err =3D=3D ERROR_SUCCESS) { - msg_handler(0, "Block_DNS: Added a persistent sublayer with pr= e-defined UUID"); + msg_handler(0, "WFP Block: Added a persistent sublayer with pr= e-defined UUID"); } else { - CHECK_ERROR(err, "add_sublayer: failed to add persistent subla= yer"); + OUT_ON_ERROR(err, "add_sublayer: failed to add persistent subl= ayer"); } } - err =3D ConvertInterfaceIndexToLuid(index, &tapluid); - CHECK_ERROR(err, "Convert interface index to luid failed"); + err =3D ConvertInterfaceIndexToLuid(index, &itf_luid); + OUT_ON_ERROR(err, "Convert interface index to luid failed"); err =3D FwpmGetAppIdFromFileName0(exe_path, &openvpnblob); - CHECK_ERROR(err, "Get byte blob for openvpn executable name failed"); + OUT_ON_ERROR(err, "Get byte blob for openvpn executable name failed"); + + /* Prepare match conditions */ + match_openvpn.fieldKey =3D FWPM_CONDITION_ALE_APP_ID; + match_openvpn.matchType =3D FWP_MATCH_EQUAL; + match_openvpn.conditionValue.type =3D FWP_BYTE_BLOB_TYPE; + match_openvpn.conditionValue.byteBlob =3D openvpnblob; + + match_port_53.fieldKey =3D FWPM_CONDITION_IP_REMOTE_PORT; + match_port_53.matchType =3D FWP_MATCH_EQUAL; + match_port_53.conditionValue.type =3D FWP_UINT16; + match_port_53.conditionValue.uint16 =3D 53; + + match_interface.fieldKey =3D FWPM_CONDITION_IP_LOCAL_INTERFACE; + match_interface.matchType =3D FWP_MATCH_EQUAL; + match_interface.conditionValue.type =3D FWP_UINT64; + match_interface.conditionValue.uint64 =3D &itf_luid.Value; + + match_loopback.fieldKey =3D FWPM_CONDITION_FLAGS; + match_loopback.matchType =3D FWP_MATCH_FLAGS_ALL_SET; + match_loopback.conditionValue.type =3D FWP_UINT32; + match_loopback.conditionValue.uint32 =3D FWP_CONDITION_FLAG_IS_LOOPBAC= K; + + match_not_loopback.fieldKey =3D FWPM_CONDITION_FLAGS; + match_not_loopback.matchType =3D FWP_MATCH_FLAGS_NONE_SET; + match_not_loopback.conditionValue.type =3D FWP_UINT32; + match_not_loopback.conditionValue.uint32 =3D FWP_CONDITION_FLAG_IS_LOO= PBACK; /* Prepare filter. */ - Filter.subLayerKey =3D OPENVPN_BLOCK_OUTSIDE_DNS_SUBLAYER; + Filter.subLayerKey =3D OPENVPN_WFP_BLOCK_SUBLAYER; Filter.displayData.name =3D FIREWALL_NAME; Filter.weight.type =3D FWP_UINT8; Filter.weight.uint8 =3D 0xF; Filter.filterCondition =3D Condition; - Filter.numFilterConditions =3D 2; + Filter.numFilterConditions =3D 1; - /* First filter. Permit IPv4 DNS queries from OpenVPN itself. */ + /* First filter. Permit IPv4 from OpenVPN itself. */ Filter.layerKey =3D FWPM_LAYER_ALE_AUTH_CONNECT_V4; Filter.action.type =3D FWP_ACTION_PERMIT; - - Condition[0].fieldKey =3D FWPM_CONDITION_IP_REMOTE_PORT; - Condition[0].matchType =3D FWP_MATCH_EQUAL; - Condition[0].conditionValue.type =3D FWP_UINT16; - Condition[0].conditionValue.uint16 =3D 53; - - Condition[1].fieldKey =3D FWPM_CONDITION_ALE_APP_ID; - Condition[1].matchType =3D FWP_MATCH_EQUAL; - Condition[1].conditionValue.type =3D FWP_BYTE_BLOB_TYPE; - Condition[1].conditionValue.byteBlob =3D openvpnblob; - + Condition[0] =3D match_openvpn; + if (dns_only) + { + Filter.numFilterConditions =3D 2; + Condition[1] =3D match_port_53; + } err =3D FwpmFilterAdd0(*engine_handle, &Filter, NULL, &filterid); - CHECK_ERROR(err, "Add filter to permit IPv4 port 53 traffic from OpenV= PN failed"); + OUT_ON_ERROR(err, "Add filter to permit IPv4 traffic from OpenVPN fail= ed"); - /* Second filter. Permit IPv6 DNS queries from OpenVPN itself. */ + /* Second filter. Permit IPv6 from OpenVPN itself. */ Filter.layerKey =3D FWPM_LAYER_ALE_AUTH_CONNECT_V6; - err =3D FwpmFilterAdd0(*engine_handle, &Filter, NULL, &filterid); - CHECK_ERROR(err, "Add filter to permit IPv6 port 53 traffic from OpenV= PN failed"); + OUT_ON_ERROR(err, "Add filter to permit IPv6 traffic from OpenVPN fail= ed"); - msg_handler(0, "Block_DNS: Added permit filters for exe_path"); + msg_handler(0, "WFP Block: Added permit filters for exe_path"); - /* Third filter. Block all IPv4 DNS queries. */ + /* Third filter. Block IPv4 to port 53 or all except loopback. */ Filter.layerKey =3D FWPM_LAYER_ALE_AUTH_CONNECT_V4; Filter.action.type =3D FWP_ACTION_BLOCK; Filter.weight.type =3D FWP_EMPTY; Filter.numFilterConditions =3D 1; - + Condition[0] =3D match_not_loopback; + if (dns_only) + { + Filter.numFilterConditions =3D 2; + Condition[1] =3D match_port_53; + } err =3D FwpmFilterAdd0(*engine_handle, &Filter, NULL, &filterid); - CHECK_ERROR(err, "Add filter to block IPv4 DNS traffic failed"); + OUT_ON_ERROR(err, "Add filter to block IPv4 traffic failed"); - /* Forth filter. Block all IPv6 DNS queries. */ + /* Fourth filter. Block IPv6 to port 53 or all besides loopback */ Filter.layerKey =3D FWPM_LAYER_ALE_AUTH_CONNECT_V6; - err =3D FwpmFilterAdd0(*engine_handle, &Filter, NULL, &filterid); - CHECK_ERROR(err, "Add filter to block IPv6 DNS traffic failed"); + OUT_ON_ERROR(err, "Add filter to block IPv6 traffic failed"); - msg_handler(0, "Block_DNS: Added block filters for all interfaces"); + msg_handler(0, "WFP Block: Added block filters for all interfaces"); - /* Fifth filter. Permit IPv4 DNS queries from TAP. + /* Fifth filter. Permit all IPv4 or just DNS traffic for the VPN inter= face. * Use a non-zero weight so that the permit filters get higher priority * over the block filter added with automatic weighting */ - Filter.weight.type =3D FWP_UINT8; Filter.weight.uint8 =3D 0xE; Filter.layerKey =3D FWPM_LAYER_ALE_AUTH_CONNECT_V4; Filter.action.type =3D FWP_ACTION_PERMIT; - Filter.numFilterConditions =3D 2; - - Condition[1].fieldKey =3D FWPM_CONDITION_IP_LOCAL_INTERFACE; - Condition[1].matchType =3D FWP_MATCH_EQUAL; - Condition[1].conditionValue.type =3D FWP_UINT64; - Condition[1].conditionValue.uint64 =3D &tapluid.Value; - + Filter.numFilterConditions =3D 1; + Condition[0] =3D match_interface; + if (dns_only) + { + Filter.numFilterConditions =3D 2; + Condition[1] =3D match_port_53; + } err =3D FwpmFilterAdd0(*engine_handle, &Filter, NULL, &filterid); - CHECK_ERROR(err, "Add filter to permit IPv4 DNS traffic through TAP fa= iled"); + OUT_ON_ERROR(err, "Add filter to permit IPv4 traffic through VPN inter= face failed"); - /* Sixth filter. Permit IPv6 DNS queries from TAP. + /* Sixth filter. Permit all IPv6 or just DNS traffic for the VPN inter= face. * Use same weight as IPv4 filter */ Filter.layerKey =3D FWPM_LAYER_ALE_AUTH_CONNECT_V6; - err =3D FwpmFilterAdd0(*engine_handle, &Filter, NULL, &filterid); - CHECK_ERROR(err, "Add filter to permit IPv6 DNS traffic through TAP fa= iled"); + OUT_ON_ERROR(err, "Add filter to permit IPv6 traffic through VPN inter= face failed"); - msg_handler(0, "Block_DNS: Added permit filters for TAP interface"); + msg_handler(0, "WFP Block: Added permit filters for VPN interface"); + + /* Seventh Filter. Block IPv4 DNS requests to loopback from other apps= */ + Filter.layerKey =3D FWPM_LAYER_ALE_AUTH_CONNECT_V4; + Filter.action.type =3D FWP_ACTION_BLOCK; + Filter.weight.type =3D FWP_EMPTY; + Filter.numFilterConditions =3D 2; + Condition[0] =3D match_loopback; + Condition[1] =3D match_port_53; + err =3D FwpmFilterAdd0(*engine_handle, &Filter, NULL, &filterid); + OUT_ON_ERROR(err, "Add filter to block IPv4 DNS traffic to loopback fa= iled"); + + /* Eighth Filter. Block IPv6 DNS requests to loopback from other apps = */ + Filter.layerKey =3D FWPM_LAYER_ALE_AUTH_CONNECT_V6; + err =3D FwpmFilterAdd0(*engine_handle, &Filter, NULL, &filterid); + OUT_ON_ERROR(err, "Add filter to block IPv6 DNS traffic to loopback fa= iled"); + + msg_handler(0, "WFP Block: Added block filters for DNS traffic to loop= back"); out: - if (openvpnblob) { FwpmFreeMemory0((void **)&openvpnblob); @@ -322,7 +376,7 @@ } DWORD -delete_block_dns_filters(HANDLE engine_handle) +delete_wfp_block_filters(HANDLE engine_handle) { DWORD err =3D 0; /* diff --git a/src/openvpn/block_dns.h b/src/openvpn/wfp_block.h similarity index 83% rename from src/openvpn/block_dns.h rename to src/openvpn/wfp_block.h index 68fea83..56dabf6 100644 --- a/src/openvpn/block_dns.h +++ b/src/openvpn/wfp_block.h @@ -23,20 +23,24 @@ #ifdef _WIN32 -#ifndef OPENVPN_BLOCK_DNS_H -#define OPENVPN_BLOCK_DNS_H +#ifndef WFP_BLOCK_H +#define WFP_BLOCK_H + +#include +#include +#include =20 /* Any value less than 5 should work fine. 3 is chosen without any real re= ason. */ -#define BLOCK_DNS_IFACE_METRIC 3 +#define WFP_BLOCK_IFACE_METRIC 3 -typedef void (*block_dns_msg_handler_t) (DWORD err, const char *msg); +typedef void (*wfp_block_msg_handler_t) (DWORD err, const char *msg); DWORD -delete_block_dns_filters(HANDLE engine); +delete_wfp_block_filters(HANDLE engine); DWORD -add_block_dns_filters(HANDLE *engine, int iface_index, const WCHAR *exe_pa= th, - block_dns_msg_handler_t msg_handler_callback); +add_wfp_block_filters(HANDLE *engine, int iface_index, const WCHAR *exe_pa= th, + wfp_block_msg_handler_t msg_handler_callback, BOOL d= ns_only); /** * Return interface metric value for the specified interface index. @@ -65,5 +69,5 @@ set_interface_metric(const NET_IFINDEX index, const ADDRESS_FAMILY family, const ULONG metric); -#endif /* ifndef OPENVPN_BLOCK_DNS_H */ +#endif /* ifndef WFP_BLOCK_H */ #endif /* ifdef _WIN32 */ diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c index 98955ba..72496fa 100644 --- a/src/openvpn/win32.c +++ b/src/openvpn/win32.c @@ -34,6 +34,9 @@ #ifdef _WIN32 +#include +#include + #include "buffer.h" #include "error.h" #include "mtu.h" @@ -47,7 +50,7 @@ #include -#include "block_dns.h" +#include "wfp_block.h" /* * WFP handle @@ -1138,43 +1141,19 @@ } static bool -win_block_dns_service(bool add, int index, const HANDLE pipe) +win_get_exe_path(PWCHAR path, DWORD size) { - bool ret =3D false; - ack_message_t ack; - struct gc_arena gc =3D gc_new(); - - block_dns_message_t data =3D { - .header =3D { - (add ? msg_add_block_dns : msg_del_block_dns), - sizeof(block_dns_message_t), - 0 - }, - .iface =3D { .index =3D index, .name =3D "" } - }; - - if (!send_msg_iservice(pipe, &data, sizeof(data), &ack, "Block_DNS")) + DWORD status =3D GetModuleFileNameW(NULL, path, size); + if (status =3D=3D 0 || status =3D=3D size) { - goto out; + msg(M_WARN|M_ERRNO, "cannot get executable path"); + return false; } - - if (ack.error_number !=3D NO_ERROR) - { - msg(M_WARN, "Block_DNS: %s block dns filters using service failed:= %s [status=3D0x%x if_index=3D%d]", - (add ? "adding" : "deleting"), strerror_win32(ack.error_number= , &gc), - ack.error_number, data.iface.index); - goto out; - } - - ret =3D true; - msg(M_INFO, "%s outside dns using service succeeded.", (add ? "Blockin= g" : "Unblocking")); -out: - gc_free(&gc); - return ret; + return true; } static void -block_dns_msg_handler(DWORD err, const char *msg) +win_wfp_msg_handler(DWORD err, const char *msg) { struct gc_arena gc =3D gc_new(); @@ -1184,15 +1163,52 @@ } else { - msg(M_WARN, "Error in add_block_dns_filters(): %s : %s [status=3D0= x%lx]", + msg(M_WARN, "Error in WFP: %s : %s [status=3D0x%lx]", msg, strerror_win32(err, &gc), err); } gc_free(&gc); } +static bool +win_wfp_block_service(bool add, bool dns_only, int index, const HANDLE pip= e) +{ + bool ret =3D false; + ack_message_t ack; + struct gc_arena gc =3D gc_new(); + + wfp_block_message_t data =3D { + .header =3D { + (add ? msg_add_wfp_block : msg_del_wfp_block), + sizeof(wfp_block_message_t), + 0 + }, + .flags =3D dns_only ? wfp_block_dns : wfp_block_local, + .iface =3D { .index =3D index, .name =3D "" } + }; + + if (!send_msg_iservice(pipe, &data, sizeof(data), &ack, "WFP block")) + { + goto out; + } + + 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]", + (add ? "adding" : "deleting"), strerror_win32(ack.error_number= , &gc), + ack.error_number, data.iface.index); + goto out; + } + + ret =3D true; + msg(M_INFO, "%s WFP block filters using service succeeded.", (add ? "A= dding" : "Deleting")); +out: + gc_free(&gc); + return ret; +} + bool -win_wfp_block_dns(const NET_IFINDEX index, const HANDLE msg_channel) +win_wfp_block(const NET_IFINDEX index, const HANDLE msg_channel, BOOL dns_= only) { WCHAR openvpnpath[MAX_PATH]; bool ret =3D false; @@ -1200,20 +1216,19 @@ if (msg_channel) { - dmsg(D_LOW, "Using service to add block dns filters"); - ret =3D win_block_dns_service(true, index, msg_channel); + dmsg(D_LOW, "Using service to add WFP block filters"); + ret =3D win_wfp_block_service(true, dns_only, index, msg_channel); goto out; } - status =3D GetModuleFileNameW(NULL, openvpnpath, _countof(openvpnpath)= ); - if (status =3D=3D 0 || status =3D=3D _countof(openvpnpath)) + ret =3D win_get_exe_path(openvpnpath, _countof(openvpnpath)); + if (ret =3D=3D false) { - msg(M_WARN|M_ERRNO, "block_dns: cannot get executable path"); goto out; } - status =3D add_block_dns_filters(&m_hEngineHandle, index, openvpnpath, - block_dns_msg_handler); + status =3D add_wfp_block_filters(&m_hEngineHandle, index, openvpnpath, + win_wfp_msg_handler, dns_only); if (status =3D=3D 0) { int is_auto =3D 0; @@ -1227,10 +1242,10 @@ { tap_metric_v6 =3D 0; } - status =3D set_interface_metric(index, AF_INET, BLOCK_DNS_IFACE_ME= TRIC); + status =3D set_interface_metric(index, AF_INET, WFP_BLOCK_IFACE_ME= TRIC); if (!status) { - set_interface_metric(index, AF_INET6, BLOCK_DNS_IFACE_METRIC); + set_interface_metric(index, AF_INET6, WFP_BLOCK_IFACE_METRIC); } } @@ -1248,12 +1263,12 @@ if (msg_channel) { - msg(D_LOW, "Using service to delete block dns filters"); - win_block_dns_service(false, index, msg_channel); + msg(D_LOW, "Using service to delete WFP block filters"); + win_wfp_block_service(false, false, index, msg_channel); } else { - delete_block_dns_filters(m_hEngineHandle); + delete_wfp_block_filters(m_hEngineHandle); m_hEngineHandle =3D NULL; if (tap_metric_v4 >=3D 0) { diff --git a/src/openvpn/win32.h b/src/openvpn/win32.h index fd75992..ffad6d9 100644 --- a/src/openvpn/win32.h +++ b/src/openvpn/win32.h @@ -25,8 +25,10 @@ #ifndef OPENVPN_WIN32_H #define OPENVPN_WIN32_H -#include +#include +#include +#include "syshead.h" #include "mtu.h" #include "openvpn-msg.h" #include "argv.h" @@ -286,7 +288,7 @@ /* call self in a subprocess */ void fork_to_self(const char *cmdline); -bool win_wfp_block_dns(const NET_IFINDEX index, const HANDLE msg_channel); +bool win_wfp_block(const NET_IFINDEX index, const HANDLE msg_channel, BOOL= dns_only); =20 bool win_wfp_uninit(const NET_IFINDEX index, const HANDLE msg_channel); =20 diff --git a/src/openvpnserv/CMakeLists.txt b/src/openvpnserv/CMakeLists.txt index 17cd90c..154e17c 100644 --- a/src/openvpnserv/CMakeLists.txt +++ b/src/openvpnserv/CMakeLists.txt @@ -17,7 +17,7 @@ interactive.c service.c service.h validate.c validate.h - ../openvpn/block_dns.c ../openvpn/block_dns.h + ../openvpn/wfp_block.c ../openvpn/wfp_block.h openvpnserv_resources.rc ../openvpn/ring_buffer.h ) diff --git a/src/openvpnserv/Makefile.am b/src/openvpnserv/Makefile.am index 33d2d01..621ce73 100644 --- a/src/openvpnserv/Makefile.am +++ b/src/openvpnserv/Makefile.am @@ -33,6 +33,6 @@ interactive.c \ service.c service.h \ validate.c validate.h \ - $(top_srcdir)/src/openvpn/block_dns.c $(top_srcdir)/src/openvpn/block_dns= .h \ + $(top_srcdir)/src/openvpn/wfp_block.c $(top_srcdir)/src/openvpn/wfp_block= .h \ openvpnserv_resources.rc \ $(top_srcdir)/src/openvpn/ring_buffer.h diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index 294db00..b3c0015 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -39,7 +39,7 @@ #include "openvpn-msg.h" #include "validate.h" -#include "block_dns.h" +#include "wfp_block.h" #include "ring_buffer.h" #define IO_TIMEOUT 2000 /*ms*/ @@ -85,7 +85,7 @@ typedef enum { address, route, - block_dns, + wfp_block, undo_dns4, undo_dns6, undo_domain, @@ -100,7 +100,7 @@ int index; int metric_v4; int metric_v6; -} block_dns_data_t; +} wfp_block_data_t; typedef struct { struct tun_ring *send_ring; @@ -112,7 +112,7 @@ address_message_t address; route_message_t route; flush_neighbors_message_t flush_neighbors; - block_dns_message_t block_dns; + wfp_block_message_t wfp_block; dns_cfg_message_t dns; enable_dhcp_message_t dhcp; register_ring_buffers_message_t rrb; @@ -787,74 +787,76 @@ } static DWORD -DeleteBlockDNS(const block_dns_message_t *msg, undo_lists_t *lists) +DeleteWfpBlock(const wfp_block_message_t *msg, undo_lists_t *lists) { DWORD err =3D 0; - block_dns_data_t *interface_data =3D RemoveListItem(&(*lists)[block_dn= s], CmpAny, NULL); + wfp_block_data_t *block_data =3D RemoveListItem(&(*lists)[wfp_block], = CmpAny, NULL); - if (interface_data) + if (block_data) { - err =3D delete_block_dns_filters(interface_data->engine); - if (interface_data->metric_v4 >=3D 0) + err =3D delete_wfp_block_filters(block_data->engine); + if (block_data->metric_v4 >=3D 0) { set_interface_metric(msg->iface.index, AF_INET, - interface_data->metric_v4); + block_data->metric_v4); } - if (interface_data->metric_v6 >=3D 0) + if (block_data->metric_v6 >=3D 0) { set_interface_metric(msg->iface.index, AF_INET6, - interface_data->metric_v6); + block_data->metric_v6); } - free(interface_data); + free(block_data); } else { - MsgToEventLog(M_ERR, TEXT("No previous block DNS filters to delete= ")); + MsgToEventLog(M_ERR, TEXT("No previous block filters to delete")); } return err; } static DWORD -AddBlockDNS(const block_dns_message_t *msg, undo_lists_t *lists) +AddWfpBlock(const wfp_block_message_t *msg, undo_lists_t *lists) { DWORD err =3D 0; - block_dns_data_t *interface_data =3D NULL; + wfp_block_data_t *block_data =3D NULL; HANDLE engine =3D NULL; LPCWSTR exe_path; + BOOL dns_only; exe_path =3D settings.exe_path; + dns_only =3D (msg->flags =3D=3D wfp_block_dns); - err =3D add_block_dns_filters(&engine, msg->iface.index, exe_path, Blo= ckDNSErrHandler); + err =3D add_wfp_block_filters(&engine, msg->iface.index, exe_path, Blo= ckDNSErrHandler, dns_only); if (!err) { - interface_data =3D malloc(sizeof(block_dns_data_t)); - if (!interface_data) + block_data =3D malloc(sizeof(wfp_block_data_t)); + if (!block_data) { err =3D ERROR_OUTOFMEMORY; goto out; } - interface_data->engine =3D engine; - interface_data->index =3D msg->iface.index; + block_data->engine =3D engine; + block_data->index =3D msg->iface.index; int is_auto =3D 0; - interface_data->metric_v4 =3D get_interface_metric(msg->iface.inde= x, - AF_INET, &is_auto= ); + block_data->metric_v4 =3D get_interface_metric(msg->iface.index, + AF_INET, &is_auto); if (is_auto) { - interface_data->metric_v4 =3D 0; + block_data->metric_v4 =3D 0; } - interface_data->metric_v6 =3D get_interface_metric(msg->iface.inde= x, - AF_INET6, &is_aut= o); + block_data->metric_v6 =3D get_interface_metric(msg->iface.index, + AF_INET6, &is_auto); if (is_auto) { - interface_data->metric_v6 =3D 0; + block_data->metric_v6 =3D 0; } - err =3D AddListItem(&(*lists)[block_dns], interface_data); + err =3D AddListItem(&(*lists)[wfp_block], block_data); if (!err) { err =3D set_interface_metric(msg->iface.index, AF_INET, - BLOCK_DNS_IFACE_METRIC); + WFP_BLOCK_IFACE_METRIC); if (!err) { /* for IPv6, we intentionally ignore errors, because @@ -863,12 +865,12 @@ * (if OpenVPN wants IPv6 ifconfig, we'll fail there) */ set_interface_metric(msg->iface.index, AF_INET6, - BLOCK_DNS_IFACE_METRIC); + WFP_BLOCK_IFACE_METRIC); } if (err) { /* delete the filters, remove undo item and free interface= data */ - DeleteBlockDNS(msg, lists); + DeleteWfpBlock(msg, lists); engine =3D NULL; } } @@ -877,23 +879,23 @@ out: if (err && engine) { - delete_block_dns_filters(engine); - free(interface_data); + delete_wfp_block_filters(engine); + free(block_data); } return err; } static DWORD -HandleBlockDNSMessage(const block_dns_message_t *msg, undo_lists_t *lists) +HandleWfpBlockMessage(const wfp_block_message_t *msg, undo_lists_t *lists) { - if (msg->header.type =3D=3D msg_add_block_dns) + if (msg->header.type =3D=3D msg_add_wfp_block) { - return AddBlockDNS(msg, lists); + return AddWfpBlock(msg, lists); } else { - return DeleteBlockDNS(msg, lists); + return DeleteWfpBlock(msg, lists); } } @@ -1666,11 +1668,11 @@ } break; - case msg_add_block_dns: - case msg_del_block_dns: - if (msg.header.size =3D=3D sizeof(msg.block_dns)) + case msg_add_wfp_block: + case msg_del_wfp_block: + if (msg.header.size =3D=3D sizeof(msg.wfp_block)) { - ack.error_number =3D HandleBlockDNSMessage(&msg.block_dns,= lists); + ack.error_number =3D HandleWfpBlockMessage(&msg.wfp_block,= lists); } break; @@ -1724,7 +1726,7 @@ Undo(undo_lists_t *lists) { undo_type_t type; - block_dns_data_t *interface_data; + wfp_block_data_t *interface_data; for (type =3D 0; type < _undo_type_max; type++) { list_item_t **pnext =3D &(*lists)[type]; @@ -1757,9 +1759,9 @@ SetDNSDomain(item->data, "", NULL); break; - case block_dns: - interface_data =3D (block_dns_data_t *)(item->data); - delete_block_dns_filters(interface_data->engine); + case wfp_block: + interface_data =3D (wfp_block_data_t *)(item->data); + delete_wfp_block_filters(interface_data->engine); if (interface_data->metric_v4 >=3D 0) { set_interface_metric(interface_data->index, AF_INE= T, -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/489?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ic9bf797bfc7e2d471998a84cb0f071db3e4832ba Gerrit-Change-Number: 489 Gerrit-PatchSet: 6 Gerrit-Owner: d12fk Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-Reviewer: stipa Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: flichtenheld Gerrit-Attention: stipa Gerrit-MessageType: newpatchset --Fs4w2dJgzi0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: cron2, flichtenheld, plaisthos, s= tipa.

d12fk uploaded patch set #6 to this change.

View Change

The following approvals got outdated and were removed: Code-Review+1 by flichtenheld, Code-Review+2 by stipa, Code-Review-1 by cro= n2

The change is no longer submittable: Code-Review and checks~Checks= SubmitRule are unsatisfied now.

Windows: enforce 'block-local' with=
 WFP filters

In an attempt to better defend against the TunnelCrack = attacks, enforce
that no traffic can pass to anything else than the VPN = interface when
the 'block-local' flags is given with either --re= direct-gateway or
--redirect-private.

Reuse much of the existing = --block-outside-dns code, but make it more
general, so that it can also = block any traffic, not just port 53.

Uses the Windows Filtering Plat= form for enforcement in addition to the
routes redirecting the networks = into the tunnel.

Change-Id: Ic9bf797bfc7e2d471998a84cb0f071db3e4832b= a
Signed-off-by: Heiko Hund <heiko@...2662...>
---
M CMakeLi= sts.txt
M doc/man-sections/vpn-network-options.rst
M include/openvpn-= msg.h
M src/openvpn/Makefile.am
M src/openvpn/init.c
M src/openvpn= /route.c
M src/openvpn/route.h
M src/openvpn/tun.c
R src/openvpn/w= fp_block.c
R src/openvpn/wfp_block.h
M src/openvpn/win32.c
M src/o= penvpn/win32.h
M src/openvpnserv/CMakeLists.txt
M src/openvpnserv/Mak= efile.am
M src/openvpnserv/interactive.c
15 files changed, 365 insert= ions(+), 243 deletions(-)

git pull ssh://gerrit.openvpn.net:29418=
/openvpn refs/changes/89/489/6
diff --git a/CMakeLists.txt b/CMakeL=
ists.txt
index f8b37a9..096837d 100644
--- = a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3= 69,8 +369,6 @@
src/openvpn/base64.c
= src/openvpn/base64.h
src/openvpn/basic.h
= - src/openvpn/block_dns.h
- src/openvpn/block_dns.= c
src/openvpn/buffer.c
src/openvp= n/buffer.h
src/openvpn/circ_list.h
@@ = -550,6 +548,8 @@
src/openvpn/ssl_util.h
src/openvpn/vlan.c

src/openvpn/vlan.h+ src/openvpn/wfp_block.c
+ src/openvpn/wfp_b= lock.h
src/openvpn/win32.c
src/op= envpn/win32-util.c
src/openvpn/win32.h
diff --git a/doc/man-sections/vpn-network-options.rst b/doc/man-sections/v= pn-network-options.rst

index 98b4971..84d4273 100644=
--- a/doc/man-sections/vpn-network-options.rst
++= + b/doc/man-sections/vpn-network-options.rst
@@ -352,6 +352= ,10 @@
Block access to local LAN when the tunnel is = active, except for
the LAN gateway itself. This is a= ccomplished by routing the local
LAN (except for the= LAN gateway address) into the tunnel.
+ On Windows WFP filters are added in addition to th= e routes which
+ = block access to resources not routed through the VPN adapter.
+ Push this flag to protect = against TunnelCrack type of attacks
+ (see: https://tunnelcrack.mathyvanhoef.com/).<= br>
:code:`ipv6`
Redirect = IPv6 routing into the tunnel. This works similar to
diff --= git a/include/openvpn-msg.h b/include/openvpn-msg.h
index 6= 57eb5e..7a99335 100644
--- a/include/openvpn-msg.h+++ b/include/openvpn-msg.h
@@ -24,6 +24,9 @@
#ifndef OPENVPN_MSG_H_
#define OPENVPN_MSG_H_<= /span>

+#i= nclude <windef.h>
+#include <ws2tcpip.h>
+
typedef enum {
msg_ackno= wledgement,
msg_add_address,
@@ -35,8 = +38,8 @@
msg_add_nbt_cfg,
msg_del= _nbt_cfg,
msg_flush_neighbors,
- msg_add_block_dns,
- msg_del_block_dns,
+ msg_add_wfp_block,
+ msg_del_wfp_block,
msg_register_dns,

msg_enable_dhcp,
<= span> msg_register_ring_buffers,

@@ -61,6 +64,11 @@
char name[256];
} interface_t;
+typedef enu= m {
+ wfp_block_lo= cal =3D 1<<0,
+= wfp_block_dns =3D 1<<1
+} wfp_block_flags_t;
+
typedef struct {
messa= ge_header_t header;
short family;
@@ -= 120,8 +128,9 @@

typedef struct {<= br> message_header_t header;
+ wfp_block_flags_t flags;
interf= ace_t iface;
-} block_d= ns_message_t;
+} wfp_= block_message_t;

typedef struct {=
message_header_t header;
diff --git a/src/op= envpn/Makefile.am b/src/openvpn/Makefile.am
index 7ceec0c..= 56cce9d 100644
--- a/src/openvpn/Makefile.am
+++ b/src/openvpn/Makefile.am

@@ -156,6 +156,6 @@<= br> $(OPTIONAL_DL_LIBS) \
$(OPTIONAL_INOTIFY_LIBS)=
if WIN32
-openvpn_SOURCES +=3D openvpn_win32_resources.rc block_dns.c block_dns.= h ring_buffer.h
+open= vpn_SOURCES +=3D openvpn_win32_resources.rc wfp_block.c wfp_block.h ring_bu= ffer.h
openvpn_LDADD +=3D -lgdi32 -lws2_32 -lwininet -lcry= pt32 -liphlpapi -lwinmm -lfwpuclnt -lrpcrt4 -lncrypt -lsetupapi -lbcrypt

endif
diff --git a/src/openvpn/init.c b/src/= openvpn/init.c
index ec0c309..b081b2f 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c<= br>@@ -1782,6 +1782,54 @@
#endif
}<= /span>

+/*= *
+ * Add WFP filters= to block traffic to local networks.
+ * Depending on the configuration all or just DNS is filte= red.
+ * This functio= nality is only available on Windows on all other
+ * systems this function is a noop.
= + *
+ * @param c pointer to the connection context
+ */
+static void
+add_wfp_block(struct context *c)
+{

+#if defined(_WIN32)
+ /* Fortify 'redirect-gateway block-local&#= 39; with firewall rules? */
+ bool block_local =3D block_local_needed(c->c1.route_list);
+
+ if (c->options.block_outside_dns = || block_local)
+ = {
+ BOOL dns_o= nly =3D !block_local;
+ if (!win_wfp_block(c->c1.tuntap->adapter_index, c->optio= ns.msg_channel, dns_only))
+ {
+ = msg(M_FATAL, "WFP: initialization failed");
+ }

+ }
+#endif
+}
+
= +/**
+ * Remove any WFP block filters previously add= ed.
+ * This function= ality is only available on Windows on all other
+ * systems the function is a noop.
+ *

+ * @param c pointer to the connection= context
+ * @param a= dapter_index the VPN adapter index
+ */
+s= tatic void
+del_wfp_b= lock(struct context *c, unsigned long adapter_index)
+{
+#if defined(_WIN32)
+ if (c->options.block_outside_dns || block_local_need= ed(c->c1.route_list))
+ {
+ i= f (!win_wfp_uninit(adapter_index, c->options.msg_channel))
+ {
+ msg(M_FATAL, "WFP: deini= tialization failed");
+ }
+ = }
+#endif
= +}
+
static bool
d= o_open_tun(struct context *c, int *error_flags)
{@@ -1904,16 +1952,7 @@
"u= p",
c->c2.es);

-#if defined(_WIN32)=
- if (c->opt= ions.block_outside_dns)
- {
- = dmsg(D_LOW, "Blocking outside DNS");
- if (!win_wfp_block_dns(c->c1.tunt= ap->adapter_index, c->options.msg_channel))
- {
- msg(M_FATAL, "Blocking DNS failed!= ");
- }=
- }
<= span style=3D"color: hsl(0, 100%, 40%);">-#endif
+ add_wfp_block(c);

/* possibly add routes */
i= f ((route_order() =3D=3D ROUTE_AFTER_TUN) && (!c->options.route_= delay_defined))
@@ -1953,17 +1992,8 @@
= "up",
= c->c2.es);
}
-#if defined(_WIN32)
- if (c->options.block_outside_dns)
= - {
- dmsg(D_LOW, "Blocking outs= ide DNS");
- = if (!win_wfp_block_dns(c->c1.tuntap->adapter_index, c->optio= ns.msg_channel))
- = {
- = msg(M_FATAL, "Blocking DNS failed!");
- }
- }
-#endif

+ add_wfp_block(c);
}
gc_free(&gc);

return ret;
@@ -2012,11 +2042,12 @@

struct gc_a= rena gc =3D gc_new();
const char *tuntap_actual =3D st= ring_alloc(c->c1.tuntap->actual_name, &gc);
-#ifdef _WIN32
- DWORD adapter_index =3D c->c1.tuntap->ada= pter_index;
-#endif

const in_addr_t local =3D c->c1.tuntap->local;

const in_addr_t remote_netmask =3D c->c1.tuntap->rem= ote_netmask;
+ uns= igned long adapter_index =3D 0;
+#ifdef _WIN32
+ adapter_index =3D c->c1.tuntap->adapter_index;
+#endif
<= br> if (force || !(c->sig->signal_received =3D=3D SIGUSR1 &= amp;& c->options.persist_tun))
{
@@ -2081,15 +2112,7 @@
"down&qu= ot;,
c->c2.es);

-#if defined(_WIN32)
- if (c->options= .block_outside_dns)
- = {
- if= (!win_wfp_uninit(adapter_index, c->options.msg_channel))
- {

- msg(M_FATAL, "Uninitia= lising WFP failed!");
- }
- = }
-#endif+ del_wfp_block(c, ada= pter_index);

/* actually close t= un/tap device based on --down-pre flag */
if (c-&g= t;options.down_pre)
@@ -2120,16 +2143,7 @@
= c->c2.es);
}
-#if defined(_= WIN32)
- if (c-&= gt;options.block_outside_dns)
- {
- = if (!win_wfp_uninit(adapter_index, c->options.msg_channel))

- {
- msg(M_FATAL, "= ;Uninitialising WFP failed!");
- }
- }
-#endif=
-
+ del_wfp_block(c, adapter_index);=
}
gc_free(&gc);
}
diff --git a/src/openvpn/route.c b/src/openvpn/route= .c
index 68bbcfd..91f2032 100644
--- a/src/= openvpn/route.c
+++ b/src/openvpn/route.c
@= @ -25,6 +25,7 @@
* Support routines for adding/deleting n= etwork routes.
*/
#include <stddef.h&= gt;
+#include <std= bool.h>

#ifdef HAVE_CONFIG_H #include "config.h"
@@ -74,7 +75,9 @@


#endif

-static void delete_route(struct route_i= pv4 *r, const struct tuntap *tt, unsigned int flags, const struct route_gat= eway_info *rgi, const struct env_set *es, openvpn_net_ctx_t *ctx);+static void delete_route(str= uct route_ipv4 *r, const struct tuntap *tt, unsigned int flags,
<= span style=3D"color: hsl(120, 100%, 40%);">+ const = struct route_gateway_info *rgi, const struct env_set *es,
+ openvpn_net_= ctx_t *ctx);

static void get_bypass_addr= esses(struct route_bypass *rb, const unsigned int flags);
=
@@ -566,9 +569,7 @@
= const struct route_gateway_address *gateway,
= in_addr_t target)
{
- const int rgi_needed =3D (RGI_ADDR_DEFINED|RGI_N= ETMASK_DEFINED);
- i= f ((rl->rgi.flags & rgi_needed) =3D=3D rgi_needed
- && rl->rgi.gateway.ne= tmask < 0xFFFFFFFF)
-add_block_local(struct route_list *rl)
+add_block_local_routes(s= truct route_list *rl)
{
- const int rgi_needed =3D (RGI_ADDR_DEFINED|RGI_NETMA= SK_DEFINED);
- if ((= rl->flags & RG_BLOCK_LOCAL)
- && (rl->rgi.flags & rgi_needed) =3D=3D = rgi_needed
- &am= p;& (rl->spec.flags & RTSA_REMOTE_ENDPOINT)
- && rl->spec.remote_host= _local !=3D TLA_LOCAL)
= - {
- size_t = i;
-
#= ifndef TARGET_ANDROID
-= /* add bypass for gateway addr */
- add_bypass_address(&rl->spec.bypass, rl-= >rgi.gateway.addr);
+ add_bypass_address(&rl->spec.bypass, rl->= ;rgi.gateway.addr);
#endif

- /* block access to local su= bnet */

- add_bl= ock_local_item(rl, &rl->rgi.gateway, rl->spec.remote_endpoint);
+ /* block access t= o local subnet */
+ = add_block_local_item(rl, &rl->rgi.gateway, rl->spec.remote_endp= oint);

- for (i =3D 0; i < rl-= >rgi.n_addrs; ++i)
+ /* process additional subnets on gateway interface */
+ for (size_t i =3D 0; i < rl-= >rgi.n_addrs; ++i)

+ {
+ cons= t struct route_gateway_address *gwa =3D &rl->rgi.addrs[i];+ /* omit the add/subne= t in &rl->rgi which we processed above */
+ if (!((rl->rgi.gateway.addr & r= l->rgi.gateway.netmask) =3D=3D (gwa->addr & gwa->netmask)
+ &&= rl->rgi.gateway.netmask =3D=3D gwa->netmask))
= {
- const= struct route_gateway_address *gwa =3D &rl->rgi.addrs[i];
= - /* omit the add/subn= et in &rl->rgi which we processed above */
- if (!((rl->rgi.gateway.addr &= ; rl->rgi.gateway.netmask) =3D=3D (gwa->addr & gwa->netmask)
- &= & rl->rgi.gateway.netmask =3D=3D gwa->netmask))
- {
- add_block_local_item(rl, gwa, r= l->spec.remote_endpoint);
- }
= + add_block_local_item(rl, gwa, rl->spec.remote_endpoint);

}
}
}
bool
+block_local_needed(const struct route_list *rl)
+{
+ const int rgi_needed =3D (RGI_ADDR_DEFINED|RGI_NE= TMASK_DEFINED);
+ = return (rl->flags & RG_BLOCK_LOCAL)
+ && (rl->rgi.flags & rgi_ne= eded) =3D=3D rgi_needed
+ && (rl->spec.flags & RTSA_REMOTE_ENDPOINT)

+ && = rl->spec.remote_host_local !=3D TLA_LOCAL;
+}
+
+bool=
init_route_list(struct route_list *rl,
= const struct route_option_list *opt,
= const char *remote_endpoint,
@@ -698,7 +700,10 @@=

if (rl->flags & RG_ENABLE) {
- = add_block_local(rl);
+ if (block_local_needed(rl))
+ {
+ add_block_local_routes(rl);
+ }
get_bypass_a= ddresses(&rl->spec.bypass, rl->flags);
#ifdef EN= ABLE_DEBUG
print_bypass_addresses(&rl->spec= .bypass);
@@ -1241,6 +1246,7 @@
}<= /span>
rl6->iflags |=3D RL_ROUTES_ADDED;
}

+ return ret;
}

diff --git a/src/openvpn/route.h b/src/openvpn/route.h
in= dex eb98c71..421e7d2 100644
--- a/src/openvpn/route.h
+++ b/src/openvpn/route.h
@@ -243,6 +243,18 @@
struct iroute_ipv6 *next;
};
+/**<= br>+ * Get the decision whether= to block traffic to local networks while the VPN
+ * is connected. This definitely returns fals= e when not redirecting the gateway
+ * or when the 'block-local' flag is not set. Also c= hecks for other
+ * p= rerequisites to redirect local networks into the tunnel.
+ *
+ * @param rl const pointer to the struct route_list to = base the decision on.
+ *
+ * @return bool= ean indicating whether local traffic should be blocked.
+ */
+bool block_local_needed(const struct route_list *rl);
+
str= uct route_option_list *new_route_option_list(struct gc_arena *a);
struct route_ipv6_option_list *new_route_ipv6_opt= ion_list(struct gc_arena *a);
diff --git a/src/openvpn/tun.= c b/src/openvpn/tun.c
index d01515d..ce3d882 100644<= br>--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -44,7 +44,7 @@
#include "manage.h&qu= ot;
#include "route.h"
#include= "win32.h"
-#= include "block_dns.h"
+#include "wfp_block.h"
#include &quo= t;networking.h"

#include "memd= bg.h"
diff --git a/src/openvpn/block_dns.c b/src/openv= pn/wfp_block.c
similarity index 63%
rename = from src/openvpn/block_dns.c
rename to src/openvpn/wfp_bloc= k.c
index 5f4925f..cf5b39c 100644
--- a/src= /openvpn/block_dns.c
+++ b/src/openvpn/wfp_block.c@@ -37,7 +37,8 @@
#include <winsock2.h>

#include <ws2ipdef.h>
#include <iphl= papi.h>
-#include &q= uot;block_dns.h"
+
+#include "wf= p_block.h"

/*
* W= FP-related defines and GUIDs not in mingw32
@@ -92,10 +93,1= 9 @@
0xb7, 0xf3, 0xbd, 0xa5, 0xd3, 0x28, 0x90, 0xa4
);

+/* 632ce23b-5167-435c-86d7-e903684aa80c */
+DEFINE_GUID(

+ FWPM_CONDITION_FLAGS,
+ 0x632ce23b,
+ 0x5167,
+ 0x435c,
+ 0x86, 0xd7, 0xe9, 0x03, 0x68, 0x4a, 0xa8, 0x0c
+ );
+

/* UUID of WFP su= blayer used by all instances of openvpn
* 2f660d7e-6a37-1= 1e6-a181-001e8c6e04a2 */
DEFINE_GUID(
- OPENVPN_BLOCK_OUTSIDE_DNS_SUBLAYER,
+ OPENVPN_WFP_BLOCK_= SUBLAYER,
0x2f660d7e,
0x6a37,

0x11e6,
@@ -113,7 +123,7 @@
return;
}

-#define CHECK_ERROR(err, msg) \
<= span style=3D"color: hsl(120, 100%, 40%);">+#define OUT_ON_ERROR(err, msg) = \
if (err) { msg_handler(err, msg); goto out; }=

/*
@@ -154,36 +164,42 @@
}

/*
- * Block outgoing port 53 traffic except fo= r
- * (i) adapter with = the specified index
+= * Block outgoing local traffic, possibly DNS only, except for
+ * (i) adapter with the specifie= d index (and loopback, if all is blocked)

* OR
= * (ii) processes with the specified executable path
* The firewall filters added here are automatically removed when the pro= cess exits or
- * on ca= lling delete_block_dns_filters().
+ * on calling delete_wfp_block_filters().
*= Arguments:
* engine_handle : On successful return cont= ains the handle for a newly opened fwp session
* = in which the filters are added.
- * May be closed by passing to delete= _block_dns_filters to remove the filters.
+ * May be closed by passing to dele= te_wfp_block_filters to remove the filters.
* index = : The index of adapter for which traffic is permitted.
* exe_path : Path of executable for which traffic is permitted.
* msg_handler : An optional callback function for erro= r reporting.
+ * dn= s_only : Whether the blocking filters should apply for DNS only.

* Returns 0 on success, a non-zero status code of the last fai= led action on failure.
*/

DWORD
-add_block_dn= s_filters(HANDLE *engine_handle,
+add_wfp_block_filters(HANDLE *engine_handle,
= int index,
con= st WCHAR *exe_path,
- = block_dns_msg_handler_t msg_handler
- )
+ wfp_block_msg_h= andler_t msg_handler,
+ BOOL dns_only)
{
= FWPM_SESSION0 session =3D {0};
FWPM_SUBLAYER0 *sub= layer_ptr =3D NULL;
- = NET_LUID tapluid;
+= NET_LUID itf_luid;
UINT64 filterid;
FWP_BYTE_BLOB *openvpnblob =3D NULL;
FWPM_FILTE= R0 Filter =3D {0};
- = FWPM_FILTER_CONDITION0 Condition[2] =3D {0};
+ FWPM_FILTER_CONDITION0 Condition[2];+ FWPM_FILTER_CONDITION0 m= atch_openvpn =3D {0};
+ FWPM_FILTER_CONDITION0 match_port_53 =3D {0};
+ FWPM_FILTER_CONDITION0 match_interfac= e =3D {0};
+ FWPM_= FILTER_CONDITION0 match_loopback =3D {0};
+ FWPM_FILTER_CONDITION0 match_not_loopback =3D {0}= ;
DWORD err =3D 0;

= if (!msg_handler)
@@ -197,116 +213,154 @@
*engine_handle =3D NULL;

err= =3D FwpmEngineOpen0(NULL, RPC_C_AUTHN_WINNT, NULL, &session, engine_ha= ndle);
- CHECK_ERROR= (err, "FwpEngineOpen: open fwp session failed");
- msg_handler(0, "Block_DNS: WF= P engine opened");
+ OUT_ON_ERROR(err, "FwpEngineOpen: open fwp session failed"= ;);
+ msg_handler(= 0, "WFP Block: WFP engine opened");

<= span> /* Check sublayer exists and add one if it does not. */- if (FwpmSubLayerGetByKey0(*= engine_handle, &OPENVPN_BLOCK_OUTSIDE_DNS_SUBLAYER, &sublayer_ptr)<= /span>
+ if (FwpmSubLayer= GetByKey0(*engine_handle, &OPENVPN_WFP_BLOCK_SUBLAYER, &sublayer_pt= r)
=3D=3D ERROR_SUCCESS)
{
- msg_handler(0, &= quot;Block_DNS: Using existing sublayer");
+ msg_handler(0, "WFP Block: Using e= xisting sublayer");
FwpmFreeMemory0((void **)= &sublayer_ptr);
}
else=
{ /* Add a new sublayer -- as another process may add it in= the meantime,
* do not treat "already exists= " as an error */
-= err =3D add_sublayer(OPENVPN_BLOCK_OUTSIDE_DNS_SUBLAYER);+ err =3D add_sublayer(= OPENVPN_WFP_BLOCK_SUBLAYER);

if = (err =3D=3D FWP_E_ALREADY_EXISTS || err =3D=3D ERROR_SUCCESS)
{

- = msg_handler(0, "Block_DNS: Added a persistent sublayer with pre-de= fined UUID");
+ = msg_handler(0, "WFP Block: Added a persistent sublayer with= pre-defined UUID");
}
= else
{
- CHECK_ERROR(err, "add_sublayer: failed to add= persistent sublayer");
+ OUT_ON_ERROR(err, "add_sublayer: failed to add pe= rsistent sublayer");
}
}=

- = err =3D ConvertInterfaceIndexToLuid(index, &tapluid);
- CHECK_ERROR(err, "Convert int= erface index to luid failed");
+ err =3D ConvertInterfaceIndexToLuid(index, &itf_lui= d);
+ OUT_ON_ERROR= (err, "Convert interface index to luid failed");
=
err =3D FwpmGetAppIdFromFileName0(exe_path, &ope= nvpnblob);
- CHECK_E= RROR(err, "Get byte blob for openvpn executable name failed");
+ OUT_ON_ERROR(err, = "Get byte blob for openvpn executable name failed");
+

+ /* Prepare match conditions */
+ match_openvpn.fieldKey =3D FWPM_= CONDITION_ALE_APP_ID;
+ match_openvpn.matchType =3D FWP_MATCH_EQUAL;
+ match_openvpn.conditionValue.type =3D FW= P_BYTE_BLOB_TYPE;
+ = match_openvpn.conditionValue.byteBlob =3D openvpnblob;
+
+ match_port_53.fieldKey =3D FWPM_CONDITION_IP_REMOTE_P= ORT;
+ match_port_= 53.matchType =3D FWP_MATCH_EQUAL;
+ match_port_53.conditionValue.type =3D FWP_UINT16;<= br>+ match_port_53.condition= Value.uint16 =3D 53;
= +
+ match_interfac= e.fieldKey =3D FWPM_CONDITION_IP_LOCAL_INTERFACE;
+ match_interface.matchType =3D FWP_MATCH_E= QUAL;
+ match_inte= rface.conditionValue.type =3D FWP_UINT64;
+ match_interface.conditionValue.uint64 =3D &it= f_luid.Value;
+

+ match_loopback.fieldK= ey =3D FWPM_CONDITION_FLAGS;
+ match_loopback.matchType =3D FWP_MATCH_FLAGS_ALL_SET;+ match_loopback.condition= Value.type =3D FWP_UINT32;
+ match_loopback.conditionValue.uint32 =3D FWP_CONDITION_FLAG_IS_L= OOPBACK;
+
= + match_not_loopback.fieldKe= y =3D FWPM_CONDITION_FLAGS;
+ match_not_loopback.matchType =3D FWP_MATCH_FLAGS_NONE_SET;
+ match_not_loopback.c= onditionValue.type =3D FWP_UINT32;
+ match_not_loopback.conditionValue.uint32 =3D FWP_CONDITI= ON_FLAG_IS_LOOPBACK;

/* Prepare filt= er. */
- Filter.subL= ayerKey =3D OPENVPN_BLOCK_OUTSIDE_DNS_SUBLAYER;
+ Filter.subLayerKey =3D OPENVPN_WFP_BLOCK_SU= BLAYER;
Filter.displayData.name =3D FIREWALL_NAME;

Filter.weight.type =3D FWP_UINT8;
Fi= lter.weight.uint8 =3D 0xF;
Filter.filterCondition =3D = Condition;
- Filter.= numFilterConditions =3D 2;
+ Filter.numFilterConditions =3D 1;

- /* First filter. Permit IPv4 D= NS queries from OpenVPN itself. */
+ /* First filter. Permit IPv4 from OpenVPN itself. */
Filter.layerKey =3D FWPM_LAYER_ALE_AUTH_CONNECT_V4;
Filter.action.type =3D FWP_ACTION_PERMIT;
-
- Condition[0].fieldKey =3D FWPM_CONDITION_IP_REMOTE_PORT;=
- Condition[0].matc= hType =3D FWP_MATCH_EQUAL;
- Condition[0].conditionValue.type =3D FWP_UINT16;
- Condition[0].conditionValue.uint16 = =3D 53;
-
- Condition[1].fieldKey =3D FWPM_= CONDITION_ALE_APP_ID;

-= Condition[1].matchType =3D FWP_MATCH_EQUAL;
- Condition[1].conditionValue.type =3D FWP_BYTE= _BLOB_TYPE;
- Condit= ion[1].conditionValue.byteBlob =3D openvpnblob;
-
+ Condition[0] =3D match_openvpn;
+ if (dns_only)
+ {
+ Filter.numFilterConditions =3D 2;
+ Condition[1] =3D match_port_53;=
+ }
= err =3D FwpmFilterAdd0(*engine_handle, &Filter, NULL, &filterid);<= /span>
- CHECK_ERROR(err, &= quot;Add filter to permit IPv4 port 53 traffic from OpenVPN failed");<= /span>
+ OUT_ON_ERROR(err= , "Add filter to permit IPv4 traffic from OpenVPN failed");

- /* Se= cond filter. Permit IPv6 DNS queries from OpenVPN itself. */
+ /* Second filter. Permit IPv6 = from OpenVPN itself. */

Filter.layerKey =3D FWPM_LAYER= _ALE_AUTH_CONNECT_V6;
-=
err =3D FwpmFilterAdd0(*engine_handle, &Filter, N= ULL, &filterid);
- = CHECK_ERROR(err, "Add filter to permit IPv6 port 53 traffic from Op= enVPN failed");
= + OUT_ON_ERROR(err, "Add filter to permit IPv6 traffic from OpenVPN= failed");

- msg_handler(0, "Block_DNS: Added permit filters for ex= e_path");
+ m= sg_handler(0, "WFP Block: Added permit filters for exe_path");


- /*= Third filter. Block all IPv4 DNS queries. */
+ /* Third filter. Block IPv4 to port 53 or all= except loopback. */
Filter.layerKey =3D FWPM_LAYER_AL= E_AUTH_CONNECT_V4;
Filter.action.type =3D FWP_ACTION_B= LOCK;
Filter.weight.type =3D FWP_EMPTY;
Filter.numFilterConditions =3D 1;
-
+= Condition[0] =3D match_not_loopback;
+ if (dns_only)
+ {
+ Filter.numFilterConditions =3D 2;
+ Condition[1] =3D match_port_53;+ }
e= rr =3D FwpmFilterAdd0(*engine_handle, &Filter, NULL, &filterid);
- CHECK_ERROR(err, &qu= ot;Add filter to block IPv4 DNS traffic failed");
+ OUT_ON_ERROR(err, "Add filter t= o block IPv4 traffic failed");

- /* Forth filter. Block all IPv6 DNS que= ries. */
+ /* Four= th filter. Block IPv6 to port 53 or all besides loopback */
Filter.layerKey =3D FWPM_LAYER_ALE_AUTH_CONNECT_V6;

-
err =3D FwpmFilte= rAdd0(*engine_handle, &Filter, NULL, &filterid);
- CHECK_ERROR(err, "Add filter to= block IPv6 DNS traffic failed");
+ OUT_ON_ERROR(err, "Add filter to block IPv6 tra= ffic failed");

- msg_handler(0, "Block_DNS: Added block filters for= all interfaces");
+ msg_handler(0, "WFP Block: Added block filters for all interfa= ces");

- /* Fifth filter. Permit IPv4 DNS queries from TAP.
+ /* Fifth filter. Permit all = IPv4 or just DNS traffic for the VPN interface.
* Use= a non-zero weight so that the permit filters get higher priority * over the block filter added with automatic weighting */

-
Filt= er.weight.type =3D FWP_UINT8;
Filter.weight.uint8 =3D = 0xE;
Filter.layerKey =3D FWPM_LAYER_ALE_AUTH_CONNECT_V= 4;
Filter.action.type =3D FWP_ACTION_PERMIT;- Filter.numFilterConditions = =3D 2;
-
- Condition[1].fieldKey =3D FWPM_C= ONDITION_IP_LOCAL_INTERFACE;
- Condition[1].matchType =3D FWP_MATCH_EQUAL;
- Condition[1].conditionValue.type =3D F= WP_UINT64;
- Conditi= on[1].conditionValue.uint64 =3D &tapluid.Value;
-
+ Filter.numFilterConditions =3D 1;
+ Condition[0] =3D match_interface;=
+ if (dns_only)+ {
+ Filter.numFilterConditions =3D 2;=
+ Condition[1= ] =3D match_port_53;
= + }
err =3D FwpmFilterAdd0(*engine_handle, &Fil= ter, NULL, &filterid);
- CHECK_ERROR(err, "Add filter to permit IPv4 DNS traffic throu= gh TAP failed");
+ OUT_ON_ERROR(err, "Add filter to permit IPv4 traffic through VPN= interface failed");

- /* Sixth filter. Permit IPv6 DNS queries from TAP= .
+ /* Sixth filte= r. Permit all IPv6 or just DNS traffic for the VPN interface.
* Use same weight as IPv4 filter */
Filter.la= yerKey =3D FWPM_LAYER_ALE_AUTH_CONNECT_V6;
-
err =3D FwpmFilterAdd0(*engine_h= andle, &Filter, NULL, &filterid);
- CHECK_ERROR(err, "Add filter to permit IPv6 DN= S traffic through TAP failed");
+ OUT_ON_ERROR(err, "Add filter to permit IPv6 traf= fic through VPN interface failed");

- msg_handler(0, "Block_DNS: Ad= ded permit filters for TAP interface");
+ msg_handler(0, "WFP Block: Added permit f= ilters for VPN interface");
+
+ /*= Seventh Filter. Block IPv4 DNS requests to loopback from other apps */

+ Filter.layerKey =3D= FWPM_LAYER_ALE_AUTH_CONNECT_V4;
+ Filter.action.type =3D FWP_ACTION_BLOCK;
+ Filter.weight.type =3D FWP_EMPTY;=
+ Filter.numFilte= rConditions =3D 2;
+ = Condition[0] =3D match_loopback;
+ Condition[1] =3D match_port_53;
+ err =3D FwpmFilterAdd0(*engine_handle= , &Filter, NULL, &filterid);
+ OUT_ON_ERROR(err, "Add filter to block IPv4 DNS t= raffic to loopback failed");
+
+ /= * Eighth Filter. Block IPv6 DNS requests to loopback from other apps */
+ Filter.layerKey =3D= FWPM_LAYER_ALE_AUTH_CONNECT_V6;
+ err =3D FwpmFilterAdd0(*engine_handle, &Filter, NULL, = &filterid);
+ = OUT_ON_ERROR(err, "Add filter to block IPv6 DNS traffic to loopback fa= iled");
+=
+ msg_handler(0, "W= FP Block: Added block filters for DNS traffic to loopback");
out:
-
if (openvpnblob)
{

FwpmFreeMemory0((void **)&openvpnblob);
= @@ -322,7 +376,7 @@
}

DWORD
-delete_bloc= k_dns_filters(HANDLE engine_handle)
+delete_wfp_block_filters(HANDLE engine_handle)
{
DWORD err =3D 0;
/*=
diff --git a/src/openvpn/block_dns.h b/src/openvpn/wfp_block.h

similarity index 83%
rename from src/openvpn/= block_dns.h
rename to src/openvpn/wfp_block.h
index 68fea83..56dabf6 100644
--- a/src/openvpn/block_dn= s.h
+++ b/src/openvpn/wfp_block.h
@@ -23,20= +23,24 @@

#ifdef _WIN32

-#ifndef OPENVPN_BLO= CK_DNS_H
-#define OPENV= PN_BLOCK_DNS_H
+#ifnd= ef WFP_BLOCK_H
+#defi= ne WFP_BLOCK_H
+
+#include <windef.h>= ;
+#include <iphlp= api.h>
+#include &= lt;ws2tcpip.h>

/* Any value less than= 5 should work fine. 3 is chosen without any real reason. */
-#define BLOCK_DNS_IFACE_METRIC 3

+#define WFP_BLOCK_IFACE= _METRIC 3

-typedef void (*block_dns_msg_handler_t) (DWORD err, const char *msg);=
+typedef void (*wfp_= block_msg_handler_t) (DWORD err, const char *msg);
=
DWORD
-delet= e_block_dns_filters(HANDLE engine);
+delete_wfp_block_filters(HANDLE engine);
<= /span>
DWORD
= -add_block_dns_filters(HANDLE *engine, int iface_index, const WCHAR *exe_pa= th,
- = block_dns_msg_handler_t msg_handler_callback);
+add_wfp_block_filters(HANDLE *engine, int if= ace_index, const WCHAR *exe_path,
+ wfp_block_msg_handler_t msg_handler_cal= lback, BOOL dns_only);

/**
* Return interface metric value for the specified interface index.
@@ -65,5 +69,5 @@
set_interface_metric(const = NET_IFINDEX index, const ADDRESS_FAMILY family,
= const ULONG metric);

-#endif /* ifndef OPENVPN_BLOCK_DNS_H */<= br>+#endif /* ifndef WFP_BLOCK_= H */
#endif /* ifdef _WIN32 */
diff --git = a/src/openvpn/win32.c b/src/openvpn/win32.c
index 98955ba..= 72496fa 100644
--- a/src/openvpn/win32.c
++= + b/src/openvpn/win32.c
@@ -34,6 +34,9 @@
=
#ifdef _WIN32

+#include <minwindef.h>
+#include <winsock2.h>+
#include &= quot;buffer.h"
#include "error.h" #include "mtu.h"
@@ -47,7 +50,7 @@=

#include <versionhelpers.h>

-#include "b= lock_dns.h"
+#in= clude "wfp_block.h"

/*<= br> * WFP handle
@@ -1138,43 +1141,19 @@
<= span> }

static bool
-win_block_dns_service(bool add, int index,= const HANDLE pipe)
+= win_get_exe_path(PWCHAR path, DWORD size)
{
- bool ret =3D false;
- ack_message_t ack;
<= span style=3D"color: hsl(0, 100%, 40%);">- struct gc_arena gc =3D gc_new= ();
-
- block_dns_message_t data =3D {

- .header =3D {
- (add ? msg_add= _block_dns : msg_del_block_dns),
- sizeof(block_dns_message_t),
- 0
- },
- .iface =3D { .index =3D index, .name =3D "" = }
- };
-

- if (!send_msg_iservice(pipe, &data, sizeof(data)= , &ack, "Block_DNS"))
+ DWORD status =3D GetModuleFileNameW(NULL, path, size);<= /span>
+ if (status =3D= =3D 0 || status =3D=3D size)
{
- goto out;
+ msg(M_WARN|M_ERRNO, "cannot get = executable path");
+ return false;
}
-
- if (ack.error_number !=3D NO_ERROR)
- {
- msg(M_WARN, "Block_DNS: %s block dns filters using ser= vice failed: %s [status=3D0x%x if_index=3D%d]",
- (add ? "adding" : &qu= ot;deleting"), strerror_win32(ack.error_number, &gc),
- ack.error_number, data= .iface.index);

- = goto out;
- }
-
- ret =3D true;
- msg(M_INFO, "%s outside dns using service s= ucceeded.", (add ? "Blocking" : "Unblocking"));

-out:
- gc_free(&gc);
- return ret;
+ return true;
}
static void
-block_dns_msg_handler(DWORD err, const char *msg)+win_wfp_msg_handler(DWORD err= , const char *msg)
{
struct gc_arena = gc =3D gc_new();

@@ -1184,15 +1163,52 @@<= /span>
}
else
{
- msg(M_WARN, "= ;Error in add_block_dns_filters(): %s : %s [status=3D0x%lx]",+ msg(M_WARN, "Er= ror in WFP: %s : %s [status=3D0x%lx]",
ms= g, strerror_win32(err, &gc), err);
}

gc_free(&gc);
}

+static bool
+win_wfp_block_service(= bool add, bool dns_only, int index, const HANDLE pipe)
+{
+ bool ret =3D false;
+ ack_message_t ack;
+ struct gc_arena gc =3D gc_new();
+

+ wfp_block_message_t data =3D {
+ .header =3D {
+ (add ? msg_add_wfp_block= : msg_del_wfp_block),
+ 0
+ },
+ .flags =3D dns_only ? wfp_block_dns : wfp_block_local,
+ .iface =3D { .i= ndex =3D index, .name =3D "" }
+ };
+
+ if (!se= nd_msg_iservice(pipe, &data, sizeof(data), &ack, "WFP block&qu= ot;))
+ {+ goto out;
= + }
+
+ if (ack.error_number !=3D NO_ERROR)
+ {
+ msg(M_WARN, "WFP block: %s block filters u= sing service failed: %s [status=3D0x%x if_index=3D%d]",
+ (add ? "adding&qu= ot; : "deleting"), strerror_win32(ack.error_number, &gc),
+ ack.error_n= umber, data.iface.index);
+ goto out;
+ }
++ ret =3D true;
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg(M_INFO, "%s WFP bl= ock filters using service succeeded.", (add ? "Adding" : &qu= ot;Deleting"));

= +out:
+ gc_free(&a= mp;gc);
+ return r= et;
+}
+
bool
<= span style=3D"color: hsl(0, 100%, 40%);">-win_wfp_block_dns(const NET_IFIND= EX index, const HANDLE msg_channel)
+win_wfp_block(const NET_IFINDEX index, const HANDLE msg_cha= nnel, BOOL dns_only)
{
WCHAR openvpnp= ath[MAX_PATH];
bool ret =3D false;
@@ = -1200,20 +1216,19 @@

if (msg_channel= )
{
- ret =3D win_b= lock_dns_service(true, index, msg_channel);
+ dmsg(D_LOW, "Using service to add WFP = block filters");
+ ret =3D win_wfp_block_service(true, dns_only, index, msg_channel)= ;
goto out;
}

- status =3D GetM= oduleFileNameW(NULL, openvpnpath, _countof(openvpnpath));
- if (status =3D=3D 0 || status =3D= =3D _countof(openvpnpath))
+ ret =3D win_get_exe_path(openvpnpath, _countof(openvpnpath));
+ if (ret =3D=3D fal= se)
{
- msg(M_WARN|M_ERRNO, "block_dns: cannot get executable pat= h");
goto out;
}<= br>
- status = =3D add_block_dns_filters(&m_hEngineHandle, index, openvpnpath,<= br>- = block_dns_msg_handler);
+ status =3D add_wfp_block_filters(&m_hEngineHandle, index,= openvpnpath,
+ = win_wfp_msg_handler, dns_only);
if (status =3D=3D 0)

{
= int is_auto =3D 0;
@@ -1227,10 +1242,10 @@
{
tap_metric_v6 =3D 0;
}
- = status =3D set_interface_metric(index, AF_INET, BLOCK_DNS_IFACE_METRIC);
+ status =3D set= _interface_metric(index, AF_INET, WFP_BLOCK_IFACE_METRIC);
= if (!status)
{
- set_interface_metric(index, AF_INET6= , BLOCK_DNS_IFACE_METRIC);
+ set_interface_metric(index, AF_INET6, WFP_BLOCK_IFACE_ME= TRIC);
}
}
<= /span>
@@ -1248,12 +1263,12 @@

= if (msg_channel)
{
- msg(D_LOW, "Using service to delete bloc= k dns filters");
-= win_block_dns_service(false, index, msg_channel);
+ msg(D_LOW, "Using servic= e to delete WFP block filters");
+ win_wfp_block_service(false, false, index, msg_ch= annel);
}
else
= {
- delete_bl= ock_dns_filters(m_hEngineHandle);
+ delete_wfp_block_filters(m_hEngineHandle);
= m_hEngineHandle =3D NULL;
if (tap_m= etric_v4 >=3D 0)
{
diff --git a= /src/openvpn/win32.h b/src/openvpn/win32.h
index fd75992..f= fad6d9 100644
--- a/src/openvpn/win32.h
+++= b/src/openvpn/win32.h
@@ -25,8 +25,10 @@
= #ifndef OPENVPN_WIN32_H
#define OPENVPN_WIN32_H
=
-#include <w= inioctl.h>
+#inclu= de <iphlpapi.h>
+#include <ws2tcpip.h>

+#include "syshead.h"
= #include "mtu.h"
#include "openvpn-msg.h&q= uot;
#include "argv.h"
@@ -286,7= +288,7 @@
/* call self in a subprocess */
void fork_to_self(const char *cmdline);


-bool win_wfp_block_dns(const NET_IFIN= DEX index, const HANDLE msg_channel);

+bool win_wfp_block(const NET_IFINDEX index, const HANDLE = msg_channel, BOOL dns_only);

bool win_wf= p_uninit(const NET_IFINDEX index, const HANDLE msg_channel);

diff --git a/src/openvpnserv/CMakeLists.txt b/src/openv= pnserv/CMakeLists.txt
index 17cd90c..154e17c 100644<= br>--- a/src/openvpnserv/CMakeLists.txt
+++ b/src/ope= nvpnserv/CMakeLists.txt
@@ -17,7 +17,7 @@
= interactive.c
service.c service.h
= validate.c validate.h
- ../openvpn/block_dns.c ../openvpn/block_dns.h
+ ../openvpn/wfp_block.c ../openvpn/wf= p_block.h
openvpnserv_resources.rc
= ../openvpn/ring_buffer.h
)
diff --gi= t a/src/openvpnserv/Makefile.am b/src/openvpnserv/Makefile.am
index 33d2d01..621ce73 100644
--- a/src/openvpnserv/Make= file.am
+++ b/src/openvpnserv/Makefile.am
@= @ -33,6 +33,6 @@
interactive.c \
servic= e.c service.h \
validate.c validate.h \
- $(top_srcdir)/src/openvpn/block_dns.c = $(top_srcdir)/src/openvpn/block_dns.h \
+ $(top_srcdir)/src/openvpn/wfp_block.c $(top_srcdir)/sr= c/openvpn/wfp_block.h \
openvpnserv_resources.rc \=
$(top_srcdir)/src/openvpn/ring_buffer.h
diff --= git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c<= br>index 294db00..b3c0015 100644
--- a/src/openvpnser= v/interactive.c
+++ b/src/openvpnserv/interactive.c<= br>@@ -39,7 +39,7 @@

#include &quo= t;openvpn-msg.h"
#include "validate.h"

-#include "block_dns.h= "
+#include &quo= t;wfp_block.h"
#include "ring_buffer.h"


#define IO_TIMEOUT 2000 /*ms*/
<= span>@@ -85,7 +85,7 @@
typedef enum {
= address,
route,
- block_dns,
+ wfp_block,
undo_dns4,
= undo_dns6,
undo_domain,
@@ -100,7 = +100,7 @@
int index;
int metric_v= 4;
int metric_v6;
-} block_dns_data_t;
+} wfp_block_data_t;

typ= edef struct {
struct tun_ring *send_ring;
@@ -112,7 +112,7 @@
address_message_t address;
route_message_t route;
flush_neighbo= rs_message_t flush_neighbors;
- block_dns_message_t block_dns;
+ wfp_block_message_t wfp_block;
= dns_cfg_message_t dns;
enable_dhcp_message_t dhcp;=
register_ring_buffers_message_t rrb;
= @@ -787,74 +787,76 @@
}

= static DWORD
-DeleteBl= ockDNS(const block_dns_message_t *msg, undo_lists_t *lists)
+DeleteWfpBlock(const wfp_block_mess= age_t *msg, undo_lists_t *lists)

{
DW= ORD err =3D 0;
- blo= ck_dns_data_t *interface_data =3D RemoveListItem(&(*lists)[block_dns], = CmpAny, NULL);
+ w= fp_block_data_t *block_data =3D RemoveListItem(&(*lists)[wfp_block], Cm= pAny, NULL);

- if (interface_data)
+ if (block_data)
{
- err =3D delete_block_dns_filters(= interface_data->engine);
- if (interface_data->metric_v4 >=3D 0)
+ err =3D delete_wfp_block_filt= ers(block_data->engine);
+ if (block_data->metric_v4 >=3D 0)
= {
set_interface_metric(msg->iface.ind= ex, AF_INET,
- = interface_data->metric_v4);
+ block_d= ata->metric_v4);
}
- if (interface_data->metric_v6 >=3D 0= )
+ if (block_= data->metric_v6 >=3D 0)
{
= set_interface_metric(msg->iface.index, AF_INET6,
- i= nterface_data->metric_v6);
+ block_data->metric_v6);

}
-= free(interface_data);
+ free(block_data);
}
= else
{
- MsgToEventLog(M_ERR, TEXT("No previous block DNS fi= lters to delete"));
+ MsgToEventLog(M_ERR, TEXT("No previous block filters to d= elete"));
}

= return err;
}

static = DWORD
-AddBlockDNS(cons= t block_dns_message_t *msg, undo_lists_t *lists)
+AddWfpBlock(const wfp_block_message_t *msg, un= do_lists_t *lists)
{
DWORD err =3D 0;=
- block_dns_data_t = *interface_data =3D NULL;
+ wfp_block_data_t *block_data =3D NULL;
HANDL= E engine =3D NULL;
LPCWSTR exe_path;
+ BOOL dns_only;
<= /span>
exe_path =3D settings.exe_path;
+ dns_only =3D (msg->flags =3D=3D wf= p_block_dns);

- err =3D add_block_dns_filters(&engine, msg->iface.inde= x, exe_path, BlockDNSErrHandler);
+ err =3D add_wfp_block_filters(&engine, msg->iface.= index, exe_path, BlockDNSErrHandler, dns_only);
if (!e= rr)
{
- interface_data =3D malloc(sizeof(block_dns_data_t));- if (!interface_data)
+ block_data =3D= malloc(sizeof(wfp_block_data_t));
+ if (!block_data)
{ err =3D ERROR_OUTOFMEMORY;
= goto out;
}
- interface_data->engine =3D engine;
- interface_data->index = =3D msg->iface.index;

+ block_data->engine =3D engine;
+ block_data->index =3D msg->iface.i= ndex;
int is_auto =3D 0;
- interface_data->metric_v4 =3D get_in= terface_metric(msg->iface.index,
- AF_I= NET, &is_auto);
+= block_data->metric_v4 =3D get_interface_metric(msg->iface.ind= ex,
+ = AF_INET, &is_auto);
if (is_auto)

{
- interface_data->metric_v4 =3D 0= ;
+ block_= data->metric_v4 =3D 0;
}
- interface_data->metric_v6 =3D ge= t_interface_metric(msg->iface.index,
- = AF_INET6, &is_auto);
+ block_data->metric_v6 =3D get_interface_metric(msg->ifac= e.index,
+ = AF_INET6, &is_auto); if (is_auto)
{
- interface_data->metric_v6= =3D 0;
+ = block_data->metric_v6 =3D 0;
}
=
- err =3D AddL= istItem(&(*lists)[block_dns], interface_data);
+ err =3D AddListItem(&(*lists)[wf= p_block], block_data);
if (!err)
= {
err =3D set_interface_metric(msg->= ;iface.index, AF_INET,
= - BLOCK_DNS_IFACE_METRIC);
= + = WFP_BLOCK_IFACE_METRIC);
if (!err)
{
/* for IPv6, = we intentionally ignore errors, because
@@ -863,12 +865,12 = @@
* (if OpenVPN wants IPv6 ifconfig, we&= #39;ll fail there)
*/
= set_interface_metric(msg->iface.index, AF_INET6,- = BLOCK_DNS_IFACE_METRIC);
+ WFP_BLOCK_IFACE_METRIC);
}
if (err) {
/* delete the filte= rs, remove undo item and free interface data */
- DeleteBlockDNS(msg, lists);

+ DeleteWfp= Block(msg, lists);
engine =3D NULL;=
}
}
@@ -877= ,23 +879,23 @@
out:
if (err &&= ; engine)
{
- delete_block_dns_filters(engine);
- free(interface_data);
+ delete_wfp_block_filters(= engine);
+ fre= e(block_data);
}

= return err;
}

static = DWORD
-HandleBlockDNSMe= ssage(const block_dns_message_t *msg, undo_lists_t *lists)
+HandleWfpBlockMessage(const wfp_bloc= k_message_t *msg, undo_lists_t *lists)
{
- if (msg->header.type =3D=3D msg_= add_block_dns)
+ i= f (msg->header.type =3D=3D msg_add_wfp_block)
{

- return AddBlockDN= S(msg, lists);
+ = return AddWfpBlock(msg, lists);
}
= else
{
- return DeleteBlockDNS(msg, lists);
+ return DeleteWfpBlock(msg, lists)= ;
}
}

@@ -1666,11 +1668,11 @@
}
= break;

- case msg_add_block_dns:
- case msg_del_block_dns:
- if (msg.header.size =3D=3D s= izeof(msg.block_dns))
+ case msg_add_wfp_block:
+ case msg_del_wfp_block:
+ if (msg.header.size =3D=3D sizeof(msg= .wfp_block))
{
- ack.error_number =3D HandleBlockDNSMe= ssage(&msg.block_dns, lists);
+ ack.error_number =3D HandleWfpBlockMessage(&a= mp;msg.wfp_block, lists);
}
= break;

@@ -1724,7 +1726,7 @@
Undo(undo_lists_t *lists)
{
undo_type_t type;

+ wfp_block_data_t *interface_data;
= for (type =3D 0; type < _undo_type_max; type++)
= {
list_item_t **pnext =3D &(*lists)[type];
@@ -1757,9 +1759,9 @@
S= etDNSDomain(item->data, "", NULL);
= break;

- case block_dns:
- interface_data =3D (block_dns_da= ta_t *)(item->data);
- delete_block_dns_filters(interface_data->engine);<= /span>
+ case= wfp_block:
+ = interface_data =3D (wfp_block_data_t *)(item->data);<= br>+ delete_= wfp_block_filters(interface_data->engine);
= if (interface_data->metric_v4 >=3D 0)
= {
set_interface_metr= ic(interface_data->index, AF_INET,

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

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic9bf797bfc7e2d471998a84cb0f= 071db3e4832ba
Gerrit-Change-Number: 489
Gerrit-PatchSet: 6
Gerrit-Owner: d12fk <heiko@...515...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-Reviewer: stipa <lstipakov@...277...= >
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...>
Gerrit-Attention: stipa <lstipakov@...1663...= .>
Gerrit-MessageType: newpatchset
--Fs4w2dJgzi0=--