Skip to content

Commit 4f76b19

Browse files
jpayne3506jpayne3506
andauthored
fix: [CNI] NAT hostPort mapping for HNSv2 (#1922)
* NAT update * NAT update * Cleaning up and unit test * Fix Lint * Fix Lint * Fix Lint - Addr. comments --------- Co-authored-by: jpayne3506 <[email protected]>
1 parent 2df9d27 commit 4f76b19

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

cni/network/network_windows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,14 @@ func getPoliciesFromRuntimeCfg(nwCfg *cni.NetworkConfig) []policy.Policy {
252252
protocol = policy.ProtocolUdp
253253
}
254254

255+
// To support hostport policy mapping
256+
// uint32 NatFlagsLocalRoutedVip = 1
255257
rawPolicy, _ := json.Marshal(&hnsv2.PortMappingPolicySetting{
256258
ExternalPort: uint16(mapping.HostPort),
257259
InternalPort: uint16(mapping.ContainerPort),
258260
VIP: mapping.HostIp,
259261
Protocol: protocol,
262+
Flags: hnsv2.NatFlagsLocalRoutedVip,
260263
})
261264

262265
hnsv2Policy, _ := json.Marshal(&hnsv2.EndpointPolicy{

cni/network/network_windows_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,21 @@ func TestSetPoliciesFromNwCfg(t *testing.T) {
235235
},
236236
},
237237
},
238+
{
239+
name: "Runtime hostPort mapping polices",
240+
nwCfg: cni.NetworkConfig{
241+
RuntimeConfig: cni.RuntimeConfig{
242+
PortMappings: []cni.PortMapping{
243+
{
244+
Protocol: "tcp",
245+
HostPort: 44000,
246+
ContainerPort: 80,
247+
},
248+
},
249+
},
250+
},
251+
},
238252
}
239-
240253
for _, tt := range tests {
241254
tt := tt
242255
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)