Skip to content

Commit 529c7f1

Browse files
committed
CP-54444: Return MAC addresses to host installer
The host installer uses this utility to get the management interface from the management bridge. Now it changes to use MAC address(es) to find out the management interface(s). This is because the interface-rename functionality will be deprecated and the names of the network interfaces are not guaranteed to be the same between dom0 and host installer's running environment. Note that this change must be delivered to a host before upgrading to a new version in which the interface-rename is deprecated because the host installer is built from the new version and it will not be able to find the management network interface by name if the networkd_db command returns only names generated by interface-rename. Specifically, the "interface_order" field is only available when the networkd takes place of interface-rename to generate order. Before that, only the "bridge_mac" can be used because at that time, the host installer only uses one interface to setup its own networking during installation and no MAC addresses are recorded in networkd.db for individual interfaces. The "bridge_mac" is just the MAC address of one of the interfaces which construct the management bridge. Signed-off-by: Ming Lu <[email protected]>
1 parent d248e2f commit 529c7f1

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

ocaml/networkd/bin_db/networkd_db.ml

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,56 @@ let _ =
3232
try
3333
let config = Network_config.read_config () in
3434
if !bridge <> "" then
35-
if List.mem_assoc !bridge config.bridge_config then (
35+
if List.mem_assoc !bridge config.bridge_config then
3636
let bridge_config = List.assoc !bridge config.bridge_config in
3737
let ifaces =
3838
List.concat_map (fun (_, port) -> port.interfaces) bridge_config.ports
3939
in
40-
Printf.printf "interfaces=%s\n" (String.concat "," ifaces) ;
41-
match bridge_config.vlan with
42-
| None ->
43-
()
44-
| Some (parent, id) ->
45-
Printf.printf "vlan=%d\nparent=%s\n" id parent
46-
) else (
40+
let mac_of_iface ~order name =
41+
match List.find_opt (fun dev -> dev.name = name) order with
42+
| Some dev ->
43+
Ok (Macaddr.to_string dev.mac)
44+
| None ->
45+
Error (Printf.sprintf "Could not find MAC address of %s\n" name)
46+
in
47+
let macs =
48+
match config.interface_order with
49+
| Some order ->
50+
List.map (mac_of_iface ~order) ifaces
51+
|> List.fold_left
52+
(fun acc mac ->
53+
match (acc, mac) with
54+
| Ok acc, Ok mac ->
55+
Ok (mac :: acc)
56+
| Ok _, Error msg ->
57+
Error msg
58+
| Error msg, _ ->
59+
Error msg
60+
)
61+
(Ok [])
62+
| None ->
63+
if ifaces <> [] then
64+
(* Fallback to use the bridge MAC address when the interface_order
65+
is not available. This can work only because the host installer
66+
requires only one network interface to setup its own networking so far. *)
67+
Ok (Option.to_list bridge_config.bridge_mac)
68+
else (* No ifaces, no hwaddrs. *)
69+
Ok []
70+
in
71+
match macs with
72+
| Error msg ->
73+
rc := 1 ;
74+
Printf.fprintf stderr "%s\n" msg
75+
| Ok macs -> (
76+
Printf.printf "interfaces=%s\n" (String.concat "," ifaces) ;
77+
Printf.printf "hwaddrs=%s\n" (String.concat "," (List.rev macs)) ;
78+
match bridge_config.vlan with
79+
| None ->
80+
()
81+
| Some (parent, id) ->
82+
Printf.printf "vlan=%d\nparent=%s\n" id parent
83+
)
84+
else (
4785
rc := 1 ;
4886
Printf.fprintf stderr "Could not find bridge %s\n" !bridge
4987
) ;

0 commit comments

Comments
 (0)