From 22691e516898b0d54ad4100c9f04beb1e70f9dc0 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sun, 28 Jul 2024 14:49:42 +0100 Subject: [PATCH] v2v: --mac: Allow gw and len fields to be empty Even if these appear in the middle of the list, allow them to be empty. For example this is now permitted whereas previously it was an error: virt-v2v --mac :ip:,,,nameserver Reported-by: Arik Hadas (cherry picked from commit 159fda411d2f75b087106e7293d273ae142c9fbe) --- in-place/in_place.ml | 12 +++++++----- inspector/inspector.ml | 12 +++++++----- v2v/v2v.ml | 12 +++++++----- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/in-place/in_place.ml b/in-place/in_place.ml index 2049db16..a61d9795 100644 --- a/in-place/in_place.ml +++ b/in-place/in_place.ml @@ -90,10 +90,10 @@ let rec main () = | "ip" -> (match String.nsplit "," out with | [] -> error (f_"invalid --mac ip option") - | [ip] -> add_static_ip mac ip None None [] - | [ip; gw] -> add_static_ip mac ip (Some gw) None [] + | [ip] -> add_static_ip mac ip "" "" [] + | [ip; gw] -> add_static_ip mac ip gw "" [] | ip :: gw :: len :: nameservers -> - add_static_ip mac ip (Some gw) (Some len) nameservers + add_static_ip mac ip gw len nameservers ) | _ -> assert false and add_static_ip if_mac_addr if_ip_address if_default_gateway @@ -108,12 +108,14 @@ let rec main () = an IP address") what addr in error_unless_ip_addr "ipaddr" if_ip_address; + let if_default_gateway = + match if_default_gateway with "" -> None | gw -> Some gw in Option.iter (error_unless_ip_addr "gw") if_default_gateway; List.iter (error_unless_ip_addr "nameserver") if_nameservers; let if_prefix_length = match if_prefix_length_str with - | None -> None - | Some len -> + | "" -> None + | len -> let len = try int_of_string len with | Failure _ -> error (f_"cannot parse --mac ip prefix length \ diff --git a/inspector/inspector.ml b/inspector/inspector.ml index 02d1a0e7..417b31c5 100644 --- a/inspector/inspector.ml +++ b/inspector/inspector.ml @@ -97,10 +97,10 @@ let rec main () = | "ip" -> (match String.nsplit "," out with | [] -> error (f_"invalid --mac ip option") - | [ip] -> add_static_ip mac ip None None [] - | [ip; gw] -> add_static_ip mac ip (Some gw) None [] + | [ip] -> add_static_ip mac ip "" "" [] + | [ip; gw] -> add_static_ip mac ip gw "" [] | ip :: gw :: len :: nameservers -> - add_static_ip mac ip (Some gw) (Some len) nameservers + add_static_ip mac ip gw len nameservers ) | _ -> assert false and add_static_ip if_mac_addr if_ip_address if_default_gateway @@ -115,12 +115,14 @@ let rec main () = is an IP address") what addr in error_unless_ip_addr "ipaddr" if_ip_address; + let if_default_gateway = + match if_default_gateway with "" -> None | gw -> Some gw in Option.iter (error_unless_ip_addr "gw") if_default_gateway; List.iter (error_unless_ip_addr "nameserver") if_nameservers; let if_prefix_length = match if_prefix_length_str with - | None -> None - | Some len -> + | "" -> None + | len -> let len = try int_of_string len with | Failure _ -> error (f_"cannot parse --mac ip prefix \ diff --git a/v2v/v2v.ml b/v2v/v2v.ml index 89c08fc5..6d9e3792 100644 --- a/v2v/v2v.ml +++ b/v2v/v2v.ml @@ -109,10 +109,10 @@ let rec main () = | "ip" -> (match String.nsplit "," out with | [] -> error (f_"invalid --mac ip option") - | [ip] -> add_static_ip mac ip None None [] - | [ip; gw] -> add_static_ip mac ip (Some gw) None [] + | [ip] -> add_static_ip mac ip "" "" [] + | [ip; gw] -> add_static_ip mac ip gw "" [] | ip :: gw :: len :: nameservers -> - add_static_ip mac ip (Some gw) (Some len) nameservers + add_static_ip mac ip gw len nameservers ) | _ -> assert false and add_static_ip if_mac_addr if_ip_address if_default_gateway @@ -127,12 +127,14 @@ let rec main () = is an IP address") what addr in error_unless_ip_addr "ipaddr" if_ip_address; + let if_default_gateway = + match if_default_gateway with "" -> None | gw -> Some gw in Option.iter (error_unless_ip_addr "gw") if_default_gateway; List.iter (error_unless_ip_addr "nameserver") if_nameservers; let if_prefix_length = match if_prefix_length_str with - | None -> None - | Some len -> + | "" -> None + | len -> let len = try int_of_string len with | Failure _ -> error (f_"cannot parse --mac ip prefix length field \