@@ -170,7 +170,11 @@ var _ = Describe("portmapping configuration", func() {
170
170
{ "hostPort": 8080, "containerPort": 80, "protocol": "tcp"},
171
171
{ "hostPort": 8081, "containerPort": 80, "protocol": "tcp"},
172
172
{ "hostPort": 8080, "containerPort": 81, "protocol": "udp"},
173
- { "hostPort": 8082, "containerPort": 82, "protocol": "udp"}
173
+ { "hostPort": 8082, "containerPort": 82, "protocol": "udp"},
174
+ { "hostPort": 8083, "containerPort": 83, "protocol": "tcp", "hostIP": "192.168.0.2"},
175
+ { "hostPort": 8084, "containerPort": 84, "protocol": "tcp", "hostIP": "0.0.0.0"},
176
+ { "hostPort": 8085, "containerPort": 85, "protocol": "tcp", "hostIP": "2001:db8:a::1"},
177
+ { "hostPort": 8086, "containerPort": 86, "protocol": "tcp", "hostIP": "::"}
174
178
]
175
179
},
176
180
"snat": true,
@@ -197,7 +201,7 @@ var _ = Describe("portmapping configuration", func() {
197
201
fmt .Sprintf ("dnat name: \" test\" id: \" %s\" " , containerID ),
198
202
"-m" , "multiport" ,
199
203
"-p" , "tcp" ,
200
- "--destination-ports" , "8080,8081" ,
204
+ "--destination-ports" , "8080,8081,8083,8084,8085,8086 " ,
201
205
"a" , "b" },
202
206
{"-m" , "comment" , "--comment" ,
203
207
fmt .Sprintf ("dnat name: \" test\" id: \" %s\" " , containerID ),
@@ -208,18 +212,28 @@ var _ = Describe("portmapping configuration", func() {
208
212
}))
209
213
210
214
Expect (ch .rules ).To (Equal ([][]string {
215
+ // tcp rules and not hostIP
211
216
{"-p" , "tcp" , "--dport" , "8080" , "-s" , "10.0.0.2/24" , "-j" , "CNI-HOSTPORT-SETMARK" },
212
217
{"-p" , "tcp" , "--dport" , "8080" , "-s" , "127.0.0.1" , "-j" , "CNI-HOSTPORT-SETMARK" },
213
218
{"-p" , "tcp" , "--dport" , "8080" , "-j" , "DNAT" , "--to-destination" , "10.0.0.2:80" },
214
219
{"-p" , "tcp" , "--dport" , "8081" , "-s" , "10.0.0.2/24" , "-j" , "CNI-HOSTPORT-SETMARK" },
215
220
{"-p" , "tcp" , "--dport" , "8081" , "-s" , "127.0.0.1" , "-j" , "CNI-HOSTPORT-SETMARK" },
216
221
{"-p" , "tcp" , "--dport" , "8081" , "-j" , "DNAT" , "--to-destination" , "10.0.0.2:80" },
222
+ // udp rules and not hostIP
217
223
{"-p" , "udp" , "--dport" , "8080" , "-s" , "10.0.0.2/24" , "-j" , "CNI-HOSTPORT-SETMARK" },
218
224
{"-p" , "udp" , "--dport" , "8080" , "-s" , "127.0.0.1" , "-j" , "CNI-HOSTPORT-SETMARK" },
219
225
{"-p" , "udp" , "--dport" , "8080" , "-j" , "DNAT" , "--to-destination" , "10.0.0.2:81" },
220
226
{"-p" , "udp" , "--dport" , "8082" , "-s" , "10.0.0.2/24" , "-j" , "CNI-HOSTPORT-SETMARK" },
221
227
{"-p" , "udp" , "--dport" , "8082" , "-s" , "127.0.0.1" , "-j" , "CNI-HOSTPORT-SETMARK" },
222
228
{"-p" , "udp" , "--dport" , "8082" , "-j" , "DNAT" , "--to-destination" , "10.0.0.2:82" },
229
+ // tcp rules and hostIP
230
+ {"-p" , "tcp" , "--dport" , "8083" , "-d" , "192.168.0.2" , "-s" , "10.0.0.2/24" , "-j" , "CNI-HOSTPORT-SETMARK" },
231
+ {"-p" , "tcp" , "--dport" , "8083" , "-d" , "192.168.0.2" , "-s" , "127.0.0.1" , "-j" , "CNI-HOSTPORT-SETMARK" },
232
+ {"-p" , "tcp" , "--dport" , "8083" , "-d" , "192.168.0.2" , "-j" , "DNAT" , "--to-destination" , "10.0.0.2:83" },
233
+ // tcp rules and hostIP = "0.0.0.0"
234
+ {"-p" , "tcp" , "--dport" , "8084" , "-s" , "10.0.0.2/24" , "-j" , "CNI-HOSTPORT-SETMARK" },
235
+ {"-p" , "tcp" , "--dport" , "8084" , "-s" , "127.0.0.1" , "-j" , "CNI-HOSTPORT-SETMARK" },
236
+ {"-p" , "tcp" , "--dport" , "8084" , "-j" , "DNAT" , "--to-destination" , "10.0.0.2:84" },
223
237
}))
224
238
225
239
ch .rules = nil
@@ -229,14 +243,22 @@ var _ = Describe("portmapping configuration", func() {
229
243
fillDnatRules (& ch , conf , * n )
230
244
231
245
Expect (ch .rules ).To (Equal ([][]string {
246
+ // tcp rules and not hostIP
232
247
{"-p" , "tcp" , "--dport" , "8080" , "-s" , "2001:db8::2/64" , "-j" , "CNI-HOSTPORT-SETMARK" },
233
248
{"-p" , "tcp" , "--dport" , "8080" , "-j" , "DNAT" , "--to-destination" , "[2001:db8::2]:80" },
234
249
{"-p" , "tcp" , "--dport" , "8081" , "-s" , "2001:db8::2/64" , "-j" , "CNI-HOSTPORT-SETMARK" },
235
250
{"-p" , "tcp" , "--dport" , "8081" , "-j" , "DNAT" , "--to-destination" , "[2001:db8::2]:80" },
251
+ // udp rules and not hostIP
236
252
{"-p" , "udp" , "--dport" , "8080" , "-s" , "2001:db8::2/64" , "-j" , "CNI-HOSTPORT-SETMARK" },
237
253
{"-p" , "udp" , "--dport" , "8080" , "-j" , "DNAT" , "--to-destination" , "[2001:db8::2]:81" },
238
254
{"-p" , "udp" , "--dport" , "8082" , "-s" , "2001:db8::2/64" , "-j" , "CNI-HOSTPORT-SETMARK" },
239
255
{"-p" , "udp" , "--dport" , "8082" , "-j" , "DNAT" , "--to-destination" , "[2001:db8::2]:82" },
256
+ // tcp rules and hostIP
257
+ {"-p" , "tcp" , "--dport" , "8085" , "-d" , "2001:db8:a::1" , "-s" , "2001:db8::2/64" , "-j" , "CNI-HOSTPORT-SETMARK" },
258
+ {"-p" , "tcp" , "--dport" , "8085" , "-d" , "2001:db8:a::1" , "-j" , "DNAT" , "--to-destination" , "[2001:db8::2]:85" },
259
+ // tcp rules and hostIP = "::"
260
+ {"-p" , "tcp" , "--dport" , "8086" , "-s" , "2001:db8::2/64" , "-j" , "CNI-HOSTPORT-SETMARK" },
261
+ {"-p" , "tcp" , "--dport" , "8086" , "-j" , "DNAT" , "--to-destination" , "[2001:db8::2]:86" },
240
262
}))
241
263
242
264
// Disable snat, generate rules
@@ -252,6 +274,8 @@ var _ = Describe("portmapping configuration", func() {
252
274
{"-p" , "tcp" , "--dport" , "8081" , "-j" , "DNAT" , "--to-destination" , "10.0.0.2:80" },
253
275
{"-p" , "udp" , "--dport" , "8080" , "-j" , "DNAT" , "--to-destination" , "10.0.0.2:81" },
254
276
{"-p" , "udp" , "--dport" , "8082" , "-j" , "DNAT" , "--to-destination" , "10.0.0.2:82" },
277
+ {"-p" , "tcp" , "--dport" , "8083" , "-d" , "192.168.0.2" , "-j" , "DNAT" , "--to-destination" , "10.0.0.2:83" },
278
+ {"-p" , "tcp" , "--dport" , "8084" , "-j" , "DNAT" , "--to-destination" , "10.0.0.2:84" },
255
279
}))
256
280
})
257
281
0 commit comments