diff --git a/ocaml/xapi/xapi_host.ml b/ocaml/xapi/xapi_host.ml index 875b3be5cf2..768f33aba7b 100644 --- a/ocaml/xapi/xapi_host.ml +++ b/ocaml/xapi/xapi_host.ml @@ -20,6 +20,7 @@ let with_lock = Xapi_stdext_threads.Threadext.Mutex.execute module Unixext = Xapi_stdext_unix.Unixext open Xapi_host_helpers +open Xapi_pif_helpers open Db_filter_types open Workload_balancing @@ -2555,14 +2556,10 @@ let migrate_receive ~__context ~host ~network ~options:_ = let configuration_mode = Db.PIF.get_ipv6_configuration_mode ~__context ~self:pif in - match Db.PIF.get_IPv6 ~__context ~self:pif with + match Xapi_pif_helpers.get_non_link_ipv6 ~__context ~pif with | [] -> ("", configuration_mode) - | ip :: _ -> - (* The CIDR is also stored in the IPv6 field of a PIF. *) - let ipv6 = - match String.split_on_char '/' ip with hd :: _ -> hd | _ -> "" - in + | ipv6 :: _ -> (ipv6, configuration_mode) ) in diff --git a/ocaml/xapi/xapi_pif_helpers.ml b/ocaml/xapi/xapi_pif_helpers.ml index fc6c9708511..ae29c3c366e 100644 --- a/ocaml/xapi/xapi_pif_helpers.ml +++ b/ocaml/xapi/xapi_pif_helpers.ml @@ -255,10 +255,22 @@ let is_device_underneath_same_type ~__context pif1 pif2 = in get_device_info pif1 = get_device_info pif2 +let get_non_link_ipv6 ~__context ~pif = + let valid_nonlink ipv6 = + let open Ipaddr.V6 in + ipv6 + |> Prefix.of_string + |> Result.to_option + |> Fun.flip Option.bind @@ fun cidr -> + let addr = Prefix.address cidr in + match scope addr with Ipaddr.Link -> None | _ -> Some (to_string addr) + in + List.filter_map valid_nonlink (Db.PIF.get_IPv6 ~__context ~self:pif) + let get_primary_address ~__context ~pif = match Db.PIF.get_primary_address_type ~__context ~self:pif with | `IPv4 -> ( match Db.PIF.get_IP ~__context ~self:pif with "" -> None | ip -> Some ip ) | `IPv6 -> - List.nth_opt (Db.PIF.get_IPv6 ~__context ~self:pif) 0 + List.nth_opt (get_non_link_ipv6 ~__context ~pif) 0