mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-15 10:25:40 +00:00
8f862997eb
* feat: support allocating public IPv6 addresses from a provider Add a provider/leaser architecture for public IPv6 address allocation between nodes in the same network: - A node with `--ipv6-public-addr-provider` advertises a delegable public IPv6 prefix (auto-detected from kernel routes or manually configured via `--ipv6-public-addr-prefix`). - Other nodes with `--ipv6-public-addr-auto` request a /128 lease from the selected provider via a new RPC service (PublicIpv6AddrRpc). - Leases have a 30s TTL, renewed every 10s by the client routine. - The provider allocates addresses deterministically from its prefix using instance-UUID-based hashing to prefer stable assignments. - Routes to peer leases are installed on the TUN device, and each client's own /128 is assigned as its IPv6 address. Also includes netlink IPv6 route table inspection, integration tests, and event-driven route/address reconciliation. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
66 lines
2.0 KiB
Rust
66 lines
2.0 KiB
Rust
use std::net::Ipv6Addr;
|
|
|
|
use crate::{
|
|
common::config::{ConfigLoader, TomlConfigLoader},
|
|
common::global_ctx::tests::get_mock_global_ctx,
|
|
peers::peer_manager::RouteAlgoType,
|
|
proto::peer_rpc::RoutePeerInfo,
|
|
};
|
|
|
|
#[tokio::test]
|
|
async fn test_ipv6_config_support() {
|
|
let config = TomlConfigLoader::default();
|
|
|
|
// Test IPv6 configuration setting and getting
|
|
let ipv6_cidr = "fd00::1/64".parse().unwrap();
|
|
config.set_ipv6(Some(ipv6_cidr));
|
|
|
|
assert_eq!(config.get_ipv6(), Some(ipv6_cidr));
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_global_ctx_ipv6() {
|
|
let global_ctx = get_mock_global_ctx();
|
|
|
|
// Test setting and getting IPv6 from global context
|
|
let ipv6_cidr = "fd00::1/64".parse().unwrap();
|
|
global_ctx.set_ipv6(Some(ipv6_cidr));
|
|
|
|
assert_eq!(global_ctx.get_ipv6(), Some(ipv6_cidr));
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_route_peer_info_ipv6() {
|
|
let global_ctx = get_mock_global_ctx();
|
|
|
|
// Set IPv6 address in global context
|
|
let ipv6_cidr = "fd00::1/64".parse().unwrap();
|
|
global_ctx.set_ipv6(Some(ipv6_cidr));
|
|
|
|
// Create RoutePeerInfo with IPv6 support
|
|
let updated_info = RoutePeerInfo::new_updated_self(123, 456, &global_ctx, None);
|
|
|
|
// Verify IPv6 address is included
|
|
assert!(updated_info.ipv6_addr.is_some());
|
|
let ipv6_addr: Ipv6Addr = updated_info.ipv6_addr.unwrap().address.unwrap().into();
|
|
assert_eq!(ipv6_addr, ipv6_cidr.address());
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_peer_manager_ipv6() {
|
|
let global_ctx = get_mock_global_ctx();
|
|
let (packet_sender, _packet_receiver) = tokio::sync::mpsc::channel(100);
|
|
let peer_mgr = crate::peers::peer_manager::PeerManager::new(
|
|
RouteAlgoType::Ospf,
|
|
global_ctx.clone(),
|
|
packet_sender,
|
|
);
|
|
|
|
// Test IPv6 address lookup for unknown address
|
|
let ipv6_addr = Ipv6Addr::new(0xfd00, 0, 0, 0, 0, 0, 0, 2);
|
|
let (peers, _is_self) = peer_mgr.get_msg_dst_peer_ipv6(&ipv6_addr).await;
|
|
|
|
// Should return empty peers list for unknown IPv6
|
|
assert!(peers.is_empty());
|
|
}
|