diff options
author | Scott Ullrich <sullrich@pfsense.org> | 2005-10-17 16:11:07 +0000 |
---|---|---|
committer | Scott Ullrich <sullrich@pfsense.org> | 2005-10-17 16:11:07 +0000 |
commit | b7ff5e40d22b485d42be070d28937699a92d5983 (patch) | |
tree | edfeca80bd7ca1a8fcaedd57e9ac2d5eafdcf572 | |
parent | c435798ff939fe2309e8abfa3c9c923becc5faf6 (diff) | |
download | pfsense-b7ff5e40d22b485d42be070d28937699a92d5983.zip pfsense-b7ff5e40d22b485d42be070d28937699a92d5983.tar.gz |
MFC 6920
Allow for parent queues to work. Cleaned up code that does root queue detection and discovered some odd bugs that made me wonder how it worked correctly. Queues can be reordered (honestly, this is kinda pointless, but I put it in cause it was easier to punt to the user than doing queue trees correctly) This is obviously an XXX and needs to be fixed.
-rw-r--r-- | etc/inc/shaper.inc | 68 | ||||
-rwxr-xr-x | usr/local/www/firewall_shaper_queues.php | 95 |
2 files changed, 112 insertions, 51 deletions
diff --git a/etc/inc/shaper.inc b/etc/inc/shaper.inc index 3fadcb2..21d931a 100644 --- a/etc/inc/shaper.inc +++ b/etc/inc/shaper.inc @@ -156,13 +156,17 @@ function is_subqueue_used_on_interface($queuename, $interface) { if (!is_array($qconfig['shaper']['queue'])) return 0; foreach ($qconfig['shaper']['queue'] as $queue) { - if($queue['attachtoqueue'] == $queuename) - $subqueue_interface = filter_is_queue_being_used_on_interface($queue['name'], $interface); - /* Useful debugging code for when queues are messed up - * echo "{$subqueue_interface}/{$interface}/{$queue['name']}/{$queuename}\n"; - */ - if ($subqueue_interface != ""){ - return 1; + if($queue['attachtoqueue'] == $queuename) { + /* recurse if we're a parent queue */ + if ($queue['parentqueue'] == "on") { + return is_subqueue_used_on_interface($queue['name'], $interface); + } + + /* If we're not a parent check to see if the queue is used on this interface */ + $subqueue_interface = filter_is_queue_being_used_on_interface($queue['name'], $interface); + if ($subqueue_interface != ""){ + return 1; + } } } return 0; @@ -199,28 +203,8 @@ function filter_setup_altq_interfaces() { $queue_names = ""; $is_first = ""; - $workting_with_interface = $ifname; - - foreach ($config['shaper']['queue'] as $queue) { - $rule_interface = ""; - $q = $queue; - $rule_interface = filter_is_queue_being_used_on_interface($q['name'], $workting_with_interface); - if ($rule_interface == $workting_with_interface) { - if(!isset($q['attachtoqueue'])) { - if($is_first) $queue_names .= ", "; - $queue_names .= $q['name']; - $is_first = "1"; - } - } else { - if(isset($q['parentqueue']) && ($q['parentqueue'] <> "")) { - if(is_subqueue_used_on_interface($q['name'], $workting_with_interface)) { - $queue_names .= " "; - $queue_names .= $q['name']; - } - } - } + $queue_names = find_root_queue($ifname); - } if($queue_names <> ""){ $altq_rules .= "altq on {$config['interfaces'][$ifname]['if']} "; if($config['interfaces'][$ifname]['bandwidth'] <> "") @@ -234,6 +218,34 @@ function filter_setup_altq_interfaces() { return $altq_rules; } +/* Find the root queue for an interface */ +function find_root_queue($ifname) { + global $config; + + $dbg = fopen("/tmp/debug", 'a'); + foreach ($config['shaper']['queue'] as $queue) { + $rule_interface = ""; + $q = $queue; + fwrite($dbg, "interface: {$ifname}\n"); + fwrite($dbg, "queue: {$q['name']} parent: {$q['parentqueue']} attached: {$q['attachtoqueue']}\n"); + /* if we're a parentqueue and aren't attached to another queue we're probably a root */ + if ((isset($q['parentqueue']) && $q['parentqueue'] <> "") && (!isset($q['attachtoqueue']) || $q['attachtoqueue'] == "")) { + fwrite($dbg, "queue: {$q['name']} is a parent\n"); + /* Confirm that this is a valid queue for this interface */ + $rule_interface = is_subqueue_used_on_interface($q['name'], $ifname); + if ($rule_interface == 1) { + fwrite($dbg, "queue: {$q['name']} is a parent on {$ifname}\n"); + $queue_names .= " "; + $queue_names .= $q['name']; + } + } + } + fclose($dbg); + return $queue_names; +} + + + function is_queue_attached_children($name) { global $config; diff --git a/usr/local/www/firewall_shaper_queues.php b/usr/local/www/firewall_shaper_queues.php index 1379ee6..a07538c 100755 --- a/usr/local/www/firewall_shaper_queues.php +++ b/usr/local/www/firewall_shaper_queues.php @@ -101,6 +101,53 @@ if ($_GET['act'] == "del") { } } +if ($_POST) { + /* yuck - IE won't send value attributes for image buttons, while Mozilla does - + so we use .x/.y to fine move button clicks instead... */ + unset($movebtn); + foreach ($_POST as $pn => $pd) { + if (preg_match("/move_(\d+)_x/", $pn, $matches)) { + $movebtn = $matches[1]; + break; + } + } + /* move selected rules before this rule */ + if (isset($movebtn) && is_array($_POST['queue']) && count($_POST['queue'])) { + $a_queue_new = array(); + + /* copy all rules < $movebtn and not selected */ + for ($i = 0; $i < $movebtn; $i++) { + if (!in_array($i, $_POST['queue'])) + $a_queue_new[] = $a_queues[$i]; + } + + /* copy all selected rules */ + for ($i = 0; $i < count($a_queues); $i++) { + if ($i == $movebtn) + continue; + if (in_array($i, $_POST['queue'])) + $a_queue_new[] = $a_queues[$i]; + } + + /* copy $movebtn rule */ + if ($movebtn < count($a_queues)) + $a_queue_new[] = $a_queues[$movebtn]; + + /* copy all rules > $movebtn and not selected */ + for ($i = $movebtn+1; $i < count($a_queues); $i++) { + if (!in_array($i, $_POST['queue'])) + $a_queue_new[] = $a_queues[$i]; + } + + $a_queues = $a_queue_new; + write_config(); + touch($d_shaperconfdirty_path); + header("Location: firewall_shaper_queues.php"); + exit; + } +} + + $pgtitle = "Firewall: Shaper: Queues"; include("head.inc"); @@ -110,6 +157,7 @@ include("head.inc"); <?php include("fbegin.inc"); ?> <p class="pgtitle"><?=$pgtitle?></p> <form action="firewall_shaper_queues.php" method="post"> +<script type="text/javascript" language="javascript" src="row_toggle.js"></script> <?php if ($input_errors) print_input_errors($input_errors); ?> <?php if ($savemsg) print_info_box($savemsg); ?> <?php if (file_exists($d_shaperconfdirty_path)): ?><p> @@ -129,34 +177,34 @@ include("head.inc"); <td> <div id="mainarea"> <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0"> - <tr> - <td width="5%" class="listhdrr">No.</td> + <tr id="frheader"> + <td width="3%" class="list"> </td> + <td width="0%" class="list"> </td> <td width="5%" class="listhdrr">Flags</td> <td width="5%" class="listhdrr">Priority</td> <td width="5%" class="listhdr">Default</td> <td width="5%" class="listhdr">Bandwidth</td> - <td width="70%" class="listhdr">Name</td> - <td width="10%" class="list"></td> + <td width="65%" class="listhdr">Name</td> + <td width="10%" class="list"> </td> </tr> <?php $i = 0; foreach ($a_queues as $queue): ?> - <tr valign="top"> - <td class="listlr" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';"> - <?=($i+1);?> - </td> - <td class="listlr" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';"> - <?php - if($queue['red'] <> "") echo " RED"; - if($queue['rio'] <> "") echo " RIO"; - if($queue['ecn'] <> "") echo " ECN"; - if($queue['borrow'] <> "") echo " Borrow"; - if(isset($queue['ack'])) echo "ACK" - ?> - + <tr valign="top" id="fr<?=$i;?>"> +<td class="listt"><input type="checkbox" id="frc<?=$i;?>" name="queue[]" value="<?=$i;?>" onClick="fr_bgcolor('<?=$i;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;"></td> + <td class="listt" onClick="fr_toggle(<?=$i;?>)" id="frc<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';"> </td> + <td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';"> +<?php + if($queue['red'] <> "") echo " RED"; + if($queue['rio'] <> "") echo " RIO"; + if($queue['ecn'] <> "") echo " ECN"; + if($queue['borrow'] <> "") echo " Borrow"; + if(isset($queue['ack'])) echo "ACK" +?> + </td> - <td class="listr" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';"> + <td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';"> <?=$queue['priority'];?> </td> - <td class="listr" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';"> + <td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';"> <?php if($queue['defaultqueue'] <> "") { echo "Yes"; @@ -165,17 +213,18 @@ include("head.inc"); } ?> </td> - <td class="listr" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';"> + <td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';"> <?=htmlspecialchars($queue['bandwidth']);?> <?=htmlspecialchars($queue['bandwidthtype']);?> </td> - <td class="listbg" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';"> + <td class="listbg" onClick="fr_toggle(<?=$i;?>)" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';"> <font color="#FFFFFF"><?=htmlspecialchars($queue['name']);?> </td> <td valign="middle" nowrap class="list"> <table border="0" cellspacing="0" cellpadding="1"> <tr> + <td><input name="move_<?=$i;?>" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" width="17" height="17" title="move selected queue before this rule" onMouseOver="fr_insline(<?=$i;?>, true)" onMouseOut="fr_insline(<?=$i;?>, false)"></td> <td valign="middle"><a href="firewall_shaper_queues_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td> <td valign="middle"><a href="firewall_shaper_queues.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this queue?')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td> </tr> @@ -184,7 +233,7 @@ include("head.inc"); </tr> <?php $i++; endforeach; $total_queues = $i; ?> <tr> - <td class="list" colspan="6"></td> + <td class="list" colspan="7"></td> <td class="list"> <table border="0" cellspacing="0" cellpadding="1"> <tr> @@ -193,7 +242,7 @@ include("head.inc"); </table> </td> </tr> - <tr><td colspan="6"> + <tr><td colspan="7"> <p> <strong><span class="red">Note:</span></strong><strong><br></strong> A queue can only be deleted if it is not referenced by any rules.<br> |