Use IpNet for Interface Addresses

This commit is contained in:
Samuel Lorch 2024-02-19 01:28:11 +01:00
parent 5f20f7711d
commit f43e44c820
4 changed files with 4 additions and 11 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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)],

View file

@ -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,