2017-03-13 07:46:46 +00:00
|
|
|
package libnetwork
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/libnetwork/iptables"
|
2017-07-26 21:18:31 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-03-13 07:46:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const userChain = "DOCKER-USER"
|
|
|
|
|
2018-01-12 15:29:09 +00:00
|
|
|
func (c *controller) arrangeUserFilterRule() {
|
|
|
|
c.Lock()
|
2019-10-11 16:37:18 +00:00
|
|
|
arrangeUserFilterRule()
|
2018-01-12 15:29:09 +00:00
|
|
|
c.Unlock()
|
|
|
|
iptables.OnReloaded(func() {
|
|
|
|
c.Lock()
|
2019-10-11 16:37:18 +00:00
|
|
|
arrangeUserFilterRule()
|
2018-01-12 15:29:09 +00:00
|
|
|
c.Unlock()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-13 07:46:46 +00:00
|
|
|
// 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.
|
|
|
|
func arrangeUserFilterRule() {
|
|
|
|
_, err := iptables.NewChain(userChain, iptables.Filter, false)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Warnf("Failed to create %s chain: %v", userChain, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = iptables.AddReturnRule(userChain); err != nil {
|
|
|
|
logrus.Warnf("Failed to add the RETURN rule for %s: %v", userChain, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = iptables.EnsureJumpRule("FORWARD", userChain)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Warnf("Failed to ensure the jump rule for %s: %v", userChain, err)
|
|
|
|
}
|
|
|
|
}
|