Revision dc13f5e0
Added by Phil Davis almost 9 years ago
src/etc/inc/services.inc | ||
---|---|---|
548 | 548 |
$custoptions .= "option custom-{$dhcpif}-{$itemidx} code {$item['number']} = {$itemtype};\n"; |
549 | 549 |
} |
550 | 550 |
} |
551 |
if (is_array($dhcpifconf['pool'])) { |
|
552 |
foreach ($dhcpifconf['pool'] as $poolidx => $poolconf) { |
|
553 |
if (is_array($poolconf['numberoptions']) && is_array($poolconf['numberoptions']['item'])) { |
|
554 |
foreach ($poolconf['numberoptions']['item'] as $itemidx => $item) { |
|
555 |
if (!empty($item['type'])) { |
|
556 |
$itemtype = $item['type']; |
|
557 |
} else { |
|
558 |
$itemtype = "text"; |
|
559 |
} |
|
560 |
$custoptions .= "option custom-{$dhcpif}-{$poolidx}-{$itemidx} code {$item['number']} = {$itemtype};\n"; |
|
561 |
} |
|
562 |
} |
|
563 |
} |
|
564 |
} |
|
551 | 565 |
} |
552 | 566 |
|
553 | 567 |
$dhcpdconf = <<<EOD |
... | ... | |
786 | 800 |
$dhcpdconf .= "subnet {$subnet} netmask {$subnetmask} {\n"; |
787 | 801 |
|
788 | 802 |
// Setup pool options |
789 |
foreach ($all_pools as $poolconf) { |
|
803 |
foreach ($all_pools as $all_pools_idx => $poolconf) {
|
|
790 | 804 |
if (!(ip_in_subnet($poolconf['range']['from'], "{$subnet}/{$ifcfgsn}") && ip_in_subnet($poolconf['range']['to'], "{$subnet}/{$ifcfgsn}"))) { |
791 | 805 |
// If the user has changed the subnet from the interfaces page and applied, |
792 | 806 |
// but has not updated the DHCP range, then the range to/from of the pool can be outside the subnet. |
... | ... | |
916 | 930 |
$dhcpdconf .= " option tftp-server-name \"{$poolconf['tftp']}\";\n"; |
917 | 931 |
} |
918 | 932 |
|
933 |
// Handle pool-specific options |
|
934 |
$dhcpdconf .= "\n"; |
|
935 |
// Ignore the first pool, which is the "overall" pool when $all_pools_idx is 0 - those are put outside the pool block later |
|
936 |
if ($poolconf['numberoptions']['item'] && ($all_pools_idx > 0)) { |
|
937 |
// Use the "real" pool index from the config, excluding the "overall" pool, and based from 0. |
|
938 |
// This matches the way $poolidx was used when generating the $custoptions string earlier. |
|
939 |
$poolidx = $all_pools_idx - 1; |
|
940 |
foreach ($poolconf['numberoptions']['item'] as $itemidx => $item) { |
|
941 |
$item_value = base64_decode($item['value']); |
|
942 |
if (empty($item['type']) || $item['type'] == "text") { |
|
943 |
$dhcpdconf .= " option custom-{$dhcpif}-{$poolidx}-{$itemidx} \"{$item_value}\";\n"; |
|
944 |
} else { |
|
945 |
$dhcpdconf .= " option custom-{$dhcpif}-{$poolidx}-{$itemidx} {$item_value};\n"; |
|
946 |
} |
|
947 |
} |
|
948 |
} |
|
949 |
|
|
919 | 950 |
// ldap-server |
920 | 951 |
if (!empty($poolconf['ldap']) && ($poolconf['ldap'] != $dhcpifconf['ldap'])) { |
921 | 952 |
$dhcpdconf .= " option ldap-server \"{$poolconf['ldap']}\";\n"; |
Also available in: Unified diff
Fix #6720 DHCP options by pool
It is a little bit tricky having to generate the unique "option custom-if-n-m code ..." lines at first where n = pool index and m = item index in the items of the pool. Then make sure to reference that later, getting the same pool index into the array of pools. The $all_pools array as the "overall" or "base" pool first (at index 0), followed by the user-specified pools at index 1, 2, 3,... - which are actually at indexes 0, 1, 2,... in the ordinary array of pools in the config. So the -1 at line 910 has to happen.
But it works for me.
(cherry picked from commit 285987208f31f38abe35b984b08645d43c11b001)