Skip to content

Commit 1d83693

Browse files
authored
CA-416532: Revert #6586, overwrites /etc/resolve.conf (#6643)
This reverts @psafont's PR, #6586, this causing the `/etc/resolve.conf` to be overwritten during update, after the dhclient writes it. This happens because `set_dns` no longer checks the mode before applying the DNS config, This reverts commit 05e6317, reversing changes made to 1fbdaae.
2 parents 4f80ccf + ec61f8e commit 1d83693

File tree

5 files changed

+41
-43
lines changed

5 files changed

+41
-43
lines changed

ocaml/networkd/bin/network_server.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,7 @@ module Interface = struct
554554
let set_dns _ dbg ~name ~nameservers ~domains =
555555
Debug.with_thread_associated dbg
556556
(fun () ->
557-
update_config name
558-
{(get_config name) with dns= Some (nameservers, domains)} ;
557+
update_config name {(get_config name) with dns= (nameservers, domains)} ;
559558
debug "Configuring DNS for %s: nameservers: [%s]; domains: [%s]" name
560559
(String.concat ", " (List.map Unix.string_of_inet_addr nameservers))
561560
(String.concat ", " domains) ;
@@ -728,7 +727,7 @@ module Interface = struct
728727
; ipv6_conf
729728
; ipv6_gateway
730729
; ipv4_routes
731-
; dns
730+
; dns= nameservers, domains
732731
; mtu
733732
; ethtool_settings
734733
; ethtool_offload
@@ -737,10 +736,15 @@ module Interface = struct
737736
) ) ->
738737
update_config name c ;
739738
exec (fun () ->
740-
match dns with
741-
| Some (nameservers, domains) ->
739+
(* We only apply the DNS settings when not in a DHCP mode
740+
to avoid conflicts. The `dns` field
741+
should really be an option type so that we don't have to
742+
derive the intention of the caller by looking at other
743+
fields. *)
744+
match (ipv4_conf, ipv6_conf) with
745+
| Static4 _, _ | _, Static6 _ | _, Autoconf6 ->
742746
set_dns () dbg ~name ~nameservers ~domains
743-
| None ->
747+
| _ ->
744748
()
745749
) ;
746750
exec (fun () -> set_ipv4_conf dbg name ipv4_conf) ;

ocaml/networkd/bin_db/networkd_db.ml

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,20 @@ let _ =
7474
[("gateway", Unix.string_of_inet_addr addr)]
7575
in
7676
let dns =
77-
interface_config.dns
78-
|> Option.map fst
79-
|> Option.map (List.map Unix.string_of_inet_addr)
80-
|> Option.fold ~none:[] ~some:(function
81-
| [] ->
82-
[]
83-
| dns' ->
84-
[("dns", String.concat "," dns')]
85-
)
77+
let dns' =
78+
List.map Unix.string_of_inet_addr (fst interface_config.dns)
79+
in
80+
if dns' = [] then
81+
[]
82+
else
83+
[("dns", String.concat "," dns')]
8684
in
8785
let domains =
88-
interface_config.dns
89-
|> Option.map snd
90-
|> Option.fold ~none:[] ~some:(function
91-
| [] ->
92-
[]
93-
| domains' ->
94-
[("domain", String.concat "," domains')]
95-
)
86+
let domains' = snd interface_config.dns in
87+
if domains' = [] then
88+
[]
89+
else
90+
[("domain", String.concat "," domains')]
9691
in
9792
mode @ addrs @ gateway @ dns @ domains
9893
| None4 ->

ocaml/networkd/lib/network_config.ml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ let bridge_naming_convention (device : string) =
3737
let get_list_from ~sep ~key args =
3838
List.assoc_opt key args
3939
|> Option.map (fun v -> Astring.String.cuts ~empty:false ~sep v)
40+
|> Option.value ~default:[]
4041

4142
let parse_ipv4_config args = function
4243
| Some "static" ->
@@ -72,13 +73,11 @@ let parse_ipv6_config args = function
7273
(None6, None)
7374

7475
let parse_dns_config args =
75-
let ( let* ) = Option.bind in
76-
let* nameservers =
77-
get_list_from ~sep:"," ~key:"DNS" args
78-
|> Option.map (List.map Unix.inet_addr_of_string)
76+
let nameservers =
77+
get_list_from ~sep:"," ~key:"DNS" args |> List.map Unix.inet_addr_of_string
7978
in
80-
let* domains = get_list_from ~sep:" " ~key:"DOMAIN" args in
81-
Some (nameservers, domains)
79+
let domains = get_list_from ~sep:" " ~key:"DOMAIN" args in
80+
(nameservers, domains)
8281

8382
let read_management_conf () =
8483
try
@@ -104,15 +103,15 @@ let read_management_conf () =
104103
let device =
105104
(* Take 1st member of bond *)
106105
match (bond_mode, bond_members) with
107-
| None, _ | _, (None | Some []) -> (
106+
| None, _ | _, [] -> (
108107
match List.assoc_opt "LABEL" args with
109108
| Some x ->
110109
x
111110
| None ->
112111
error "%s: missing LABEL in %s" __FUNCTION__ management_conf ;
113112
raise Read_error
114113
)
115-
| _, Some (hd :: _) ->
114+
| _, hd :: _ ->
116115
hd
117116
in
118117
Inventory.reread_inventory () ;

ocaml/xapi-idl/network/network_interface.ml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,7 @@ type interface_config_t = {
158158
; ipv6_conf: ipv6 [@default None6]
159159
; ipv6_gateway: Unix.inet_addr option [@default None]
160160
; ipv4_routes: ipv4_route_t list [@default []]
161-
; dns: (Unix.inet_addr list * string list) option [@default None]
162-
(** the list
163-
of nameservers and domains to persist in /etc/resolv.conf. Must be None when
164-
using a DHCP mode *)
161+
; dns: Unix.inet_addr list * string list [@default [], []]
165162
; mtu: int [@default 1500]
166163
; ethtool_settings: (string * string) list [@default []]
167164
; ethtool_offload: (string * string) list [@default [("lro", "off")]]
@@ -203,7 +200,7 @@ let default_interface =
203200
; ipv6_conf= None6
204201
; ipv6_gateway= None
205202
; ipv4_routes= []
206-
; dns= None
203+
; dns= ([], [])
207204
; mtu= 1500
208205
; ethtool_settings= []
209206
; ethtool_offload= [("lro", "off")]

ocaml/xapi/nm.ml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -634,25 +634,28 @@ let bring_pif_up ~__context ?(management_interface = false) (pif : API.ref_PIF)
634634
rc.API.pIF_ip_configuration_mode = `Static
635635
| `IPv6 ->
636636
rc.API.pIF_ipv6_configuration_mode = `Static
637-
|| rc.API.pIF_ipv6_configuration_mode = `Autoconf
638637
in
639638
let dns =
640639
match (static, rc.API.pIF_DNS) with
641640
| false, _ | true, "" ->
642-
None
641+
([], [])
643642
| true, pif_dns ->
644643
let nameservers =
645644
List.map Unix.inet_addr_of_string
646-
(String.split_on_char ',' pif_dns)
645+
(String.split ',' pif_dns)
647646
in
648647
let domains =
649648
match List.assoc_opt "domain" rc.API.pIF_other_config with
650-
| None | Some "" ->
649+
| None ->
651650
[]
652-
| Some domains ->
653-
String.split_on_char ',' domains
651+
| Some domains -> (
652+
try String.split ',' domains
653+
with _ ->
654+
warn "Invalid DNS search domains: %s" domains ;
655+
[]
656+
)
654657
in
655-
Some (nameservers, domains)
658+
(nameservers, domains)
656659
in
657660
let mtu = determine_mtu rc net_rc in
658661
let ethtool_settings, ethtool_offload =

0 commit comments

Comments
 (0)