get back add_client with local clients map

This commit is contained in:
Pierre Alain 2024-12-22 19:15:36 +01:00
parent a5d61cb034
commit d8a20eadc8

View file

@ -17,8 +17,6 @@ struct
module I = Static_ipv4.Make (R) (Clock) (UplinkEth) (Arp) module I = Static_ipv4.Make (R) (Clock) (UplinkEth) (Arp)
module U = Udp.Make (I) (R) module U = Udp.Make (I) (R)
let clients : Cleanup.t Dao.VifMap.t ref = ref Dao.VifMap.empty
class client_iface eth ~domid ~gateway_ip ~client_ip client_mac : client_link class client_iface eth ~domid ~gateway_ip ~client_ip client_mac : client_link
= =
let log_header = Fmt.str "dom%d:%a" domid Ipaddr.V4.pp client_ip in let log_header = Fmt.str "dom%d:%a" domid Ipaddr.V4.pp client_ip in
@ -411,7 +409,6 @@ struct
(** A new client VM has been found in XenStore. Find its interface and connect to it. *) (** A new client VM has been found in XenStore. Find its interface and connect to it. *)
let add_client get_ts dns_client dns_servers ~router vif client_ip qubesDB = let add_client get_ts dns_client dns_servers ~router vif client_ip qubesDB =
let open Lwt.Syntax in
let cleanup_tasks = Cleanup.create () in let cleanup_tasks = Cleanup.create () in
Log.info (fun f -> Log.info (fun f ->
f "add client vif %a with IP %a" Dao.ClientVif.pp vif Ipaddr.V4.pp f "add client vif %a with IP %a" Dao.ClientVif.pp vif Ipaddr.V4.pp
@ -430,25 +427,28 @@ struct
(** Watch XenStore for notifications of new clients. *) (** Watch XenStore for notifications of new clients. *)
let wait_clients get_ts dns_client dns_servers qubesDB router = let wait_clients get_ts dns_client dns_servers qubesDB router =
Dao.watch_clients (fun new_set -> let clients : Cleanup.t Dao.VifMap.t ref = ref Dao.VifMap.empty in
(* Check for removed clients *) Dao.watch_clients @@ fun new_set ->
!clients (* Check for removed clients *)
|> Dao.VifMap.iter (fun key cleanup -> let clean_up_clients key cleanup =
if not (Dao.VifMap.mem key new_set) then ( if not (Dao.VifMap.mem key new_set) then begin
clients := !clients |> Dao.VifMap.remove key; clients := !clients |> Dao.VifMap.remove key;
Log.info (fun f -> f "client %a has gone" Dao.ClientVif.pp key); Log.info (fun f -> f "client %a has gone" Dao.ClientVif.pp key);
Cleanup.cleanup cleanup)); Cleanup.cleanup cleanup
(* Check for added clients *) end
new_set in
|> Dao.VifMap.iter (fun key ip_addr -> Dao.VifMap.iter clean_up_clients !clients;
if not (Dao.VifMap.mem key !clients) then ( (* Check for added clients *)
let cleanup = let rec go seq = match Seq.uncons seq with
add_client get_ts dns_client dns_servers ~router key ip_addr | None -> Lwt.return_unit
qubesDB | Some ((key, ipaddr), seq) when not (Dao.VifMap.mem key !clients) ->
in let cleanup = add_client get_ts dns_client dns_servers ~router key ipaddr qubesDB in
Log.debug (fun f -> f "client %a arrived" Dao.ClientVif.pp key); Log.debug (fun f -> f "client %a arrived" Dao.ClientVif.pp key);
clients := !clients |> Dao.VifMap.add key cleanup)); clients := Dao.VifMap.add key cleanup !clients;
Lwt.return_unit) go seq
| Some (_, seq) -> go seq
in
go (Dao.VifMap.to_seq new_set)
let send_dns_client_query t ~src_port ~dst ~dst_port buf = let send_dns_client_query t ~src_port ~dst ~dst_port buf =
match t.uplink with match t.uplink with