Skip to content

Commit

Permalink
Merge pull request #5463 from xcp-ng/filter-out-local-ipv6
Browse files Browse the repository at this point in the history
  • Loading branch information
psafont authored Mar 4, 2024
2 parents acf72f2 + c31eb14 commit 4a2c1bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 3 additions & 6 deletions ocaml/xapi/xapi_host.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion ocaml/xapi/xapi_pif_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4a2c1bf

Please sign in to comment.