Skip to content

Commit 4a2c1bf

Browse files
authored
Merge pull request #5463 from xcp-ng/filter-out-local-ipv6
2 parents acf72f2 + c31eb14 commit 4a2c1bf

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

ocaml/xapi/xapi_host.ml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ let with_lock = Xapi_stdext_threads.Threadext.Mutex.execute
2020

2121
module Unixext = Xapi_stdext_unix.Unixext
2222
open Xapi_host_helpers
23+
open Xapi_pif_helpers
2324
open Db_filter_types
2425
open Workload_balancing
2526

@@ -2555,14 +2556,10 @@ let migrate_receive ~__context ~host ~network ~options:_ =
25552556
let configuration_mode =
25562557
Db.PIF.get_ipv6_configuration_mode ~__context ~self:pif
25572558
in
2558-
match Db.PIF.get_IPv6 ~__context ~self:pif with
2559+
match Xapi_pif_helpers.get_non_link_ipv6 ~__context ~pif with
25592560
| [] ->
25602561
("", configuration_mode)
2561-
| ip :: _ ->
2562-
(* The CIDR is also stored in the IPv6 field of a PIF. *)
2563-
let ipv6 =
2564-
match String.split_on_char '/' ip with hd :: _ -> hd | _ -> ""
2565-
in
2562+
| ipv6 :: _ ->
25662563
(ipv6, configuration_mode)
25672564
)
25682565
in

ocaml/xapi/xapi_pif_helpers.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,22 @@ let is_device_underneath_same_type ~__context pif1 pif2 =
255255
in
256256
get_device_info pif1 = get_device_info pif2
257257

258+
let get_non_link_ipv6 ~__context ~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)
267+
in
268+
List.filter_map valid_nonlink (Db.PIF.get_IPv6 ~__context ~self:pif)
269+
258270
let get_primary_address ~__context ~pif =
259271
match Db.PIF.get_primary_address_type ~__context ~self:pif with
260272
| `IPv4 -> (
261273
match Db.PIF.get_IP ~__context ~self:pif with "" -> None | ip -> Some ip
262274
)
263275
| `IPv6 ->
264-
List.nth_opt (Db.PIF.get_IPv6 ~__context ~self:pif) 0
276+
List.nth_opt (get_non_link_ipv6 ~__context ~pif) 0

0 commit comments

Comments
 (0)