WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
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: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ futures-core = "0.3.31"
futures-util = "0.3.31"
tower = { version = "0.5.2", features = ["util"] }
hyper-util = "0.1.17"
hex = "0.4.3"
dhcproto = "0.12.0"

[build-dependencies]
chrono = { version = "0.4.42", default-features = false, features = ["clock"] }
Expand Down
24 changes: 19 additions & 5 deletions src/commands/dhcp_proxy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![cfg_attr(not(unix), allow(unused_imports))]

use crate::dhcp_proxy::cache::{Clear, LeaseCache};
use crate::dhcp_proxy::dhcp_service::{process_client_stream, DhcpV4Service};
use crate::dhcp_proxy::dhcp_service::{
process_client_stream, DhcpService, DhcpV4Service, DhcpV6Service,
};
use crate::dhcp_proxy::ip;
use crate::dhcp_proxy::lib::g_rpc::netavark_proxy_server::{NetavarkProxy, NetavarkProxyServer};
use crate::dhcp_proxy::lib::g_rpc::{
Expand All @@ -14,6 +16,7 @@ use crate::error::{NetavarkError, NetavarkResult};
use crate::network::core_utils;
use clap::Parser;
use log::{debug, error, warn};
use mozim::DhcpV6IaType;
use tokio::task::AbortHandle;

use std::collections::HashMap;
Expand All @@ -38,7 +41,7 @@ use tonic::{
transport::Server, Code, Code::Internal, Code::InvalidArgument, Request, Response, Status,
};

type TaskData = (Arc<tokio::sync::Mutex<DhcpV4Service>>, AbortHandle);
type TaskData = (Arc<tokio::sync::Mutex<DhcpService>>, AbortHandle);

#[derive(Debug)]
/// This is the tonic netavark proxy service that is required to impl the Netavark Proxy trait which
Expand Down Expand Up @@ -437,7 +440,7 @@ async fn process_setup<W: Write + Clear>(
let mut service = DhcpV4Service::new(network_config, timeout)?;

let lease = service.get_lease().await?;
let service_arc = Arc::new(tokio::sync::Mutex::new(service));
let service_arc = Arc::new(tokio::sync::Mutex::new(DhcpService::V4(service)));
let service_arc_clone = service_arc.clone();
let task_handle = tokio::spawn(process_client_stream(service_arc_clone));
tasks
Expand All @@ -446,9 +449,20 @@ async fn process_setup<W: Write + Clear>(
.insert(mac.to_string(), (service_arc, task_handle.abort_handle()));
lease
}
//V6 TODO implement DHCPv6
1 => {
return Err(Status::new(InvalidArgument, "ipv6 not yet supported"));
// ia_type for conatainers is generally NonTemporaryAddresses
let mut service =
DhcpV6Service::new(network_config, timeout, DhcpV6IaType::NonTemporaryAddresses)?;
let lease = service.get_lease().await?;
// service in the generic DhcpService enum.
let service_arc = Arc::new(tokio::sync::Mutex::new(DhcpService::V6(service)));
let service_arc_clone = service_arc.clone();
let task_handle = tokio::spawn(process_client_stream(service_arc_clone));
tasks
.lock()
.expect("lock tasks")
.insert(mac.to_string(), (service_arc, task_handle.abort_handle()));
lease
}
_ => {
return Err(Status::new(InvalidArgument, "invalid protocol version"));
Expand Down
Loading