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 a89b06e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ocaml/xapi/xapi_pif_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,11 @@ let get_primary_address ~__context ~pif =
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
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 a89b06e

Please sign in to comment.