commit
3819ef7e86
2
go.mod
2
go.mod
@ -8,7 +8,7 @@ require (
|
|||||||
github.com/alexflint/go-filemutex v0.0.0-20171022225611-72bdc8eae2ae
|
github.com/alexflint/go-filemutex v0.0.0-20171022225611-72bdc8eae2ae
|
||||||
github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44
|
github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44
|
||||||
github.com/containernetworking/cni v0.8.0
|
github.com/containernetworking/cni v0.8.0
|
||||||
github.com/coreos/go-iptables v0.4.5
|
github.com/coreos/go-iptables v0.5.0
|
||||||
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7
|
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7
|
||||||
github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c
|
github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c
|
||||||
github.com/d2g/dhcp4client v1.0.0
|
github.com/d2g/dhcp4client v1.0.0
|
||||||
|
4
go.sum
4
go.sum
@ -8,8 +8,8 @@ github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44 h1:y853v6rXx+zefE
|
|||||||
github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
|
github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
|
||||||
github.com/containernetworking/cni v0.8.0 h1:BT9lpgGoH4jw3lFC7Odz2prU5ruiYKcgAjMCbgybcKI=
|
github.com/containernetworking/cni v0.8.0 h1:BT9lpgGoH4jw3lFC7Odz2prU5ruiYKcgAjMCbgybcKI=
|
||||||
github.com/containernetworking/cni v0.8.0/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
|
github.com/containernetworking/cni v0.8.0/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
|
||||||
github.com/coreos/go-iptables v0.4.5 h1:DpHb9vJrZQEFMcVLFKAAGMUVX0XoRC0ptCthinRYm38=
|
github.com/coreos/go-iptables v0.5.0 h1:mw6SAibtHKZcNzAsOxjoHIG0gy5YFHhypWSSNc6EjbQ=
|
||||||
github.com/coreos/go-iptables v0.4.5/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmekav8Dbxlm1MU=
|
github.com/coreos/go-iptables v0.5.0/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmekav8Dbxlm1MU=
|
||||||
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7 h1:u9SHYsPQNyt5tgDm3YN7+9dYrpK96E5wFilTFWIDZOM=
|
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7 h1:u9SHYsPQNyt5tgDm3YN7+9dYrpK96E5wFilTFWIDZOM=
|
||||||
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||||
github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c h1:Xo2rK1pzOm0jO6abTPIQwbAmqBIOj132otexc1mmzFc=
|
github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c h1:Xo2rK1pzOm0jO6abTPIQwbAmqBIOj132otexc1mmzFc=
|
||||||
|
112
vendor/github.com/coreos/go-iptables/iptables/iptables.go
generated
vendored
112
vendor/github.com/coreos/go-iptables/iptables/iptables.go
generated
vendored
@ -31,7 +31,6 @@ type Error struct {
|
|||||||
exec.ExitError
|
exec.ExitError
|
||||||
cmd exec.Cmd
|
cmd exec.Cmd
|
||||||
msg string
|
msg string
|
||||||
proto Protocol
|
|
||||||
exitStatus *int //for overriding
|
exitStatus *int //for overriding
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,9 +50,8 @@ func (e *Error) IsNotExist() bool {
|
|||||||
if e.ExitStatus() != 1 {
|
if e.ExitStatus() != 1 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
cmdIptables := getIptablesCommand(e.proto)
|
msgNoRuleExist := "Bad rule (does a matching rule exist in that chain?).\n"
|
||||||
msgNoRuleExist := fmt.Sprintf("%s: Bad rule (does a matching rule exist in that chain?).\n", cmdIptables)
|
msgNoChainExist := "No chain/target/match by that name.\n"
|
||||||
msgNoChainExist := fmt.Sprintf("%s: No chain/target/match by that name.\n", cmdIptables)
|
|
||||||
return strings.Contains(e.msg, msgNoRuleExist) || strings.Contains(e.msg, msgNoChainExist)
|
return strings.Contains(e.msg, msgNoRuleExist) || strings.Contains(e.msg, msgNoChainExist)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +73,7 @@ type IPTables struct {
|
|||||||
v2 int
|
v2 int
|
||||||
v3 int
|
v3 int
|
||||||
mode string // the underlying iptables operating mode, e.g. nf_tables
|
mode string // the underlying iptables operating mode, e.g. nf_tables
|
||||||
|
timeout int // time to wait for the iptables lock, default waits forever
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stat represents a structured statistic entry.
|
// Stat represents a structured statistic entry.
|
||||||
@ -91,19 +90,42 @@ type Stat struct {
|
|||||||
Options string `json:"options"`
|
Options string `json:"options"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new IPTables.
|
type option func(*IPTables)
|
||||||
// For backwards compatibility, this always uses IPv4, i.e. "iptables".
|
|
||||||
func New() (*IPTables, error) {
|
func IPFamily(proto Protocol) option {
|
||||||
return NewWithProtocol(ProtocolIPv4)
|
return func(ipt *IPTables) {
|
||||||
|
ipt.proto = proto
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new IPTables for the given proto.
|
func Timeout(timeout int) option {
|
||||||
// The proto will determine which command is used, either "iptables" or "ip6tables".
|
return func(ipt *IPTables) {
|
||||||
func NewWithProtocol(proto Protocol) (*IPTables, error) {
|
ipt.timeout = timeout
|
||||||
path, err := exec.LookPath(getIptablesCommand(proto))
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates a new IPTables configured with the options passed as parameter.
|
||||||
|
// For backwards compatibility, by default always uses IPv4 and timeout 0.
|
||||||
|
// i.e. you can create an IPv6 IPTables using a timeout of 5 seconds passing
|
||||||
|
// the IPFamily and Timeout options as follow:
|
||||||
|
// ip6t := New(IPFamily(ProtocolIPv6), Timeout(5))
|
||||||
|
func New(opts ...option) (*IPTables, error) {
|
||||||
|
|
||||||
|
ipt := &IPTables{
|
||||||
|
proto: ProtocolIPv4,
|
||||||
|
timeout: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(ipt)
|
||||||
|
}
|
||||||
|
|
||||||
|
path, err := exec.LookPath(getIptablesCommand(ipt.proto))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
ipt.path = path
|
||||||
|
|
||||||
vstring, err := getIptablesVersionString(path)
|
vstring, err := getIptablesVersionString(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not get iptables version: %v", err)
|
return nil, fmt.Errorf("could not get iptables version: %v", err)
|
||||||
@ -112,21 +134,23 @@ func NewWithProtocol(proto Protocol) (*IPTables, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to extract iptables version from [%s]: %v", vstring, err)
|
return nil, fmt.Errorf("failed to extract iptables version from [%s]: %v", vstring, err)
|
||||||
}
|
}
|
||||||
|
ipt.v1 = v1
|
||||||
|
ipt.v2 = v2
|
||||||
|
ipt.v3 = v3
|
||||||
|
ipt.mode = mode
|
||||||
|
|
||||||
checkPresent, waitPresent, randomFullyPresent := getIptablesCommandSupport(v1, v2, v3)
|
checkPresent, waitPresent, randomFullyPresent := getIptablesCommandSupport(v1, v2, v3)
|
||||||
|
ipt.hasCheck = checkPresent
|
||||||
|
ipt.hasWait = waitPresent
|
||||||
|
ipt.hasRandomFully = randomFullyPresent
|
||||||
|
|
||||||
ipt := IPTables{
|
return ipt, nil
|
||||||
path: path,
|
}
|
||||||
proto: proto,
|
|
||||||
hasCheck: checkPresent,
|
// New creates a new IPTables for the given proto.
|
||||||
hasWait: waitPresent,
|
// The proto will determine which command is used, either "iptables" or "ip6tables".
|
||||||
hasRandomFully: randomFullyPresent,
|
func NewWithProtocol(proto Protocol) (*IPTables, error) {
|
||||||
v1: v1,
|
return New(IPFamily(proto), Timeout(0))
|
||||||
v2: v2,
|
|
||||||
v3: v3,
|
|
||||||
mode: mode,
|
|
||||||
}
|
|
||||||
return &ipt, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proto returns the protocol used by this IPTables.
|
// Proto returns the protocol used by this IPTables.
|
||||||
@ -185,6 +209,14 @@ func (ipt *IPTables) Delete(table, chain string, rulespec ...string) error {
|
|||||||
return ipt.run(cmd...)
|
return ipt.run(cmd...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ipt *IPTables) DeleteIfExists(table, chain string, rulespec ...string) error {
|
||||||
|
exists, err := ipt.Exists(table, chain, rulespec...)
|
||||||
|
if err == nil && exists {
|
||||||
|
err = ipt.Delete(table, chain, rulespec...)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// List rules in specified table/chain
|
// List rules in specified table/chain
|
||||||
func (ipt *IPTables) List(table, chain string) ([]string, error) {
|
func (ipt *IPTables) List(table, chain string) ([]string, error) {
|
||||||
args := []string{"-t", table, "-S", chain}
|
args := []string{"-t", table, "-S", chain}
|
||||||
@ -222,6 +254,21 @@ func (ipt *IPTables) ListChains(table string) ([]string, error) {
|
|||||||
return chains, nil
|
return chains, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// '-S' is fine with non existing rule index as long as the chain exists
|
||||||
|
// therefore pass index 1 to reduce overhead for large chains
|
||||||
|
func (ipt *IPTables) ChainExists(table, chain string) (bool, error) {
|
||||||
|
err := ipt.run("-t", table, "-S", chain, "1")
|
||||||
|
eerr, eok := err.(*Error)
|
||||||
|
switch {
|
||||||
|
case err == nil:
|
||||||
|
return true, nil
|
||||||
|
case eok && eerr.ExitStatus() == 1:
|
||||||
|
return false, nil
|
||||||
|
default:
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Stats lists rules including the byte and packet counts
|
// Stats lists rules including the byte and packet counts
|
||||||
func (ipt *IPTables) Stats(table, chain string) ([][]string, error) {
|
func (ipt *IPTables) Stats(table, chain string) ([][]string, error) {
|
||||||
args := []string{"-t", table, "-L", chain, "-n", "-v", "-x"}
|
args := []string{"-t", table, "-L", chain, "-n", "-v", "-x"}
|
||||||
@ -401,6 +448,18 @@ func (ipt *IPTables) DeleteChain(table, chain string) error {
|
|||||||
return ipt.run("-t", table, "-X", chain)
|
return ipt.run("-t", table, "-X", chain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ipt *IPTables) ClearAndDeleteChain(table, chain string) error {
|
||||||
|
exists, err := ipt.ChainExists(table, chain)
|
||||||
|
if err != nil || !exists {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ipt.run("-t", table, "-F", chain)
|
||||||
|
if err == nil {
|
||||||
|
err = ipt.run("-t", table, "-X", chain)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// ChangePolicy changes policy on chain to target
|
// ChangePolicy changes policy on chain to target
|
||||||
func (ipt *IPTables) ChangePolicy(table, chain, target string) error {
|
func (ipt *IPTables) ChangePolicy(table, chain, target string) error {
|
||||||
return ipt.run("-t", table, "-P", chain, target)
|
return ipt.run("-t", table, "-P", chain, target)
|
||||||
@ -428,6 +487,9 @@ func (ipt *IPTables) runWithOutput(args []string, stdout io.Writer) error {
|
|||||||
args = append([]string{ipt.path}, args...)
|
args = append([]string{ipt.path}, args...)
|
||||||
if ipt.hasWait {
|
if ipt.hasWait {
|
||||||
args = append(args, "--wait")
|
args = append(args, "--wait")
|
||||||
|
if ipt.timeout != 0 {
|
||||||
|
args = append(args, strconv.Itoa(ipt.timeout))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmu, err := newXtablesFileLock()
|
fmu, err := newXtablesFileLock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -452,7 +514,7 @@ func (ipt *IPTables) runWithOutput(args []string, stdout io.Writer) error {
|
|||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
switch e := err.(type) {
|
switch e := err.(type) {
|
||||||
case *exec.ExitError:
|
case *exec.ExitError:
|
||||||
return &Error{*e, cmd, stderr.String(), ipt.proto, nil}
|
return &Error{*e, cmd, stderr.String(), nil}
|
||||||
default:
|
default:
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -38,7 +38,7 @@ github.com/containernetworking/cni/pkg/types/020
|
|||||||
github.com/containernetworking/cni/pkg/types/current
|
github.com/containernetworking/cni/pkg/types/current
|
||||||
github.com/containernetworking/cni/pkg/utils
|
github.com/containernetworking/cni/pkg/utils
|
||||||
github.com/containernetworking/cni/pkg/version
|
github.com/containernetworking/cni/pkg/version
|
||||||
# github.com/coreos/go-iptables v0.4.5
|
# github.com/coreos/go-iptables v0.5.0
|
||||||
## explicit
|
## explicit
|
||||||
github.com/coreos/go-iptables/iptables
|
github.com/coreos/go-iptables/iptables
|
||||||
# github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7
|
# github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7
|
||||||
|
Loading…
x
Reference in New Issue
Block a user