libnetwork/iptables: Passthrough: re-use IPVersion type
Use the existing IPVersion type to switch between ipv4 and ipv6. The IPV type was only used for this function, and currently required callers to map a IPVersion to IPV. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
c1b64fbbdb
commit
55f2e111e9
3 changed files with 13 additions and 16 deletions
|
@ -12,14 +12,11 @@ import (
|
|||
dbus "github.com/godbus/dbus/v5"
|
||||
)
|
||||
|
||||
// IPV defines the table string
|
||||
type IPV string
|
||||
|
||||
const (
|
||||
// Iptables point ipv4 table
|
||||
Iptables IPV = "ipv4"
|
||||
// IP6Tables point to ipv6 table
|
||||
IP6Tables IPV = "ipv6"
|
||||
// ipTables point ipv4 table
|
||||
ipTables = "ipv4"
|
||||
// ip6Tables point to ipv6 table
|
||||
ip6Tables = "ipv6"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -219,7 +216,13 @@ func (fwd *firewalldConnection) isRunning() bool {
|
|||
}
|
||||
|
||||
// Passthrough method simply passes args through to iptables/ip6tables
|
||||
func Passthrough(ipv IPV, args ...string) ([]byte, error) {
|
||||
func Passthrough(ipVersion IPVersion, args ...string) ([]byte, error) {
|
||||
// select correct IP version for firewalld
|
||||
ipv := ipTables
|
||||
if ipVersion == IPv6 {
|
||||
ipv = ip6Tables
|
||||
}
|
||||
|
||||
var output string
|
||||
log.G(context.TODO()).Debugf("Firewalld passthrough: %s, %s", ipv, args)
|
||||
if err := firewalld.sysObj.Call(dbusInterface+".direct.passthrough", 0, ipv, args).Store(&output); err != nil {
|
||||
|
|
|
@ -100,7 +100,7 @@ func TestPassthrough(t *testing.T) {
|
|||
"-j", "ACCEPT",
|
||||
}
|
||||
|
||||
_, err := Passthrough(Iptables, append([]string{"-A"}, rule1...)...)
|
||||
_, err := Passthrough(IPv4, append([]string{"-A"}, rule1...)...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -519,14 +519,8 @@ func filterOutput(start time.Time, output []byte, args ...string) []byte {
|
|||
// Raw calls 'iptables' system command, passing supplied arguments.
|
||||
func (iptable IPTable) Raw(args ...string) ([]byte, error) {
|
||||
if firewalld.isRunning() {
|
||||
// select correct IP version for firewalld
|
||||
ipv := Iptables
|
||||
if iptable.ipVersion == IPv6 {
|
||||
ipv = IP6Tables
|
||||
}
|
||||
|
||||
startTime := time.Now()
|
||||
output, err := Passthrough(ipv, args...)
|
||||
output, err := Passthrough(iptable.ipVersion, args...)
|
||||
if err == nil || !strings.Contains(err.Error(), "was not provided by any .service files") {
|
||||
return filterOutput(startTime, output, args...), err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue