Skip to content

Commit 1483c12

Browse files
committed
add support for --block-outside-dns option
The option is only enforced with the --dns option, since DNS settings coming in via --dhcp-option have always voluntarily blocked port 53. This behavior is kept for backwards compatibility. Since the --dns option allows local name servers to continue to work, even thought no split DNS is pushed, supporting the option makes sense. If admins do not want any DNS queries outside the tunnel, this is the option to push alongside the --dns options. Signed-off-by: Heiko Hund <[email protected]>
1 parent 157c66f commit 1483c12

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

openvpn/client/cliopt.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,6 @@ class ClientOptions : public RC<thread_unsafe_refcount>
683683
"allow-compression", /* TODO: maybe check against our client option compression setting? */
684684
"allow-recursive-routing",
685685
"auth-retry",
686-
"block-outside-dns", /* Core will decide on its own when to block outside dns, so this is not 100% identical in behaviour, so still warn */
687686
"compat-mode",
688687
"connect-retry",
689688
"connect-retry-max",

openvpn/tun/builder/base.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,17 @@ class TunBuilderBase
222222
return true;
223223
}
224224

225+
// Optional callback that indicates whether local DNS traffic
226+
// should be blocked or allowed, to prevent DNS queries to leak
227+
// while the tunnel is connected.
228+
// Note that this option is only relevant on Windows when the
229+
// --dns option is used. If DNS is set via --dhcp-option port 53
230+
// is always blocked for backwards compatibility reasons.
231+
virtual bool tun_builder_set_allow_local_dns(bool allow)
232+
{
233+
return true;
234+
}
235+
225236
// Optional callback to set a DNS suffix on tun/tap adapter.
226237
// Currently only implemented on Windows, where it will
227238
// set the "Connection-specific DNS Suffix" property on

openvpn/tun/builder/capture.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,12 @@ class TunBuilderCapture : public TunBuilderBase, public RC<thread_unsafe_refcoun
610610
return true;
611611
}
612612

613+
bool tun_builder_set_allow_local_dns(bool allow) override
614+
{
615+
block_outside_dns = !allow;
616+
return true;
617+
}
618+
613619
void reset_tunnel_addresses()
614620
{
615621
tunnel_addresses.clear();
@@ -691,6 +697,7 @@ class TunBuilderCapture : public TunBuilderBase, public RC<thread_unsafe_refcoun
691697
os << "Reroute Gateway: " << reroute_gw.to_string() << std::endl;
692698
os << "Block IPv4: " << (block_ipv4 ? "yes" : "no") << std::endl;
693699
os << "Block IPv6: " << (block_ipv6 ? "yes" : "no") << std::endl;
700+
os << "Block local DNS: " << (block_outside_dns ? "yes" : "no") << std::endl;
694701
if (route_metric_default >= 0)
695702
os << "Route Metric Default: " << route_metric_default << std::endl;
696703
render_list(os, "Add Routes", add_routes);
@@ -733,6 +740,7 @@ class TunBuilderCapture : public TunBuilderBase, public RC<thread_unsafe_refcoun
733740
root["tunnel_address_index_ipv6"] = Json::Value(tunnel_address_index_ipv6);
734741
root["reroute_gw"] = reroute_gw.to_json();
735742
root["block_ipv6"] = Json::Value(block_ipv6);
743+
root["block_outside_dns"] = Json::Value(block_outside_dns);
736744
root["route_metric_default"] = Json::Value(route_metric_default);
737745
json::from_vector(root, add_routes, "add_routes");
738746
json::from_vector(root, exclude_routes, "exclude_routes");
@@ -765,6 +773,7 @@ class TunBuilderCapture : public TunBuilderBase, public RC<thread_unsafe_refcoun
765773
json::to_int(root, tbc->tunnel_address_index_ipv6, "tunnel_address_index_ipv6", title);
766774
tbc->reroute_gw.from_json(root["reroute_gw"], "reroute_gw");
767775
json::to_bool(root, tbc->block_ipv6, "block_ipv6", title);
776+
json::to_bool(root, tbc->block_outside_dns, "block_outside_dns", title);
768777
json::to_int(root, tbc->route_metric_default, "route_metric_default", title);
769778
json::to_vector(root, tbc->add_routes, "add_routes", title);
770779
json::to_vector(root, tbc->exclude_routes, "exclude_routes", title);
@@ -793,6 +802,7 @@ class TunBuilderCapture : public TunBuilderBase, public RC<thread_unsafe_refcoun
793802
RerouteGW reroute_gw; // redirect-gateway info
794803
bool block_ipv4 = false; // block IPv4 traffic while VPN is active
795804
bool block_ipv6 = false; // block IPv6 traffic while VPN is active
805+
bool block_outside_dns = false; // block traffic to port 53 locally while VPN is active
796806
int route_metric_default = -1; // route-metric directive
797807
std::vector<Route> add_routes; // routes that should be added to tunnel
798808
std::vector<Route> exclude_routes; // routes that should be excluded from tunnel

openvpn/tun/client/tunprop.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ class TunProp
181181
tb->tun_builder_set_allow_family(AF_INET, !opt.exists("block-ipv4"));
182182
tb->tun_builder_set_allow_family(AF_INET6, !opt.exists("block-ipv6"));
183183

184+
// Allow access to local port 53 with --dns options unless explicitly blocked
185+
tb->tun_builder_set_allow_local_dns(!opt.exists("block-outside-dns"));
186+
184187
// DNS fallback
185188
if (ipv.rgv4() && !(dhcp_option_flags & F_ADD_DNS))
186189
{

openvpn/tun/win/client/tunsetup.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,13 @@ class Setup : public SetupBase
650650
create.add(new DNS::ActionCreate(tap.name, search_domains));
651651
destroy.add(new NRPT::ActionDelete(pid));
652652
destroy.add(new DNS::ActionDelete(tap.name, search_domains));
653+
654+
// block local DNS lookup unless all traffic is blocked already
655+
if (use_wfp && pull.block_outside_dns && !block_local_traffic && !openvpn_app_path.empty())
656+
{
657+
create.add(new WFP::ActionBlock(openvpn_app_path, tap.index, true, wfp));
658+
destroy.add(new WFP::ActionUnblock(openvpn_app_path, tap.index, true, wfp));
659+
}
653660
}
654661
else
655662
{

0 commit comments

Comments
 (0)