From 73085f2f00172a27c43b5be7fbbf3d63b0181edd Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 30 May 2024 13:21:08 +1000 Subject: [PATCH] test(connlib): use same tunnel IP subnets as real code (#5162) This doesn't really matter for the functionality of the test because in connlib, we don't expect the IPs to adhere to a certain range. Nevertheless, to make output more readable, it is nicer if these IPs match what we also see in production logs. --- rust/connlib/tunnel/src/tests.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/rust/connlib/tunnel/src/tests.rs b/rust/connlib/tunnel/src/tests.rs index e5361ff2a..a0f6dfc6e 100644 --- a/rust/connlib/tunnel/src/tests.rs +++ b/rust/connlib/tunnel/src/tests.rs @@ -10,7 +10,7 @@ use connlib_shared::{ StaticSecret, }; use firezone_relay::{AddressFamily, AllocationPort, ClientSocket, PeerSocket}; -use ip_network::Ipv4Network; +use ip_network::{Ipv4Network, Ipv6Network}; use ip_network_table::IpNetworkTable; use ip_packet::MutableIpPacket; use pretty_assertions::assert_eq; @@ -1477,9 +1477,10 @@ fn gateway_id() -> impl Strategy { /// Generates an IPv4 address for the tunnel interface. /// /// We use the CG-NAT range for IPv4. +/// See . fn tunnel_ip4() -> impl Strategy { any::().prop_map(|idx| { - let cgnat_block = Ipv4Network::new(Ipv4Addr::new(100, 64, 0, 0), 10).unwrap(); + let cgnat_block = Ipv4Network::new(Ipv4Addr::new(100, 64, 0, 0), 11).unwrap(); let mut hosts = cgnat_block.hosts(); @@ -1489,9 +1490,19 @@ fn tunnel_ip4() -> impl Strategy { /// Generates an IPv6 address for the tunnel interface. /// -/// TODO: Which subnet do we use here? +/// See . fn tunnel_ip6() -> impl Strategy { - any::() + any::().prop_map(|idx| { + let cgnat_block = + Ipv6Network::new(Ipv6Addr::new(64_768, 8_225, 4_369, 0, 0, 0, 0, 0), 107).unwrap(); + + let mut subnets = cgnat_block.subnets_with_prefix(128); + + subnets + .nth(idx.index(subnets.len())) + .unwrap() + .network_address() + }) } fn sim_node_prototype(