Skip to content

Commit c5ebbb8

Browse files
committed
CA-115557: networkd: implement enic workaround
When the enic workaround needs to be applied (according to the check implemented in the previous commit), then when asked to add an interface to a bridge, create a VLAN0 device for the given interface, and add that to the bridge instead. This applies to bonded interfaces as well as individual ones (we simply add the VLAN0 device on top of the bond device). Also, in Interface.make_config, we need to take care to configure both the base device as well as the VLAN0 device with the same parameters. Finally, when destroying a bridge with a VLAN0 bond, we need to destroy the bond device as well. Signed-off-by: Rob Hoes <[email protected]>
1 parent 7b85912 commit c5ebbb8

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

networkd/network_server.ml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,17 @@ module Interface = struct
364364
end else
365365
config
366366
in
367+
let config =
368+
if need_enic_workaround () then
369+
List.fold_left (fun accu (name, interface) ->
370+
if (Sysfs.is_physical name && Linux_bonding.get_bond_master_of name = None) || Linux_bonding.is_bond_device name then
371+
(name, interface) :: (Ip.vlan_name name 0, interface) :: accu
372+
else
373+
(name, interface) :: accu
374+
) [] config
375+
else
376+
config
377+
in
367378
debug "** Configuring the following interfaces: %s" (String.concat ", " (List.map (fun (name, _) -> name) config));
368379
let exec f = if conservative then (try f () with _ -> ()) else f () in
369380
List.iter (function (name, ({ipv4_conf; ipv4_gateway; ipv6_conf; ipv6_gateway; ipv4_routes; dns=nameservers,domains; mtu;
@@ -539,8 +550,14 @@ module Bridge = struct
539550
Interface.bring_down () dbg ~name:dev;
540551
if Linux_bonding.is_bond_device dev then
541552
Linux_bonding.remove_bond_master dev;
542-
if String.startswith "eth" dev && String.contains dev '.' then
543-
ignore (Ip.destroy_vlan dev)
553+
if (String.startswith "eth" dev || String.startswith "bond" dev) && String.contains dev '.' then begin
554+
ignore (Ip.destroy_vlan dev);
555+
let n = String.length dev in
556+
if String.sub dev (n - 2) 2 = ".0" && need_enic_workaround () then
557+
let vlan_base = String.sub dev 0 (n - 2) in
558+
if Linux_bonding.is_bond_device vlan_base then
559+
Linux_bonding.remove_bond_master (String.sub dev 0 (n - 2))
560+
end;
544561
) ifs;
545562
Interface.set_ipv4_conf () dbg ~name ~conf:None4;
546563
ignore (Brctl.destroy_bridge name)
@@ -643,10 +660,9 @@ module Bridge = struct
643660
name bridge
644661
end
645662
| Bridge ->
646-
if List.length interfaces = 1 then begin
647-
List.iter (fun name -> Interface.bring_up () dbg ~name) interfaces;
648-
ignore (Brctl.create_port bridge name)
649-
end else begin
663+
if List.length interfaces = 1 then
664+
List.iter (fun name -> Interface.bring_up () dbg ~name) interfaces
665+
else begin
650666
if not (List.mem name (Sysfs.bridge_to_interfaces bridge)) then begin
651667
Linux_bonding.add_bond_master name;
652668
let bond_properties =
@@ -662,9 +678,16 @@ module Bridge = struct
662678
| None -> warn "No MAC address specified for the bond"
663679
end
664680
end;
665-
Interface.bring_up () dbg ~name;
681+
Interface.bring_up () dbg ~name
682+
end;
683+
if need_enic_workaround () then begin
684+
debug "Applying enic workaround: adding VLAN0 device to bridge";
685+
Ip.create_vlan name 0;
686+
let vlan0 = Ip.vlan_name name 0 in
687+
Interface.bring_up () dbg ~name:vlan0;
688+
ignore (Brctl.create_port bridge vlan0)
689+
end else
666690
ignore (Brctl.create_port bridge name)
667-
end
668691
) ()
669692

670693
let remove_port _ dbg ~bridge ~name =

0 commit comments

Comments
 (0)