Skip to content

Commit 3f588db

Browse files
committed
Filter our link IPv6 when migrating VMs
- New pif helper: `get_non_link_ipv6` to get the 1st non link IPv6 of a PIF - Use the helper in `migrate_receive` and `get_primary_address` used in host evacuation to have a valid IPv6 of the destination host Signed-off-by: Benjamin Reis <[email protected]>
1 parent 34dabdf commit 3f588db

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-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: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,29 @@ 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 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)
273+
in
274+
List.map (Option.fold ~none:"" ~some:Fun.id) non_link_ip6s
275+
|> List.filter (( <> ) "")
276+
258277
let get_primary_address ~__context ~pif =
259278
match Db.PIF.get_primary_address_type ~__context ~self:pif with
260279
| `IPv4 -> (
261280
match Db.PIF.get_IP ~__context ~self:pif with "" -> None | ip -> Some ip
262281
)
263282
| `IPv6 ->
264-
List.nth_opt (Db.PIF.get_IPv6 ~__context ~self:pif) 0
283+
List.nth_opt (get_non_link_ipv6 ~__context ~pif) 0

0 commit comments

Comments
 (0)