diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-03-11 18:13:46 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-03-11 18:13:46 +0000 |
commit | 858e180272d709c91dabe23745a9b4d5bd537c31 (patch) | |
tree | 1c19c3d92e2fec98dddab4ba351fc70678e3a50d /pkg/tcpip/iptables/iptables.go | |
parent | 30c6814d44a4c8bba7905bd1da1d9da3e5939bf1 (diff) | |
parent | 2c2622b9428672de8032e1ff3c28283327ba158e (diff) |
Merge release-20200219.0-145-g2c2622b (automated)
Diffstat (limited to 'pkg/tcpip/iptables/iptables.go')
-rw-r--r-- | pkg/tcpip/iptables/iptables.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/pkg/tcpip/iptables/iptables.go b/pkg/tcpip/iptables/iptables.go index dbaccbb36..2ab9e0675 100644 --- a/pkg/tcpip/iptables/iptables.go +++ b/pkg/tcpip/iptables/iptables.go @@ -135,6 +135,27 @@ func EmptyFilterTable() Table { } } +// EmptyNatTable returns a Table with no rules and the filter table chains +// mapped to HookUnset. +func EmptyNatTable() Table { + return Table{ + Rules: []Rule{}, + BuiltinChains: map[Hook]int{ + Prerouting: HookUnset, + Input: HookUnset, + Output: HookUnset, + Postrouting: HookUnset, + }, + Underflows: map[Hook]int{ + Prerouting: HookUnset, + Input: HookUnset, + Output: HookUnset, + Postrouting: HookUnset, + }, + UserChains: map[string]int{}, + } +} + // A chainVerdict is what a table decides should be done with a packet. type chainVerdict int @@ -240,6 +261,12 @@ func (it *IPTables) checkChain(hook Hook, pkt tcpip.PacketBuffer, table Table, r func (it *IPTables) checkRule(hook Hook, pkt tcpip.PacketBuffer, table Table, ruleIdx int) (RuleVerdict, int) { rule := table.Rules[ruleIdx] + // If pkt.NetworkHeader hasn't been set yet, it will be contained in + // pkt.Data.First(). + if pkt.NetworkHeader == nil { + pkt.NetworkHeader = pkt.Data.First() + } + // First check whether the packet matches the IP header filter. // TODO(gvisor.dev/issue/170): Support other fields of the filter. if rule.Filter.Protocol != 0 && rule.Filter.Protocol != header.IPv4(pkt.NetworkHeader).TransportProtocol() { |