Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S/R iptables #11368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/tcpip/stack/conntrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ type ConnTrack struct {

// clock provides timing used to determine conntrack reapings.
clock tcpip.Clock
// TODO(b/341946753): Restore when netstack is savable.

rand *rand.Rand `state:"nosave"`

mu connTrackRWMutex `state:"nosave"`
Expand Down
19 changes: 11 additions & 8 deletions pkg/tcpip/stack/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package stack

import (
"context"
"fmt"
"math/rand"
"reflect"
Expand Down Expand Up @@ -606,15 +605,19 @@ func (it *IPTables) check(table Table, hook Hook, pkt *PacketBuffer, r *Route, a

// beforeSave is invoked by stateify.
func (it *IPTables) beforeSave() {
// Ensure the reaper exits cleanly.
it.reaper.Stop()
// Prevent others from modifying the connection table.
it.connections.mu.Lock()
if it.reaper != nil {
// Ensure the reaper exits cleanly.
it.reaper.Stop()
}
}

// afterLoad is invoked by stateify.
func (it *IPTables) afterLoad(context.Context) {
it.startReaper(reaperDelay)
func (it *IPTables) Resume() {
it.mu.Lock()
defer it.mu.Unlock()

if it.modified {
it.startReaper(reaperDelay)
}
}

// startReaper periodically reaps timed out connections.
Expand Down
2 changes: 1 addition & 1 deletion pkg/tcpip/stack/iptables_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const (
type IPTables struct {
connections ConnTrack

reaper tcpip.Timer
reaper tcpip.Timer `state:"nosave"`

mu ipTablesRWMutex `state:"nosave"`
// v4Tables and v6tables map tableIDs to tables. They hold builtin
Expand Down
1 change: 1 addition & 0 deletions pkg/tcpip/stack/save_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ import (
func (s *Stack) afterLoad(context.Context) {
s.insecureRNG = rand.New(rand.NewSource(time.Now().UnixNano()))
s.secureRNG = cryptorand.RNGFrom(cryptorand.Reader)
s.tables.connections.rand = s.insecureRNG
}
5 changes: 3 additions & 2 deletions pkg/tcpip/stack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ type Stack struct {
handleLocal bool

// tables are the iptables packet filtering and manipulation rules.
// TODO(gvisor.dev/issue/4595): S/R this field.
tables *IPTables `state:"nosave"`
tables *IPTables

// restoredEndpoints is a list of endpoints that need to be restored if the
// stack is being restored.
Expand Down Expand Up @@ -2005,6 +2004,7 @@ func (s *Stack) Restore() {
eps := s.restoredEndpoints
s.restoredEndpoints = nil
saveRestoreEnabled := s.saveRestoreEnabled
s.tables.Resume()
s.mu.Unlock()
for _, e := range eps {
e.Restore(s)
Expand All @@ -2024,6 +2024,7 @@ func (s *Stack) Resume() {
s.mu.Lock()
eps := s.resumableEndpoints
s.resumableEndpoints = nil
s.tables.Resume()
s.mu.Unlock()
for _, e := range eps {
e.Resume()
Expand Down
Loading