diff --git a/src/etc/inc/filter.inc b/src/etc/inc/filter.inc index 611425e665..18c4cc36b7 100644 --- a/src/etc/inc/filter.inc +++ b/src/etc/inc/filter.inc @@ -136,8 +136,19 @@ $icmp6types = array( "mtrace" => gettext("mtrace messages") ); -global $tracker; -global $negate_tracker; +/* + * Fixed tracker values (used to group and track usage in GUI): + * + * bogons rules: 10000 + * anti-lockout rules: 11000 + * RFC1918 rules: 12000 + * + */ + +define("ANTILOCKOUT_TRACKER", 10000); +define("BOGONS_TRACKER", 11000); +define("RFC1918_TRACKER", 12000); + $tracker = 1000000000; $negate_tracker = 10000000; @@ -3271,10 +3282,11 @@ EOD; } if (isset($config['interfaces'][$on]['blockbogons'])) { + $bogons_tracker = BOGONS_TRACKER; $ipfrules .= << to any tracker {$increment_tracker($tracker)} label "{$fix_rule_label("block bogon IPv4 networks from {$oc['descr']}")}" +block in $bogonlog quick on \${$oc['descr']} from to any tracker $bogons_tracker label "{$fix_rule_label("block bogon IPv4 networks from {$oc['descr']}")}" EOD; @@ -3282,7 +3294,7 @@ EOD; $ipfrules .= << to any tracker {$increment_tracker($tracker)} label "{$fix_rule_label("block bogon IPv6 networks from {$oc['descr']}")}" +block in $bogonlog quick on \${$oc['descr']} from to any tracker $bogons_tracker label "{$fix_rule_label("block bogon IPv6 networks from {$oc['descr']}")}" EOD; } @@ -3317,13 +3329,14 @@ EOD; if (isset($config['interfaces'][$on]['blockpriv'])) { if ($isbridged == false) { + $rfc1918_tracker = RFC1918_TRACKER; $ipfrules .= << 1 && !empty($FilterIflist['lan']['if'])) { /* if antilockout is enabled, LAN exists and has * an IP and subnet mask assigned @@ -3540,7 +3554,7 @@ EOD; $lanif = $FilterIflist['lan']['if']; $ipfrules .= << 1000 && $i < count($units)) { + $num /= 1000; + $i++; + } + round($num, $precision); + + return ("$num {$units[$i]}"); +} + function update_filter_reload_status($text) { global $g; diff --git a/src/usr/local/www/firewall_rules.php b/src/usr/local/www/firewall_rules.php index 98472804c0..04d9ee7651 100644 --- a/src/usr/local/www/firewall_rules.php +++ b/src/usr/local/www/firewall_rules.php @@ -72,6 +72,51 @@ require_once("shaper.inc"); $pgtitle = array(gettext("Firewall"), gettext("Rules")); $shortcut_section = "firewall"; +function get_pf_rules($rules, $tracker) { + + if ($rules == NULL || !is_array($rules)) + return (NULL); + + $arr = array(); + for ($i = 0; $i < count($rules); $i++) { + if ($rules[$i]['tracker'] === $tracker) + $arr[] = $rules[$i]; + } + + if (count($arr) == 0) + return (NULL); + + return ($arr); +} + +function print_states($tracker) { + global $rulescnt; + + $rulesid = ""; + $bytes = 0; + $states = 0; + $packets = 0; + $evaluations = 0; + $stcreations = 0; + $rules = get_pf_rules($rulescnt, $tracker); + for ($j = 0; is_array($rules) && $j < count($rules); $j++) { + $bytes += $rules[$j]['bytes']; + $states += $rules[$j]['states']; + $packets += $rules[$j]['packets']; + $evaluations += $rules[$j]['evaluations']; + $stcreations += $rules[$j]['state creations']; + if (strlen($rulesid) > 0) + $rulesid .= ","; + $rulesid .= "{$rules[$j]['id']}"; + } + printf("packets: %s
bytes: %s
states: %s
state creations: %s\" data-html=\"true\">", + format_number($evaluations), format_number($packets), format_bytes($bytes), + format_number($states), format_number($stcreations)); + printf("%d/%s

", format_number($states), format_bytes($bytes)); +} + function delete_nat_association($id) { global $config; @@ -300,8 +345,10 @@ if (isset($config['interfaces'][$if]['blockbogons'])) { $showblockbogons = true; } -?> +/* Load the counter data of each pf rule. */ +$rulescnt = pfSense_get_pf_rules(); +?>

@@ -311,6 +358,7 @@ if (isset($config['interfaces'][$if]['blockbogons'])) { + @@ -335,6 +383,7 @@ if (isset($config['interfaces'][$if]['blockbogons'])) { "> + * * * @@ -353,6 +402,7 @@ if (isset($config['interfaces'][$if]['blockbogons'])) { "> + * * @@ -371,6 +421,7 @@ if (isset($config['interfaces'][$if]['blockbogons'])) { "> + * * @@ -592,6 +643,7 @@ for ($i = 0; isset($a_filter[$i]); $i++): } } ?> + -