From 944e7004daec418005f650791deaa24352b211b9 Mon Sep 17 00:00:00 2001 From: BenjiReis Date: Wed, 21 Feb 2024 17:00:37 +0100 Subject: [PATCH] Update ocaml/xapi/xapi_pif_helpers.ml Co-authored-by: Pau Ruiz Safont Signed-off-by: BenjiReis --- ocaml/xapi/xapi_pif_helpers.ml | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/ocaml/xapi/xapi_pif_helpers.ml b/ocaml/xapi/xapi_pif_helpers.ml index 912c641f399..ae29c3c366e 100644 --- a/ocaml/xapi/xapi_pif_helpers.ml +++ b/ocaml/xapi/xapi_pif_helpers.ml @@ -256,23 +256,16 @@ let is_device_underneath_same_type ~__context pif1 pif2 = get_device_info pif1 = get_device_info pif2 let get_non_link_ipv6 ~__context ~pif = - let non_link_ip6s = - List.map - (fun ip6 -> - match Ipaddr.V6.Prefix.of_string ip6 with - | Error _ -> - None - | Ok ip6 -> - let ip6 = Ipaddr.V6.Prefix.address ip6 in - if Ipaddr.V6.scope ip6 = Ipaddr.Link then - None - else - Some (Ipaddr.V6.to_string ip6) - ) - (Db.PIF.get_IPv6 ~__context ~self: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.map (Option.fold ~none:"" ~some:Fun.id) non_link_ip6s - |> List.filter (( <> ) "") + 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