Add templates and rust configuration types to render configuration for
the isis daemon. This allows us to generate the config in perl, then
pass it to rust and then render the template in rust.

Co-authored-by: Stefan Hanreich <[email protected]>
Signed-off-by: Gabriel Goller <[email protected]>
---
 .../templates/frr.conf.jinja                  |  1 +
 proxmox-frr-templates/templates/isisd.jinja   | 32 ++++++++++++
 proxmox-frr/src/ser/isis.rs                   | 49 +++++++++++++++++++
 proxmox-frr/src/ser/mod.rs                    | 14 +++++-
 proxmox-frr/src/ser/serializer.rs             |  3 ++
 5 files changed, 98 insertions(+), 1 deletion(-)
 create mode 100644 proxmox-frr-templates/templates/isisd.jinja
 create mode 100644 proxmox-frr/src/ser/isis.rs

diff --git a/proxmox-frr-templates/templates/frr.conf.jinja 
b/proxmox-frr-templates/templates/frr.conf.jinja
index 8458c6a61112..c8495b417990 100644
--- a/proxmox-frr-templates/templates/frr.conf.jinja
+++ b/proxmox-frr-templates/templates/frr.conf.jinja
@@ -1,4 +1,5 @@
 {% include "fabricd.jinja" %}
+{% include "isisd.jinja" %}
 {% include "ospfd.jinja" %}
 {% include "access_lists.jinja" %}
 {% include "route_maps.jinja" %}
diff --git a/proxmox-frr-templates/templates/isisd.jinja 
b/proxmox-frr-templates/templates/isisd.jinja
new file mode 100644
index 000000000000..75f066166ad2
--- /dev/null
+++ b/proxmox-frr-templates/templates/isisd.jinja
@@ -0,0 +1,32 @@
+{% from "interface.jinja" import interface %}
+{% for router_name, router_config in isis.router|items %}
+!
+router isis {{ router_name }}
+ net {{ router_config.net }}
+{% if router_config.redistribute.ipv4_connected %}
+ redistribute ipv4 connected {{ router_config.redistribute.ipv4_connected }}
+{% endif %}
+{% if router_config.redistribute.ipv6_connected %}
+ redistribute ipv6 connected {{ router_config.redistribute.ipv6_connected }}
+{% endif %}
+{% if router_config.log_adjacency_changes %}
+ log-adjacency-changes
+{% endif %}
+{% for line in router_config.custom_frr_config %}
+{{ line }}
+{% endfor %}
+exit
+{% endfor %}
+{% for interface_name, interface_config in isis.interfaces|items %}
+{% call interface(interface_name, interface_config.addresses) %}
+{% if interface_config.domain and interface_config.is_ipv4 %}
+ ip router isis {{ interface_config.domain }}
+{% endif %}
+{% if interface_config.domain and interface_config.is_ipv6 %}
+ ipv6 router isis {{ interface_config.domain }}
+{% endif %}
+{% for line in interface_config.custom_frr_config %}
+{{ line }}
+{% endfor %}
+{% endcall %}
+{% endfor %}
diff --git a/proxmox-frr/src/ser/isis.rs b/proxmox-frr/src/ser/isis.rs
new file mode 100644
index 000000000000..2a38a8310fb5
--- /dev/null
+++ b/proxmox-frr/src/ser/isis.rs
@@ -0,0 +1,49 @@
+use std::fmt::Debug;
+
+use bon::Builder;
+
+use proxmox_sdn_types::net::Net;
+use serde::Deserialize;
+use serde::Serialize;
+
+use crate::ser::FrrWord;
+
+#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, 
Deserialize)]
+pub struct IsisRouterName(FrrWord);
+
+#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, 
Deserialize)]
+pub enum IsisLevel {
+    #[serde(rename = "level-1")]
+    Level1,
+    #[serde(rename = "level-2")]
+    Level2,
+    #[serde(rename = "level-1-2")]
+    Level12,
+}
+
+#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, 
Deserialize)]
+pub struct Redistribute {
+    ipv4_connected: IsisLevel,
+    ipv6_connected: IsisLevel,
+}
+
+#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, 
Deserialize)]
+pub struct IsisRouter {
+    pub net: Net,
+    #[serde(default, deserialize_with = 
"proxmox_serde::perl::deserialize_bool")]
+    pub log_adjacency_changes: Option<bool>,
+    pub redistribute: Option<Redistribute>,
+    #[serde(default)]
+    pub custom_frr_config: Vec<String>,
+}
+
+#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, 
Deserialize, Builder)]
+pub struct IsisInterface {
+    pub domain: IsisRouterName,
+    #[serde(deserialize_with = "proxmox_serde::perl::deserialize_bool")]
+    pub is_ipv4: bool,
+    #[serde(deserialize_with = "proxmox_serde::perl::deserialize_bool")]
+    pub is_ipv6: bool,
+    #[serde(default)]
+    pub custom_frr_config: Vec<String>,
+}
diff --git a/proxmox-frr/src/ser/mod.rs b/proxmox-frr/src/ser/mod.rs
index 666845ecab74..9aaee74d7af0 100644
--- a/proxmox-frr/src/ser/mod.rs
+++ b/proxmox-frr/src/ser/mod.rs
@@ -1,3 +1,4 @@
+pub mod isis;
 pub mod openfabric;
 pub mod ospf;
 pub mod route_map;
@@ -173,8 +174,11 @@ pub struct FrrConfig {
     pub ospf: OspfFrrConfig,
     #[builder(default)]
     #[serde(default)]
-    pub protocol_routemaps: BTreeMap<FrrProtocol, IpProtocolRouteMap>,
+    pub isis: IsisFrrConfig,
 
+    #[builder(default)]
+    #[serde(default)]
+    pub protocol_routemaps: BTreeMap<FrrProtocol, IpProtocolRouteMap>,
     #[builder(default)]
     #[serde(default)]
     pub routemaps: BTreeMap<RouteMapName, Vec<RouteMapEntry>>,
@@ -191,6 +195,14 @@ pub struct OpenfabricFrrConfig {
     pub interfaces: BTreeMap<InterfaceName, 
Interface<openfabric::OpenfabricInterface>>,
 }
 
+#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
+pub struct IsisFrrConfig {
+    #[serde(default)]
+    pub router: BTreeMap<isis::IsisRouterName, isis::IsisRouter>,
+    #[serde(default)]
+    pub interfaces: BTreeMap<InterfaceName, Interface<isis::IsisInterface>>,
+}
+
 #[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
 pub struct OspfFrrConfig {
     #[serde(default)]
diff --git a/proxmox-frr/src/ser/serializer.rs 
b/proxmox-frr/src/ser/serializer.rs
index da7a31b7cbf6..646b81ab6044 100644
--- a/proxmox-frr/src/ser/serializer.rs
+++ b/proxmox-frr/src/ser/serializer.rs
@@ -22,6 +22,9 @@ fn create_env<'a>() -> Environment<'a> {
                 "fabricd.jinja" => Ok(Some(
                     
include_str!("/usr/share/proxmox-frr/templates/fabricd.jinja").to_owned(),
                 )),
+                "isisd.jinja" => Ok(Some(
+                    
include_str!("/usr/share/proxmox-frr/templates/isisd.jinja").to_owned(),
+                )),
                 "ospfd.jinja" => Ok(Some(
                     
include_str!("/usr/share/proxmox-frr/templates/ospfd.jinja").to_owned(),
                 )),
-- 
2.47.3




Reply via email to