diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-06-19 02:49:06 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-06-19 02:49:06 +0000 |
commit | ea05bb1ce68abd67d6bb7b36b58f8ee43f4d5405 (patch) | |
tree | 169f5e6dbf58a7c3a36795cddeffeecd7cf11d91 /pkg/tcpip/stack/iptables.go | |
parent | 3bff8759da51739080475f03d0da29423182bb0e (diff) | |
parent | 0c169b6ad598200a57db7bf0f679da1d6cb395c4 (diff) |
Merge release-20200608.0-88-g0c169b6ad (automated)
Diffstat (limited to 'pkg/tcpip/stack/iptables.go')
-rw-r--r-- | pkg/tcpip/stack/iptables.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/pkg/tcpip/stack/iptables.go b/pkg/tcpip/stack/iptables.go index dc2b77c9d..62d4eb1b6 100644 --- a/pkg/tcpip/stack/iptables.go +++ b/pkg/tcpip/stack/iptables.go @@ -170,6 +170,7 @@ func (it *IPTables) GetTable(name string) (Table, bool) { func (it *IPTables) ReplaceTable(name string, table Table) { it.mu.Lock() defer it.mu.Unlock() + it.modified = true it.tables[name] = table } @@ -201,6 +202,15 @@ const ( // // Precondition: pkt.NetworkHeader is set. func (it *IPTables) Check(hook Hook, pkt *PacketBuffer, gso *GSO, r *Route, address tcpip.Address, nicName string) bool { + // Many users never configure iptables. Spare them the cost of rule + // traversal if rules have never been set. + it.mu.RLock() + if !it.modified { + it.mu.RUnlock() + return true + } + it.mu.RUnlock() + // Packets are manipulated only if connection and matching // NAT rule exists. it.connections.HandlePacket(pkt, hook, gso, r) |