Merge pull request #171 from steveeJ/bump-cni

vendoring: bump coreos/go-iptables to 0.1.0
This commit is contained in:
Zach Gershman 2016-03-31 08:46:55 -07:00
commit bacaa11d2d
2 changed files with 12 additions and 16 deletions

3
Godeps/Godeps.json generated
View File

@ -7,7 +7,8 @@
"Deps": [ "Deps": [
{ {
"ImportPath": "github.com/coreos/go-iptables/iptables", "ImportPath": "github.com/coreos/go-iptables/iptables",
"Rev": "90456be57fcb8185b264b77ce42a9539df42df25" "Comment": "v0.1.0",
"Rev": "fbb73372b87f6e89951c2b6b31470c2c9d5cfae3"
}, },
{ {
"ImportPath": "github.com/coreos/go-systemd/activation", "ImportPath": "github.com/coreos/go-systemd/activation",

View File

@ -18,7 +18,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"log"
"os/exec" "os/exec"
"regexp" "regexp"
"strconv" "strconv"
@ -44,8 +43,6 @@ type IPTables struct {
path string path string
hasCheck bool hasCheck bool
hasWait bool hasWait bool
fmu *fileLock
} }
func New() (*IPTables, error) { func New() (*IPTables, error) {
@ -55,21 +52,13 @@ func New() (*IPTables, error) {
} }
checkPresent, waitPresent, err := getIptablesCommandSupport() checkPresent, waitPresent, err := getIptablesCommandSupport()
if err != nil { if err != nil {
log.Printf("Error checking iptables version, assuming version at least 1.4.20: %v", err) return nil, fmt.Errorf("error checking iptables version: %v", err)
checkPresent = true
waitPresent = true
} }
ipt := IPTables{ ipt := IPTables{
path: path, path: path,
hasCheck: checkPresent, hasCheck: checkPresent,
hasWait: waitPresent, hasWait: waitPresent,
} }
if !waitPresent {
ipt.fmu, err = newXtablesFileLock()
if err != nil {
return nil, err
}
}
return &ipt, nil return &ipt, nil
} }
@ -81,10 +70,11 @@ func (ipt *IPTables) Exists(table, chain string, rulespec ...string) (bool, erro
} }
cmd := append([]string{"-t", table, "-C", chain}, rulespec...) cmd := append([]string{"-t", table, "-C", chain}, rulespec...)
err := ipt.run(cmd...) err := ipt.run(cmd...)
eerr, eok := err.(*Error)
switch { switch {
case err == nil: case err == nil:
return true, nil return true, nil
case err.(*Error).ExitStatus() == 1: case eok && eerr.ExitStatus() == 1:
return false, nil return false, nil
default: default:
return false, err return false, err
@ -148,10 +138,11 @@ func (ipt *IPTables) NewChain(table, chain string) error {
func (ipt *IPTables) ClearChain(table, chain string) error { func (ipt *IPTables) ClearChain(table, chain string) error {
err := ipt.NewChain(table, chain) err := ipt.NewChain(table, chain)
eerr, eok := err.(*Error)
switch { switch {
case err == nil: case err == nil:
return nil return nil
case err.(*Error).ExitStatus() == 1: case eok && eerr.ExitStatus() == 1:
// chain already exists. Flush (clear) it. // chain already exists. Flush (clear) it.
return ipt.run("-t", table, "-F", chain) return ipt.run("-t", table, "-F", chain)
default: default:
@ -183,7 +174,11 @@ func (ipt *IPTables) runWithOutput(args []string, stdout io.Writer) error {
if ipt.hasWait { if ipt.hasWait {
args = append(args, "--wait") args = append(args, "--wait")
} else { } else {
ul, err := ipt.fmu.tryLock() fmu, err := newXtablesFileLock()
if err != nil {
return err
}
ul, err := fmu.tryLock()
if err != nil { if err != nil {
return err return err
} }