Skip to content

Commit b547737

Browse files
authored
Merge pull request #162 from robhoes/master
Extend the naughty DHCP-server workaround to DNS
2 parents 1562ee7 + 75a4c5d commit b547737

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

lib/network_utils.ml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,11 @@ module Dhclient = struct
743743
then (debug "%s is the default gateway interface" interface; ["routers"])
744744
else (debug "%s is NOT the default gateway interface" interface; [])
745745
in
746-
let set_dns = if List.mem `set_dns options then ["domain-name"; "domain-name-servers"] else [] in
746+
let set_dns =
747+
if List.mem (`dns interface) options
748+
then (debug "%s is the DNS interface" interface; ["domain-name"; "domain-name-servers"])
749+
else (debug "%s is NOT the DNS interface" interface; [])
750+
in
747751
let request = minimal @ set_gateway @ set_dns in
748752
Printf.sprintf "interface \"%s\" {\n request %s;\n}\n" interface (String.concat ", " request)
749753

@@ -760,19 +764,22 @@ module Dhclient = struct
760764
(* This prevents the default route being set erroneously on CentOS *)
761765
(* Normally this wouldn't happen as we're not requesting routers, *)
762766
(* but some buggy DHCP servers ignore this *)
767+
(* Same story for DNS! *)
763768
(* See CA-137892 *)
764769
let gw_opt = List.fold_left
765770
(fun l x ->
766771
match x with
767772
| `gateway y -> ["-e"; "GATEWAYDEV="^y]
768773
| _ -> l) [] options in
774+
let dns_opt = if List.mem (`dns interface) options then [] else ["-e"; "PEERDNS=no"] in
769775
write_conf_file ~ipv6 interface options;
770776
let ipv6' = if ipv6 then ["-6"] else [] in
771-
call_script ~timeout:None dhclient (ipv6' @ gw_opt @ ["-q";
772-
"-pf"; pid_file ~ipv6 interface;
773-
"-lf"; lease_file ~ipv6 interface;
774-
"-cf"; conf_file ~ipv6 interface;
775-
interface])
777+
call_script ~timeout:None dhclient (ipv6' @ gw_opt @ dns_opt @
778+
["-q";
779+
"-pf"; pid_file ~ipv6 interface;
780+
"-lf"; lease_file ~ipv6 interface;
781+
"-cf"; conf_file ~ipv6 interface;
782+
interface])
776783

777784
let stop ?(ipv6=false) interface =
778785
try

networkd/network_server.ml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,7 @@ module Interface = struct
250250
| DHCP4 ->
251251
let open Xapi_stdext_monadic in
252252
let gateway = Opt.default [] (Opt.map (fun n -> [`gateway n]) !config.gateway_interface) in
253-
let dns =
254-
if !config.dns_interface = None || !config.dns_interface = Some name then begin
255-
debug "%s is the DNS interface" name;
256-
[`set_dns]
257-
end else begin
258-
debug "%s is NOT the DNS interface" name;
259-
[]
260-
end
261-
in
253+
let dns = Opt.default [] (Opt.map (fun n -> [`dns n]) !config.dns_interface) in
262254
let options = gateway @ dns in
263255
Dhclient.ensure_running name options
264256
| Static4 addrs ->

0 commit comments

Comments
 (0)