Add tethering client data limitation
[platform/core/connectivity/stc-manager.git] / src / helper / helper-iptables.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "stc-manager-gdbus.h"
18 #include "helper-iptables.h"
19
20 #define STC_IPTABLES_DBUS_SERVICE                    "net.stc.iptables"
21 #define STC_IPTABLES_DBUS_RULE_INTERFACE             STC_IPTABLES_DBUS_SERVICE ".rule"
22 #define STC_IPTABLES_DBUS_CHAIN_INTERFACE            STC_IPTABLES_DBUS_SERVICE ".chain"
23 #define STC_IPTABLES_DBUS_RULE_PATH                  "/net/stc/iptables/rule"
24 #define STC_IPTABLES_DBUS_CHAIN_PATH                 "/net/stc/iptables/chain"
25 #define STC_IPTABLES_DBUS_METHOD_IPT_ADD_CHAIN       "IptAddChain"
26 #define STC_IPTABLES_DBUS_METHOD_IPT_REMOVE_CHAIN    "IptRemoveChain"
27 #define STC_IPTABLES_DBUS_METHOD_IPT_FLUSH_CHAIN     "IptFlushChain"
28 #define STC_IPTABLES_DBUS_METHOD_IP6T_ADD_CHAIN      "Ip6tAddChain"
29 #define STC_IPTABLES_DBUS_METHOD_IP6T_REMOVE_CHAIN   "Ip6tRemoveChain"
30 #define STC_IPTABLES_DBUS_METHOD_IP6T_FLUSH_CHAIN    "Ip6tFlushChain"
31 #define STC_IPTABLES_DBUS_METHOD_IPT_ADD_RULE        "IptAddRule"
32 #define STC_IPTABLES_DBUS_METHOD_IPT_REMOVE_RULE     "IptRemoveRule"
33 #define STC_IPTABLES_DBUS_METHOD_IP6T_ADD_RULE       "Ip6tAddRule"
34 #define STC_IPTABLES_DBUS_METHOD_IP6T_REMOVE_RULE    "Ip6tRemoveRule"
35
36 #define RULE_CHAIN      "chain"
37 #define RULE_DIRECTION  "direction"
38 #define RULE_IFNAME     "ifname"
39 #define RULE_CGROUP     "cgroup"
40 #define RULE_NFACCT     "nfacct"
41 #define RULE_TARGET     "target"
42 #define RULE_SIPTYPE    "s_ip_type"
43 #define RULE_SIP1       "s_ip1"
44 #define RULE_SIP2       "s_ip2"
45 #define RULE_DIPTYPE    "d_ip_type"
46 #define RULE_DIP1       "d_ip1"
47 #define RULE_DIP2       "d_ip2"
48
49 static void __add_rule_info_to_builder(GVariantBuilder *builder,
50                                        iptables_rule_s *rule)
51 {
52         if (builder == NULL || rule == NULL)
53                 return; //LCOV_EXCL_LINE
54
55         g_variant_builder_add(builder, "{sv}", RULE_CHAIN,
56                               g_variant_new_string(rule->chain));
57
58         g_variant_builder_add(builder, "{sv}", RULE_DIRECTION,
59                               g_variant_new_uint16(rule->direction));
60
61         if (rule->ifname)
62                 g_variant_builder_add(builder, "{sv}", RULE_IFNAME,
63                                       g_variant_new_string(rule->ifname));
64
65         if (rule->classid > 0)
66                 g_variant_builder_add(builder, "{sv}", RULE_CGROUP,
67                                       g_variant_new_uint32(rule->classid));
68
69         if (rule->nfacct_name)
70                 g_variant_builder_add(builder, "{sv}", RULE_NFACCT,
71                                       g_variant_new_string(rule->nfacct_name));
72
73         if (rule->target)
74                 g_variant_builder_add(builder, "{sv}", RULE_TARGET,
75                                       g_variant_new_string(rule->target));
76
77         g_variant_builder_add(builder, "{sv}", RULE_SIPTYPE,
78                                       g_variant_new_uint16(rule->s_iprange_type));
79
80         g_variant_builder_add(builder, "{sv}", RULE_DIPTYPE,
81                                       g_variant_new_uint16(rule->d_iprange_type));
82
83         if (rule->s_ip1.s_addr)
84                 g_variant_builder_add(builder, "{sv}", RULE_SIP1,
85                                       g_variant_new_uint32(rule->s_ip1.s_addr));
86
87         if (rule->s_ip2.s_addr)
88                 g_variant_builder_add(builder, "{sv}", RULE_SIP2,
89                                       g_variant_new_uint32(rule->s_ip2.s_addr));
90
91         if (rule->d_ip1.s_addr)
92                 g_variant_builder_add(builder, "{sv}", RULE_DIP1,
93                                       g_variant_new_uint32(rule->d_ip1.s_addr));
94
95         if (rule->d_ip2.s_addr)
96                 g_variant_builder_add(builder, "{sv}", RULE_DIP2,
97                                       g_variant_new_uint32(rule->d_ip2.s_addr));
98 }
99
100 static int __iptables_rule_add(GDBusConnection *connection,
101                                iptables_rule_s *rule)
102 {
103         int result = 0;
104         GVariantBuilder *builder = NULL;
105         GVariant *params = NULL;
106         GVariant *message = NULL;
107
108         builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
109         __add_rule_info_to_builder(builder, rule);
110         params = g_variant_new("(a{sv})", builder);
111         g_variant_builder_unref(builder);
112
113         message = stc_manager_gdbus_call_sync(connection,
114                                               STC_IPTABLES_DBUS_SERVICE,
115                                               STC_IPTABLES_DBUS_RULE_PATH,
116                                               STC_IPTABLES_DBUS_RULE_INTERFACE,
117                                               STC_IPTABLES_DBUS_METHOD_IPT_ADD_RULE,
118                                               params);
119
120         if (message == NULL) {
121                 STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
122                 return STC_ERROR_FAIL; //LCOV_EXCL_LINE
123         }
124
125         g_variant_get(message, "(i)", &result);
126         if (STC_DEBUG_LOG)
127                 STC_LOGD("Successfully Add Rule [%d:%s]", result, rule->nfacct_name);
128         g_variant_unref(message);
129
130         return STC_ERROR_NONE;
131 }
132
133 static int __iptables_rule_remove(GDBusConnection *connection,
134                                   iptables_rule_s *rule)
135 {
136         int result = 0;
137         GVariantBuilder *builder = NULL;
138         GVariant *params = NULL;
139         GVariant *message = NULL;
140
141         builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
142         __add_rule_info_to_builder(builder, rule);
143         params = g_variant_new("(a{sv})", builder);
144         g_variant_builder_unref(builder);
145
146         message = stc_manager_gdbus_call_sync(connection,
147                                               STC_IPTABLES_DBUS_SERVICE,
148                                               STC_IPTABLES_DBUS_RULE_PATH,
149                                               STC_IPTABLES_DBUS_RULE_INTERFACE,
150                                               STC_IPTABLES_DBUS_METHOD_IPT_REMOVE_RULE,
151                                               params);
152
153         if (message == NULL) {
154                 STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
155                 return STC_ERROR_FAIL; //LCOV_EXCL_LINE
156         }
157
158         g_variant_get(message, "(i)", &result);
159         if (STC_DEBUG_LOG)
160                 STC_LOGD("Successfully Remove Rule [%d:%s]", result, rule->nfacct_name);
161         g_variant_unref(message);
162
163         return STC_ERROR_NONE;
164 }
165
166 static int __ip6tables_rule_add(GDBusConnection *connection,
167                                 iptables_rule_s *rule)
168 {
169         int result = 0;
170         GVariantBuilder *builder = NULL;
171         GVariant *params = NULL;
172         GVariant *message = NULL;
173
174         builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
175         __add_rule_info_to_builder(builder, rule);
176         params = g_variant_new("(a{sv})", builder);
177         g_variant_builder_unref(builder);
178
179         message = stc_manager_gdbus_call_sync(connection,
180                                               STC_IPTABLES_DBUS_SERVICE,
181                                               STC_IPTABLES_DBUS_RULE_PATH,
182                                               STC_IPTABLES_DBUS_RULE_INTERFACE,
183                                               STC_IPTABLES_DBUS_METHOD_IP6T_ADD_RULE,
184                                               params);
185
186         if (message == NULL) {
187                 STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
188                 return STC_ERROR_FAIL; //LCOV_EXCL_LINE
189         }
190
191         g_variant_get(message, "(i)", &result);
192         if (STC_DEBUG_LOG)
193                 STC_LOGD("Successfully Add 6 Rule [%d:%s]", result, rule->nfacct_name);
194         g_variant_unref(message);
195
196         return STC_ERROR_NONE;
197 }
198
199 static int __ip6tables_rule_remove(GDBusConnection *connection,
200                                    iptables_rule_s *rule)
201 {
202         int result = 0;
203         GVariantBuilder *builder = NULL;
204         GVariant *params = NULL;
205         GVariant *message = NULL;
206
207         builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
208         __add_rule_info_to_builder(builder, rule);
209         params = g_variant_new("(a{sv})", builder);
210         g_variant_builder_unref(builder);
211
212         message = stc_manager_gdbus_call_sync(connection,
213                                               STC_IPTABLES_DBUS_SERVICE,
214                                               STC_IPTABLES_DBUS_RULE_PATH,
215                                               STC_IPTABLES_DBUS_RULE_INTERFACE,
216                                               STC_IPTABLES_DBUS_METHOD_IP6T_REMOVE_RULE,
217                                               params);
218
219         if (message == NULL) {
220                 STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
221                 return STC_ERROR_FAIL; //LCOV_EXCL_LINE
222         }
223
224         g_variant_get(message, "(i)", &result);
225         if (STC_DEBUG_LOG)
226                 STC_LOGD("Successfully Remove 6 Rule [%d:%s]", result, rule->nfacct_name);
227         g_variant_unref(message);
228
229         return STC_ERROR_NONE;
230 }
231
232 static int __iptables_add_chain(GDBusConnection *connection,
233                                 const char *chain)
234 {
235         int result = 0;
236         GVariant *message = NULL;
237
238         message = stc_manager_gdbus_call_sync(connection,
239                                               STC_IPTABLES_DBUS_SERVICE,
240                                               STC_IPTABLES_DBUS_CHAIN_PATH,
241                                               STC_IPTABLES_DBUS_CHAIN_INTERFACE,
242                                               STC_IPTABLES_DBUS_METHOD_IPT_ADD_CHAIN,
243                                               g_variant_new("(s)", chain));
244
245         if (message == NULL) {
246                 STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
247                 return STC_ERROR_FAIL; //LCOV_EXCL_LINE
248         }
249
250         g_variant_get(message, "(i)", &result);
251         STC_LOGD("Successfully added ipv4 chain [%d:%s]", result, chain);
252         g_variant_unref(message);
253
254         return STC_ERROR_NONE;
255 }
256
257 static int __ip6tables_add_chain(GDBusConnection *connection,
258                                  const char *chain)
259 {
260         int result = 0;
261         GVariant *message = NULL;
262
263         message = stc_manager_gdbus_call_sync(connection,
264                                               STC_IPTABLES_DBUS_SERVICE,
265                                               STC_IPTABLES_DBUS_CHAIN_PATH,
266                                               STC_IPTABLES_DBUS_CHAIN_INTERFACE,
267                                               STC_IPTABLES_DBUS_METHOD_IP6T_ADD_CHAIN,
268                                               g_variant_new("(s)", chain));
269
270         if (message == NULL) {
271                 STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
272                 return STC_ERROR_FAIL; //LCOV_EXCL_LINE
273         }
274
275         g_variant_get(message, "(i)", &result);
276         STC_LOGD("Successfully added ipv6 chain [%d:%s]", result, chain);
277         g_variant_unref(message);
278
279         return STC_ERROR_NONE;
280 }
281
282 static int __iptables_remove_chain(GDBusConnection *connection,
283                                    const char *chain)
284 {
285         int result = 0;
286         GVariant *message = NULL;
287
288         message = stc_manager_gdbus_call_sync(connection,
289                                               STC_IPTABLES_DBUS_SERVICE,
290                                               STC_IPTABLES_DBUS_CHAIN_PATH,
291                                               STC_IPTABLES_DBUS_CHAIN_INTERFACE,
292                                               STC_IPTABLES_DBUS_METHOD_IPT_REMOVE_CHAIN,
293                                               g_variant_new("(s)", chain));
294
295         if (message == NULL) {
296                 STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
297                 return STC_ERROR_FAIL; //LCOV_EXCL_LINE
298         }
299
300         g_variant_get(message, "(i)", &result);
301         STC_LOGD("Successfully removed ipv4 chain [%d:%s]", result, chain);
302         g_variant_unref(message);
303
304         return STC_ERROR_NONE;
305 }
306
307 static int __ip6tables_remove_chain(GDBusConnection *connection,
308                                     const char *chain)
309 {
310         int result = 0;
311         GVariant *message = NULL;
312
313         message = stc_manager_gdbus_call_sync(connection,
314                                               STC_IPTABLES_DBUS_SERVICE,
315                                               STC_IPTABLES_DBUS_CHAIN_PATH,
316                                               STC_IPTABLES_DBUS_CHAIN_INTERFACE,
317                                               STC_IPTABLES_DBUS_METHOD_IP6T_REMOVE_CHAIN,
318                                               g_variant_new("(s)", chain));
319
320         if (message == NULL) {
321                 STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
322                 return STC_ERROR_FAIL; //LCOV_EXCL_LINE
323         }
324
325         g_variant_get(message, "(i)", &result);
326         STC_LOGD("Successfully removed ipv6 chain [%d:%s]", result, chain);
327         g_variant_unref(message);
328
329         return STC_ERROR_NONE;
330 }
331
332 static int __iptables_flush_chain(GDBusConnection *connection,
333                                   const char *chain)
334 {
335         int result = 0;
336         GVariant *message = NULL;
337
338         message = stc_manager_gdbus_call_sync(connection,
339                                               STC_IPTABLES_DBUS_SERVICE,
340                                               STC_IPTABLES_DBUS_CHAIN_PATH,
341                                               STC_IPTABLES_DBUS_CHAIN_INTERFACE,
342                                               STC_IPTABLES_DBUS_METHOD_IPT_FLUSH_CHAIN,
343                                               g_variant_new("(s)", chain));
344
345         if (message == NULL) {
346                 STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
347                 return STC_ERROR_FAIL; //LCOV_EXCL_LINE
348         }
349
350         g_variant_get(message, "(i)", &result);
351         STC_LOGD("Successfully flushed ipv4 chain [%d:%s]", result, chain);
352         g_variant_unref(message);
353
354         return STC_ERROR_NONE;
355 }
356
357 static int __ip6tables_flush_chain(GDBusConnection *connection,
358                                    const char *chain)
359 {
360         int result = 0;
361         GVariant *message = NULL;
362
363         message = stc_manager_gdbus_call_sync(connection,
364                                               STC_IPTABLES_DBUS_SERVICE,
365                                               STC_IPTABLES_DBUS_CHAIN_PATH,
366                                               STC_IPTABLES_DBUS_CHAIN_INTERFACE,
367                                               STC_IPTABLES_DBUS_METHOD_IP6T_FLUSH_CHAIN,
368                                               g_variant_new("(s)", chain));
369
370         if (message == NULL) {
371                 STC_LOGE("Failed to invoke dbus method"); //LCOV_EXCL_LINE
372                 return STC_ERROR_FAIL; //LCOV_EXCL_LINE
373         }
374
375         g_variant_get(message, "(i)", &result);
376         STC_LOGD("Successfully flushed ipv6 chain [%d:%s]", result, chain);
377         g_variant_unref(message);
378
379         return STC_ERROR_NONE;
380 }
381
382 static int __iptables_add_chain_jump_rule(const char *chain,
383                                           const char *target)
384 {
385         stc_error_e ret = STC_ERROR_NONE;
386         iptables_rule_s iptables_rule;
387         memset(&iptables_rule, 0, sizeof(iptables_rule_s));
388
389         iptables_rule.target = g_strdup(target);
390         iptables_rule.chain = g_strdup(chain);
391
392         ret = iptables_add(&iptables_rule, IP_TYPE_IPV4_IPV6);
393
394         g_free(iptables_rule.target);
395         g_free(iptables_rule.chain);
396
397         return ret;
398 }
399
400 stc_error_e iptables_add(iptables_rule_s *rule, iptables_ip_type_e iptype)
401 {
402         stc_error_e ret = STC_ERROR_NONE;
403         stc_s *stc = stc_get_manager();
404
405         if (!stc || !stc->connection)
406                 return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
407
408         if (iptype == IP_TYPE_IPV4 ||
409                 iptype == IP_TYPE_IPV4_IPV6) {
410                 ret = __iptables_rule_add(stc->connection, rule);
411                 if (ret != STC_ERROR_NONE)
412                         goto done; //LCOV_EXCL_LINE
413         }
414
415         if (iptype == IP_TYPE_IPV6 ||
416                 iptype == IP_TYPE_IPV4_IPV6)
417                 ret = __ip6tables_rule_add(stc->connection, rule);
418
419 done:
420         return ret;
421 }
422
423 stc_error_e iptables_remove(iptables_rule_s *rule, iptables_ip_type_e iptype)
424 {
425         stc_error_e ret = STC_ERROR_NONE;
426         stc_s *stc = stc_get_manager();
427
428         if (!stc || !stc->connection)
429                 return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
430
431         if (iptype == IP_TYPE_IPV4 ||
432                 iptype == IP_TYPE_IPV4_IPV6) {
433                 ret = __iptables_rule_remove(stc->connection, rule);
434                 if (ret != STC_ERROR_NONE)
435                         goto done; //LCOV_EXCL_LINE
436         }
437
438         if (iptype == IP_TYPE_IPV6 ||
439                 iptype == IP_TYPE_IPV4_IPV6)
440                 ret = __ip6tables_rule_remove(stc->connection, rule);
441
442 done:
443         return ret;
444 }
445
446 stc_error_e iptables_flush_chains(void)
447 {
448         stc_error_e ret = STC_ERROR_NONE;
449         stc_s *stc = stc_get_manager();
450
451         if (!stc || !stc->connection)
452                 return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
453
454         ret = __iptables_flush_chain(stc->connection, STC_IN_CHAIN);
455         if (ret != STC_ERROR_NONE)
456                 goto done; //LCOV_EXCL_LINE
457
458         ret = __iptables_flush_chain(stc->connection, STC_OUT_CHAIN);
459         if (ret != STC_ERROR_NONE)
460                 goto done; //LCOV_EXCL_LINE
461
462         ret = __iptables_flush_chain(stc->connection, STC_FRWD_CHAIN);
463         if (ret != STC_ERROR_NONE)
464                 goto done; //LCOV_EXCL_LINE
465
466         ret = __iptables_flush_chain(stc->connection, STC_TETHER_CHAIN);
467         if (ret != STC_ERROR_NONE)
468                 goto done; //LCOV_EXCL_LINE
469
470         ret = __ip6tables_flush_chain(stc->connection, STC_IN_CHAIN);
471         if (ret != STC_ERROR_NONE)
472                 goto done; //LCOV_EXCL_LINE
473
474         ret = __ip6tables_flush_chain(stc->connection, STC_OUT_CHAIN);
475         if (ret != STC_ERROR_NONE)
476                 goto done; //LCOV_EXCL_LINE
477
478         ret = __ip6tables_flush_chain(stc->connection, STC_FRWD_CHAIN);
479 done:
480         return ret;
481 }
482
483 stc_error_e iptables_init(void)
484 {
485         __STC_LOG_FUNC_ENTER__;
486
487         stc_error_e ret = STC_ERROR_NONE;
488         stc_s *stc = stc_get_manager();
489
490         if (!stc || !stc->connection) {
491                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
492                 return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
493         }
494
495         ret = __iptables_add_chain(stc->connection, STC_IN_CHAIN);
496         if (ret != STC_ERROR_NONE) {
497                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
498                 goto done; //LCOV_EXCL_LINE
499         }
500
501         ret = __iptables_add_chain(stc->connection, STC_OUT_CHAIN);
502         if (ret != STC_ERROR_NONE) {
503                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
504                 goto done; //LCOV_EXCL_LINE
505         }
506
507         ret = __iptables_add_chain(stc->connection, STC_FRWD_CHAIN);
508         if (ret != STC_ERROR_NONE) {
509                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
510                 goto done; //LCOV_EXCL_LINE
511         }
512
513         ret = __iptables_add_chain(stc->connection, STC_TETHER_CHAIN);
514         if (ret != STC_ERROR_NONE) {
515                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
516                 goto done; //LCOV_EXCL_LINE
517         }
518
519         ret = __ip6tables_add_chain(stc->connection, STC_IN_CHAIN);
520         if (ret != STC_ERROR_NONE) {
521                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
522                 goto done; //LCOV_EXCL_LINE
523         }
524
525         ret = __ip6tables_add_chain(stc->connection, STC_OUT_CHAIN);
526         if (ret != STC_ERROR_NONE) {
527                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
528                 goto done; //LCOV_EXCL_LINE
529         }
530
531         ret = __ip6tables_add_chain(stc->connection, STC_FRWD_CHAIN);
532         if (ret != STC_ERROR_NONE) {
533                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
534                 goto done; //LCOV_EXCL_LINE
535         }
536
537         ret = __iptables_add_chain_jump_rule("INPUT", STC_IN_CHAIN);
538         if (ret != STC_ERROR_NONE) {
539                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
540                 goto done; //LCOV_EXCL_LINE
541         }
542
543         ret = __iptables_add_chain_jump_rule("OUTPUT", STC_OUT_CHAIN);
544         if (ret != STC_ERROR_NONE) {
545                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
546                 goto done; //LCOV_EXCL_LINE
547         }
548
549         ret = __iptables_add_chain_jump_rule("FORWARD", STC_FRWD_CHAIN);
550         if (ret != STC_ERROR_NONE) {
551                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
552                 goto done; //LCOV_EXCL_LINE
553         }
554
555         ret = __iptables_add_chain_jump_rule("FORWARD", STC_TETHER_CHAIN);
556         if (ret != STC_ERROR_NONE) {
557                 __STC_LOG_FUNC_EXIT__;
558                 goto done;
559         }
560 done:
561         return ret;
562 }
563
564 stc_error_e iptables_deinit(void)
565 {
566         __STC_LOG_FUNC_ENTER__;
567
568         stc_error_e ret = STC_ERROR_NONE;
569         stc_s *stc = stc_get_manager();
570
571         if (!stc || !stc->connection) {
572                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
573                 return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
574         }
575
576         ret = __iptables_remove_chain(stc->connection, STC_IN_CHAIN);
577         if (ret != STC_ERROR_NONE) {
578                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
579                 goto done; //LCOV_EXCL_LINE
580         }
581
582         ret = __iptables_remove_chain(stc->connection, STC_OUT_CHAIN);
583         if (ret != STC_ERROR_NONE) {
584                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
585                 goto done; //LCOV_EXCL_LINE
586         }
587
588         ret = __iptables_remove_chain(stc->connection, STC_TETHER_CHAIN);
589         if (ret != STC_ERROR_NONE) {
590                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
591                 goto done; //LCOV_EXCL_LINE
592         }
593
594         ret = __iptables_remove_chain(stc->connection, STC_FRWD_CHAIN);
595         if (ret != STC_ERROR_NONE) {
596                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
597                 goto done; //LCOV_EXCL_LINE
598         }
599
600         ret = __ip6tables_remove_chain(stc->connection, STC_IN_CHAIN);
601         if (ret != STC_ERROR_NONE) {
602                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
603                 goto done; //LCOV_EXCL_LINE
604         }
605
606         ret = __ip6tables_remove_chain(stc->connection, STC_OUT_CHAIN);
607         if (ret != STC_ERROR_NONE) {
608                 __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
609                 goto done; //LCOV_EXCL_LINE
610         }
611
612         ret = __ip6tables_remove_chain(stc->connection, STC_FRWD_CHAIN);
613 done:
614         return ret;
615 }