Use a global -m conntrack --ctstate DNAT rule to accept all port forwards of a given...
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 6 Nov 2013 23:56:36 +0000 (23:56 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Thu, 7 Nov 2013 00:15:57 +0000 (00:15 +0000)
redirects.c
zones.c

index b95c1ba1cb5b51f0178b403ca661a1fd109e7665..ca5d4d14f082c036603ac9c48e84018f17823a81 100644 (file)
@@ -422,33 +422,33 @@ set_target_nat(struct fw3_ipt_rule *r, struct fw3_redirect *redir)
                set_snat_dnat(r, redir->target, &redir->ip_dest, &redir->port_dest);
 }
 
-static void
-append_chain_filter(struct fw3_ipt_rule *r, struct fw3_redirect *redir)
-{
-       if (redir->target == FW3_FLAG_DNAT)
-       {
-               if (redir->local)
-                       fw3_ipt_rule_append(r, "zone_%s_input", redir->src.name);
-               else
-                       fw3_ipt_rule_append(r, "zone_%s_forward", redir->src.name);
-       }
-       else
-       {
-               if (redir->src.set && !redir->src.any)
-                       fw3_ipt_rule_append(r, "zone_%s_forward", redir->src.name);
-               else
-                       fw3_ipt_rule_append(r, "delegate_forward");
-       }
-}
-
-static void
-set_target_filter(struct fw3_ipt_rule *r, struct fw3_redirect *redir)
-{
-       if (redir->local)
-               fw3_ipt_rule_extra(r, "-m conntrack --ctstate DNAT");
-
-       fw3_ipt_rule_target(r, "ACCEPT");
-}
+//static void
+//append_chain_filter(struct fw3_ipt_rule *r, struct fw3_redirect *redir)
+//{
+//     if (redir->target == FW3_FLAG_DNAT)
+//     {
+//             if (redir->local)
+//                     fw3_ipt_rule_append(r, "zone_%s_input", redir->src.name);
+//             else
+//                     fw3_ipt_rule_append(r, "zone_%s_forward", redir->src.name);
+//     }
+//     else
+//     {
+//             if (redir->src.set && !redir->src.any)
+//                     fw3_ipt_rule_append(r, "zone_%s_forward", redir->src.name);
+//             else
+//                     fw3_ipt_rule_append(r, "delegate_forward");
+//     }
+//}
+//
+//static void
+//set_target_filter(struct fw3_ipt_rule *r, struct fw3_redirect *redir)
+//{
+//     if (redir->local)
+//             fw3_ipt_rule_extra(r, "-m conntrack --ctstate DNAT");
+//
+//     fw3_ipt_rule_target(r, "ACCEPT");
+//}
 
 static void
 set_comment(struct fw3_ipt_rule *r, const char *name, int num, bool ref)
@@ -506,22 +506,22 @@ print_redirect(struct fw3_ipt_handle *h, struct fw3_state *state,
                break;
 
        case FW3_TABLE_FILTER:
-               src = &redir->ip_src;
-               dst = &redir->ip_redir;
-               spt = &redir->port_src;
-               dpt = &redir->port_redir;
-
-               r = fw3_ipt_rule_create(h, proto, NULL, NULL, src, dst);
-               fw3_ipt_rule_sport_dport(r, spt, dpt);
-               fw3_ipt_rule_mac(r, mac);
-               fw3_ipt_rule_ipset(r, &redir->ipset);
-               fw3_ipt_rule_limit(r, &redir->limit);
-               fw3_ipt_rule_time(r, &redir->time);
-               fw3_ipt_rule_mark(r, &redir->mark);
-               set_target_filter(r, redir);
-               fw3_ipt_rule_extra(r, redir->extra);
-               set_comment(r, redir->name, num, false);
-               append_chain_filter(r, redir);
+               //src = &redir->ip_src;
+               //dst = &redir->ip_redir;
+               //spt = &redir->port_src;
+               //dpt = &redir->port_redir;
+               //
+               //r = fw3_ipt_rule_create(h, proto, NULL, NULL, src, dst);
+               //fw3_ipt_rule_sport_dport(r, spt, dpt);
+               //fw3_ipt_rule_mac(r, mac);
+               //fw3_ipt_rule_ipset(r, &redir->ipset);
+               //fw3_ipt_rule_limit(r, &redir->limit);
+               //fw3_ipt_rule_time(r, &redir->time);
+               //fw3_ipt_rule_mark(r, &redir->mark);
+               //set_target_filter(r, redir);
+               //fw3_ipt_rule_extra(r, redir->extra);
+               //set_comment(r, redir->name, num, false);
+               //append_chain_filter(r, redir);
                break;
 
        default:
@@ -557,15 +557,15 @@ print_reflection(struct fw3_ipt_handle *h, struct fw3_state *state,
                fw3_ipt_rule_replace(r, "zone_%s_postrouting", redir->dest.name);
                break;
 
-       case FW3_TABLE_FILTER:
-               r = fw3_ipt_rule_create(h, proto, NULL, NULL, ia, &redir->ip_redir);
-               fw3_ipt_rule_sport_dport(r, NULL, &redir->port_redir);
-               fw3_ipt_rule_limit(r, &redir->limit);
-               fw3_ipt_rule_time(r, &redir->time);
-               set_comment(r, redir->name, num, true);
-               fw3_ipt_rule_target(r, "zone_%s_dest_ACCEPT", redir->dest.name);
-               fw3_ipt_rule_replace(r, "zone_%s_forward", redir->dest.name);
-               break;
+       //case FW3_TABLE_FILTER:
+       //      r = fw3_ipt_rule_create(h, proto, NULL, NULL, ia, &redir->ip_redir);
+       //      fw3_ipt_rule_sport_dport(r, NULL, &redir->port_redir);
+       //      fw3_ipt_rule_limit(r, &redir->limit);
+       //      fw3_ipt_rule_time(r, &redir->time);
+       //      set_comment(r, redir->name, num, true);
+       //      fw3_ipt_rule_target(r, "zone_%s_dest_ACCEPT", redir->dest.name);
+       //      fw3_ipt_rule_replace(r, "zone_%s_forward", redir->dest.name);
+       //      break;
 
        default:
                break;
diff --git a/zones.c b/zones.c
index 8225601897f1d3c8d788e4d74bd6d1f6b5d235a7..982424930a365887fe657b4c06c2d817ffed3d57 100644 (file)
--- a/zones.c
+++ b/zones.c
@@ -473,6 +473,19 @@ print_zone_rule(struct fw3_ipt_handle *handle, struct fw3_state *state,
        switch (handle->table)
        {
        case FW3_TABLE_FILTER:
+               if (has(zone->flags, handle->family, FW3_FLAG_DNAT))
+               {
+                       r = fw3_ipt_rule_new(handle);
+                       fw3_ipt_rule_extra(r, "-m conntrack --ctstate DNAT");
+                       fw3_ipt_rule_target(r, fw3_flag_names[FW3_FLAG_ACCEPT]);
+                       fw3_ipt_rule_append(r, "zone_%s_input", zone->name);
+
+                       r = fw3_ipt_rule_new(handle);
+                       fw3_ipt_rule_extra(r, "-m conntrack --ctstate DNAT");
+                       fw3_ipt_rule_target(r, fw3_flag_names[FW3_FLAG_ACCEPT]);
+                       fw3_ipt_rule_append(r, "zone_%s_forward", zone->name);
+               }
+
                r = fw3_ipt_rule_new(handle);
                fw3_ipt_rule_target(r, "zone_%s_src_%s", zone->name,
                                     fw3_flag_names[zone->policy_input]);