diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index 7cb1524463..f5826a586d 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -560,6 +560,9 @@ function interfaces_configure() { /* bring ip IP aliases */ interfaces_ipalias_configure(); + /* configure interface groups */ + interfaces_group_setup(); + if (!$g['booting']) { /* reconfigure static routes (kernel may have deleted them) */ system_routing_configure(); @@ -1758,6 +1761,33 @@ EOD; return 0; } + +function interfaces_group_setup() { + global $config; + + if (!is_array($config['ifgroups']['ifgroupentry'])) + return; + + foreach ($config['ifgroups']['ifgroupentry'] as $grouppar) + interface_group_setup($groupar); + + return; +} + +function interface_group_setup($groupname /* The parameter is an array */) { + global $config; + + if (!is_array($groupname)) + return; + $members = explode(" ", $groupname['members']); + foreach($members as $ifs) { + $realif = get_real_interface($ifs); + if ($realif) + mwexec("/sbin/ifconfig {$realif} group {$groupname['ifname']}"); + } + + return; +} /* XXX: stub for code that references the old functions(mostly packages) */ function get_real_wan_interface($interface = "wan") { diff --git a/usr/local/www/interfaces_groups.php b/usr/local/www/interfaces_groups.php index 09d0b9937f..3cffab79a6 100755 --- a/usr/local/www/interfaces_groups.php +++ b/usr/local/www/interfaces_groups.php @@ -43,9 +43,14 @@ $a_ifgroups = &$config['ifgroups']['ifgroupentry']; if ($_GET['act'] == "del") { if ($a_ifgroups[$_GET['id']]) { + $members = explode(" ", $a_ifgroups[$_GET[$id]]); + foreach ($members as $ifs) { + $realif = get_real_interface($ifs); + if ($realif) + mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$_GET[$id]]['ifname']); + } unset($a_ifgroups[$_GET['id']]); write_config(); - touch($d_ifgroupsdirty_path); header("Location: interfaces_groups.php"); exit; } @@ -93,7 +98,7 @@ include("head.inc"); - + diff --git a/usr/local/www/interfaces_groups_edit.php b/usr/local/www/interfaces_groups_edit.php index 1044beda27..68758859ce 100755 --- a/usr/local/www/interfaces_groups_edit.php +++ b/usr/local/www/interfaces_groups_edit.php @@ -59,9 +59,13 @@ if ($_POST) { unset($input_errors); $pconfig = $_POST; - foreach ($a_ifgroups as $groupentry) - if ($groupentry['ifname'] == $_POST['ifname']) - $input_errors[] = "Group name already exists!"; + if (empty($id)) { + foreach ($a_ifgroups as $groupentry) + if ($groupentry['ifname'] == $_POST['ifname']) + $input_errors[] = "Group name already exists!"; + } + if (preg_match("/([^a-zA-Z])+/", $_POST['ifname'], $match)) + $input_errors[] = "Only characters in a-z A-Z are allowed as interface name."; $ifgroupentry = array(); $ifgroupentry['ifname'] = $_POST['ifname']; @@ -81,13 +85,25 @@ if ($_POST) { $ifgroupentry['members'] = $members; $ifgroupentry['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto"); - if (isset($id) && $a_ifgroups[$id]) + if (isset($id) && $a_ifgroups[$id]) { + $omembers = explode(" ", $a_ifgroups[$id]['members']); + $nmembers = explode(" ", $members); + $delmembers = array_diff($omembers, $nmembers); + if (count($delmembers) > 0) { + foreach ($delmembers as $ifs) { + $realif = get_real_interface($ifs); + if ($realif) + mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']); + } + } $a_ifgroups[$id] = $ifgroupentry; - else + } else $a_ifgroups[] = $ifgroupentry; write_config(); + interface_group_setup($ifgroupentry); + header("Location: interfaces_groups.php"); exit; } else { @@ -186,6 +202,8 @@ function removeRow(el) { Interface +
+ No numbers or spaces are allowed. Only characters in a-zA-Z