1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #930 from aboch/fd

When programming iptables in container use native API
This commit is contained in:
Madhu Venugopal 2016-02-05 15:44:08 -08:00
commit 0a568e954e
2 changed files with 13 additions and 2 deletions

View file

@ -325,9 +325,11 @@ func Raw(args ...string) ([]byte, error) {
if err == nil || !strings.Contains(err.Error(), "was not provided by any .service files") {
return output, err
}
}
return raw(args...)
}
func raw(args ...string) ([]byte, error) {
if err := initCheck(); err != nil {
return nil, err
}
@ -362,6 +364,15 @@ func RawCombinedOutput(args ...string) error {
return nil
}
// RawCombinedOutputNative behave as RawCombinedOutput with the difference it
// will always invoke `iptables` binary
func RawCombinedOutputNative(args ...string) error {
if output, err := raw(args...); err != nil || len(output) != 0 {
return fmt.Errorf("%s (%v)", string(output), err)
}
return nil
}
// ExistChain checks if a chain exists
func ExistChain(chain string, table Table) bool {
if _, err := Raw("-t", string(table), "-L", chain); err == nil {

View file

@ -95,7 +95,7 @@ func (r *resolver) SetupFunc() func() {
}
for _, rule := range rules {
r.err = iptables.RawCombinedOutput(rule...)
r.err = iptables.RawCombinedOutputNative(rule...)
if r.err != nil {
return
}