MCPcopy Create free account
hub / github.com/SamNet-dev/snix / flowKey

Method flowKey

core/engine/engine.go:138–158  ·  view source on GitHub ↗

flowKey returns the conntrack.Tuple (always oriented local→remote) and whether this packet is within our scope.

(dir platform.Direction, p pkt)

Source from the content-addressed store, hash-verified

136// flowKey returns the conntrack.Tuple (always oriented local→remote) and
137// whether this packet is within our scope.
138func (e *Engine) flowKey(dir platform.Direction, p pkt) (conntrack.Tuple, bool) {
139 sc := e.cfg.Scope
140 var localAddr, remoteAddr netip.Addr
141 var localPort, remotePort uint16
142 if dir == platform.DirOutbound {
143 localAddr, _ = netip.AddrFromSlice(p.srcIP[:])
144 remoteAddr, _ = netip.AddrFromSlice(p.dstIP[:])
145 localPort, remotePort = p.srcPort, p.dstPort
146 } else {
147 localAddr, _ = netip.AddrFromSlice(p.dstIP[:])
148 remoteAddr, _ = netip.AddrFromSlice(p.srcIP[:])
149 localPort, remotePort = p.dstPort, p.srcPort
150 }
151 if remoteAddr != sc.RemoteIP || remotePort != sc.RemotePort {
152 return conntrack.Tuple{}, false
153 }
154 return conntrack.Tuple{
155 SrcIP: localAddr, SrcPort: localPort,
156 DstIP: remoteAddr, DstPort: remotePort,
157 }, true
158}
159
160func (e *Engine) handleOutbound(key conntrack.Tuple, parsed pkt, p platform.Packet) {
161 switch {

Callers 1

dispatchMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected