diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-07-31 14:01:03 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-07-31 14:01:03 -0700 |
commit | b22c2ab1d769c65bdb8ec789668587559e98f1ae (patch) | |
tree | 172ee05cec57bb21bc594d3bf6316faeefbc5d2a /pkg/tcpip/stack/conntrack.go | |
parent | 8908baaf79fdd137241596fd2444828d1a33fe27 (diff) | |
parent | 2a7b2a61e3ea32129c26eeaa6fab3d81a5d8ad6e (diff) |
Merge pull request #3348 from kevinGC:so-orig-dst
PiperOrigin-RevId: 324279280
Diffstat (limited to 'pkg/tcpip/stack/conntrack.go')
-rw-r--r-- | pkg/tcpip/stack/conntrack.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/tcpip/stack/conntrack.go b/pkg/tcpip/stack/conntrack.go index 559a1c4dd..470c265aa 100644 --- a/pkg/tcpip/stack/conntrack.go +++ b/pkg/tcpip/stack/conntrack.go @@ -240,7 +240,10 @@ func (ct *ConnTrack) connFor(pkt *PacketBuffer) (*conn, direction) { if err != nil { return nil, dirOriginal } + return ct.connForTID(tid) +} +func (ct *ConnTrack) connForTID(tid tupleID) (*conn, direction) { bucket := ct.bucket(tid) now := time.Now() @@ -604,3 +607,26 @@ func (ct *ConnTrack) reapTupleLocked(tuple *tuple, bucket int, now time.Time) bo return true } + +func (ct *ConnTrack) originalDst(epID TransportEndpointID) (tcpip.Address, uint16, *tcpip.Error) { + // Lookup the connection. The reply's original destination + // describes the original address. + tid := tupleID{ + srcAddr: epID.LocalAddress, + srcPort: epID.LocalPort, + dstAddr: epID.RemoteAddress, + dstPort: epID.RemotePort, + transProto: header.TCPProtocolNumber, + netProto: header.IPv4ProtocolNumber, + } + conn, _ := ct.connForTID(tid) + if conn == nil { + // Not a tracked connection. + return "", 0, tcpip.ErrNotConnected + } else if conn.manip == manipNone { + // Unmanipulated connection. + return "", 0, tcpip.ErrInvalidOptionValue + } + + return conn.original.dstAddr, conn.original.dstPort, nil +} |