Skip to content

Commit babf619

Browse files
authored
CP-53719: Update monitor and collecting list for host network devices (#6480)
With interface-rename functionality, the host network devices are ordered and renamed like "eth<N>". So they can be filtered by hard-coded "eth" and added into the networkd monitor list and rrdd collecting list. While the interface-rename is being replaced by the ordering function in networkd. Unlike the interface-rename, the networkd will not rename the host network devices anymore. Instead, the naming of them are left to the built-in systemd and Kernel. In both cases, the networkd's Interface.get_interface_position can return the managed (ordered) host network devices: when the interface-rename functionality is still working, it returns the list of "eth<N>"; when networkd takes the place to perform the ordering, it returns the names generated by systemd and Kernel.
2 parents a34b3d4 + 1f4cc9a commit babf619

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

ocaml/networkd/bin/network_monitor_thread.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ let bonds_status : (string, int * int) Hashtbl.t = Hashtbl.create 10
2626

2727
let monitor_whitelist =
2828
ref
29-
[
30-
"eth"
31-
; "vif" (* This includes "tap" owing to the use of standardise_name below *)
32-
]
29+
["vif" (* This includes "tap" owing to the use of standardise_name below *)]
3330

3431
let rpc xml =
3532
let open Xmlrpc_client in
@@ -108,7 +105,10 @@ let standardise_name name =
108105
newname
109106
with _ -> name
110107

111-
let get_link_stats () =
108+
let get_link_stats dbg () =
109+
let managed_host_net_devs =
110+
Network_server.Interface.get_interface_positions dbg () |> List.map fst
111+
in
112112
let open Netlink in
113113
let s = Socket.alloc () in
114114
Socket.connect s Socket.NETLINK_ROUTE ;
@@ -119,9 +119,10 @@ let get_link_stats () =
119119
List.exists
120120
(fun s -> Astring.String.is_prefix ~affix:s name)
121121
!monitor_whitelist
122+
|| List.mem name managed_host_net_devs
122123
in
123124
let is_vlan name =
124-
Astring.String.is_prefix ~affix:"eth" name && String.contains name '.'
125+
List.mem name managed_host_net_devs && String.contains name '.'
125126
in
126127
List.map (fun link -> standardise_name (Link.get_name link)) links
127128
|> (* Only keep interfaces with prefixes on the whitelist, and exclude VLAN
@@ -226,7 +227,7 @@ let rec monitor dbg () =
226227
Network_server.Bridge.get_all_bonds dbg from_cache
227228
in
228229
let add_bonds bonds devs = List.map fst bonds @ devs in
229-
let devs = get_link_stats () |> add_bonds bonds |> get_stats bonds in
230+
let devs = get_link_stats dbg () |> add_bonds bonds |> get_stats bonds in
230231
( if List.length bonds <> Hashtbl.length bonds_status then
231232
let dead_bonds =
232233
Hashtbl.fold

ocaml/xcp-rrdd/bin/rrdp-netdev/rrdp_netdev.ml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,18 @@ let default_stats =
4242

4343
let monitor_whitelist =
4444
ref
45-
[
46-
"eth"
47-
; "vif" (* This includes "tap" owing to the use of standardise_name below *)
48-
]
45+
["vif" (* This includes "tap" owing to the use of standardise_name below *)]
4946

5047
(** Transform names of the form 'tapX.X' to 'vifX.X' so these can be handled
5148
consistently later *)
5249
let standardise_name name =
5350
try Scanf.sscanf name "tap%d.%d" @@ Printf.sprintf "vif%d.%d" with _ -> name
5451

55-
let get_link_stats () =
52+
let get_link_stats dbg () =
53+
let managed_host_net_devs =
54+
Network_client.Client.Interface.get_interface_positions dbg ()
55+
|> List.map fst
56+
in
5657
let open Netlink in
5758
let s = Socket.alloc () in
5859
Socket.connect s Socket.NETLINK_ROUTE ;
@@ -63,9 +64,10 @@ let get_link_stats () =
6364
List.exists
6465
(fun s -> Astring.String.is_prefix ~affix:s name)
6566
!monitor_whitelist
67+
|| List.mem name managed_host_net_devs
6668
in
6769
let is_vlan name =
68-
Astring.String.is_prefix ~affix:"eth" name && String.contains name '.'
70+
List.mem name managed_host_net_devs && String.contains name '.'
6971
in
7072
List.map (fun link -> (standardise_name (Link.get_name link), link)) links
7173
|> (* Only keep interfaces with prefixes on the whitelist, and exclude VLAN
@@ -160,7 +162,7 @@ let generate_netdev_dss () =
160162
Network_client.Client.Bridge.get_all_bonds dbg from_cache
161163
in
162164

163-
let stats = get_link_stats () |> add_bonds bonds |> transform_taps in
165+
let stats = get_link_stats dbg () |> add_bonds bonds |> transform_taps in
164166
let dss, sum_rx, sum_tx =
165167
List.fold_left
166168
(fun (dss, sum_rx, sum_tx) (dev, stat) ->

0 commit comments

Comments
 (0)