add support for setting sysctls, remove tcp_westwood option, its not present on curre...
authorJo-Philipp Wich <jow@openwrt.org>
Fri, 22 Feb 2013 13:30:21 +0000 (14:30 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Fri, 22 Feb 2013 13:40:17 +0000 (14:40 +0100)
defaults.c
defaults.h
main.c
options.h

index d2037f8..7f41c83 100644 (file)
@@ -74,7 +74,6 @@ const struct fw3_option fw3_default_opts[] = {
 
        FW3_OPT("tcp_syncookies",      bool,     defaults, tcp_syncookies),
        FW3_OPT("tcp_ecn",             bool,     defaults, tcp_ecn),
-       FW3_OPT("tcp_westwood",        bool,     defaults, tcp_westwood),
        FW3_OPT("tcp_window_scaling",  bool,     defaults, tcp_window_scaling),
 
        FW3_OPT("accept_redirects",    bool,     defaults, accept_redirects),
@@ -289,6 +288,36 @@ fw3_print_default_tail_rules(enum fw3_table table, enum fw3_family family,
 }
 
 static void
+set_default(const char *name, bool set)
+{
+       FILE *f;
+       char path[sizeof("/proc/sys/net/ipv4/tcp_window_scaling\0")];
+
+       snprintf(path, sizeof(path), "/proc/sys/net/ipv4/tcp_%s", name);
+
+       info(" * Set tcp_%s to %s", name, set ? "on" : "off", name);
+
+       if (!(f = fopen(path, "w")))
+       {
+               info("   ! Unable to write value: %s", strerror(errno));
+               return;
+       }
+
+       fprintf(f, "%u\n", set);
+       fclose(f);
+}
+
+void
+fw3_set_defaults(struct fw3_state *state)
+{
+       info("Setting sysctl values");
+
+       set_default("ecn",            state->defaults.tcp_ecn);
+       set_default("syncookies",     state->defaults.tcp_syncookies);
+       set_default("window_scaling", state->defaults.tcp_window_scaling);
+}
+
+static void
 reset_policy(enum fw3_table table)
 {
        if (table != FW3_TABLE_FILTER)
index 562b895..29babd8 100644 (file)
@@ -34,6 +34,8 @@ void fw3_print_default_head_rules(enum fw3_table table, enum fw3_family family,
 void fw3_print_default_tail_rules(enum fw3_table table, enum fw3_family family,
                                   struct fw3_state *state);
 
+void fw3_set_defaults(struct fw3_state *state);
+
 void fw3_flush_rules(enum fw3_table table, enum fw3_family family,
                      bool pass2, struct fw3_state *state);
 
diff --git a/main.c b/main.c
index 6eb002f..65de9f5 100644 (file)
--- a/main.c
+++ b/main.c
@@ -240,11 +240,15 @@ start(struct fw3_state *state, bool reload)
        enum fw3_family family;
        enum fw3_table table;
 
-       if (!print_rules && !reload &&
-           fw3_command_pipe(false, "ipset", "-exist", "-"))
+       if (!print_rules && !reload)
        {
-               fw3_create_ipsets(state);
-               fw3_command_close();
+               fw3_set_defaults(state);
+
+               if (fw3_command_pipe(false, "ipset", "-exist", "-"))
+               {
+                       fw3_create_ipsets(state);
+                       fw3_command_close();
+               }
        }
 
        for (family = FW3_FAMILY_V4; family <= FW3_FAMILY_V6; family++)
index a9257a3..96afcd2 100644 (file)
--- a/options.h
+++ b/options.h
@@ -228,7 +228,6 @@ struct fw3_defaults
 
        bool tcp_syncookies;
        bool tcp_ecn;
-       bool tcp_westwood;
        bool tcp_window_scaling;
 
        bool accept_redirects;