Skip to content

Commit 944e700

Browse files
benjamreispsafont
andauthored
Update ocaml/xapi/xapi_pif_helpers.ml
Co-authored-by: Pau Ruiz Safont <psafont@users.noreply.github.com> Signed-off-by: BenjiReis <benjamin.reis@vates.tech>
1 parent 6cc2339 commit 944e700

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

ocaml/xapi/xapi_pif_helpers.ml

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -256,23 +256,16 @@ let is_device_underneath_same_type ~__context pif1 pif2 =
256256
get_device_info pif1 = get_device_info pif2
257257

258258
let get_non_link_ipv6 ~__context ~pif =
259-
let non_link_ip6s =
260-
List.map
261-
(fun ip6 ->
262-
match Ipaddr.V6.Prefix.of_string ip6 with
263-
| Error _ ->
264-
None
265-
| Ok ip6 ->
266-
let ip6 = Ipaddr.V6.Prefix.address ip6 in
267-
if Ipaddr.V6.scope ip6 = Ipaddr.Link then
268-
None
269-
else
270-
Some (Ipaddr.V6.to_string ip6)
271-
)
272-
(Db.PIF.get_IPv6 ~__context ~self:pif)
259+
let valid_nonlink ipv6 =
260+
let open Ipaddr.V6 in
261+
ipv6
262+
|> Prefix.of_string
263+
|> Result.to_option
264+
|> Fun.flip Option.bind @@ fun cidr ->
265+
let addr = Prefix.address cidr in
266+
match scope addr with Ipaddr.Link -> None | _ -> Some (to_string addr)
273267
in
274-
List.map (Option.fold ~none:"" ~some:Fun.id) non_link_ip6s
275-
|> List.filter (( <> ) "")
268+
List.filter_map valid_nonlink (Db.PIF.get_IPv6 ~__context ~self:pif)
276269

277270
let get_primary_address ~__context ~pif =
278271
match Db.PIF.get_primary_address_type ~__context ~self:pif with

0 commit comments

Comments
 (0)