Skip to content

Commit

Permalink
微调.
Browse files Browse the repository at this point in the history
  • Loading branch information
rui0572 authored and yuhan6665 committed Nov 12, 2023
1 parent 3da5998 commit 0499b5c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
25 changes: 25 additions & 0 deletions proxy/wireguard/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package wireguard

func (c *DeviceConfig) preferIP4() bool {
return c.DomainStrategy == DeviceConfig_FORCE_IP ||
c.DomainStrategy == DeviceConfig_FORCE_IP4 ||
c.DomainStrategy == DeviceConfig_FORCE_IP46
}

func (c *DeviceConfig) preferIP6() bool {
return c.DomainStrategy == DeviceConfig_FORCE_IP ||
c.DomainStrategy == DeviceConfig_FORCE_IP6 ||
c.DomainStrategy == DeviceConfig_FORCE_IP64
}

func (c *DeviceConfig) hasFallback() bool {
return c.DomainStrategy == DeviceConfig_FORCE_IP46 || c.DomainStrategy == DeviceConfig_FORCE_IP64
}

func (c *DeviceConfig) fallbackIP4() bool {
return c.DomainStrategy == DeviceConfig_FORCE_IP64
}

func (c *DeviceConfig) fallbackIP6() bool {
return c.DomainStrategy == DeviceConfig_FORCE_IP46
}
15 changes: 5 additions & 10 deletions proxy/wireguard/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,14 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
addr := destination.Address
if addr.Family().IsDomain() {
ips, err := h.dns.LookupIP(addr.Domain(), dns.IPOption{
IPv4Enable: h.hasIPv4 && (h.conf.DomainStrategy == DeviceConfig_FORCE_IP ||
h.conf.DomainStrategy == DeviceConfig_FORCE_IP4 ||
h.conf.DomainStrategy == DeviceConfig_FORCE_IP46),

IPv6Enable: h.hasIPv6 && (h.conf.DomainStrategy == DeviceConfig_FORCE_IP ||
h.conf.DomainStrategy == DeviceConfig_FORCE_IP6 ||
h.conf.DomainStrategy == DeviceConfig_FORCE_IP64),
IPv4Enable: h.hasIPv4 && h.conf.preferIP4(),
IPv6Enable: h.hasIPv6 && h.conf.preferIP6(),
})
{ // Resolve fallback
if (len(ips) == 0 || err != nil) && (h.conf.DomainStrategy == DeviceConfig_FORCE_IP46 || h.conf.DomainStrategy == DeviceConfig_FORCE_IP64) {
if (len(ips) == 0 || err != nil) && h.conf.hasFallback() {
ips, err = h.dns.LookupIP(addr.Domain(), dns.IPOption{
IPv4Enable: h.hasIPv4 && h.conf.DomainStrategy != DeviceConfig_FORCE_IP46,
IPv6Enable: h.hasIPv6 && h.conf.DomainStrategy != DeviceConfig_FORCE_IP64,
IPv4Enable: h.hasIPv4 && h.conf.fallbackIP4(),
IPv6Enable: h.hasIPv6 && h.conf.fallbackIP6(),
})
}
}
Expand Down

0 comments on commit 0499b5c

Please sign in to comment.