Skip to content

Commit 35bfdcb

Browse files
author
Emil Fresk
committed
Make DHCP option 15 optional
1 parent a7d7918 commit 35bfdcb

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ defmt = ["dep:defmt", "heapless/defmt-03"]
6060
"proto-sixlowpan" = ["proto-ipv6"]
6161
"proto-sixlowpan-fragmentation" = ["proto-sixlowpan", "_proto-fragmentation"]
6262
"proto-dns" = []
63+
"proto-domainname" = []
6364
"proto-ipsec" = ["proto-ipsec-ah", "proto-ipsec-esp"]
6465
"proto-ipsec-ah" = []
6566
"proto-ipsec-esp" = []
@@ -96,7 +97,7 @@ default = [
9697
"std", "log", # needed for `cargo test --no-default-features --features default` :/
9798
"medium-ethernet", "medium-ip", "medium-ieee802154",
9899
"phy-raw_socket", "phy-tuntap_interface",
99-
"proto-ipv4", "proto-igmp", "proto-dhcpv4", "proto-ipv6", "proto-dns",
100+
"proto-ipv4", "proto-igmp", "proto-dhcpv4", "proto-ipv6", "proto-dns", "proto-domainname",
100101
"proto-ipv4-fragmentation", "proto-sixlowpan-fragmentation",
101102
"socket-raw", "socket-icmp", "socket-udp", "socket-tcp", "socket-dhcpv4", "socket-dns", "socket-mdns",
102103
"packetmeta-id", "async"

src/socket/dhcpv4.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use core::str::FromStr;
22
#[cfg(feature = "async")]
33
use core::task::Waker;
44

5+
#[cfg(feature = "proto-domainname")]
56
use crate::config::DHCP_MAX_DOMAIN_NAME_SIZE;
67
use crate::iface::Context;
78
use crate::time::{Duration, Instant};
@@ -24,6 +25,7 @@ const DEFAULT_PARAMETER_REQUEST_LIST: &[u8] = &[
2425
dhcpv4_field::OPT_SUBNET_MASK,
2526
dhcpv4_field::OPT_ROUTER,
2627
dhcpv4_field::OPT_DOMAIN_NAME_SERVER,
28+
#[cfg(feature = "proto-domainname")]
2729
dhcpv4_field::OPT_DOMAIN_NAME,
2830
];
2931

@@ -42,6 +44,7 @@ pub struct Config<'a> {
4244
/// DNS servers
4345
pub dns_servers: Vec<Ipv4Address, DHCP_MAX_DNS_SERVER_COUNT>,
4446
/// Domain name
47+
#[cfg(feature = "proto-domainname")]
4548
pub domain_name: Option<String<DHCP_MAX_DOMAIN_NAME_SIZE>>,
4649
/// Received DHCP packet
4750
pub packet: Option<DhcpPacket<&'a [u8]>>,
@@ -499,6 +502,7 @@ impl<'a> Socket<'a> {
499502
address: Ipv4Cidr::new(dhcp_repr.your_ip, prefix_len),
500503
router: dhcp_repr.router,
501504
dns_servers,
505+
#[cfg(feature = "proto-domainname")]
502506
domain_name: dhcp_repr
503507
.domain_name
504508
.map(String::from_str)
@@ -598,6 +602,7 @@ impl<'a> Socket<'a> {
598602
renew_duration: None,
599603
rebind_duration: None,
600604
dns_servers: None,
605+
#[cfg(feature = "proto-domainname")]
601606
domain_name: None,
602607
additional_options: self.outgoing_options,
603608
};
@@ -749,6 +754,7 @@ impl<'a> Socket<'a> {
749754
address: state.config.address,
750755
router: state.config.router,
751756
dns_servers: state.config.dns_servers.clone(),
757+
#[cfg(feature = "proto-domainname")]
752758
domain_name: state.config.domain_name.clone(),
753759
packet: self
754760
.receive_packet_buffer

src/wire/dhcpv4.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ pub struct Repr<'a> {
648648
/// DNS servers
649649
pub dns_servers: Option<Vec<Ipv4Address, MAX_DNS_SERVER_COUNT>>,
650650
/// Domain name
651+
#[cfg(feature = "proto-domainname")]
651652
pub domain_name: Option<&'a str>,
652653
/// The maximum size dhcp packet the interface can receive
653654
pub max_size: Option<u16>,
@@ -694,6 +695,7 @@ impl<'a> Repr<'a> {
694695
len += 2;
695696
len += dns_servers.iter().count() * core::mem::size_of::<u32>();
696697
}
698+
#[cfg(feature = "proto-domainname")]
697699
if let Some(domain_name) = &self.domain_name {
698700
len += 2;
699701
len += domain_name.as_bytes().len();
@@ -744,6 +746,7 @@ impl<'a> Repr<'a> {
744746
let mut subnet_mask = None;
745747
let mut parameter_request_list = None;
746748
let mut dns_servers = None;
749+
#[cfg(feature = "proto-domainname")]
747750
let mut domain_name = None;
748751
let mut max_size = None;
749752
let mut lease_duration = None;
@@ -809,10 +812,9 @@ impl<'a> Repr<'a> {
809812
net_trace!("DHCP domain name servers contained invalid address");
810813
}
811814
}
815+
#[cfg(feature = "proto-domainname")]
812816
(field::OPT_DOMAIN_NAME, _) => {
813-
if let Ok(name) = core::str::from_utf8(data) {
814-
domain_name = Some(name);
815-
}
817+
domain_name = core::str::from_utf8(data).ok();
816818
}
817819
_ => {}
818820
}
@@ -836,6 +838,7 @@ impl<'a> Repr<'a> {
836838
client_identifier,
837839
parameter_request_list,
838840
dns_servers,
841+
#[cfg(feature = "proto-domainname")]
839842
domain_name,
840843
max_size,
841844
lease_duration,
@@ -953,6 +956,7 @@ impl<'a> Repr<'a> {
953956
})?;
954957
}
955958

959+
#[cfg(feature = "proto-domainname")]
956960
if let Some(domain_name) = &self.domain_name {
957961
options.emit(DhcpOption {
958962
kind: field::OPT_DOMAIN_NAME,
@@ -1187,6 +1191,7 @@ mod test {
11871191
server_identifier: None,
11881192
parameter_request_list: None,
11891193
dns_servers: None,
1194+
#[cfg(feature = "proto-domainname")]
11901195
domain_name: None,
11911196
max_size: None,
11921197
renew_duration: None,
@@ -1218,6 +1223,7 @@ mod test {
12181223
server_identifier: None,
12191224
parameter_request_list: Some(&[1, 3, 6, 42]),
12201225
dns_servers: None,
1226+
#[cfg(feature = "proto-domainname")]
12211227
domain_name: None,
12221228
additional_options: &[],
12231229
}

0 commit comments

Comments
 (0)