1

FIx a bug with address assignment

This commit is contained in:
Evan Pratten 2023-08-04 19:08:22 -04:00
parent 41708f15eb
commit 79a861acbf
2 changed files with 8 additions and 4 deletions

View File

@ -182,13 +182,17 @@ impl CrossProtocolNetworkAddressTableWithIpv4Pool {
let new_address = self
.pool
.iter()
.map(|(network_address, netmask)| (*network_address, *network_address | !netmask))
.find(|(network_address, _)| self.table.get_ipv6(*network_address).is_none())
.map(|(_, new_address)| new_address)
.map(|(network_address, netmask)| (*network_address)..(*network_address | !netmask))
.find_map(|mut addr_range| addr_range.find(|addr| !self.table.get_ipv6(*addr).is_some()))
.ok_or(Error::Ipv4PoolExhausted(self.max_mappings))?;
// Insert the new mapping
self.table.insert(new_address, ipv6, self.timeout);
log::info!(
"New cross-protocol address mapping: {:02x} -> {:02x}",
ipv6,
new_address
);
// Return the new address
Ok(new_address)

View File

@ -142,7 +142,7 @@ pub async fn main() {
let mut addr_table = RefCell::new(CrossProtocolNetworkAddressTableWithIpv4Pool::new(
pool_prefixes
.iter()
.map(|prefix| (u32::from(prefix.addr()), prefix.prefix_len() as u32))
.map(|prefix| (u32::from(prefix.addr()), u32::from(prefix.netmask())))
.collect::<Vec<(u32, u32)>>()
.as_slice(),
Duration::from_secs(args.reservation_timeout),