openvswitch: better integration with systemd
Systemd dependencies for scripted mode were refactored according to analysis in #34586. networking.vswitches can now be used with systemd-networkd, although they are not supported by the daemon, a nixos receipe creates the switch and attached required interfaces (just like the scripted version). Vlans and internal interfaces are implemented following the template format i.e. each interface is described using an attributeSet (vlan and type at the moment). If vlan is present, then interface is added to the vswitch with given tag (access mode). Type internal enabled vswitch to create interfaces (see openvswitch docs). Added configuration for configuring supported openFlow version on the vswitch This commit is a split from the original PR #35127.
This commit is contained in:
@@ -13,7 +13,7 @@ let
|
||||
|
||||
slaves = concatMap (i: i.interfaces) (attrValues cfg.bonds)
|
||||
++ concatMap (i: i.interfaces) (attrValues cfg.bridges)
|
||||
++ concatMap (i: i.interfaces) (attrValues cfg.vswitches);
|
||||
++ concatMap (i: attrNames (filterAttrs (name: config: ! (config.type == "internal" || hasAttr name cfg.interfaces)) i.interfaces)) (attrValues cfg.vswitches);
|
||||
|
||||
slaveIfs = map (i: cfg.interfaces.${i}) (filter (i: cfg.interfaces ? ${i}) slaves);
|
||||
|
||||
@@ -310,6 +310,32 @@ let
|
||||
|
||||
};
|
||||
|
||||
vswitchInterfaceOpts = {name, ...}: {
|
||||
|
||||
options = {
|
||||
|
||||
name = mkOption {
|
||||
description = "Name of the interface";
|
||||
example = "eth0";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
vlan = mkOption {
|
||||
description = "Vlan tag to apply to interface";
|
||||
example = 10;
|
||||
type = types.nullOr types.int;
|
||||
default = null;
|
||||
};
|
||||
|
||||
type = mkOption {
|
||||
description = "Openvswitch type to assign to interface";
|
||||
example = "internal";
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
hexChars = stringToCharacters "0123456789abcdef";
|
||||
|
||||
isHexString = s: all (c: elem c hexChars) (stringToCharacters (toLower s));
|
||||
@@ -460,8 +486,8 @@ in
|
||||
networking.vswitches = mkOption {
|
||||
default = { };
|
||||
example =
|
||||
{ vs0.interfaces = [ "eth0" "eth1" ];
|
||||
vs1.interfaces = [ "eth2" "wlan0" ];
|
||||
{ vs0.interfaces = { eth0 = { }; lo1 = { type="internal"; }; };
|
||||
vs1.interfaces = [ { name = "eth2"; } { name = "lo2"; type="internal"; } ];
|
||||
};
|
||||
description =
|
||||
''
|
||||
@@ -478,9 +504,8 @@ in
|
||||
|
||||
interfaces = mkOption {
|
||||
example = [ "eth0" "eth1" ];
|
||||
type = types.listOf types.str;
|
||||
description =
|
||||
"The physical network interfaces connected by the vSwitch.";
|
||||
description = "The physical network interfaces connected by the vSwitch.";
|
||||
type = with types; loaOf (submodule vswitchInterfaceOpts);
|
||||
};
|
||||
|
||||
controllers = mkOption {
|
||||
@@ -504,6 +529,25 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
# TODO: custom "openflow version" type, with list from existing openflow protocols
|
||||
supportedOpenFlowVersions = mkOption {
|
||||
type = types.listOf types.str;
|
||||
example = [ "OpenFlow10" "OpenFlow13" "OpenFlow14" ];
|
||||
default = [ "OpenFlow13" ];
|
||||
description = ''
|
||||
Supported versions to enable on this switch.
|
||||
'';
|
||||
};
|
||||
|
||||
# TODO: use same type as elements from supportedOpenFlowVersions
|
||||
openFlowVersion = mkOption {
|
||||
type = types.str;
|
||||
default = "OpenFlow13";
|
||||
description = ''
|
||||
Version of OpenFlow protocol to use when communicating with the switch internally (e.g. with <literal>openFlowRules</literal>).
|
||||
'';
|
||||
};
|
||||
|
||||
extraOvsctlCmds = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
|
||||
Reference in New Issue
Block a user