mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-18 19:15:03 +03:00
feat(amneziawg): restore per-client public IPv6 identity (Phase 3.5)
Adds internal/amneziawg.FirstIPv6 and a new internal/amneziawgnet/v6alias.go that aliases each IPv6-enabled peer's own address onto the host NIC (ip -6 addr add), wired into the Manager's Ensure/Remove/Reconcile/StopAll lifecycle. internal/web/service/xray.go's new injectAmneziawgV6Egress gives each such peer a dedicated freedom outbound (sendThrough) plus a routing rule matching its own email, so its outbound connections carry a distinct public source address again -- restoring what the embedded-architecture hard cutover temporarily dropped. Scoped to outbound source identity only (not unsolicited inbound/port-forwarding, which stays the separate Phase 3.6); no frontend changes needed since IPv6Enabled/IPv6ExternalInterface were already in the UI and per-peer opt-in is just an IPv6 AllowedIPs entry, same as today.
This commit is contained in:
@@ -141,3 +141,26 @@ func FirstIPv4(allowedIPs []string) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// FirstIPv6 returns the first IPv6 address (mask stripped) among allowedIPs,
|
||||
// or "" if none — the IPv6 counterpart of FirstIPv4, used by
|
||||
// internal/amneziawgnet's IPv6-address-alias mechanism to find which
|
||||
// address, if any, a peer wants aliased onto the host, and by
|
||||
// internal/web/service/xray.go's injectAmneziawgV6Egress to build that
|
||||
// peer's own freedom outbound (sendThrough). Only the first match is
|
||||
// returned, exactly like FirstIPv4 — more than one IPv6 AllowedIPs entry
|
||||
// per peer is not a supported configuration for either feature.
|
||||
func FirstIPv6(allowedIPs []string) string {
|
||||
for _, a := range allowedIPs {
|
||||
if prefix, err := netip.ParsePrefix(a); err == nil {
|
||||
if prefix.Addr().Is6() && !prefix.Addr().Is4In6() {
|
||||
return prefix.Addr().String()
|
||||
}
|
||||
continue
|
||||
}
|
||||
if addr, err := netip.ParseAddr(a); err == nil && addr.Is6() && !addr.Is4In6() {
|
||||
return addr.String()
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user