add support for setting sysctls, remove tcp_westwood option, its not present on curre...
[project/firewall3.git] / defaults.c
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)