Exercise signed LAN endpoints over isolated IPv6 interfaces

This commit is contained in:
evgeny committed 2026-10-25 18:06:46 +01:00
1 parent 1e89279860
commit e0cc25f93e
2 files changed
+18 -6

No files matched your search

+4 -3
View File
@@ -1,8 +1,9 @@
#!/bin/sh
# Изолированная IPv6-only LAN без default route. Namespace исчезает вместе с тестом.
# Изолированная IPv6-only LAN без default route. Необязательный аргумент — имя LAN-теста.
# Namespace исчезает вместе с тестом.
set -eu
if [ "${1:-}" != "--inside" ]; then
exec unshare --user --map-root-user --net --fork -- sh "$0" --inside
exec unshare --user --map-root-user --net --fork -- sh "$0" --inside "${1:-test_local_transport}"
fi
ip link set lo up
ip link add local-a type veth peer name local-b
@@ -12,4 +13,4 @@ ip link set local-a up
ip link set local-b up
ip -6 addr add fe80::1/64 dev local-a nodad
ip -6 addr add fe80::2/64 dev local-b nodad
exec "$(dirname "$0")/test_local_transport" --ipv6
exec "$(dirname "$0")/${2:-test_local_transport}" --ipv6
+14 -3
View File
@@ -22,6 +22,7 @@
#define REQUIRE(x) do { if (!(x)) { DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "line=%d failed: %s", __LINE__, #x); exit(1); } } while (0)
static uint32_t interface_index;
static int ipv6_only;
static struct UTUN_INSTANCE *a, *b;
static int corrupt_proof, suppress_routes, block_transport, proofs, challenges;
static struct captured {
@@ -33,7 +34,13 @@ static struct captured {
} proof;
/* Изолированный снимок LAN без привилегий network namespace. */
int __real_local_interfaces(struct local_interface*, size_t);
int __wrap_local_interfaces(struct local_interface* out, size_t capacity) {
if (ipv6_only) {
int count = __real_local_interfaces(out, capacity), used = 0;
for (int i = 0; i < count; i++) if (out[i].address.ss_family == AF_INET6) out[used++] = out[i];
return count < 0 ? count : used;
}
REQUIRE(capacity);
memset(out, 0, sizeof(*out)); out->index = interface_index; out->mask4 = htonl(0xff000000);
struct sockaddr_in* address = (struct sockaddr_in*)&out->address;
@@ -80,9 +87,11 @@ static int route(struct local_route* out) { return local_transport_route(a->loca
static struct UTUN_INSTANCE* create_core(struct UASYNC* ua, int tcp) {
char config[512];
const char* address = ipv6_only ? (a ? "[fe80::2%local-b]:0" : "[fe80::1%local-a]:0") : "127.0.0.1:0";
const char* netif = ipv6_only ? (a ? "netif=local-b\n" : "netif=local-a\n") : "";
snprintf(config, sizeof(config),
"[global]\nclient_type=1\nauto_sockets=no\nkeepalive_interval=100\n"
"[server: lan]\naddr=127.0.0.1:0\ntype=local\ntransport=%s\n[allowed_keys]\nallow_all=1\n", tcp ? "tcp" : "udp");
"[server: lan]\naddr=%s\n%stype=local\ntransport=%s\n[allowed_keys]\nallow_all=1\n", address, netif, tcp ? "tcp" : "udp");
struct UTUN_INSTANCE* inst = utun_instance_create_from_str(ua, config);
REQUIRE(inst && !utun_core_start(inst));
REQUIRE(inst->etcp_sockets && inst->etcp_sockets->generation);
@@ -151,12 +160,13 @@ static void bgp_gate(struct UASYNC* ua) {
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "PASS: live BGP intermediary blocks LAN update; stored DOWN path does not");
}
int main(void) {
int main(int argc, char** argv) {
debug_config_init(); debug_set_level(DEBUG_LEVEL_WARN);
debug_set_category_level(DEBUG_CATEGORY_DISCOVERY, DEBUG_LEVEL_DEBUG);
debug_set_category_level(DEBUG_CATEGORY_ETCP, DEBUG_LEVEL_INFO);
debug_set_category_level(DEBUG_CATEGORY_GENERAL, DEBUG_LEVEL_INFO);
test_clock_init(10000); interface_index = if_nametoindex("lo"); REQUIRE(interface_index);
ipv6_only = argc == 2 && !strcmp(argv[1], "--ipv6");
test_clock_init(10000); interface_index = if_nametoindex(ipv6_only ? "local-a" : "lo"); REQUIRE(interface_index);
struct UASYNC* ua = uasync_create(); REQUIRE(ua);
a = create_core(ua, 0); b = create_core(ua, 0);
REQUIRE(!chat_local_start(a) && !chat_local_start(b));
@@ -178,6 +188,7 @@ int main(void) {
REQUIRE(!local_transport_set_name(b->local_transport, "Valid endpoints"));
test_clock_run_for(ua, 10000); REQUIRE(route(&found));
REQUIRE(found.interface_index == interface_index && found.socket.protocol == LOCAL_ROUTE_UDP);
if (ipv6_only) REQUIRE(((struct sockaddr_in6*)&found.address)->sin6_scope_id == interface_index);
REQUIRE(found.socket.socket_id == b->etcp_sockets->sock_id && found.socket.generation == b->etcp_sockets->generation);
REQUIRE(ss_get_port(&found.address) == ss_get_port(&b->etcp_sockets->local_addr));
REQUIRE(proof.size == LOCAL_HEADER_SIZE + LOCAL_ROUTE_HEADER_SIZE + LOCAL_ROUTE_SOCKET_SIZE + 64);