@@ -30,19 +30,19 @@ const (
30
30
Destination = "-d "
31
31
// Source represents the source address flag
32
32
Source = "-s "
33
- // DPort represents the destination port
33
+ // DPort represents the destination port flag
34
34
DPort = "--dport "
35
- // Protocol represents the protocol flag which takes input by number of name
35
+ // Protocol represents the protocol flag
36
36
Protocol = "-p "
37
37
// Jump represents jump flag specifies the jump target
38
38
Jump = "-j "
39
39
// Reject specifies the reject target
40
40
Reject = "REJECT"
41
- // ToDest represents the --to-destination flag used to specify the destination address in DNAT
41
+ // ToDest represents the flag used to specify the destination address in DNAT
42
42
ToDest = "--to-destination "
43
43
// Recent represents the sub-command recent that allows to dynamically create list of IP address to match against
44
44
Recent = "recent "
45
- // MatchSet represents the --match-set flag which match packets against the specified set
45
+ // MatchSet represents the flag which match packets against the specified set
46
46
MatchSet = "--match-set "
47
47
// SrcType represents the --src-type flag which matches if the source address is of given type
48
48
SrcType = "--src-type "
@@ -53,79 +53,78 @@ const (
53
53
// Rule holds a map of rules.
54
54
type Rule map [string ]string
55
55
56
- // FakeIPTables no-op implementation of iptables Interface.
56
+ // FakeIPTables is no-op implementation of iptables Interface.
57
57
type FakeIPTables struct {
58
58
hasRandomFully bool
59
59
Lines []byte
60
60
}
61
61
62
- // NewFake returns a pointer for no-op implementation of iptables Interface.
62
+ // NewFake returns a no-op iptables.Interface
63
63
func NewFake () * FakeIPTables {
64
64
return & FakeIPTables {}
65
65
}
66
66
67
- // SetHasRandomFully will enable the port maping fully randomized in the no-op implementation of iptables Interface.
67
+ // SetHasRandomFully is part of iptables.Interface
68
68
func (f * FakeIPTables ) SetHasRandomFully (can bool ) * FakeIPTables {
69
69
f .hasRandomFully = can
70
70
return f
71
71
}
72
72
73
- // EnsureChain will returns true and states the specified chain exists for testing.
73
+ // EnsureChain is part of iptables.Interface
74
74
func (* FakeIPTables ) EnsureChain (table iptables.Table , chain iptables.Chain ) (bool , error ) {
75
75
return true , nil
76
76
}
77
77
78
- // FlushChain returns nil and states that the specified chain is cleared.
78
+ // FlushChain is part of iptables.Interface
79
79
func (* FakeIPTables ) FlushChain (table iptables.Table , chain iptables.Chain ) error {
80
80
return nil
81
81
}
82
82
83
- // DeleteChain returns nil and states that the specified chain exists and it is deleted.
83
+ // DeleteChain is part of iptables.Interface
84
84
func (* FakeIPTables ) DeleteChain (table iptables.Table , chain iptables.Chain ) error {
85
85
return nil
86
86
}
87
87
88
- // EnsureRule return true and states that the specified rule is present.
88
+ // EnsureRule is part of iptables.Interface
89
89
func (* FakeIPTables ) EnsureRule (position iptables.RulePosition , table iptables.Table , chain iptables.Chain , args ... string ) (bool , error ) {
90
90
return true , nil
91
91
}
92
92
93
- // DeleteRule returns nil and states that the specified rule is present and is deleted.
93
+ // DeleteRule is part of iptables.Interface
94
94
func (* FakeIPTables ) DeleteRule (table iptables.Table , chain iptables.Chain , args ... string ) error {
95
95
return nil
96
96
}
97
97
98
- // IsIpv6 returns false and states that it is managing only ipv4 tables.
98
+ // IsIpv6 is part of iptables.Interface
99
99
func (* FakeIPTables ) IsIpv6 () bool {
100
100
return false
101
101
}
102
102
103
- // Save returns a copy of the iptables lines byte array.
103
+ // Save is part of iptables.Interface
104
104
func (f * FakeIPTables ) Save (table iptables.Table ) ([]byte , error ) {
105
105
lines := make ([]byte , len (f .Lines ))
106
106
copy (lines , f .Lines )
107
107
return lines , nil
108
108
}
109
109
110
- // SaveInto calls `iptables-save` command for table and stores result in a given buffer.
110
+ // SaveInto is part of iptables.Interface
111
111
func (f * FakeIPTables ) SaveInto (table iptables.Table , buffer * bytes.Buffer ) error {
112
112
buffer .Write (f .Lines )
113
113
return nil
114
114
}
115
115
116
- // Restore returns null and states that it ran ` iptables-restore` successfully.
116
+ // Restore is part of iptables.Interface
117
117
func (* FakeIPTables ) Restore (table iptables.Table , data []byte , flush iptables.FlushFlag , counters iptables.RestoreCountersFlag ) error {
118
118
return nil
119
119
}
120
120
121
- // RestoreAll is the same as Restore except that no table is specified.
121
+ // RestoreAll is part of iptables.Interface
122
122
func (f * FakeIPTables ) RestoreAll (data []byte , flush iptables.FlushFlag , counters iptables.RestoreCountersFlag ) error {
123
123
f .Lines = data
124
124
return nil
125
125
}
126
126
127
- // Monitor detects when the given iptables tables have been flushed by an external
128
- // tool (e.g. a firewall reload) by creating canary chains and polling to see if they have been deleted.
127
+ // Monitor is part of iptables.Interface
129
128
func (f * FakeIPTables ) Monitor (canary iptables.Chain , tables []iptables.Table , reloadFunc func (), interval time.Duration , stopCh <- chan struct {}) {
130
129
}
131
130
@@ -137,9 +136,7 @@ func getToken(line, separator string) string {
137
136
return ""
138
137
}
139
138
140
- // GetRules returns a list of rules for the given chain.
141
- // The chain name must match exactly.
142
- // The matching is pretty dumb, don't rely on it for anything but testing.
139
+ // GetRules is part of iptables.Interface
143
140
func (f * FakeIPTables ) GetRules (chainName string ) (rules []Rule ) {
144
141
for _ , l := range strings .Split (string (f .Lines ), "\n " ) {
145
142
if strings .Contains (l , fmt .Sprintf ("-A %v" , chainName )) {
@@ -156,7 +153,7 @@ func (f *FakeIPTables) GetRules(chainName string) (rules []Rule) {
156
153
return
157
154
}
158
155
159
- // HasRandomFully returns the value of the flag --random-fully
156
+ // HasRandomFully is part of iptables.Interface
160
157
func (f * FakeIPTables ) HasRandomFully () bool {
161
158
return f .hasRandomFully
162
159
}
0 commit comments