iptables: fix regression with unintended free in need_protomatch
[project/firewall3.git] / xtables-10.h
index 6b52fff21265706dcdbe9af541fd2403bd6a86e1..6a2275d276ab62060363d9c6cf566bb4719dc4e6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * firewall3 - 3rd OpenWrt UCI firewall implementation
  *
- *   Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
+ *   Copyright (C) 2013 Jo-Philipp Wich <jo@mein.io>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
 #ifndef __FW3_XTABLES_10_H
 #define __FW3_XTABLES_10_H
 
+extern struct xtables_match *xtables_pending_matches;
+extern struct xtables_target *xtables_pending_targets;
+
+static inline void
+fw3_xt_reset(void)
+{
+       xtables_matches = NULL;
+       xtables_targets = NULL;
+
+       xtables_pending_matches = NULL;
+       xtables_pending_targets = NULL;
+}
+
+
 static inline const char *
 fw3_xt_get_match_name(struct xtables_match *m)
 {
@@ -31,10 +45,8 @@ fw3_xt_get_match_name(struct xtables_match *m)
 static inline void
 fw3_xt_set_match_name(struct xtables_match *m)
 {
-    if (m->real_name)
-        strcpy(m->m->u.user.name, m->real_name);
-    else
-        strcpy(m->m->u.user.name, m->name);
+    snprintf(m->m->u.user.name, sizeof(m->m->u.user.name), "%s",
+             m->real_name ? m->real_name : m->name);
 }
 
 static inline bool
@@ -78,10 +90,8 @@ fw3_xt_get_target_name(struct xtables_target *t)
 static inline void
 fw3_xt_set_target_name(struct xtables_target *t, const char *name)
 {
-    if (t->real_name)
-        strcpy(t->t->u.user.name, t->real_name);
-    else
-        strcpy(t->t->u.user.name, name);
+    snprintf(t->t->u.user.name, sizeof(t->t->u.user.name), "%s",
+             t->real_name ? t->real_name : name);
 }
 
 static inline bool
@@ -111,4 +121,32 @@ fw3_xt_merge_target_options(struct xtables_globals *g, struct xtables_target *t)
                                                t->extra_opts, &t->option_offset);
 }
 
+static inline void
+fw3_xt_print_matches(void *ip, struct xtables_rule_match *matches)
+{
+       struct xtables_rule_match *rm;
+       struct xtables_match *m;
+
+       for (rm = matches; rm; rm = rm->next)
+       {
+               m = rm->match;
+               printf(" -m %s", fw3_xt_get_match_name(m));
+
+               if (m->save)
+                       m->save(ip, m->m);
+       }
+}
+
+static inline void
+fw3_xt_print_target(void *ip, struct xtables_target *target)
+{
+       if (target)
+       {
+               printf(" -j %s", fw3_xt_get_target_name(target));
+
+               if (target->save)
+                       target->save(ip, target->t);
+       }
+}
+
 #endif