summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/stack/iptables_state.go
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2020-07-13 11:59:26 -0700
committergVisor bot <gvisor-bot@google.com>2020-07-13 12:00:46 -0700
commit43c209f48e0aa9024705583cc6f0fafa7d6380ca (patch)
tree86d22b7950dfcefb07b4b4bc0bb8af7367bc655c /pkg/tcpip/stack/iptables_state.go
parent76b392bc262d5c0af10b3127b7aad85a4130da78 (diff)
garbage collect connections
As in Linux, we must periodically clean up unused connections. PiperOrigin-RevId: 321003353
Diffstat (limited to 'pkg/tcpip/stack/iptables_state.go')
-rw-r--r--pkg/tcpip/stack/iptables_state.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/pkg/tcpip/stack/iptables_state.go b/pkg/tcpip/stack/iptables_state.go
new file mode 100644
index 000000000..529e02a07
--- /dev/null
+++ b/pkg/tcpip/stack/iptables_state.go
@@ -0,0 +1,40 @@
+// Copyright 2020 The gVisor Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package stack
+
+import (
+ "time"
+)
+
+// +stateify savable
+type unixTime struct {
+ second int64
+ nano int64
+}
+
+// saveLastUsed is invoked by stateify.
+func (cn *conn) saveLastUsed() unixTime {
+ return unixTime{cn.lastUsed.Unix(), cn.lastUsed.UnixNano()}
+}
+
+// loadLastUsed is invoked by stateify.
+func (cn *conn) loadLastUsed(unix unixTime) {
+ cn.lastUsed = time.Unix(unix.second, unix.nano)
+}
+
+// beforeSave is invoked by stateify.
+func (ct *ConnTrack) beforeSave() {
+ ct.mu.Lock()
+}