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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Crash when enabling napt in EspNetif (#545)

### Added
- New example, `wifi_dhcp_with_hostname` to demonstrate setting a custom hostname when establishing a DHCP connection

Expand Down
27 changes: 23 additions & 4 deletions src/netif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,33 @@ impl EspNetif {
Ok(())
}

/// Enables or disables NAPT on this netif.
///
/// Enable operation can be performed only on one interface at a time.
/// NAPT cannot be enabled on multiple interfaces according to this implementation.
#[cfg(esp_idf_lwip_ipv4_napt)]
pub fn enable_napt(&mut self, enable: bool) {
pub fn enable_napt(&mut self, enable: bool) -> Result<(), EspError> {
unsafe extern "C" fn napt_wrapper(ctx: *mut ffi::c_void) -> i32 {
let ctx = unsafe { *(ctx as *mut (u8, i32)) };

ip_napt_enable_no(ctx.0, ctx.1);

0
}

unsafe {
crate::sys::ip_napt_enable_no(
let ctx = (
(esp_netif_get_netif_impl_index(self.handle) - 1) as u8,
if enable { 1 } else { 0 },
)
};
);

esp!(esp_netif_tcpip_exec(
Some(napt_wrapper),
&ctx as *const _ as *mut _
))?;
}

Ok(())
}
}

Expand Down