Skip to content

Commit 27deff4

Browse files
committed
libnet/iptables: deprecate type IPV
The iptables package has two different types to specify the IP version: IPVersion, used by iptables code, and IPV, used by firewalld code. Both are representing the ip version as a string. For iptables, the case doesn't matter because the string is never used as-is. However, for firewalld the case matters. Make the IPV type an alias of IPVersion, and deprecate it. Also change the case used in IPVersion strings to make IPV consts aliases of IPVersion consts. Signed-off-by: Albin Kerouanton <[email protected]>
1 parent 1ce3474 commit 27deff4

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

libnetwork/iptables/firewalld.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ import (
1313
)
1414

1515
// IPV defines the table string
16-
type IPV string
16+
//
17+
// Deprecated: use [IPVersion]
18+
type IPV = IPVersion
1719

1820
const (
1921
// Iptables point ipv4 table
20-
Iptables IPV = "ipv4"
22+
//
23+
// Deprecated: use [IPv4].
24+
Iptables IPV = IPv4
2125
// IP6Tables point to ipv6 table
22-
IP6Tables IPV = "ipv6"
26+
//
27+
// Deprecated: use [IPv6].
28+
IP6Tables IPV = IPv6
2329
)
2430

2531
const (
@@ -169,7 +175,7 @@ func checkRunning() bool {
169175
}
170176

171177
// Passthrough method simply passes args through to iptables/ip6tables
172-
func Passthrough(ipv IPV, args ...string) ([]byte, error) {
178+
func Passthrough(ipv IPVersion, args ...string) ([]byte, error) {
173179
var output string
174180
log.G(context.TODO()).Debugf("Firewalld passthrough: %s, %s", ipv, args)
175181
if err := connection.sysObj.Call(dbusInterface+".direct.passthrough", 0, ipv, args).Store(&output); err != nil {

libnetwork/iptables/firewalld_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestPassthrough(t *testing.T) {
9696
"-j", "ACCEPT",
9797
}
9898

99-
_, err := Passthrough(Iptables, append([]string{"-A"}, rule1...)...)
99+
_, err := Passthrough(IPv4, append([]string{"-A"}, rule1...)...)
100100
if err != nil {
101101
t.Fatal(err)
102102
}

libnetwork/iptables/iptables.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ type IPVersion string
5757

5858
const (
5959
// IPv4 is version 4.
60-
IPv4 IPVersion = "IPV4"
60+
IPv4 IPVersion = "ipv4"
6161
// IPv6 is version 6.
62-
IPv6 IPVersion = "IPV6"
62+
IPv6 IPVersion = "ipv6"
6363
)
6464

6565
var (
@@ -435,14 +435,8 @@ func filterOutput(start time.Time, output []byte, args ...string) []byte {
435435
// Raw calls 'iptables' system command, passing supplied arguments.
436436
func (iptable IPTable) Raw(args ...string) ([]byte, error) {
437437
if firewalldRunning {
438-
// select correct IP version for firewalld
439-
ipv := Iptables
440-
if iptable.ipVersion == IPv6 {
441-
ipv = IP6Tables
442-
}
443-
444438
startTime := time.Now()
445-
output, err := Passthrough(ipv, args...)
439+
output, err := Passthrough(iptable.ipVersion, args...)
446440
if err == nil || !strings.Contains(err.Error(), "was not provided by any .service files") {
447441
return filterOutput(startTime, output, args...), err
448442
}

0 commit comments

Comments
 (0)