Add common fw3_address_to_string() helper function
[project/firewall3.git] / forwards.c
index c212c8c..6ea0497 100644 (file)
 #include "forwards.h"
 
 
-static struct fw3_option forward_opts[] = {
+const struct fw3_option fw3_forward_opts[] = {
+       FW3_OPT("enabled",             bool,     forward,     enabled),
+
        FW3_OPT("name",                string,   forward,     name),
        FW3_OPT("family",              family,   forward,     family),
 
        FW3_OPT("src",                 device,   forward,     src),
        FW3_OPT("dest",                device,   forward,     dest),
+
+       { }
 };
 
 
@@ -51,7 +55,15 @@ fw3_load_forwards(struct fw3_state *state, struct uci_package *p)
 
                memset(forward, 0, sizeof(*forward));
 
-               fw3_parse_options(forward, forward_opts, ARRAY_SIZE(forward_opts), s);
+               forward->enabled = true;
+
+               fw3_parse_options(forward, fw3_forward_opts, s);
+
+               if (!forward->enabled)
+               {
+                       fw3_free_forward(forward);
+                       continue;
+               }
 
                if (forward->src.invert || forward->dest.invert)
                {
@@ -74,9 +86,11 @@ fw3_load_forwards(struct fw3_state *state, struct uci_package *p)
                        continue;
                }
 
+               /* NB: forward family... */
                if (forward->_dest)
                {
-                       forward->_dest->has_dest_target[FW3_TARGET_ACCEPT] = true;
+                       setbit(forward->_dest->flags[0], FW3_FLAG_ACCEPT);
+                       setbit(forward->_dest->flags[1], FW3_FLAG_ACCEPT);
 
                        if (forward->_src &&
                            (forward->_src->conntrack || forward->_dest->conntrack))
@@ -109,26 +123,28 @@ static void print_target(struct fw3_forward *forward)
 }
 
 static void
-print_forward(enum fw3_table table, enum fw3_family family,
-              struct fw3_forward *forward)
+print_forward(struct fw3_forward *forward, enum fw3_family family,
+              enum fw3_table table)
 {
        const char *s, *d;
 
        if (table != FW3_TABLE_FILTER)
                return;
 
-       if (!fw3_is_family(forward, family) ||
-           (forward->_src && !fw3_is_family(forward->_src, family)) ||
-               (forward->_dest && !fw3_is_family(forward->_dest, family)))
+       if (!fw3_is_family(forward, family))
                return;
 
        s = forward->_src  ? forward->_src->name  : "*";
        d = forward->_dest ? forward->_dest->name : "*";
 
-       if (forward->name)
-               info("   * Forward '%s'", forward->name);
-       else
-               info("   * Forward %s->%s", s, d);
+       info("   * Forward '%s' -> '%s'", s, d);
+
+       if (!fw3_is_family(forward->_src, family) ||
+           !fw3_is_family(forward->_dest, family))
+       {
+               info("     ! Skipping due to different family of zone");
+               return;
+       }
 
        print_chain(forward);
        fw3_format_comment("forwarding ", s, "->", d);
@@ -136,11 +152,11 @@ print_forward(enum fw3_table table, enum fw3_family family,
 }
 
 void
-fw3_print_forwards(enum fw3_table table, enum fw3_family family,
-                   struct fw3_state *state)
+fw3_print_forwards(struct fw3_state *state, enum fw3_family family,
+                   enum fw3_table table)
 {
        struct fw3_forward *forward;
 
        list_for_each_entry(forward, &state->forwards, list)
-               print_forward(table, family, forward);
+               print_forward(forward, family, table);
 }