Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sub_option type & sname/fname to config #6

Merged
merged 4 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ We _could_ go much faster by keeping leases in memory and appending to the db li
[perfdhcp](https://kea.readthedocs.io/en/kea-2.0.1/man/perfdhcp.8.html) can be used to test dora, include `giaddr`, the subnet select option or the relay agent link selection opt, you can use this as a starting point:

```
sudo perfdhcp -4 -N 9901 -L 9903 -r 1 -xi -t 1 -o 118,C0A80001 -R 100 127.0.0.1
sudo perfdhcp -4 -N 9900 -L 9903 -r 1 -xi -t 1 -o 118,C0A80001 -R 100 127.0.0.1
```

This will start perfdhcp using dhcpv4, send messages to `127.0.0.1:9901`, listen on port `9903` at a rate of 1/sec, and using 100 different devices. It includes the subnet select opt (118) with `C0A80001` as a hex encoded value of the integer of `192.168.0.1`. `dora` must be listening on `9901` and have a config with ranges to allocate on the `192.168.0.1` network.
This will start perfdhcp using dhcpv4, send messages to `127.0.0.1:9900`, listen on port `9903` at a rate of 1/sec, and using 100 different devices. It includes the subnet select opt (118) with `C0A80001` as a hex encoded value of the integer of `192.168.0.1`. `dora` must be listening on `9900` and have a config with ranges to allocate on the `192.168.0.1` network.

### Setting up dora on the PI

Expand All @@ -156,4 +156,4 @@ See [PI setup](./docs/pi_setup.md)

If you find a bug, or see something that doesn't look right, please open an issue and let us know. We welcome any and all constructive feedback.

We're still actively working on this. Some of the things we'd like to add in the future include: DDNS updates, stateful DHCPv6, HA & Client classification.
We're still actively working on this. Some of the things we'd like to add in the future include: DDNS updates, stateful DHCPv6, HA & Client classification.
118 changes: 0 additions & 118 deletions basic.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ OPTIONS:
Run on non-standard ports:

```
dora -c /path/to/config.yaml --v4-addr 0.0.0.0:9901
dora -c /path/to/config.yaml --v4-addr 0.0.0.0:9900
```

is equivalent to:

```
V4_ADDR="0.0.0.0:9901" CONFIG_PATH="/path/to/config.yaml" dora
V4_ADDR="0.0.0.0:9900" CONFIG_PATH="/path/to/config.yaml" dora
```

Use `DORA_LOG` to control dora's log level. Takes same arguments as `RUST_LOG`
18 changes: 9 additions & 9 deletions bin/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn test_basic_dhcpv4_unicast() -> Result<()> {
let settings = ClientSettingsBuilder::default()
.iface_name("dhcpcli")
.target("192.168.2.1".parse::<std::net::IpAddr>().unwrap())
.port(9901_u16)
.port(9900_u16)
.build()?;
// create a client that sends dhcpv4 messages
let mut client = Client::<v4::Message>::new(settings);
Expand Down Expand Up @@ -79,7 +79,7 @@ fn static_chaddr_dora() -> Result<()> {
let settings = ClientSettingsBuilder::default()
.iface_name("dhcpcli")
.target("192.168.2.1".parse::<std::net::IpAddr>().unwrap())
.port(9901_u16)
.port(9900_u16)
.build()?;
let chaddr = "aa:bb:cc:dd:ee:ff".parse::<MacAddr>()?.octets();

Expand Down Expand Up @@ -126,7 +126,7 @@ fn static_opt_dora() -> Result<()> {
let settings = ClientSettingsBuilder::default()
.iface_name("dhcpcli")
.target("192.168.2.1".parse::<std::net::IpAddr>().unwrap())
.port(9901_u16)
.port(9900_u16)
.build()?;

let mut client = Client::<v4::Message>::new(settings);
Expand Down Expand Up @@ -178,7 +178,7 @@ fn discover_req_addr() -> Result<()> {
let settings = ClientSettingsBuilder::default()
.iface_name("dhcpcli")
.target("192.168.2.1".parse::<std::net::IpAddr>().unwrap())
.port(9901_u16)
.port(9900_u16)
.build()?;

// create a client that sends dhcpv4 messages
Expand Down Expand Up @@ -226,7 +226,7 @@ fn request_nak() -> Result<()> {
let settings = ClientSettingsBuilder::default()
.iface_name("dhcpcli")
.target("192.168.2.1".parse::<std::net::IpAddr>().unwrap())
.port(9901_u16)
.port(9900_u16)
.build()?;

// create a client that sends dhcpv4 messages
Expand Down Expand Up @@ -270,7 +270,7 @@ fn requested_lease_time() -> Result<()> {
let settings = ClientSettingsBuilder::default()
.iface_name("dhcpcli")
.target("192.168.2.1".parse::<std::net::IpAddr>().unwrap())
.port(9901_u16)
.port(9900_u16)
.build()?;
// create a client that sends dhcpv4 messages
let mut client = Client::<v4::Message>::new(settings);
Expand Down Expand Up @@ -327,7 +327,7 @@ fn test_requested_opts() -> Result<()> {
let settings = ClientSettingsBuilder::default()
.iface_name("dhcpcli")
.target("192.168.2.1".parse::<std::net::IpAddr>().unwrap())
.port(9901_u16)
.port(9900_u16)
.build()?;
// create a client that sends dhcpv4 messages
let mut client = Client::<v4::Message>::new(settings);
Expand Down Expand Up @@ -363,7 +363,7 @@ fn test_exclusions() -> Result<()> {
let settings = ClientSettingsBuilder::default()
.iface_name("dhcpcli")
.target("192.168.2.1".parse::<std::net::IpAddr>().unwrap())
.port(9901_u16)
.port(9900_u16)
.build()?;
// create a client that sends dhcpv4 messages
let mut client = Client::<v4::Message>::new(settings);
Expand Down Expand Up @@ -403,7 +403,7 @@ fn test_decline() -> Result<()> {
let settings = ClientSettingsBuilder::default()
.iface_name("dhcpcli")
.target("192.168.2.1".parse::<std::net::IpAddr>().unwrap())
.port(9901_u16)
.port(9900_u16)
.build()?;
// create a client that sends dhcpv4 messages
let mut client = Client::<v4::Message>::new(settings);
Expand Down
14 changes: 7 additions & 7 deletions bin/tests/common/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ impl Drop for DhcpServerEnv {
remove_test_veth_nics(&self.veth_cli);
remove_test_net_namespace(&self.netns);
if let Err(err) = std::fs::remove_file(db) {
eprintln!("{:?}", err);
eprintln!("{err:?}");
}
if let Err(err) = std::fs::remove_file(format!("{db}-shm")) {
eprintln!("{:?}", err);
eprintln!("{err:?}");
}
if let Err(err) = std::fs::remove_file(format!("{db}-wal")) {
eprintln!("{:?}", err);
eprintln!("{err:?}");
}
}
}
Expand Down Expand Up @@ -83,7 +83,7 @@ fn start_dhcp_server(config: &str, netns: &str, db: &str) -> Child {
let workspace_root = env::var("WORKSPACE_ROOT").unwrap_or_else(|_| "..".to_owned());
let config_path = format!("{workspace_root}/bin/tests/test_configs/{config}");
let dora_debug = format!(
"./{workspace_root}/target/debug/dora -d={db} --config-path={config_path} --threads=2 --dora-log=debug --v4-addr=0.0.0.0:9901",
"./{workspace_root}/target/debug/dora -d={db} --config-path={config_path} --threads=2 --dora-log=debug --v4-addr=0.0.0.0:9900",
);
let cmd = format!("ip netns exec {netns} {dora_debug}");

Expand All @@ -94,7 +94,7 @@ fn start_dhcp_server(config: &str, netns: &str, db: &str) -> Child {
.expect("Failed to start DHCP server");
std::thread::sleep(std::time::Duration::from_secs(1));
if let Ok(Some(ret)) = child.try_wait() {
panic!("Failed to start DHCP server {:?}", ret);
panic!("Failed to start DHCP server {ret:?}");
}
child
}
Expand All @@ -108,7 +108,7 @@ fn run_cmd(cmd: &str) -> String {
let output = Command::new(cmds[0])
.args(&cmds[1..])
.output()
.unwrap_or_else(|_| panic!("failed to execute command {}", cmd));
.unwrap_or_else(|_| panic!("failed to execute command {cmd}"));
if !output.status.success() {
panic!("{}", String::from_utf8_lossy(&output.stderr));
}
Expand All @@ -121,7 +121,7 @@ fn run_cmd_ignore_failure(cmd: &str) -> String {
match Command::new(cmds[0]).args(&cmds[1..]).output() {
Ok(o) => String::from_utf8(o.stdout).unwrap_or_default(),
Err(e) => {
eprintln!("Failed to execute command {}: {}", cmd, e);
eprintln!("Failed to execute command {cmd}: {e}");
"".to_string()
}
}
Expand Down
6 changes: 3 additions & 3 deletions dora-cfg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ fn main() -> Result<()> {
Format::Wire => {
let wire_cfg = parse_wire::<wire::Config>(&args)?;
println!("printing wire format");
println!("{:#?}", wire_cfg);
println!("{wire_cfg:#?}");
}
Format::Internal => {
let cfg = config::v4::Config::from_wire(parse_wire(&args)?)?;
println!("parsed wire format into dora internal format, pretty printing");
println!("{:#?}", cfg);
println!("{cfg:#?}");
}
}
}
Expand All @@ -62,7 +62,7 @@ fn parse_schema(args: &Args) -> Result<()> {
.expect("failed to compile schema"); // can't use ? static lifetime on error
// TODO: jsonschema crate has garbage error types!
return if let Err(errs) = validator.validate(&input) {
errs.for_each(|err| eprintln!("{}", err));
errs.for_each(|err| eprintln!("{err}"));
Err(anyhow::anyhow!("failed to validate schema"))
} else {
println!("json schema validated");
Expand Down
2 changes: 2 additions & 0 deletions dora-core/src/server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ impl MsgContext<v4::Message> {
v4::MessageType::Nak => {
let giaddr = resp.giaddr();
resp.clear_addrs();
resp.clear_fname();
resp.clear_sname();
resp.set_giaddr(giaddr);
// remove all opts. in the future, we may need to remove exclusively
// what was added in the param req list, for now we will just remove all
Expand Down
12 changes: 7 additions & 5 deletions dora-core/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl RunInner<v4::Message> {
.interfaces
.iter()
.find(|int| int.index == ifindex)
.with_context(|| format!("can't find interface {}", ifindex))?;
.with_context(|| format!("can't find interface {ifindex}"))?;
trace!(meta = ?self.ctx.meta(), ?interface, "received datagram");

let resp = match time::timeout(timeout, self.service.run_handlers(&mut self.ctx)).await {
Expand Down Expand Up @@ -340,7 +340,7 @@ impl RunInner<v6::Message> {
.interfaces
.iter()
.find(|int| int.index == ifindex)
.with_context(|| format!("can't find interface {}", ifindex))?;
.with_context(|| format!("can't find interface {ifindex}"))?;
trace!(meta = ?self.ctx.meta(), ?interface, "received datagram");

let resp = match time::timeout(timeout, self.service.run_handlers(&mut self.ctx)).await {
Expand Down Expand Up @@ -506,7 +506,8 @@ impl Service<v4::Message> {
let soc = if interfaces.len() == 1 {
trace!("binding exactly one interface so use SO_BINDTODEVICE");
// to bind to an interface, we must create the socket using libc
let socket = socket2::Socket::new(socket2::Domain::IPV4, socket2::Type::DGRAM, None)?;
let socket = socket2::Socket::new(socket2::Domain::IPV4, socket2::Type::DGRAM, None)
.context("failed to bind v4 UDP socket")?;
// SO_BINDTODEVICE
socket
.bind_device(Some(interfaces.first().unwrap().name.as_bytes()))
Expand Down Expand Up @@ -534,8 +535,9 @@ impl Service<v6::Message> {
async fn create_socket(&self) -> Result<unix_udp_sock::UdpSocket> {
let addr = self.plugins.config.v6_addr;
let interfaces = self.plugins.interfaces.clone();
debug!(?addr, "binding v6 UDP socket");
let socket = socket2::Socket::new(socket2::Domain::IPV6, socket2::Type::DGRAM, None)?;
info!(?addr, "binding v6 UDP socket");
let socket = socket2::Socket::new(socket2::Domain::IPV6, socket2::Type::DGRAM, None)
.context("failed to bind v6 UDP socket")?;
socket.set_only_v6(true).context("only ipv6")?;

socket
Expand Down
2 changes: 1 addition & 1 deletion dora-core/src/server/typemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl TypeMap {
/// ```
pub fn insert<T: Send + Sync + 'static>(&mut self, val: T) -> Option<T> {
self.map
.get_or_insert_with(|| Box::new(HashMap::default()))
.get_or_insert_with(Box::default)
.insert(TypeId::of::<T>(), Box::new(val))
.and_then(|boxed| {
(boxed as Box<dyn Any + 'static>)
Expand Down
Loading