Skip to content

Commit 4bc6af3

Browse files
committed
tcp,udp,icmp: force use ipn.[Base|Exit] for firestack's own egress
1 parent 01ee3bf commit 4bc6af3

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

intra/common.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,24 @@ func (h *baseHandler) onFlow(localaddr, target netip.AddrPort) (fm *Mark, undidA
225225
log.W("com: %s: onFlow: empty res or on flow timeout %t; block!", h.proto, ok)
226226
fm = optionsBlock
227227
} else if len(fm.PIDCSV) <= 0 {
228-
log.E("com: %s: onFlow: no pid for (%s => %s) from kt (alg: %v + %v); exit!", h.proto, src, dst, ips, doms)
229-
fm.PIDCSV = ipn.Exit
228+
if pre.IsUidSelf {
229+
fm.PIDCSV = ipn.Exit
230+
} else if h.prox.AutoActive() {
231+
fm.PIDCSV = ipn.Auto
232+
} else {
233+
fm.PIDCSV = ipn.Exit
234+
}
235+
log.E("com: %s: onFlow: no pid for (%s => %s) from kt (alg: %v + %v); %s!",
236+
h.proto, src, dst, ips, doms, fm.PIDCSV)
237+
}
238+
if pre.IsUidSelf && !ipn.IsAnyLocalProxy(strings.Split(fm.PIDCSV, ",")...) {
239+
egress := ipn.Exit
240+
if h.resolver.IsDnsAddr(target) {
241+
egress = ipn.Base // see: udp.go:dnsOverride
242+
}
243+
log.W("com: %s: onFlow: preflow: pid (%s => %s) is rethink! override %s to %s!",
244+
h.proto, src, dst, fm.PIDCSV, egress)
245+
fm.PIDCSV = egress
230246
}
231247

232248
return

intra/ipn/proxies.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,15 @@ func isWG(id string) bool {
14741474
return strings.Contains(id, WG)
14751475
}
14761476

1477+
func IsAnyLocalProxy(ids ...string) bool {
1478+
for _, id := range ids {
1479+
if local(id) {
1480+
return true
1481+
}
1482+
}
1483+
return false
1484+
}
1485+
14771486
// Base, Block, Exit, Rpn64, Ingress
14781487
func local(id string) bool {
14791488
return id == Base || id == Block || id == Exit || id == Rpn64 || id == Ingress

0 commit comments

Comments
 (0)