Skip to content

Commit 7586649

Browse files
committed
Merge pull request #930 from aboch/fd
When programming iptables in container use native API
2 parents 6cd5d90 + 7199d9c commit 7586649

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

iptables/iptables.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,11 @@ func Raw(args ...string) ([]byte, error) {
325325
if err == nil || !strings.Contains(err.Error(), "was not provided by any .service files") {
326326
return output, err
327327
}
328-
329328
}
329+
return raw(args...)
330+
}
330331

332+
func raw(args ...string) ([]byte, error) {
331333
if err := initCheck(); err != nil {
332334
return nil, err
333335
}
@@ -362,6 +364,15 @@ func RawCombinedOutput(args ...string) error {
362364
return nil
363365
}
364366

367+
// RawCombinedOutputNative behave as RawCombinedOutput with the difference it
368+
// will always invoke `iptables` binary
369+
func RawCombinedOutputNative(args ...string) error {
370+
if output, err := raw(args...); err != nil || len(output) != 0 {
371+
return fmt.Errorf("%s (%v)", string(output), err)
372+
}
373+
return nil
374+
}
375+
365376
// ExistChain checks if a chain exists
366377
func ExistChain(chain string, table Table) bool {
367378
if _, err := Raw("-t", string(table), "-L", chain); err == nil {

resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (r *resolver) SetupFunc() func() {
9595
}
9696

9797
for _, rule := range rules {
98-
r.err = iptables.RawCombinedOutput(rule...)
98+
r.err = iptables.RawCombinedOutputNative(rule...)
9999
if r.err != nil {
100100
return
101101
}

0 commit comments

Comments
 (0)