Skip to content

Commit 47ce69b

Browse files
committed
wire/dhcp: remove option enum, letting higher layers specify kind+data.
This saves ~1.5kb of code size. Options like that generate a bit of code size bloat due to having many code paths that the compiler isn't able to optimize out. Also they don't scale well, adding every single option will make the bloat worse.
1 parent ffab9db commit 47ce69b

File tree

2 files changed

+229
-322
lines changed

2 files changed

+229
-322
lines changed

src/socket/dhcpv4.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use core::task::Waker;
33

44
use crate::iface::Context;
55
use crate::time::{Duration, Instant};
6-
use crate::wire::dhcpv4::{field as dhcpv4_field, DhcpOptionsBuffer};
7-
use crate::wire::HardwareAddress;
6+
use crate::wire::dhcpv4::field as dhcpv4_field;
87
use crate::wire::{
98
DhcpMessageType, DhcpPacket, DhcpRepr, IpAddress, IpProtocol, Ipv4Address, Ipv4Cidr, Ipv4Repr,
109
UdpRepr, DHCP_CLIENT_PORT, DHCP_MAX_DNS_SERVER_COUNT, DHCP_SERVER_PORT, UDP_HEADER_LEN,
1110
};
11+
use crate::wire::{DhcpOption, HardwareAddress};
1212

1313
#[cfg(feature = "async")]
1414
use super::WakerRegistration;
@@ -150,7 +150,7 @@ pub struct Socket<'a> {
150150

151151
/// A buffer contains options additional to be added to outgoing DHCP
152152
/// packets.
153-
outgoing_options: Option<DhcpOptionsBuffer<&'a [u8]>>,
153+
outgoing_options: &'a [DhcpOption<'a>],
154154
/// A buffer containing all requested parameters.
155155
parameter_request_list: Option<&'a [u8]>,
156156

@@ -180,7 +180,7 @@ impl<'a> Socket<'a> {
180180
max_lease_duration: None,
181181
retry_config: RetryConfig::default(),
182182
ignore_naks: false,
183-
outgoing_options: None,
183+
outgoing_options: &[],
184184
parameter_request_list: None,
185185
receive_packet_buffer: None,
186186
#[cfg(feature = "async")]
@@ -193,9 +193,9 @@ impl<'a> Socket<'a> {
193193
self.retry_config = config;
194194
}
195195

196-
/// Set the outgoing options buffer.
197-
pub fn set_outgoing_options_buffer(&mut self, options_buffer: DhcpOptionsBuffer<&'a [u8]>) {
198-
self.outgoing_options = Some(options_buffer);
196+
/// Set the outgoing options.
197+
pub fn set_outgoing_options(&mut self, options: &'a [DhcpOption<'a>]) {
198+
self.outgoing_options = options;
199199
}
200200

201201
/// Set the buffer into which incoming DHCP packets are copied into.
@@ -841,7 +841,7 @@ mod test {
841841
dns_servers: None,
842842
max_size: None,
843843
lease_duration: None,
844-
additional_options: None,
844+
additional_options: &[],
845845
};
846846

847847
const DHCP_DISCOVER: DhcpRepr = DhcpRepr {

0 commit comments

Comments
 (0)