firewall_linux.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package libnetwork
  2. import (
  3. "github.com/docker/docker/libnetwork/iptables"
  4. "github.com/sirupsen/logrus"
  5. )
  6. const userChain = "DOCKER-USER"
  7. var ctrl *controller
  8. func setupArrangeUserFilterRule(c *controller) {
  9. ctrl = c
  10. iptables.OnReloaded(arrangeUserFilterRule)
  11. }
  12. // This chain allow users to configure firewall policies in a way that persists
  13. // docker operations/restarts. Docker will not delete or modify any pre-existing
  14. // rules from the DOCKER-USER filter chain.
  15. // Note once DOCKER-USER chain is created, docker engine does not remove it when
  16. // IPTableForwarding is disabled, because it contains rules configured by user that
  17. // are beyond docker engine's control.
  18. func arrangeUserFilterRule() {
  19. if ctrl == nil || !ctrl.iptablesEnabled() {
  20. return
  21. }
  22. // TODO IPv6 support
  23. iptable := iptables.GetIptable(iptables.IPv4)
  24. _, err := iptable.NewChain(userChain, iptables.Filter, false)
  25. if err != nil {
  26. logrus.Warnf("Failed to create %s chain: %v", userChain, err)
  27. return
  28. }
  29. if err = iptable.AddReturnRule(userChain); err != nil {
  30. logrus.Warnf("Failed to add the RETURN rule for %s: %v", userChain, err)
  31. return
  32. }
  33. err = iptable.EnsureJumpRule("FORWARD", userChain)
  34. if err != nil {
  35. logrus.Warnf("Failed to ensure the jump rule for %s: %v", userChain, err)
  36. }
  37. }