@ -10,7 +10,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 ( _ : config : config . type != " i n t e r n a l " ) i . interfaces ) ) ( attrValues cfg . vswitches )
++ concatMap ( i : [ i . interface ] ) ( attrValues cfg . macvlans )
++ concatMap ( i : [ i . interface ] ) ( attrValues cfg . vlans ) ;
@ -336,34 +336,47 @@ let
createVswitchDevice = n : v : nameValuePair " ${ n } - n e t d e v "
( let
deps = concatLists ( map deviceDependency v . interfaces ) ;
deps = concatLists ( map deviceDependency ( attrNames ( filterAttrs ( _ : config : config . type != " i n t e r n a l " ) v . interfaces ) ) ) ;
internalConfigs = concatMap ( i : [ " n e t w o r k - l i n k - ${ i } . s e r v i c e " " n e t w o r k - a d d r e s s e s - ${ i } . s e r v i c e " ] ) ( attrNames ( filterAttrs ( _ : config : config . type == " i n t e r n a l " ) v . interfaces ) ) ;
ofRules = pkgs . writeText " v s w i t c h - ${ n } - o p e n F l o w R u l e s " v . openFlowRules ;
in
{ description = " O p e n v S w i t c h I n t e r f a c e ${ n } " ;
wantedBy = [ " n e t w o r k - s e t u p . s e r v i c e " " v s w i t c h d . s e r v i c e " ] ++ deps ;
bindsTo = [ " v s w i t c h d . s e r v i c e " ( subsystemDevice n ) ] ++ deps ;
partOf = [ " n e t w o r k - s e t u p . s e r v i c e " " v s w i t c h d . s e r v i c e " ] ;
after = [ " n e t w o r k - p r e . t a r g e t " " v s w i t c h d . s e r v i c e " ] ++ deps ;
before = [ " n e t w o r k - s e t u p . s e r v i c e " ] ;
wantedBy = [ " n e t w o r k - s e t u p . s e r v i c e " ( subsystemDevice n ) ] ++ internalConfigs ;
# before = [ "network-setup.service" ];
# should work without internalConfigs dependencies because address/link configuration depends
# on the device, which is created by ovs-vswitchd with type=internal, but it does not...
before = [ " n e t w o r k - s e t u p . s e r v i c e " ] ++ internalConfigs ;
partOf = [ " n e t w o r k - s e t u p . s e r v i c e " ] ; # shutdown the bridge when network is shutdown
bindsTo = [ " o v s - v s w i t c h d . s e r v i c e " ] ; # requires ovs-vswitchd to be alive at all times
after = [ " n e t w o r k - p r e . t a r g e t " " o v s - v s w i t c h d . s e r v i c e " ] ++ deps ; # start switch after physical interfaces and vswitch daemon
wants = deps ; # if one or more interface fails, the switch should continue to run
serviceConfig . Type = " o n e s h o t " ;
serviceConfig . RemainAfterExit = true ;
path = [ pkgs . iproute config . virtualisation . vswitch . package ] ;
preStart = ''
echo " R e s e t t i n g O p e n v S w i t c h ${ n } . . . "
ovs-vsctl - - if-exists del-br $ { n } - - add-br $ { n } \
- - set bridge $ { n } protocols = $ { concatStringsSep " , " v . supportedOpenFlowVersions }
'' ;
script = ''
echo " R e m o v i n g o l d O p e n v S w i t c h ${ n } . . . "
ovs-vsctl - - if-exists del-br $ { n }
echo " A d d i n g O p e n v S w i t c h ${ n } . . . "
ovs-vsctl - - add-br $ { n } $ { concatMapStrings ( i : " - - a d d - p o r t ${ n } ${ i } " ) v . interfaces } \
echo " C o n f i g u r i n g O p e n v S w i t c h ${ n } . . . "
ovs-vsctl $ { concatStrings ( mapAttrsToList ( name : config : " - - a d d - p o r t ${ n } ${ name } " + optionalString ( config . vlan != null ) " t a g = ${ toString config . vlan } " ) v . interfaces ) } \
$ { concatStrings ( mapAttrsToList ( name : config : optionalString ( config . type != null ) " - - s e t i n t e r f a c e ${ name } t y p e = ${ config . type } " ) v . interfaces ) } \
$ { concatMapStrings ( x : " - - s e t - c o n t r o l l e r ${ n } " + x ) v . controllers } \
$ { concatMapStrings ( x : " - - " + x ) ( splitString " \n " v . extraOvsctlCmds ) }
echo " A d d i n g O p e n F l o w r u l e s f o r O p e n v S w i t c h ${ n } . . . "
ovs-ofctl add-flows $ { n } $ { ofRules }
ovs-ofctl - - protocols = $ { v . openFlowVersion } add-flows $ { n } $ { ofRules }
'' ;
postStop = ''
echo " C l e a n i n g O p e n v S w i t c h ${ n } "
echo " S h u t i n g d o w n i n t e r n a l ${ n } i n t e r f a c e "
ip link set $ { n } down || true
ovs-ofctl del-flows $ { n } || true
ovs-vsctl - - if-exists del-br $ { n }
echo " D e l e t i n g f l o w s f o r ${ n } "
ovs-ofctl - - protocols = $ { v . openFlowVersion } del-flows $ { n } || true
echo " D e l e t i n g O p e n v S w i t c h ${ n } "
ovs-vsctl - - if-exists del-br $ { n } || true
'' ;
} ) ;
@ -476,9 +489,9 @@ let
# Remove Dead Interfaces
ip link show " ${ n } " > /dev/null 2 > & 1 && ip link delete " ${ n } "
ip link add link " ${ v . interface } " name " ${ n } " type vlan id " ${ toString v . id } "
# We try to bring up the logical VLAN interface. If the master
# interface the logical interface is dependent upon is not up yet we will
# We try to bring up the logical VLAN interface. If the master
# interface the logical interface is dependent upon is not up yet we will
# fail to immediately bring up the logical interface. The resulting logical
# interface will brought up later when the master interface is up.
ip link set " ${ n } " up || true