Skip to content

Commit

Permalink
intra/udp: fix flipped pid and cid vars
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Jan 22, 2024
1 parent 71d2126 commit 72eb7e4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion intra/icmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (h *icmpHandler) onFlow(source *net.UDPAddr, target *net.UDPAddr, realips,
// todo: handle forwarding icmp to appropriate proxy?
res := h.listener.Flow(proto, uid, src, dst, realips, domains, probableDomains, blocklists)

pid, cid, _ = splitPidCidUid(res)
cid, pid, _ = splitCidPidUid(res)
block = pid == ipn.Block
return
}
Expand Down
6 changes: 3 additions & 3 deletions intra/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (h *tcpHandler) Proxy(gconn *netstack.GTCPConn, src, target *net.TCPAddr) (
// nat-ed ips just fine, and so, use target as-is instead of ipx4
res := h.onFlow(src, target, realips, domains, probableDomains, blocklists)

pid, cid, uid := splitPidCidUid(res)
cid, pid, uid := splitCidPidUid(res)
s := tcpSummary(cid, pid, uid)

defer func() {
Expand Down Expand Up @@ -482,9 +482,9 @@ func undoAlg(r dnsx.Resolver, algip net.IP) (realips, domains, probableDomains,
}

// returns proxy-id, conn-id, user-id
func splitPidCidUid(decision *Mark) (pid, cid, uid string) {
func splitCidPidUid(decision *Mark) (cid, pid, uid string) {
if decision == nil {
return
}
return decision.PID, decision.CID, decision.UID
return decision.CID, decision.PID, decision.UID
}
11 changes: 7 additions & 4 deletions intra/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (h *udpHandler) Connect(src core.UDPConn, target *net.UDPAddr) (nat *tracke

// flow is alg/nat-aware, do not change target or any addrs
res := h.onFlow(src, target, realips, domains, probableDomains, blocklists)
nat = makeTracker(splitPidCidUid(res))
nat = makeTracker(splitCidPidUid(res))
h.track(src, nat)

defer func() {
Expand Down Expand Up @@ -597,11 +597,14 @@ func (h *udpHandler) Close(conn core.UDPConn, secs int32) {
return
}

log.V("udp: closing conn [%v -> %v]", conn.LocalAddr(), conn.RemoteAddr())
local := conn.LocalAddr()
remote := conn.RemoteAddr()
t, _ := h.probe(conn)
conn.Close()

t, ok := h.probe(conn)
if ok {
log.V("udp: close conn [%v -> %v]; tracked? %t", local, remote, t != nil)

if t != nil {
go h.untrack(conn, t)

if t.connected() {
Expand Down

0 comments on commit 72eb7e4

Please sign in to comment.