1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #2339 from phyber/iptables-check

controller: Check if IPTables is enabled for arrangeUserFilterRule
This commit is contained in:
Euan Harris 2019-06-21 17:31:52 +01:00 committed by GitHub
commit 8d76333719

View file

@ -2,6 +2,7 @@ package libnetwork
import ( import (
"github.com/docker/libnetwork/iptables" "github.com/docker/libnetwork/iptables"
"github.com/docker/libnetwork/netlabel"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -9,15 +10,44 @@ const userChain = "DOCKER-USER"
func (c *controller) arrangeUserFilterRule() { func (c *controller) arrangeUserFilterRule() {
c.Lock() c.Lock()
if c.hasIPTablesEnabled() {
arrangeUserFilterRule() arrangeUserFilterRule()
}
c.Unlock() c.Unlock()
iptables.OnReloaded(func() { iptables.OnReloaded(func() {
c.Lock() c.Lock()
if c.hasIPTablesEnabled() {
arrangeUserFilterRule() arrangeUserFilterRule()
}
c.Unlock() 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 // 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 // docker operations/restarts. Docker will not delete or modify any pre-existing
// rules from the DOCKER-USER filter chain. // rules from the DOCKER-USER filter chain.