From f43e44c820f5cdf1a9225d3179682f8eef15da73 Mon Sep 17 00:00:00 2001 From: Samuel Lorch Date: Mon, 19 Feb 2024 01:28:11 +0100 Subject: [PATCH] Use IpNet for Interface Addresses --- src/apply/chrony.rs | 4 +--- src/apply/unbound.rs | 4 +--- src/definitions/config.rs | 4 ---- src/definitions/network.rs | 3 ++- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/apply/chrony.rs b/src/apply/chrony.rs index 8c5081d..fc8f25b 100644 --- a/src/apply/chrony.rs +++ b/src/apply/chrony.rs @@ -3,9 +3,7 @@ use crate::{ definitions::{config::Config, network::AddressingMode}, templates, }; -use ipnet::IpNet; use std::process::Command; -use std::str::FromStr; use std::{error::Error, io::Write}; use tera::Context; use tracing::{error, info}; @@ -22,7 +20,7 @@ pub fn apply_chrony(pending_config: Config, _current_config: Config) -> Result<( if let AddressingMode::Static { address } = &server.interface(pending_config.clone()).addressing_mode { - subnets.push(IpNet::from_str(address)?.network().to_string()); + subnets.push(address.network().to_string()); } } context.insert("subnets", &subnets); diff --git a/src/apply/unbound.rs b/src/apply/unbound.rs index 59d3981..e316a1b 100644 --- a/src/apply/unbound.rs +++ b/src/apply/unbound.rs @@ -6,9 +6,7 @@ use crate::{ }, templates, }; -use ipnet::IpNet; use std::process::Command; -use std::str::FromStr; use std::{error::Error, io::Write}; use tera::Context; use tracing::{error, info}; @@ -33,7 +31,7 @@ pub fn apply_unbound(pending_config: Config, _current_config: Config) -> Result< if let AddressingMode::Static { address } = &server.interface(pending_config.clone()).addressing_mode { - subnets.push(IpNet::from_str(address)?.network().to_string()); + subnets.push(address.network().to_string()); } } context.insert("interfaces", &interfaces); diff --git a/src/definitions/config.rs b/src/definitions/config.rs index 9ebac40..435e71c 100644 --- a/src/definitions/config.rs +++ b/src/definitions/config.rs @@ -4,7 +4,6 @@ use validator::Validate; use super::firewall; use super::firewall::SNATType; use super::network; -use super::network::AddressingMode; use super::network::NetworkInterfaceType; use super::object; use super::object::AddressType; @@ -48,9 +47,6 @@ macro_db!( [ S: gateway, network::StaticRoute, object.addresses; network.static_routes ()], [ S: destination, network::StaticRoute, object.addresses; network.static_routes ()], - // NetworkInteface - [ E: address, network::NetworkInterface, object.addresses; network.interfaces (addressing_mode, AddressingMode, Static, address)], - // Address [ EM: members, object::Address, object.addresses; object.addresses (address_type, AddressType, Group, members)], diff --git a/src/definitions/network.rs b/src/definitions/network.rs index c240153..71cc05b 100644 --- a/src/definitions/network.rs +++ b/src/definitions/network.rs @@ -1,3 +1,4 @@ +use ipnet::IpNet; use serde::{Deserialize, Serialize}; use validator::Validate; @@ -31,7 +32,7 @@ pub enum NetworkInterfaceType { pub enum AddressingMode { None, Static { - address: String, + address: IpNet, }, #[serde(rename(serialize = "dhcp", deserialize = "dhcp"))] DHCP,