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 d2037f8c42bfab4528760b1926d7ffd48ba87720..7f41c83711573e902c3ae85bb2e824445a27e955 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),
@@ -288,6 +287,36 @@ fw3_print_default_tail_rules(enum fw3_table table, enum fw3_family family,
                fw3_pr("-A delegate_forward -j reject\n");
 }
 
+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)
 {
index 562b895cde6277f39792d7c09a0d23afb52ece85..29babd8f644d5c34e4e73a8c26cde47ad135b355 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 6eb002f4dad717437cc6b218f63a9db0904d756f..65de9f5537b2bbc16e5495cd8a9d7011adf243eb 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 a9257a3685ab1ab58635fa361d78b99d6cbf6a2d..96afcd2dda4730051d0ec272e9d6c4b420621683 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;