@@ -17,6 +17,7 @@ package create
17
17
18
18
import (
19
19
"context"
20
+ "errors"
20
21
"fmt"
21
22
"loxicmd/pkg/api"
22
23
"net/http"
@@ -31,6 +32,7 @@ import (
31
32
type CreateFirewallOptions struct {
32
33
FirewallRule []string
33
34
Redirect []string
35
+ SnatArgs []string
34
36
Allow bool
35
37
Drop bool
36
38
Trap bool
@@ -64,6 +66,8 @@ ex) loxicmd create firewall --firewallRule="sourceIP:1.2.3.2/32,destinationIP:2.
64
66
loxicmd create firewall --firewallRule="sourceIP:1.2.3.2/32,destinationIP:2.3.1.2/32,preference:200" --drop
65
67
loxicmd create firewall --firewallRule="sourceIP:1.2.3.2/32,destinationIP:2.3.1.2/32,preference:200" --trap
66
68
loxicmd create firewall --firewallRule="sourceIP:1.2.3.2/32,destinationIP:2.3.1.2/32,preference:200" --redirect=hs1
69
+ loxicmd create firewall --firewallRule="sourceIP:1.2.3.2/32,destinationIP:2.3.1.2/32,preference:200" --snat=10.10.10.1,3030
70
+ loxicmd create firewall --firewallRule="sourceIP:1.2.3.2/32,destinationIP:2.3.1.2/32,preference:200" --snat=10.10.10.1 (Do not change sourceport)
67
71
` ,
68
72
Aliases : []string {"Firewall" , "fw" , "firewalls" },
69
73
PreRun : func (cmd * cobra.Command , args []string ) {
@@ -107,6 +111,7 @@ ex) loxicmd create firewall --firewallRule="sourceIP:1.2.3.2/32,destinationIP:2.
107
111
createFirewallCmd .Flags ().BoolVarP (& o .Record , "record" , "" , false , "Record/Dump any matching rule" )
108
112
createFirewallCmd .Flags ().BoolVarP (& o .Trap , "trap" , "" , false , " Trap anything matching rule" )
109
113
createFirewallCmd .Flags ().IntVarP (& o .Mark , "setmark" , "" , 0 , " Add a fw mark" )
114
+ createFirewallCmd .Flags ().StringSliceVar (& o .SnatArgs , "snat" , o .SnatArgs , "SNAT any matching rule" )
110
115
createFirewallCmd .MarkFlagRequired ("firewallRule" )
111
116
return createFirewallCmd
112
117
}
@@ -175,6 +180,21 @@ func GetFWOptionPairList(FirewallMods *api.FwRuleMod, o CreateFirewallOptions) e
175
180
} else if len (o .Redirect ) != 0 {
176
181
FirewallMods .Opts .Rdr = true
177
182
FirewallMods .Opts .RdrPort = o .Redirect [0 ]
183
+ } else if len (o .SnatArgs ) != 0 {
184
+ if len (o .SnatArgs ) > 2 {
185
+ return errors .New ("invalid snat-args" )
186
+ }
187
+ FirewallMods .Opts .DoSnat = true
188
+ FirewallMods .Opts .ToIP = o .SnatArgs [0 ]
189
+ if len (o .SnatArgs ) > 1 {
190
+ sPort , err := strconv .Atoi (o .SnatArgs [1 ])
191
+ if err != nil {
192
+ return errors .New ("invalid snat-args" )
193
+ }
194
+ FirewallMods .Opts .ToPort = uint16 (sPort )
195
+ } else {
196
+ FirewallMods .Opts .ToPort = 0
197
+ }
178
198
}
179
199
FirewallMods .Opts .Record = o .Record
180
200
FirewallMods .Opts .Mark = o .Mark
0 commit comments