Skip to content

Commit

Permalink
Refucktoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Virv12 committed Dec 4, 2024
1 parent b739863 commit 761b875
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pixie-server/example.config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
hosts:
listen_on: 10.0.0.1
#static_dhcp: [10.187.100.1, 10.187.200.200]
dhcp: !static [10.187.100.1, 10.187.200.200]
#dhcp: !proxy 192.168.1.100
hostsfile: /etc/hosts
broadcast_speed: 52428800
http:
Expand Down
11 changes: 4 additions & 7 deletions pixie-server/src/dnsmasq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
use anyhow::{Context, Result};

use macaddr::MacAddr6;
use pixie_shared::Unit;
use pixie_shared::{DhcpMode, Unit};

use crate::{find_network, state::State};

Expand Down Expand Up @@ -40,12 +40,9 @@ async fn write_config(state: &State) -> Result<()> {

let mut dnsmasq_conf = File::create(state.storage_dir.join("dnsmasq.conf"))?;

let dhcp_dynamic_conf = match state.config.hosts.static_dhcp {
Some((low, high)) => format!("dhcp-range=tag:netboot,{low},{high}"),
None => format!(
"dhcp-range=tag:netboot,{},proxy",
state.config.hosts.listen_on
),
let dhcp_dynamic_conf = match state.config.hosts.dhcp {
DhcpMode::Static(low, high) => format!("dhcp-range=tag:netboot,{low},{high}"),
DhcpMode::Proxy(ip) => format!("dhcp-range=tag:netboot,{},proxy", ip),
};

let storage_str = state.storage_dir.to_str().unwrap();
Expand Down
15 changes: 13 additions & 2 deletions pixie-shared/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ use std::{

use crate::Bijection;

#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, Clone)]
#[serde(rename_all = "lowercase")]
pub enum DhcpMode {
/// Unknown clients will be assigned IPs in the specified range.
Static(Ipv4Addr, Ipv4Addr),
/// Unknown clients are assumed to receive an IP address by another DHCP server.
/// The specified IP must belong to the network on which the other DHCP server gives IPs,
/// and the DHCP interface must have an IP on this network.
Proxy(Ipv4Addr),
}

/// Registered clients will always be assigned an IP in the form
/// 10.{group_id}.{column_id}.{row_id}.
/// Note that for this to work, the specified network interface must have an IP on the 10.0.0.0/8
Expand All @@ -20,8 +31,8 @@ use crate::Bijection;
pub struct HostsConfig {
/// Listen on address
pub listen_on: Ipv4Addr,
/// Enables DHCP server for unregistered clients.
pub static_dhcp: Option<(Ipv4Addr, Ipv4Addr)>,
/// DHCP server.
pub dhcp: DhcpMode,
/// Hosts file to use for DHCP hostnames.
pub hostsfile: Option<PathBuf>,

Expand Down

0 comments on commit 761b875

Please sign in to comment.