From d87fcac96b45958bd777c7ac38cc0665dbde6062 Mon Sep 17 00:00:00 2001 From: Ermal Date: Mon, 10 Nov 2014 21:47:14 +0100 Subject: [PATCH] Do not require the default sysctl items to be set on the config.xml but rather extract the definitions from the sysctl tree. Also to reduce config.xml size --- conf.default/config.xml | 152 ----------------------- etc/inc/system.inc | 39 +++++- etc/inc/unbound.inc | 18 +-- usr/local/www/system_advanced_sysctl.php | 33 +++-- 4 files changed, 69 insertions(+), 173 deletions(-) diff --git a/conf.default/config.xml b/conf.default/config.xml index 01b2d5983..68c361aef 100644 --- a/conf.default/config.xml +++ b/conf.default/config.xml @@ -4,158 +4,6 @@ 9.9 pfsense_ng - - - - debug.pfftpproxy - default - - - - vfs.read_max - default - - - - net.inet.ip.portrange.first - default - - - - net.inet.tcp.blackhole - default - - - - net.inet.udp.blackhole - default - - - - net.inet.ip.random_id - default - - - - net.inet.tcp.drop_synfin - default - - - - net.inet.ip.redirect - default - - - - net.inet6.ip6.redirect - default - - - - net.inet6.ip6.use_tempaddr - default - - - - net.inet6.ip6.prefer_tempaddr - default - - - - net.inet.tcp.syncookies - default - - - - net.inet.tcp.recvspace - default - - - - net.inet.tcp.sendspace - default - - - - net.inet.ip.fastforwarding - default - - - - net.inet.tcp.delayed_ack - default - - - - net.inet.udp.maxdgram - default - - - - net.link.bridge.pfil_onlyip - default - - - - net.link.bridge.pfil_member - default - - - - net.link.bridge.pfil_bridge - default - - - - net.link.tap.user_open - default - - - - kern.randompid - default - - - - net.inet.ip.intr_queue_maxlen - default - - - - hw.syscons.kbd_reboot - default - - - - net.inet.tcp.log_debug - default - - - - net.inet.icmp.icmplim - default - - - - net.inet.tcp.tso - default - - - - net.inet.udp.checksum - default - - - - kern.ipc.maxsockbuf - default - - - - net.inet.icmp.reply_from_interface - default - - normal pfSense diff --git a/etc/inc/system.inc b/etc/inc/system.inc index 273b5a2ce..87bbdb211 100644 --- a/etc/inc/system.inc +++ b/etc/inc/system.inc @@ -72,13 +72,50 @@ function get_default_sysctl_value($id) { return $sysctls[$id]; } +function get_sysctl_descr($sysctl) { + unset($output); + $_gb = exec("/sbin/sysctl -nd {$sysctl}", $output); + + return $output[0]; +} + +function system_get_sysctls() { + global $config, $sysctls; + + $disp_sysctl = array(); + $disp_cache = array(); + if (is_array($config['sysctl']) && is_array($config['sysctl']['item'])) { + foreach($config['sysctl']['item'] as $id => $tunable) { + if ($tunable['value'] == "default") + $value = get_default_sysctl_value($tunable['tunable']); + else + $value = $tunable['value']; + + $disp_sysctl[$id] = $tunable; + $disp_sysctl[$id]['modified'] = true; + $disp_cache[$tunable['tunable']] = 'set'; + } + } + + foreach ($sysctls as $sysctl => $value) { + if (isset($disp_cache[$sysctl])) + continue; + + $disp_sysctl[$sysctl] = array('tunable' => $sysctl, 'value' => $value, 'descr' => get_sysctl_descr($sysctl)); + + + } + unset($disp_cache); + return $disp_sysctl; +} + function activate_sysctls() { global $config, $g, $sysctls; if ($g['platform'] == 'jail') return; - if (is_array($config['sysctl'])) { + if (is_array($config['sysctl']) && is_array($config['sysctl']['item'])) { foreach($config['sysctl']['item'] as $tunable) { if($tunable['value'] == "default") $value = get_default_sysctl_value($tunable['tunable']); diff --git a/etc/inc/unbound.inc b/etc/inc/unbound.inc index 408803551..b0473466f 100644 --- a/etc/inc/unbound.inc +++ b/etc/inc/unbound.inc @@ -79,14 +79,16 @@ function unbound_optimization() { * Larger socket buffer for busy servers * Check that it is set to 4MB (by default the OS has it configured to 4MB) */ - foreach ($config['sysctl']['item'] as $tunable) { - if ($tunable['tunable'] == 'kern.ipc.maxsockbuf') { - $so = floor(($tunable['value']/1024/1024)-1); - // Check to ensure that the number is not a negative - if ($so > 0) - $optimization['so_rcvbuf'] = "so-rcvbuf: {$so}m"; - else - unset($optimization['so_rcvbuf']); + if (is_array($config['sysctl']) && is_array($config['sysctl']['item'])) { + foreach ($config['sysctl']['item'] as $tunable) { + if ($tunable['tunable'] == 'kern.ipc.maxsockbuf') { + $so = floor(($tunable['value']/1024/1024)-1); + // Check to ensure that the number is not a negative + if ($so > 0) + $optimization['so_rcvbuf'] = "so-rcvbuf: {$so}m"; + else + unset($optimization['so_rcvbuf']); + } } } // Safety check in case kern.ipc.maxsockbuf is not available. diff --git a/usr/local/www/system_advanced_sysctl.php b/usr/local/www/system_advanced_sysctl.php index 7dcf3dfcf..51e1bf09b 100644 --- a/usr/local/www/system_advanced_sysctl.php +++ b/usr/local/www/system_advanced_sysctl.php @@ -47,25 +47,32 @@ require("guiconfig.inc"); $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/system_advanced_sysctl.php'); +if (!is_array($config['sysctl'])) + $config['sysctl'] = array(); if (!is_array($config['sysctl']['item'])) $config['sysctl']['item'] = array(); $a_tunable = &$config['sysctl']['item']; +$tunables = system_get_sysctls(); -if (is_numericint($_GET['id'])) - $id = $_GET['id']; -if (isset($_POST['id']) && is_numericint($_POST['id'])) - $id = $_POST['id']; +if (isset($_GET['id'])) + $id = htmlspecialchars_decode($_GET['id']); +if (isset($_POST['id'])) + $id = htmlspecialchars_decode($_POST['id']); $act = $_GET['act']; if (isset($_POST['act'])) $act = $_POST['act']; if ($act == "edit") { - if ($a_tunable[$id]) { + if (isset($a_tunable[$id])) { $pconfig['tunable'] = $a_tunable[$id]['tunable']; $pconfig['value'] = $a_tunable[$id]['value']; $pconfig['descr'] = $a_tunable[$id]['descr']; + } else if (isset($tunables[$id])) { + $pconfig['tunable'] = $tunables[$id]['tunable']; + $pconfig['value'] = $tunables[$id]['value']; + $pconfig['descr'] = $tunables[$id]['descr']; } } @@ -111,7 +118,7 @@ if ($_POST) { $tunableent['value'] = $_POST['value']; $tunableent['descr'] = $_POST['descr']; - if (isset($id) && $a_tunable[$id]) + if (isset($id) && isset($a_tunable[$id])) $a_tunable[$id] = $tunableent; else $a_tunable[] = $tunableent; @@ -175,7 +182,11 @@ include("head.inc"); - + $tunable): + + if (!isset($tunable['modified'])) + $i = $tunable['tunable']; + ?> @@ -185,10 +196,6 @@ include("head.inc"); - @@ -198,16 +205,18 @@ include("head.inc"); + +
')">
- +