Skip to content

Commit b50f402

Browse files
committed
Move ip_mtu back to smoltcp
1 parent 7686c49 commit b50f402

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

smoltcp-device/src/lib.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,6 @@ pub struct DeviceCapabilities {
201201
pub checksum: ChecksumCapabilities,
202202
}
203203

204-
impl DeviceCapabilities {
205-
pub fn ip_mtu(&self) -> usize {
206-
match self.medium {
207-
#[cfg(feature = "medium-ethernet")]
208-
Medium::Ethernet => self.max_transmission_unit - 14,
209-
#[cfg(feature = "medium-ip")]
210-
Medium::Ip => self.max_transmission_unit,
211-
#[cfg(feature = "medium-ieee802154")]
212-
Medium::Ieee802154 => self.max_transmission_unit, // TODO(thvdveld): what is the MTU for Medium::IEEE802
213-
}
214-
}
215-
}
216-
217204
/// Type of medium of a device.
218205
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
219206
#[cfg_attr(feature = "defmt", derive(defmt::Format))]

src/iface/interface/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,15 @@ impl InterfaceInner {
783783

784784
#[allow(unused)] // unused depending on which sockets are enabled
785785
pub(crate) fn ip_mtu(&self) -> usize {
786-
self.caps.ip_mtu()
786+
match self.caps.medium {
787+
#[cfg(feature = "medium-ethernet")]
788+
Medium::Ethernet => self.caps.max_transmission_unit - 14,
789+
#[cfg(feature = "medium-ip")]
790+
Medium::Ip => self.caps.max_transmission_unit,
791+
#[cfg(feature = "medium-ieee802154")]
792+
Medium::Ieee802154 => self.caps.max_transmission_unit, // TODO(thvdveld): what is the MTU for Medium::IEEE802
793+
_ => unimplemented!(),
794+
}
787795
}
788796

789797
#[allow(unused)] // unused depending on which sockets are enabled, and in tests
@@ -1210,7 +1218,7 @@ impl InterfaceInner {
12101218
#[cfg(feature = "proto-ipv4")]
12111219
IpRepr::Ipv4(repr) => {
12121220
// If we have an IPv4 packet, then we need to check if we need to fragment it.
1213-
if total_ip_len > self.caps.ip_mtu() {
1221+
if total_ip_len > self.ip_mtu() {
12141222
#[cfg(feature = "proto-ipv4-fragmentation")]
12151223
{
12161224
net_debug!("start fragmentation");
@@ -1219,7 +1227,7 @@ impl InterfaceInner {
12191227
let tx_len = self.caps.max_transmission_unit;
12201228

12211229
let ip_header_len = repr.buffer_len();
1222-
let first_frag_ip_len = self.caps.ip_mtu();
1230+
let first_frag_ip_len = self.ip_mtu();
12231231

12241232
if frag.buffer.len() < total_ip_len {
12251233
net_debug!(
@@ -1305,7 +1313,7 @@ impl InterfaceInner {
13051313
#[cfg(feature = "proto-ipv6")]
13061314
IpRepr::Ipv6(_) => {
13071315
// Check if we need to fragment it.
1308-
if total_ip_len > self.caps.ip_mtu() {
1316+
if total_ip_len > self.ip_mtu() {
13091317
net_debug!("IPv6 fragmentation support is unimplemented. Dropping.");
13101318
Ok(())
13111319
} else {

0 commit comments

Comments
 (0)