Skip to content

Commit

Permalink
Move hasIPTablesEnabled check into firewall_linux.go
Browse files Browse the repository at this point in the history
  • Loading branch information
phyber committed Apr 29, 2019
1 parent 5e34060 commit eb0c593
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
27 changes: 1 addition & 26 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,29 +679,6 @@ func (c *controller) isAgent() bool {
return c.cfg.Daemon.ClusterProvider.IsAgent()
}

func (c *controller) hasIPTablesEnabled() bool {
c.Lock()
defer c.Unlock()

if c.cfg == nil || c.cfg.Daemon.DriverCfg[netlabel.GenericData] == nil {
return false
}

genericData, ok := c.cfg.Daemon.DriverCfg[netlabel.GenericData]
if !ok {
return false
}

optMap := genericData.(map[string]interface{})

enabled, ok := optMap["EnableIPTables"].(bool)
if !ok {
return false
}

return enabled
}

func (c *controller) isDistributedControl() bool {
return !c.isManager() && !c.isAgent()
}
Expand Down Expand Up @@ -925,9 +902,7 @@ addToStore:
c.Unlock()
}

if c.hasIPTablesEnabled() {
c.arrangeUserFilterRule()
}
c.arrangeUserFilterRule()

return network, nil
}
Expand Down
34 changes: 32 additions & 2 deletions firewall_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,52 @@ package libnetwork

import (
"github.com/docker/libnetwork/iptables"
"github.com/docker/libnetwork/netlabel"
"github.com/sirupsen/logrus"
)

const userChain = "DOCKER-USER"

func (c *controller) arrangeUserFilterRule() {
c.Lock()
arrangeUserFilterRule()

if c.hasIPTablesEnabled() {
arrangeUserFilterRule()
}

c.Unlock()

iptables.OnReloaded(func() {
c.Lock()
arrangeUserFilterRule()

if c.hasIPTablesEnabled() {
arrangeUserFilterRule()
}

c.Unlock()
})
}

func (c *controller) hasIPTablesEnabled() bool {
// Locking c should be handled in the calling method.
if c.cfg == nil || c.cfg.Daemon.DriverCfg[netlabel.GenericData] == nil {
return false
}

genericData, ok := c.cfg.Daemon.DriverCfg[netlabel.GenericData]
if !ok {
return false
}

optMap := genericData.(map[string]interface{})
enabled, ok := optMap["EnableIPTables"].(bool)
if !ok {
return false
}

return enabled
}

// This chain allow users to configure firewall policies in a way that persists
// docker operations/restarts. Docker will not delete or modify any pre-existing
// rules from the DOCKER-USER filter chain.
Expand Down

0 comments on commit eb0c593

Please sign in to comment.