Skip to content

fix: propagate IPv6 scope_id through recv/bind paths (LAN-143) - #113

Merged
lance0 merged 1 commit into
masterfrom
fix/ipv6-scope-id
Jul 6, 2026
Merged

lance0 merged 1 commit into
masterfrom
fix/ipv6-scope-id

Conversation

@lance0

@lance0 lance0 commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes IPv6 link-local scope ID being dropped on receiving and binding (LAN-143).

Receiving

parse_sockaddr_storage now extracts sin6_scope_id from sockaddr_in6 and returns it alongside IpAddr. RecvResult carries the scope_id so link-local responders can be disambiguated by interface.

Binding

--source-ip now accepts IPv6 zone IDs (fe80::1%eth0 or fe80::1%5). The zone is resolved to a numeric scope_id via if_nametoindex (for interface names) or parsed directly (for numeric IDs). bind_to_source_ip and create_udp_dgram_socket_bound_full accept an optional scope_id and construct SocketAddrV6 for link-local binds.

Config

Config gains source_ip_scope_id: Option<u32>, threaded through the engine's ICMP, UDP, and TCP bind paths. CLI --source-ip is now Option<String> (was Option<IpAddr>) to accept zone syntax; the IP is parsed in validate().

Testing

  • All 577 tests pass (including 8 new tests)
  • cargo clippy --all-targets -- -D warnings clean
  • New tests:
    • test_parse_sockaddr_storage_ipv6_scope_id — link-local with scope_id=3
    • test_parse_sockaddr_storage_ipv6_no_scope_id — global IPv6, scope_id=None
    • test_parse_sockaddr_storage_ipv4 — IPv4, scope_id=None
    • test_source_ip_plain_ipv4 — plain IPv4, no zone
    • test_source_ip_plain_ipv6 — plain IPv6, no zone
    • test_source_ip_ipv6_numeric_scope — fe80::1%5 → scope_id=5
    • test_source_ip_invalid_ip — rejects bad IP
    • test_source_ip_invalid_zone_interface — rejects unknown interface name

Closes LAN-143.

Receiving: parse_sockaddr_storage now extracts sin6_scope_id from
sockaddr_in6 and returns it alongside IpAddr. RecvResult carries the
scope_id so link-local responders can be disambiguated by interface.

Binding: --source-ip now accepts IPv6 zone IDs (fe80::1%eth0 or
fe80::1%5). The zone is resolved to a numeric scope_id via
if_nametoindex (for interface names) or parsed directly (for numeric
IDs). bind_to_source_ip and create_udp_dgram_socket_bound_full accept
an optional scope_id and construct SocketAddrV6 for link-local binds.

Config gains source_ip_scope_id: Option<u32>, threaded through the
engine's ICMP, UDP, and TCP bind paths.

Closes LAN-143.
@lance0
lance0 merged commit 0ad9bc6 into master Jul 6, 2026
5 checks passed
@lance0
lance0 deleted the fix/ipv6-scope-id branch July 6, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant