Merge pull request #1668 from bjoernQ/fix-embassy-net-dual-stack

Make dual-stack work in embassy-net
This commit is contained in:
Dario Nieuwenhuis 2023-07-18 11:30:27 +00:00 committed by GitHub
commit 13964c7fca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -531,11 +531,14 @@ impl<D: Driver + 'static> Inner<D> {
debug!(" IP address: {}", config.address); debug!(" IP address: {}", config.address);
s.iface.update_ip_addrs(|addrs| { s.iface.update_ip_addrs(|addrs| {
if addrs.is_empty() { if let Some((index, _)) = addrs
addrs.push(IpCidr::Ipv4(config.address)).unwrap(); .iter()
} else { .enumerate()
addrs[0] = IpCidr::Ipv4(config.address); .find(|(_, &addr)| matches!(addr, IpCidr::Ipv4(_)))
{
addrs.remove(index);
} }
addrs.push(IpCidr::Ipv4(config.address)).unwrap();
}); });
#[cfg(feature = "medium-ethernet")] #[cfg(feature = "medium-ethernet")]
@ -570,11 +573,14 @@ impl<D: Driver + 'static> Inner<D> {
debug!(" IP address: {}", config.address); debug!(" IP address: {}", config.address);
s.iface.update_ip_addrs(|addrs| { s.iface.update_ip_addrs(|addrs| {
if addrs.is_empty() { if let Some((index, _)) = addrs
addrs.push(IpCidr::Ipv6(config.address)).unwrap(); .iter()
} else { .enumerate()
addrs[0] = IpCidr::Ipv6(config.address); .find(|(_, &addr)| matches!(addr, IpCidr::Ipv6(_)))
{
addrs.remove(index);
} }
addrs.push(IpCidr::Ipv6(config.address)).unwrap();
}); });
#[cfg(feature = "medium-ethernet")] #[cfg(feature = "medium-ethernet")]
@ -642,13 +648,21 @@ impl<D: Driver + 'static> Inner<D> {
socket.set_retry_config(config.retry_config); socket.set_retry_config(config.retry_config);
} }
#[allow(unused)] // used only with dhcp #[cfg(feature = "dhcpv4")]
fn unapply_config(&mut self, s: &mut SocketStack) { fn unapply_config_v4(&mut self, s: &mut SocketStack) {
#[cfg(feature = "medium-ethernet")] #[cfg(feature = "medium-ethernet")]
let medium = self.device.capabilities().medium; let medium = self.device.capabilities().medium;
debug!("Lost IP configuration"); debug!("Lost IP configuration");
s.iface.update_ip_addrs(|ip_addrs| ip_addrs.clear()); s.iface.update_ip_addrs(|ip_addrs| {
#[cfg(feature = "proto-ipv4")]
if let Some((index, _)) = ip_addrs
.iter()
.enumerate()
.find(|(_, &addr)| matches!(addr, IpCidr::Ipv4(_)))
{
ip_addrs.remove(index);
}
});
#[cfg(feature = "medium-ethernet")] #[cfg(feature = "medium-ethernet")]
if medium == Medium::Ethernet { if medium == Medium::Ethernet {
#[cfg(feature = "proto-ipv4")] #[cfg(feature = "proto-ipv4")]
@ -695,7 +709,7 @@ impl<D: Driver + 'static> Inner<D> {
if self.link_up { if self.link_up {
match socket.poll() { match socket.poll() {
None => {} None => {}
Some(dhcpv4::Event::Deconfigured) => self.unapply_config(s), Some(dhcpv4::Event::Deconfigured) => self.unapply_config_v4(s),
Some(dhcpv4::Event::Configured(config)) => { Some(dhcpv4::Event::Configured(config)) => {
let config = StaticConfigV4 { let config = StaticConfigV4 {
address: config.address, address: config.address,
@ -707,7 +721,7 @@ impl<D: Driver + 'static> Inner<D> {
} }
} else if old_link_up { } else if old_link_up {
socket.reset(); socket.reset();
self.unapply_config(s); self.unapply_config_v4(s);
} }
} }
//if old_link_up || self.link_up { //if old_link_up || self.link_up {