+static void __add_iptables_rule(int64_t classid, nfacct_rule_intend intend,
+ stc_iface_type_e iftype)
+{
+ char *default_ifname = stc_default_connection_get_ifname();
+ struct nfacct_rule counter;
+ stc_s *stc = stc_get_manager();
+ if (!stc) {
+ g_free(default_ifname); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
+ }
+
+ if (!stc->carg) {
+ stc->carg = MALLOC0(counter_arg_s, 1); //LCOV_EXCL_LINE
+ if (stc->carg == NULL) { //LCOV_EXCL_LINE
+ g_free(default_ifname); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
+ }
+
+ stc->carg->sock = stc_monitor_get_counter_socket(); //LCOV_EXCL_LINE
+ }
+
+ counter.carg = stc->carg;
+ counter.classid = classid;
+ counter.intend = intend;
+ counter.iftype = iftype;
+ g_strlcpy(counter.ifname, default_ifname, MAX_IFACE_LENGTH);
+ g_free(default_ifname);
+
+ /* iptables rule */
+ __add_iptables_in(&counter);
+ __add_iptables_out(&counter);
+
+ /* ip6tables rule */
+ __add_ip6tables_in(&counter);
+ __add_ip6tables_out(&counter);
+}
+
+static void __del_iptables_rule(int64_t classid, nfacct_rule_intend intend,
+ stc_iface_type_e iftype)
+{
+ char *default_ifname = stc_default_connection_get_ifname();
+ struct nfacct_rule counter;
+ stc_s *stc = stc_get_manager();
+ if (!stc) {
+ g_free(default_ifname); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
+ }
+
+ if (!stc->carg) {
+ stc->carg = MALLOC0(counter_arg_s, 1); //LCOV_EXCL_LINE
+ if (stc->carg == NULL) { //LCOV_EXCL_LINE
+ g_free(default_ifname); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
+ }
+
+ stc->carg->sock = stc_monitor_get_counter_socket(); //LCOV_EXCL_LINE
+ }
+
+ counter.carg = stc->carg;
+ counter.classid = classid;
+ counter.intend = intend;
+ counter.iftype = iftype;
+ g_strlcpy(counter.ifname, default_ifname, MAX_IFACE_LENGTH);
+ g_free(default_ifname);
+
+ /* iptables rule */
+ __del_iptables_in(&counter);
+ __del_iptables_out(&counter);
+
+ /* ip6tables rule */
+ __del_ip6tables_in(&counter);
+ __del_ip6tables_out(&counter);
+}
+