Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions ocaml/networkd/lib/lldp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -598,17 +598,30 @@ module Make (Agent : AGENT) = struct

let ifaces = ref Iface_set.empty

let push () = Agent.set_scope (Iface_set.elements !ifaces)

let add dev =
let add dev ~system_name ~configure =
with_lock @@ fun () ->
let* () = Agent.start ~system_name in
let* () = configure () in
ifaces := Iface_set.add dev !ifaces ;
push ()
let* () = Agent.set_scope (Iface_set.elements !ifaces) in
Agent.enable dev

let remove dev =
with_lock @@ fun () ->
ifaces := Iface_set.remove dev !ifaces ;
push ()
let rest = Iface_set.remove dev !ifaces in
match (Iface_set.is_empty rest, Iface_set.mem dev !ifaces) with
| true, true ->
ifaces := rest ;
Agent.stop ()
| false, true ->
ifaces := rest ;
let* () = Agent.disable dev in
Agent.set_scope (Iface_set.elements !ifaces)
| _, false ->
(* Interface is not in the LLDP scope, nothing to disable. *)
Ok ()

let is_empty () = with_lock @@ fun () -> Iface_set.is_empty !ifaces
end

let set_conf dev (config : I.lldp option) : unit =
Expand All @@ -630,21 +643,16 @@ module Make (Agent : AGENT) = struct
match (blocked, lldp.enabled) with
| true, _ ->
debug "%s: Driver of %s is in blocklist." __FUNCTION__ dev ;
let* () = Agent.disable dev in
Scope.remove dev
| false, true ->
Network_utils.Ethtool.try_to_disable_firmware_lldp dev ;
let* () = Agent.start ~system_name:lldp.system_name in
let* () =
Agent.advertising_confs dev lldp
|> List.map Agent.set_advertising_conf
|> List.find_opt Result.is_error
|> Option.fold ~none:(Ok ()) ~some:Fun.id
in
let* () = Scope.add dev in
Agent.enable dev
Scope.add dev ~system_name:lldp.system_name ~configure:(fun () ->
Agent.advertising_confs dev lldp
|> List.map Agent.set_advertising_conf
|> List.find_opt Result.is_error
|> Option.fold ~none:(Ok ()) ~some:Fun.id
)
| false, false ->
let* () = Agent.disable dev in
Scope.remove dev
)
in
Expand All @@ -664,7 +672,10 @@ module Make (Agent : AGENT) = struct
let set_tlv_management_address addrs =
Agent.set_advertising_conf (Management_address addrs)
|> Result.iter_error (fun e ->
warn "%s: %s" __FUNCTION__ (Lldp_types.string_of_error e)
if not (Scope.is_empty ()) then
warn "%s: %s" __FUNCTION__ (Lldp_types.string_of_error e)
else
()
)
end

Expand Down
Loading