use crate::{args_of, child_block, named_children};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct DhcpLocalServerGroup {
pub name: String,
pub interfaces: Vec<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct DhcpLocalServer {
pub groups: Vec<DhcpLocalServerGroup>,
pub dhcpv6_groups: Vec<DhcpLocalServerGroup>,
}
pub(super) fn parse_dhcp_local_server(server: &ConfigLine) -> DhcpLocalServer {
let groups = |parent: &ConfigLine| -> Vec<DhcpLocalServerGroup> {
named_children(parent, "group")
.map(|(name, group)| DhcpLocalServerGroup {
name: name.to_string(),
interfaces: args_of(group, "interface").into_iter().map(str::to_string).collect(),
})
.collect()
};
DhcpLocalServer {
groups: groups(server),
dhcpv6_groups: child_block(server, "dhcpv6").map(groups).unwrap_or_default(),
}
}