diff --git a/src/etc/inc/filter.inc b/src/etc/inc/filter.inc index bac2033e59..5408ae6788 100644 --- a/src/etc/inc/filter.inc +++ b/src/etc/inc/filter.inc @@ -2035,6 +2035,11 @@ function filter_nat_rules_generate() { $obtarget = ($obent['target'] == "other-subnet") ? $obent['targetip'] . '/' . $obent['targetip_subnet']: $obent['target']; $poolopts = (is_subnet($obtarget) || is_alias($obtarget)) ? $obent['poolopts'] : ""; + /* pool option source-hash allows specification of an optional source-hash key */ + if ($poolopts == "source-hash" && !empty($obent['source_hash_key'])) { + $poolopts = "source-hash ".$obent['source_hash_key']; + } + $natrules .= filter_nat_rules_generate_if($obent['interface'], $src, $obent['sourceport'], diff --git a/src/usr/local/www/firewall_nat_out_edit.php b/src/usr/local/www/firewall_nat_out_edit.php index 59ce4fae20..31c8be9ff9 100644 --- a/src/usr/local/www/firewall_nat_out_edit.php +++ b/src/usr/local/www/firewall_nat_out_edit.php @@ -97,6 +97,7 @@ if (isset($id) && $a_out[$id]) { $pconfig['targetip'] = $a_out[$id]['targetip']; $pconfig['targetip_subnet'] = $a_out[$id]['targetip_subnet']; $pconfig['poolopts'] = $a_out[$id]['poolopts']; + $pconfig['source_hash_key'] = $a_out[$id]['source_hash_key']; $pconfig['interface'] = $a_out[$id]['interface']; if (!$pconfig['interface']) { @@ -227,6 +228,7 @@ if ($_POST) { /* Verify Pool Options */ $poolopts = ""; + $source_hash_key = ""; if ($_POST['poolopts']) { if (is_subnet($_POST['target']) || ($_POST['target'] == "other-subnet")) { $poolopts = $_POST['poolopts']; @@ -237,6 +239,18 @@ if ($_POST) { $input_errors[] = gettext("Only Round Robin pool options may be chosen when selecting an alias."); } } + /* If specified, verify valid source-hash key or generate a valid key using md5 */ + if ($_POST['source_hash_key']) { + if (substr($_POST['source_hash_key'],0,2) == "0x") { + if (ctype_xdigit(substr($_POST['source_hash_key'],2)) && strlen($_POST['source_hash_key']) == 34) { + $source_hash_key = $_POST['source_hash_key']; + } else { + $input_errors[] = gettext("Incorrect format for source-hash key, \"0x\" must be followed by exactly 32 hexadecimal characters."); + } + } else { + $source_hash_key = "0x".md5($_POST['source_hash_key']); + } + } } /* if user has selected any as source, set it here */ @@ -279,6 +293,7 @@ if ($_POST) { $natent['targetip_subnet'] = (!isset($_POST['nonat'])) ? $_POST['targetip_subnet'] : ""; $natent['interface'] = $_POST['interface']; $natent['poolopts'] = $poolopts; + $natent['source_hash_key'] = $source_hash_key; /* static-port */ if (isset($_POST['staticnatport']) && $protocol_uses_ports && !isset($_POST['nonat'])) { @@ -571,6 +586,13 @@ $section->addInput(new Form_Select( '