@@ -31,60 +31,59 @@ let _ =
31
31
(Printf. sprintf " Usage: %s [-bridge <bridge> | -iface <interface>]" name) ;
32
32
try
33
33
let config = Network_config. read_config () in
34
- if ! bridge <> " " then
35
- if List. mem_assoc ! bridge config.bridge_config then
36
- let bridge_config = List. assoc ! bridge config.bridge_config in
37
- let ifaces =
38
- List. concat_map (fun (_ , port ) -> port.interfaces) bridge_config.ports
39
- in
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\n parent=%s\n " id parent
34
+ ( if ! bridge <> " " then
35
+ match List. assoc_opt ! bridge config.bridge_config with
36
+ | Some bridge_config -> (
37
+ let ifaces =
38
+ List. concat_map
39
+ (fun (_ , port ) -> port.interfaces)
40
+ bridge_config.ports
41
+ in
42
+ let macs =
43
+ let to_mac ~order name =
44
+ match List. find_opt (fun dev -> dev.name = name) order with
45
+ | Some dev ->
46
+ Either. Left (Macaddr. to_string dev.mac)
47
+ | None ->
48
+ Either. Right name
49
+ in
50
+ match (config.interface_order, ifaces) with
51
+ | Some order , ifaces ->
52
+ let oks, errs = List. partition_map (to_mac ~order ) ifaces in
53
+ if errs = [] then
54
+ Ok oks
55
+ else
56
+ Error
57
+ (Printf. sprintf " Could not find MAC address(es) for %s"
58
+ (String. concat " , " errs)
59
+ )
60
+ | None , [] ->
61
+ (* No ifaces, no hwaddrs. *)
62
+ Ok []
63
+ | None , _ :: _ ->
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
+ in
69
+ match macs with
70
+ | Error msg ->
71
+ rc := 1 ;
72
+ Printf. fprintf stderr " %s\n " msg
73
+ | Ok macs -> (
74
+ Printf. printf " interfaces=%s\n " (String. concat " ," ifaces) ;
75
+ Printf. printf " hwaddrs=%s\n " (String. concat " ," macs) ;
76
+ match bridge_config.vlan with
77
+ | None ->
78
+ ()
79
+ | Some (parent , id ) ->
80
+ Printf. printf " vlan=%d\n parent=%s\n " id parent
81
+ )
83
82
)
84
- else (
85
- rc := 1 ;
86
- Printf. fprintf stderr " Could not find bridge %s\n " ! bridge
87
- ) ;
83
+ | None ->
84
+ rc := 1 ;
85
+ Printf. fprintf stderr " Could not find bridge %s\n " ! bridge
86
+ ) ;
88
87
if ! iface <> " " then
89
88
if List. mem_assoc ! iface config.interface_config then
90
89
let interface_config = List. assoc ! iface config.interface_config in
0 commit comments