mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #126 from mrjana/cnm_integ
Brought in iptables package from docker
This commit is contained in:
commit
7d99fcdadf
11 changed files with 46 additions and 31 deletions
5
libnetwork/Godeps/Godeps.json
generated
5
libnetwork/Godeps/Godeps.json
generated
|
@ -20,11 +20,6 @@
|
||||||
"Comment": "v1.4.1-3152-g3e85803",
|
"Comment": "v1.4.1-3152-g3e85803",
|
||||||
"Rev": "3e85803f311c3883a9b395ad046c894ea255e9be"
|
"Rev": "3e85803f311c3883a9b395ad046c894ea255e9be"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/docker/docker/pkg/iptables",
|
|
||||||
"Comment": "v1.4.1-3152-g3e85803",
|
|
||||||
"Rev": "3e85803f311c3883a9b395ad046c894ea255e9be"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/docker/docker/pkg/mflag",
|
"ImportPath": "github.com/docker/docker/pkg/mflag",
|
||||||
"Comment": "v1.4.1-3152-g3e85803",
|
"Comment": "v1.4.1-3152-g3e85803",
|
||||||
|
|
|
@ -7,8 +7,8 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/iptables"
|
|
||||||
"github.com/docker/libnetwork/netutils"
|
"github.com/docker/libnetwork/netutils"
|
||||||
|
"github.com/docker/libnetwork/pkg/iptables"
|
||||||
"github.com/docker/libnetwork/pkg/netlabel"
|
"github.com/docker/libnetwork/pkg/netlabel"
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/pkg/iptables"
|
|
||||||
"github.com/docker/libnetwork/netutils"
|
"github.com/docker/libnetwork/netutils"
|
||||||
|
"github.com/docker/libnetwork/pkg/iptables"
|
||||||
)
|
)
|
||||||
|
|
||||||
type link struct {
|
type link struct {
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/iptables"
|
|
||||||
"github.com/docker/libnetwork/netutils"
|
"github.com/docker/libnetwork/netutils"
|
||||||
|
"github.com/docker/libnetwork/pkg/iptables"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DockerChain: DOCKER iptable chain name
|
// DockerChain: DOCKER iptable chain name
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/iptables"
|
|
||||||
"github.com/docker/libnetwork/netutils"
|
"github.com/docker/libnetwork/netutils"
|
||||||
|
"github.com/docker/libnetwork/pkg/iptables"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -8,11 +8,15 @@ import (
|
||||||
"github.com/godbus/dbus"
|
"github.com/godbus/dbus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IPV defines the table string
|
||||||
type IPV string
|
type IPV string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// Iptables point ipv4 table
|
||||||
Iptables IPV = "ipv4"
|
Iptables IPV = "ipv4"
|
||||||
Ip6tables IPV = "ipv6"
|
// IP6tables point to ipv6 table
|
||||||
|
IP6tables IPV = "ipv6"
|
||||||
|
// Ebtables point to bridge table
|
||||||
Ebtables IPV = "eb"
|
Ebtables IPV = "eb"
|
||||||
)
|
)
|
||||||
const (
|
const (
|
||||||
|
@ -33,6 +37,7 @@ var (
|
||||||
onReloaded []*func() // callbacks when Firewalld has been reloaded
|
onReloaded []*func() // callbacks when Firewalld has been reloaded
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FirewalldInit initializes firewalld management code.
|
||||||
func FirewalldInit() {
|
func FirewalldInit() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -97,16 +102,16 @@ func signalHandler() {
|
||||||
|
|
||||||
func dbusConnectionChanged(args []interface{}) {
|
func dbusConnectionChanged(args []interface{}) {
|
||||||
name := args[0].(string)
|
name := args[0].(string)
|
||||||
old_owner := args[1].(string)
|
oldOwner := args[1].(string)
|
||||||
new_owner := args[2].(string)
|
newOwner := args[2].(string)
|
||||||
|
|
||||||
if name != dbusInterface {
|
if name != dbusInterface {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(new_owner) > 0 {
|
if len(newOwner) > 0 {
|
||||||
connectionEstablished()
|
connectionEstablished()
|
||||||
} else if len(old_owner) > 0 {
|
} else if len(oldOwner) > 0 {
|
||||||
connectionLost()
|
connectionLost()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,7 +131,7 @@ func reloaded() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add callback
|
// OnReloaded add callback
|
||||||
func OnReloaded(callback func()) {
|
func OnReloaded(callback func()) {
|
||||||
for _, pf := range onReloaded {
|
for _, pf := range onReloaded {
|
||||||
if pf == &callback {
|
if pf == &callback {
|
||||||
|
@ -150,7 +155,7 @@ func checkRunning() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Firewalld's passthrough method simply passes args through to iptables/ip6tables
|
// Passthrough method simply passes args through to iptables/ip6tables
|
||||||
func Passthrough(ipv IPV, args ...string) ([]byte, error) {
|
func Passthrough(ipv IPV, args ...string) ([]byte, error) {
|
||||||
var output string
|
var output string
|
||||||
|
|
|
@ -12,30 +12,42 @@ import (
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//Action signifies the iptable action.
|
||||||
type Action string
|
type Action string
|
||||||
|
|
||||||
|
//Table refers to Nat, Filter or Mangle.
|
||||||
type Table string
|
type Table string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
//Append appends the rule at the end of the chain.
|
||||||
Append Action = "-A"
|
Append Action = "-A"
|
||||||
|
//Delete deletes the rule from the chain.
|
||||||
Delete Action = "-D"
|
Delete Action = "-D"
|
||||||
|
//Insert inserts the rule at the top of the chain.
|
||||||
Insert Action = "-I"
|
Insert Action = "-I"
|
||||||
|
//Nat table is used for nat translation rules.
|
||||||
Nat Table = "nat"
|
Nat Table = "nat"
|
||||||
|
//Filter table is used for filter rules.
|
||||||
Filter Table = "filter"
|
Filter Table = "filter"
|
||||||
|
//Mangle table is used for mangling the packet.
|
||||||
Mangle Table = "mangle"
|
Mangle Table = "mangle"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
iptablesPath string
|
iptablesPath string
|
||||||
supportsXlock = false
|
supportsXlock = false
|
||||||
|
//ErrIptablesNotFound is returned when the rule is not found.
|
||||||
ErrIptablesNotFound = errors.New("Iptables not found")
|
ErrIptablesNotFound = errors.New("Iptables not found")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//Chain defines the iptables chain.
|
||||||
type Chain struct {
|
type Chain struct {
|
||||||
Name string
|
Name string
|
||||||
Bridge string
|
Bridge string
|
||||||
Table Table
|
Table Table
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ChainError is returned to represent errors during ip table operation.
|
||||||
type ChainError struct {
|
type ChainError struct {
|
||||||
Chain string
|
Chain string
|
||||||
Output []byte
|
Output []byte
|
||||||
|
@ -58,6 +70,7 @@ func initCheck() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//NewChain adds a new chain to ip table.
|
||||||
func NewChain(name, bridge string, table Table) (*Chain, error) {
|
func NewChain(name, bridge string, table Table) (*Chain, error) {
|
||||||
c := &Chain{
|
c := &Chain{
|
||||||
Name: name,
|
Name: name,
|
||||||
|
@ -113,6 +126,7 @@ func NewChain(name, bridge string, table Table) (*Chain, error) {
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//RemoveExistingChain removes existing chain from the table.
|
||||||
func RemoveExistingChain(name string, table Table) error {
|
func RemoveExistingChain(name string, table Table) error {
|
||||||
c := &Chain{
|
c := &Chain{
|
||||||
Name: name,
|
Name: name,
|
||||||
|
@ -124,7 +138,7 @@ func RemoveExistingChain(name string, table Table) error {
|
||||||
return c.Remove()
|
return c.Remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add forwarding rule to 'filter' table and corresponding nat rule to 'nat' table
|
//Forward adds forwarding rule to 'filter' table and corresponding nat rule to 'nat' table
|
||||||
func (c *Chain) Forward(action Action, ip net.IP, port int, proto, destAddr string, destPort int) error {
|
func (c *Chain) Forward(action Action, ip net.IP, port int, proto, destAddr string, destPort int) error {
|
||||||
daddr := ip.String()
|
daddr := ip.String()
|
||||||
if ip.IsUnspecified() {
|
if ip.IsUnspecified() {
|
||||||
|
@ -171,7 +185,7 @@ func (c *Chain) Forward(action Action, ip net.IP, port int, proto, destAddr stri
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add reciprocal ACCEPT rule for two supplied IP addresses.
|
//Link adds reciprocal ACCEPT rule for two supplied IP addresses.
|
||||||
// Traffic is allowed from ip1 to ip2 and vice-versa
|
// Traffic is allowed from ip1 to ip2 and vice-versa
|
||||||
func (c *Chain) Link(action Action, ip1, ip2 net.IP, port int, proto string) error {
|
func (c *Chain) Link(action Action, ip1, ip2 net.IP, port int, proto string) error {
|
||||||
if output, err := Raw("-t", string(Filter), string(action), c.Name,
|
if output, err := Raw("-t", string(Filter), string(action), c.Name,
|
||||||
|
@ -199,7 +213,7 @@ func (c *Chain) Link(action Action, ip1, ip2 net.IP, port int, proto string) err
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add linking rule to nat/PREROUTING chain.
|
//Prerouting adds linking rule to nat/PREROUTING chain.
|
||||||
func (c *Chain) Prerouting(action Action, args ...string) error {
|
func (c *Chain) Prerouting(action Action, args ...string) error {
|
||||||
a := []string{"-t", string(Nat), string(action), "PREROUTING"}
|
a := []string{"-t", string(Nat), string(action), "PREROUTING"}
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
|
@ -213,7 +227,7 @@ func (c *Chain) Prerouting(action Action, args ...string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add linking rule to an OUTPUT chain
|
//Output adds linking rule to an OUTPUT chain
|
||||||
func (c *Chain) Output(action Action, args ...string) error {
|
func (c *Chain) Output(action Action, args ...string) error {
|
||||||
a := []string{"-t", string(c.Table), string(action), "OUTPUT"}
|
a := []string{"-t", string(c.Table), string(action), "OUTPUT"}
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
|
@ -227,6 +241,7 @@ func (c *Chain) Output(action Action, args ...string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove removes the chain
|
||||||
func (c *Chain) Remove() error {
|
func (c *Chain) Remove() error {
|
||||||
// Ignore errors - This could mean the chains were never set up
|
// Ignore errors - This could mean the chains were never set up
|
||||||
if c.Table == Nat {
|
if c.Table == Nat {
|
||||||
|
@ -242,7 +257,7 @@ func (c *Chain) Remove() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a rule exists
|
//Exists checks if a rule exists
|
||||||
func Exists(table Table, chain string, rule ...string) bool {
|
func Exists(table Table, chain string, rule ...string) bool {
|
||||||
if string(table) == "" {
|
if string(table) == "" {
|
||||||
table = Filter
|
table = Filter
|
||||||
|
@ -273,7 +288,7 @@ func Exists(table Table, chain string, rule ...string) bool {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call 'iptables' system command, passing supplied arguments
|
//Raw calls 'iptables' system command, passing supplied arguments
|
||||||
func Raw(args ...string) ([]byte, error) {
|
func Raw(args ...string) ([]byte, error) {
|
||||||
if firewalldRunning {
|
if firewalldRunning {
|
||||||
output, err := Passthrough(Iptables, args...)
|
output, err := Passthrough(Iptables, args...)
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/pkg/iptables"
|
"github.com/docker/libnetwork/pkg/iptables"
|
||||||
"github.com/docker/libnetwork/pkg/portallocator"
|
"github.com/docker/libnetwork/pkg/portallocator"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/iptables"
|
"github.com/docker/libnetwork/pkg/iptables"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue