Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 040d7c3

Browse files
committed
port mapping: move the pod level whitelist rules to pod setup
from container setup Signed-off-by: Xu Wang <[email protected]>
1 parent 68d80dd commit 040d7c3

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/portmapping.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,14 @@ int hyper_setup_portmapping(struct hyper_pod *pod)
161161
fprintf(stderr, "sysctl: setup default nf_conntrack_tcp_timeout_established(%s) failed\n", timeout);
162162
}
163163

164-
return 0;
165-
}
166-
167-
int hyper_setup_container_portmapping(struct hyper_container *c, struct hyper_pod *pod)
168-
{
169-
// only allow network request from internal white list
170-
int i = 0, j = 0;
171-
char rule[128] = {0};
172-
char iptables_restore[512];
173-
174-
// restore iptables rules
175-
if (sprintf(iptables_restore, "iptables-restore /tmp/hyper/shared/%s-iptables", c->id) > 0) {
176-
hyper_cmd(iptables_restore);
177-
}
178-
164+
// configure the white list rules for lan access
179165
if (pod->portmap_white_lists == NULL || (pod->portmap_white_lists->i_num == 0 &&
180166
pod->portmap_white_lists->e_num == 0)) {
181167
return 0;
182168
}
183169

170+
int j = 0;
171+
char rule[128] = {0};
184172
for (j=0; j<pod->portmap_white_lists->i_num; j++) {
185173
sprintf(rule, "-s %s -j ACCEPT",
186174
pod->portmap_white_lists->internal_networks[j]);
@@ -196,6 +184,26 @@ int hyper_setup_container_portmapping(struct hyper_container *c, struct hyper_po
196184
}
197185
}
198186

187+
return 0;
188+
}
189+
190+
int hyper_setup_container_portmapping(struct hyper_container *c, struct hyper_pod *pod)
191+
{
192+
// only allow network request from internal white list
193+
int i = 0, j = 0;
194+
char rule[128] = {0};
195+
char iptables_restore[512];
196+
197+
// restore iptables rules
198+
if (sprintf(iptables_restore, "iptables-restore /tmp/hyper/shared/%s-iptables", c->id) > 0) {
199+
hyper_cmd(iptables_restore);
200+
}
201+
202+
if (pod->portmap_white_lists == NULL || (pod->portmap_white_lists->i_num == 0 &&
203+
pod->portmap_white_lists->e_num == 0)) {
204+
return 0;
205+
}
206+
199207
if (c->ports_num == 0) {
200208
return 0;
201209
}

0 commit comments

Comments
 (0)