Skip to content

Commit

Permalink
remove AnyIP; fix IPv6 virtual addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
aramperes committed Dec 24, 2023
1 parent 38fc217 commit 488a0e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/virtual_iface/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use smoltcp::{
iface::{Config, Interface, SocketHandle, SocketSet},
socket::tcp,
time::Instant,
wire::{HardwareAddress, IpAddress, IpCidr},
wire::{HardwareAddress, IpAddress, IpCidr, IpVersion},
};
use std::{
collections::{HashMap, HashSet, VecDeque},
Expand Down Expand Up @@ -78,7 +78,7 @@ impl<'a> TcpVirtualInterface<'a> {
}
addresses
.into_iter()
.map(|addr| IpCidr::new(addr, 32))
.map(|addr| IpCidr::new(addr, addr_length(&addr)))
.collect()
}
}
Expand Down Expand Up @@ -249,3 +249,10 @@ impl VirtualInterfacePoll for TcpVirtualInterface<'_> {
}
}
}

const fn addr_length(addr: &IpAddress) -> u8 {
match addr.version() {
IpVersion::Ipv4 => 32,
IpVersion::Ipv6 => 128,
}
}
11 changes: 9 additions & 2 deletions src/virtual_iface/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use smoltcp::{
iface::{Config, Interface, SocketHandle, SocketSet},
socket::udp::{self, UdpMetadata},
time::Instant,
wire::{HardwareAddress, IpAddress, IpCidr},
wire::{HardwareAddress, IpAddress, IpCidr, IpVersion},
};
use std::{
collections::{HashMap, HashSet, VecDeque},
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<'a> UdpVirtualInterface<'a> {
}
addresses
.into_iter()
.map(|addr| IpCidr::new(addr, 32))
.map(|addr| IpCidr::new(addr, addr_length(&addr)))
.collect()
}
}
Expand Down Expand Up @@ -219,3 +219,10 @@ impl<'a> VirtualInterfacePoll for UdpVirtualInterface<'a> {
}
}
}

const fn addr_length(addr: &IpAddress) -> u8 {
match addr.version() {
IpVersion::Ipv4 => 32,
IpVersion::Ipv6 => 128,
}
}

0 comments on commit 488a0e0

Please sign in to comment.