@@ -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 }
@@ -250,14 +258,15 @@ int hyper_setup_container_portmapping(struct hyper_container *c, struct hyper_po
250258 return 0 ;
251259}
252260
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 )
254263{
255264 if (pod -> portmap_white_lists == NULL || (pod -> portmap_white_lists -> i_num == 0 &&
256265 pod -> portmap_white_lists -> e_num == 0 )) {
257266 return ;
258267 }
259268
260- int i = 0 , j = 0 ;
269+ int j = 0 ;
261270 char rule [128 ] = {0 };
262271 for (j = 0 ; j < pod -> portmap_white_lists -> i_num ; j ++ ) {
263272 sprintf (rule , "-s %s -j ACCEPT" ,
@@ -272,7 +281,17 @@ void hyper_cleanup_container_portmapping(struct hyper_container *c, struct hyper
272281 fprintf (stderr , "cleanup accept_rule '%s' failed\n" , rule );
273282 }
274283 }
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+ }
275292
293+ int i = 0 , j = 0 ;
294+ char rule [128 ] = {0 };
276295 if (c -> ports_num == 0 ) {
277296 return ;
278297 }
0 commit comments