X-Git-Url: http://git.archive.openwrt.org/?p=project%2Ffirewall3.git;a=blobdiff_plain;f=forwards.c;h=e27e4ee4c4dabbc9961dd2a4e5261f3e889871d5;hp=1715abc62c5285d0bf8e11c00506c08d8fc77f7c;hb=c03e20d7f594058ff223f30cf34de1b5e8210b8d;hpb=0004ef54410c9993eced6f518923af2d9da6c482 diff --git a/forwards.c b/forwards.c index 1715abc..e27e4ee 100644 --- a/forwards.c +++ b/forwards.c @@ -19,12 +19,16 @@ #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), + + { } }; @@ -44,14 +48,19 @@ fw3_load_forwards(struct fw3_state *state, struct uci_package *p) if (strcmp(s->type, "forwarding")) continue; - forward = malloc(sizeof(*forward)); - + forward = calloc(1, sizeof(*forward)); if (!forward) continue; - memset(forward, 0, sizeof(*forward)); + forward->enabled = true; - fw3_parse_options(forward, forward_opts, ARRAY_SIZE(forward_opts), s); + 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 +83,11 @@ fw3_load_forwards(struct fw3_state *state, struct uci_package *p) continue; } + /* NB: forward family... */ if (forward->_dest) { - setbit(forward->_dest->dst_flags, FW3_TARGET_ACCEPT); + 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)) @@ -92,60 +103,57 @@ fw3_load_forwards(struct fw3_state *state, struct uci_package *p) static void -print_chain(struct fw3_forward *forward) +append_chain(struct fw3_ipt_rule *r, struct fw3_forward *forward) { if (forward->src.any || !forward->src.set) - fw3_pr("-A delegate_forward"); + fw3_ipt_rule_append(r, "delegate_forward"); else - fw3_pr("-A zone_%s_forward", forward->src.name); + fw3_ipt_rule_append(r, "zone_%s_forward", forward->src.name); } -static void print_target(struct fw3_forward *forward) +static void set_target(struct fw3_ipt_rule *r, struct fw3_forward *forward) { if (forward->dest.any || !forward->dest.set) - fw3_pr(" -j ACCEPT\n"); + fw3_ipt_rule_target(r, "ACCEPT"); else - fw3_pr(" -j zone_%s_dest_ACCEPT\n", forward->dest.name); + fw3_ipt_rule_target(r, "zone_%s_dest_ACCEPT", forward->dest.name); } static void -print_forward(enum fw3_table table, enum fw3_family family, - struct fw3_forward *forward) +print_forward(struct fw3_ipt_handle *handle, struct fw3_forward *forward) { const char *s, *d; + struct fw3_ipt_rule *r; - if (table != FW3_TABLE_FILTER) + if (handle->table != FW3_TABLE_FILTER) return; - if (!fw3_is_family(forward, family)) + if (!fw3_is_family(forward, handle->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)) + if (!fw3_is_family(forward->_src, handle->family) || + !fw3_is_family(forward->_dest, handle->family)) { info(" ! Skipping due to different family of zone"); return; } - print_chain(forward); - fw3_format_comment("forwarding ", s, "->", d); - print_target(forward); + r = fw3_ipt_rule_new(handle); + fw3_ipt_rule_comment(r, "forwarding %s -> %s", s, d); + set_target(r, forward); + append_chain(r, forward); } void -fw3_print_forwards(enum fw3_table table, enum fw3_family family, - struct fw3_state *state) +fw3_print_forwards(struct fw3_ipt_handle *handle, struct fw3_state *state) { struct fw3_forward *forward; list_for_each_entry(forward, &state->forwards, list) - print_forward(table, family, forward); + print_forward(handle, forward); }