Skip to content

Commit 9f2af52

Browse files
authored
Merge pull request #88 from sharady/CA-219257
CA-219257: Make enic driver workaround configurable.
2 parents 9d76ea2 + 9d5309e commit 9f2af52

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

lib/network_utils.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ module Sysfs = struct
7474
warn "Failed to obtain list of drivers from sysfs";
7575
[]
7676

77+
let get_driver_version driver () =
78+
try
79+
Some (String.strip String.isspace (Unixext.string_of_file ("/sys/bus/pci/drivers/" ^ driver ^ "/module/version")))
80+
with _ ->
81+
warn "Failed to obtain driver version from sysfs";
82+
None
83+
7784
let getpath dev attr =
7885
Printf.sprintf "/sys/class/net/%s/%s" dev attr
7986

networkd/network_server.ml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type context = unit
2727
let network_conf = ref "/etc/xcp/network.conf"
2828
let config : config_t ref = ref empty_config
2929
let backend_kind = ref Openvswitch
30+
let enic_workaround_until_version = ref "2.3.0.30"
3031

3132
let legacy_management_interface_start () =
3233
try
@@ -85,12 +86,30 @@ let set_dns_interface _ dbg ~name =
8586
debug "Setting DNS interface to %s" name;
8687
config := {!config with dns_interface = Some name}
8788

89+
(* Returns `true` if vs1 is older than vs2 *)
90+
let is_older_version vs1 vs2 () =
91+
try
92+
let list_of_version vs = List.map int_of_string (String.split '.' vs) in
93+
let rec loop vs1' vs2' =
94+
match vs1', vs2' with
95+
| [], _ | _, [] -> false
96+
| a :: _, b :: _ when a < b -> true
97+
| _ :: tl1, _ :: tl2 -> loop tl1 tl2
98+
in
99+
loop (list_of_version vs1) (list_of_version vs2)
100+
with _ ->
101+
warn "Failed to compare driver version.";
102+
false
103+
88104
(* The enic driver is for Cisco UCS devices. The current driver adds VLAN0 headers
89105
* to all incoming packets, which confuses certain guests OSes. The workaround
90106
* constitutes adding a VLAN0 Linux device to strip those headers again.
91107
*)
92108
let need_enic_workaround () =
93-
!backend_kind = Bridge && List.mem "enic" (Sysfs.list_drivers ())
109+
!backend_kind = Bridge && List.mem "enic" (Sysfs.list_drivers ()) && (!enic_workaround_until_version <> "") && (
110+
match Sysfs.get_driver_version "enic" () with
111+
| Some vs -> (is_older_version vs !enic_workaround_until_version ())
112+
| None -> false )
94113

95114
module Interface = struct
96115
let get_config name =

networkd/networkd.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ let resources = [
5353
let options = [
5454
"monitor_blacklist", Arg.String (fun x -> Network_monitor_thread.monitor_blacklist := String.split ',' x), (fun () -> String.concat "," !Network_monitor_thread.monitor_blacklist), "List of prefixes of interface names that are not to be monitored";
5555
"mac-table-size", Arg.Set_int Network_utils.mac_table_size, (fun () -> string_of_int !Network_utils.mac_table_size), "Default value for the mac-table-size openvswitch parameter (see ovs-vswitchd.conf.db.5)";
56+
"enic-workaround-until-version", Arg.Set_string Network_server.enic_workaround_until_version, (fun () -> !Network_server.enic_workaround_until_version), "The version till enic driver workaround will be applied or the version set to an empty string for not applying the workaround.";
5657
]
5758

58-
5959
let start server =
6060
Network_monitor_thread.start ();
6161
Network_server.on_startup ();

xcp-networkd.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818

1919
#The list of prefix interfaces that are not to be monitored
2020
#monitor-blacklist=dummy,xenbr,xapi,ovs-system,xenapi
21+
22+
# The version till enic driver workaround will be applied or set the version to an empty string for not applying the workaround.
23+
# enic-workaround-until-version = "2.3.0.30"

0 commit comments

Comments
 (0)