Skip to content

Commit

Permalink
Fix 'PIF.get_primary_address' in IPv6
Browse files Browse the repository at this point in the history
IPv6 is stored as an array of '<ipv6>/<mask>'
So 'PIF.get_primary_address' should return only the 1st part

Signed-off-by: Benjamin Reis <[email protected]>
  • Loading branch information
benjamreis committed Feb 14, 2024
1 parent 75c28b3 commit 2bcdfb5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ocaml/xapi/xapi_pif_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,12 @@ let get_primary_address ~__context ~pif =
| `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
| `IPv6 -> (
match Db.PIF.get_IPv6 ~__context ~self:pif with
| [] | [""] ->
None
| ipv6 :: _ -> (
(* The CIDR is also stored in the IPv6 field of a PIF. *)
match String.split_on_char '/' ipv6 with hd :: _ -> Some hd | _ -> None
)
)

0 comments on commit 2bcdfb5

Please sign in to comment.