@@ -161,26 +161,14 @@ int hyper_setup_portmapping(struct hyper_pod *pod)
161
161
fprintf (stderr , "sysctl: setup default nf_conntrack_tcp_timeout_established(%s) failed\n" , timeout );
162
162
}
163
163
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
179
165
if (pod -> portmap_white_lists == NULL || (pod -> portmap_white_lists -> i_num == 0 &&
180
166
pod -> portmap_white_lists -> e_num == 0 )) {
181
167
return 0 ;
182
168
}
183
169
170
+ int j = 0 ;
171
+ char rule [128 ] = {0 };
184
172
for (j = 0 ; j < pod -> portmap_white_lists -> i_num ; j ++ ) {
185
173
sprintf (rule , "-s %s -j ACCEPT" ,
186
174
pod -> portmap_white_lists -> internal_networks [j ]);
@@ -196,6 +184,26 @@ int hyper_setup_container_portmapping(struct hyper_container *c, struct hyper_po
196
184
}
197
185
}
198
186
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
+
199
207
if (c -> ports_num == 0 ) {
200
208
return 0 ;
201
209
}
@@ -250,14 +258,15 @@ int hyper_setup_container_portmapping(struct hyper_container *c, struct hyper_po
250
258
return 0 ;
251
259
}
252
260
253
- void hyper_cleanup_container_portmapping (struct hyper_container * c , struct hyper_pod * pod )
261
+ // cleanup pod level portmapping configurations
262
+ void hyper_cleanup_portmapping (struct hyper_pod * pod )
254
263
{
255
264
if (pod -> portmap_white_lists == NULL || (pod -> portmap_white_lists -> i_num == 0 &&
256
265
pod -> portmap_white_lists -> e_num == 0 )) {
257
266
return ;
258
267
}
259
268
260
- int i = 0 , j = 0 ;
269
+ int j = 0 ;
261
270
char rule [128 ] = {0 };
262
271
for (j = 0 ; j < pod -> portmap_white_lists -> i_num ; j ++ ) {
263
272
sprintf (rule , "-s %s -j ACCEPT" ,
@@ -272,7 +281,17 @@ void hyper_cleanup_container_portmapping(struct hyper_container *c, struct hyper
272
281
fprintf (stderr , "cleanup accept_rule '%s' failed\n" , rule );
273
282
}
274
283
}
284
+ }
285
+
286
+ void hyper_cleanup_container_portmapping (struct hyper_container * c , struct hyper_pod * pod )
287
+ {
288
+ if (pod -> portmap_white_lists == NULL || (pod -> portmap_white_lists -> i_num == 0 &&
289
+ pod -> portmap_white_lists -> e_num == 0 )) {
290
+ return ;
291
+ }
275
292
293
+ int i = 0 , j = 0 ;
294
+ char rule [128 ] = {0 };
276
295
if (c -> ports_num == 0 ) {
277
296
return ;
278
297
}
0 commit comments