From be2534386ac3c37fbdbeae17f684df7a832d5942 Mon Sep 17 00:00:00 2001 From: catvayor <catvayor@katvayor.net> Date: Fri, 5 Apr 2024 19:40:35 +0200 Subject: [PATCH] making it work strange behaviors to explore, and deployement shell script todo --- configMaker.nix | 2 +- moduleMaker.nix | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/configMaker.nix b/configMaker.nix index db938c3..ded07fe 100644 --- a/configMaker.nix +++ b/configMaker.nix @@ -35,7 +35,7 @@ let module_inst = { vlans = { "users".ids = [ { begin = 3045; end = 4094; } ]; "admin" = { - ids = [ 3000 ]; + ids = 3000; management = "10.0.0.2/22"; }; "uplink-cri".ids = [ 223 ]; diff --git a/moduleMaker.nix b/moduleMaker.nix index 643e39a..bc9f59e 100644 --- a/moduleMaker.nix +++ b/moduleMaker.nix @@ -10,7 +10,9 @@ in with lib; { }; vlan_type.options = { ids = mkOption { - type = types.listOf (types.either types.ints.unsigned (types.submodule range_type)); + type = types.either + types.ints.unsigned + (types.listOf (types.either types.ints.unsigned (types.submodule range_type))); default = [ ]; }; management = mkOption { @@ -65,7 +67,7 @@ in with lib; { mgmt_fam = if !builtins.isNull cfg.interfaces.${name}.management then '' <inet> <address> - ${cfg.interfaces.${name}.management} + <name>${cfg.interfaces.${name}.management}</name> </address> </inet>'' else ""; members = map (vlan: "<members>${builtins.toString vlan}</members>") cfg.interfaces.${name}.vlans; @@ -73,6 +75,7 @@ in with lib; { <ethernet-switching> <interface-mode>${cfg.interfaces.${name}.interface-mode}</interface-mode> <vlan>${builtins.concatStringsSep "" members}</vlan> + <storm-control><profile-name>default</profile-name></storm-control> </ethernet-switching>''; in '' <interface> @@ -85,8 +88,14 @@ in with lib; { ${eth_switch} </family> </unit> - </interface>''; + </interface> + ''; interface_xmls = map intf_xmlGen interfaces; + rstp_gen = name: + if cfg.interfaces.${name}.enable && !builtins.isNull cfg.interfaces.${name}.interface-mode then + "<interface><name>${name}</name></interface>" + else ""; + rstps = map rstp_gen interfaces; vlan_trust_table = let vlan_map = inter: vlan: if builtins.isString vlan && cfg.interfaces.${inter}.enable then @@ -109,7 +118,9 @@ in with lib; { "${builtins.toString id.begin}-${builtins.toString id.end}"; in ''<vlan-id-list>${list}</vlan-id-list>''; vlan_map = vlan: let - ids = map id_map cfg.vlans.${vlan}.ids; + ids = if !builtins.isList cfg.vlans.${vlan}.ids then + [ "<vlan-id>${builtins.toString cfg.vlans.${vlan}.ids}</vlan-id>" ] + else map id_map cfg.vlans.${vlan}.ids; mgmt_flag = if !builtins.isNull cfg.vlans.${vlan}.management then "<l3-interface>irb.0</l3-interface>" else ""; in '' @@ -137,11 +148,16 @@ in with lib; { '' else ""; in [ '' - <interfaces> + <interfaces operation="replace"> ${builtins.concatStringsSep "\n" interface_xmls} ${irb_intf} </interfaces> - <vlans> + <protocols> + <rstp operation="replace"> + ${builtins.concatStringsSep "\n" rstps} + </rstp> + </protocols> + <vlans operation="replace"> ${builtins.concatStringsSep "\n" vlans} </vlans>'' vlan_trust_table ];