r3010 - maintenance->trunk sync of changesets 3008~3009
authorDenis Ovsienko <infrastation@yandex.ru>
Mon, 27 Jul 2009 12:57:18 +0000 (12:57 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Mon, 27 Jul 2009 12:57:18 +0000 (12:57 +0000)
ChangeLog
inc/database.php
inc/functions.php
inc/init.php
inc/interface.php

index 64a2e64f8d505b1bb8b37df6dd774d277bd82b5b..7ce9aec7338cb416f8d40dd76985437d18b943f1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+0.17.3
+       update: even better search function (ticket:20)
 0.17.2 2009-07-22
        new feature: configure default SNMP community (by jthurman)
        new feature: "$untagged", "$portless", "$nameless" and "$masklen_OP_NN" autotags
index 70543c0cec839060915c250f718220fa57886d4e..22e733536df7b1fe8c2eb28685b5f347016f16d5 100644 (file)
@@ -1632,6 +1632,16 @@ function getObjectSearchResults ($what)
                $ret[$objRecord['id']]['id'] = $objRecord['id'];
                $ret[$objRecord['id']]['by_attr'] = $objRecord['by_attr'];
        }
+       foreach (getObjectIfacesSearchResults ($what) as $objRecord)
+       {
+               $ret[$objRecord['id']]['id'] = $objRecord['id'];
+               $ret[$objRecord['id']]['by_iface'] = $objRecord['by_iface'];
+       }
+       foreach (getObjectNATSearchResults ($what) as $objRecord)
+       {
+               $ret[$objRecord['id']]['id'] = $objRecord['id'];
+               $ret[$objRecord['id']]['by_nat'] = $objRecord['by_nat'];
+       }
        return $ret;
 }
 
@@ -1719,6 +1729,46 @@ function getPortSearchResults ($what)
        return $ret;
 }
 
+// search in IPv4 allocations
+function getObjectIfacesSearchResults ($what)
+{
+       $ret = array();
+       $ifaces = getSearchResultByField
+       (
+               'IPv4Allocation',
+               array ('object_id', 'name'),
+               'name',
+               $what,
+               'object_id'
+       );
+       foreach ($ifaces as $row)
+       {
+               $ret[$row['object_id']]['id'] = $row['object_id'];
+               $ret[$row['object_id']]['by_iface'][] = $row['name'];
+       }
+       return $ret;
+}
+
+function getObjectNATSearchResults ($what)
+{
+       $ret = array();
+       $ifaces = getSearchResultByField
+       (
+               'IPv4NAT',
+               array ('object_id', 'description'),
+               'description',
+               $what,
+               'object_id'
+       );
+       foreach ($ifaces as $row)
+       {
+               $ret[$row['object_id']]['id'] = $row['object_id'];
+               $ret[$row['object_id']]['by_nat'][] = $row['description'];
+       }
+       return $ret;
+}
+
+// This function returns either port ID or NULL for specified arguments.
 // This function returns either port ID or NULL for specified arguments.
 function getPortID ($object_id, $port_name)
 {
index e663c83b8bf3f93143e9496bdcb9e7c7a408c426..80cfe91c6c4f1ffd798112efe89c899c4028587f 100644 (file)
@@ -964,13 +964,28 @@ function getImplicitTags ($oldtags)
 }
 
 // Minimize the chain: exclude all implicit tags and return the result.
+// This function makes use of an external cache with a miss/hit ratio
+// about 3/7 (ticket:255).
 function getExplicitTagsOnly ($chain)
 {
+       global $taglist, $tagRelCache;
        $ret = array();
-       $big_backtrace = getImplicitTags ($chain);
-       foreach ($chain as $key => $taginfo)
-               if (!tagOnChain ($taginfo, $big_backtrace))
-                       $ret[$key] = $taginfo;
+       foreach (array_keys ($chain) as $keyA) // check each A
+       {
+               $tagidA = $chain[$keyA]['id'];
+               // do not include A in result, if A is seen on the trace of any B!=A
+               foreach (array_keys ($chain) as $keyB)
+               {
+                       $tagidB = $chain[$keyB]['id'];
+                       if ($tagidA == $tagidB)
+                               continue;
+                       if (!isset ($tagRelCache[$tagidA][$tagidB]))
+                               $tagRelCache[$tagidA][$tagidB] = tagOnChain ($chain[$keyA], $taglist[$tagidB]['trace']);
+                       if ($tagRelCache[$tagidA][$tagidB] === TRUE) // A is ancestor of B
+                               continue 2; // skip this A
+               }
+               $ret[] = $chain[$keyA];
+       }
        return $ret;
 }
 
index 0e0f5c3c10e221edd90f49cd77519bb335ead4d0..ac75584f3707e053ca5b587c3c9484d557872e65 100644 (file)
@@ -156,8 +156,9 @@ $pTable = buildPredicateTable ($rackCode);
 // Constraints parse trees aren't cached in the database, so the least to keep
 // things running is to maintain application cache for them.
 $parseCache = array();
-
 $entityCache = array();
+// used by getExplicitTagsOnly()
+$tagRelCache = array();
 
 $taglist = getTagList();
 $tagtree = treeFromList ($taglist);
index d4041378684b4f126740366797a8bccd50232521..dd6352c7677b345cdce611675e3804a8e1bf34c5 100644 (file)
@@ -2915,6 +2915,20 @@ function renderSearchResults ()
                                                                        }
                                                        echo '</table>';
                                                }
+                                               if (isset ($obj['by_iface']))
+                                               {
+                                                       echo '<ul>';
+                                                       foreach ($obj['by_iface'] as $ifname)
+                                                               echo "<li>interface ${ifname}</li>";
+                                                       echo '</ul>';
+                                               }
+                                               if (isset ($obj['by_nat']))
+                                               {
+                                                       echo '<ul>';
+                                                       foreach ($obj['by_nat'] as $comment)
+                                                               echo "<li>NAT rule: ${comment}</li>";
+                                                       echo '</ul>';
+                                               }
                                                echo "</td></tr>";
                                                $order = $nextorder[$order];
                                        }