Skip to content

Commit b6555c3

Browse files
committed
tcp,udp: incl one other family ip in retries
1 parent 92950f2 commit b6555c3

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

intra/common.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,15 @@ func (h *baseHandler) undoAlg(algip netip.Addr, uid string) (undidAlg bool, real
589589
return
590590
}
591591

592+
func filterFamilyForDialingWithFailSafe(ipcsv string) (included []netip.Addr, excluded []netip.Addr, excludedIsIncluded bool) {
593+
included, excluded, excludedIsIncluded = filterFamilyForDialing(ipcsv)
594+
if (!excludedIsIncluded || len(excluded) > 0) && len(included) > 0 {
595+
// if not falling back, then include one excluded ip as a fail-safe
596+
included = append(included, core.ChooseOne(excluded))
597+
}
598+
return included, excluded, excludedIsIncluded
599+
}
600+
592601
// filterFamilyForDialing filters out invalid IPs and IPs that are not
593602
// of the family that the dialer is configured to use.
594603
func filterFamilyForDialing(ipcsv string) (included []netip.Addr, excluded []netip.Addr, excludedIsIncluded bool) {
@@ -607,11 +616,11 @@ func filterFamilyForDialing(ipcsv string) (included []netip.Addr, excluded []net
607616
invalids++
608617
continue
609618
}
610-
// always include unspecified IPs as it is used by the client
611-
// to make block/no-block decisions
612-
if ip.IsUnspecified() || use4 && ip.Is4() || use6 && ip.Is6() {
619+
// TODO: always include unspecified IPs as it is used by the client to make block/no-block decisions?
620+
// The above is not true anymore?
621+
if use4 && ip.Is4() || use6 && ip.Is6() {
613622
filtered = append(filtered, ip)
614-
} else {
623+
} else if ip.IsValid() && !ip.IsUnspecified() {
615624
unfiltered = append(unfiltered, ip)
616625
}
617626
}

intra/tcp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func (h *tcpHandler) Proxy(gconn *netstack.GTCPConn, src, target netip.AddrPort)
260260
h.maybeReplaceDest(res, &target)
261261

262262
// TODO: use res.IP only if set
263-
filtered, excluded, fallingback := filterFamilyForDialing(realips)
263+
filtered, excluded, fallingback := filterFamilyForDialingWithFailSafe(realips)
264264
actualTargets := makeIPPorts(filtered, target, !undidAlg, 0)
265265
cid, uid, fid, pids := h.judge(res, domains, target.String())
266266

intra/udp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (h *udpHandler) Connect(gconn *netstack.GUDPConn, src, target netip.AddrPor
199199

200200
h.maybeReplaceDest(res, &target)
201201

202-
filtered, _, fallingback := filterFamilyForDialing(realips)
202+
filtered, _, fallingback := filterFamilyForDialingWithFailSafe(realips)
203203
actualTargets := makeIPPorts(filtered, target, !undidAlg, 0)
204204
cid, uid, fid, pids := h.judge(res, domains, target.String())
205205

0 commit comments

Comments
 (0)