@@ -17,8 +17,8 @@ import (
17
17
const (
18
18
// IPTablesModeLegacy signals the usage of the iptables-legacy commands
19
19
IPTablesModeLegacy = "legacy"
20
- // ipTablesModeNFT signals the usage of the iptables-nft commands
21
- ipTablesModeNFT = "nft"
20
+ // IPTablesModeNFT signals the usage of the iptables-nft commands
21
+ IPTablesModeNFT = "nft"
22
22
23
23
cmdLegacy = "iptables-legacy"
24
24
cmdLegacySave = "iptables-legacy-save"
@@ -102,7 +102,10 @@ func NewRootCmd() *cobra.Command {
102
102
return err
103
103
}
104
104
105
- config , err := BuildFirewallConfiguration (options , false )
105
+ // always trigger the IPv4 rules
106
+ optIPv4 := * options
107
+ optIPv4 .IPv6 = false
108
+ config , err := BuildFirewallConfiguration (& optIPv4 )
106
109
if err != nil {
107
110
return err
108
111
}
@@ -115,7 +118,8 @@ func NewRootCmd() *cobra.Command {
115
118
return nil
116
119
}
117
120
118
- config , err = BuildFirewallConfiguration (options , true )
121
+ // trigger the IPv6 rules
122
+ config , err = BuildFirewallConfiguration (options )
119
123
if err != nil {
120
124
return err
121
125
}
@@ -157,12 +161,12 @@ func NewRootCmd() *cobra.Command {
157
161
}
158
162
159
163
// BuildFirewallConfiguration returns an iptables FirewallConfiguration suitable to use to configure iptables.
160
- func BuildFirewallConfiguration (options * RootOptions , ipv6 bool ) (* iptables.FirewallConfiguration , error ) {
164
+ func BuildFirewallConfiguration (options * RootOptions ) (* iptables.FirewallConfiguration , error ) {
161
165
if options .FirewallBinPath != "" || options .FirewallSaveBinPath != "" {
162
166
return nil , errors .New ("--firewal-bin-path and firewall-save-bin-path are no longer supported; please use --iptables-mode instead" )
163
167
}
164
168
165
- if options .IPTablesMode != IPTablesModeLegacy && options .IPTablesMode != ipTablesModeNFT {
169
+ if options .IPTablesMode != IPTablesModeLegacy && options .IPTablesMode != IPTablesModeNFT {
166
170
return nil , errors .New ("--iptables-mode valid values are only \" legacy\" and \" nft\" " )
167
171
}
168
172
@@ -174,7 +178,7 @@ func BuildFirewallConfiguration(options *RootOptions, ipv6 bool) (*iptables.Fire
174
178
return nil , fmt .Errorf ("--outgoing-proxy-port must be a valid TCP port number" )
175
179
}
176
180
177
- cmd , cmdSave := getCommands (options . IPTablesMode , ipv6 )
181
+ cmd , cmdSave := getCommands (options )
178
182
179
183
sanitizedSubnets := []string {}
180
184
for _ , subnet := range options .SubnetsToIgnore {
@@ -220,15 +224,15 @@ func getFormatter(format string) log.Formatter {
220
224
}
221
225
}
222
226
223
- func getCommands (mode string , ipv6 bool ) (string , string ) {
224
- if mode == IPTablesModeLegacy {
225
- if ipv6 {
227
+ func getCommands (options * RootOptions ) (string , string ) {
228
+ if options . IPTablesMode == IPTablesModeLegacy {
229
+ if options . IPv6 {
226
230
return cmdLegacyIPv6 , cmdLegacyIPv6Save
227
231
}
228
232
return cmdLegacy , cmdLegacySave
229
233
}
230
234
231
- if ipv6 {
235
+ if options . IPv6 {
232
236
return cmdNFTIPv6 , cmdNFTIPv6Save
233
237
}
234
238
0 commit comments