]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/delay_pools.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / delay_pools.cc
index befd7bb9285caee57b2a7733feba7389dd52c08e..4166e6df99aa9c6326ff4a2ccebe09c3f1f07c2a 100644 (file)
@@ -1,70 +1,44 @@
 /*
- * DEBUG: section 77    Delay Pools
- * AUTHOR: Robert Collins <robertc@squid-cache.org>
- * Based upon original delay pools code by
- *   David Luyer <david@luyer.net>
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
  *
- * SQUID Web Proxy Cache          http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from
- *  the Internet community; see the CONTRIBUTORS file for full
- *  details.   Many organizations have provided support for Squid's
- *  development; see the SPONSORS file for full details.  Squid is
- *  Copyrighted (C) 2001 by the Regents of the University of
- *  California; see the COPYRIGHT file for full details.  Squid
- *  incorporates software developed and/or copyrighted by other
- *  sources; see the CREDITS file for full details.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
- *
- * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
+/* DEBUG: section 77    Delay Pools */
+
 /**
  \defgroup DelayPoolsInternal Delay Pools Internal
  \ingroup DelayPoolsAPI
  */
 
-#include "config.h"
-
-#if DELAY_POOLS
 #include "squid.h"
-#include "CacheManager.h"
-#include "DelaySpec.h"
-#include "DelayPools.h"
-#include "event.h"
-#include "StoreClient.h"
-#include "Store.h"
-#include "MemObject.h"
+
+#if USE_DELAY_POOLS
 #include "client_side_request.h"
-#include "ConfigParser.h"
-#include "DelayId.h"
-#include "Array.h"
-#include "SquidString.h"
-#include "SquidTime.h"
+#include "comm/Connection.h"
 #include "CommonPool.h"
 #include "CompositePoolNode.h"
+#include "ConfigParser.h"
+#include "DelayBucket.h"
+#include "DelayId.h"
 #include "DelayPool.h"
+#include "DelayPools.h"
+#include "DelaySpec.h"
+#include "DelayTagged.h"
+#include "DelayUser.h"
 #include "DelayVector.h"
+#include "event.h"
+#include "http/Stream.h"
+#include "ip/Address.h"
+#include "MemObject.h"
+#include "mgr/Registration.h"
 #include "NullDelayId.h"
-#include "DelayBucket.h"
-#include "DelayUser.h"
-#include "DelayTagged.h"
-#include "ip/IpAddress.h"
+#include "SquidString.h"
+#include "SquidTime.h"
+#include "Store.h"
+#include "StoreClient.h"
 
 /// \ingroup DelayPoolsInternal
 long DelayPools::MemoryUsed = 0;
@@ -159,7 +133,7 @@ protected:
 
     virtual char const *label() const = 0;
 
-    virtual unsigned int makeKey (IpAddress &src_addr) const = 0;
+    virtual unsigned int makeKey(Ip::Address &src_addr) const = 0;
 
     DelaySpec spec;
 
@@ -186,13 +160,11 @@ class IndividualPool : public VectorPool
 
 public:
     void *operator new(size_t);
-    void operator delete (void *);
+    void operator delete(void *);
 
 protected:
     virtual char const *label() const {return "Individual";}
-
-    virtual unsigned int makeKey (IpAddress &src_addr) const;
-
+    virtual unsigned int makeKey(Ip::Address &src_addr) const;
 };
 
 /// \ingroup DelayPoolsInternal
@@ -205,8 +177,7 @@ public:
 
 protected:
     virtual char const *label() const {return "Network";}
-
-    virtual unsigned int makeKey (IpAddress &src_addr) const;
+    virtual unsigned int makeKey (Ip::Address &src_addr) const;
 };
 
 /* don't use remote storage for these */
@@ -250,9 +221,9 @@ protected:
 
     virtual char const *label() const {return "Individual";}
 
-    virtual unsigned int makeKey (IpAddress &src_addr) const;
+    virtual unsigned int makeKey(Ip::Address &src_addr) const;
 
-    unsigned char makeHostKey (IpAddress &src_addr) const;
+    unsigned char makeHostKey(Ip::Address &src_addr) const;
 
     DelaySpec spec;
     VectorMap<unsigned char, ClassCBucket> buckets;
@@ -293,10 +264,10 @@ CommonPool::operator new(size_t size)
 }
 
 void
-CommonPool::operator delete (void *address)
+CommonPool::operator delete(void *address)
 {
-    DelayPools::MemoryUsed -= sizeof (CommonPool);
-    ::operator delete (address);
+    DelayPools::MemoryUsed -= sizeof(CommonPool);
+    ::operator delete(address);
 }
 
 CommonPool *
@@ -322,7 +293,6 @@ CommonPool::Factory(unsigned char _class, CompositePoolNode::Pointer& compositeC
             temp->push_back (new Aggregate);
             temp->push_back(new IndividualPool);
         }
-
         break;
 
     case 3:
@@ -334,7 +304,6 @@ CommonPool::Factory(unsigned char _class, CompositePoolNode::Pointer& compositeC
             temp->push_back (new ClassCNetPool);
             temp->push_back (new ClassCHostPool);
         }
-
         break;
 
     case 4:
@@ -345,9 +314,10 @@ CommonPool::Factory(unsigned char _class, CompositePoolNode::Pointer& compositeC
             temp->push_back (new Aggregate);
             temp->push_back (new ClassCNetPool);
             temp->push_back (new ClassCHostPool);
+#if USE_AUTH
             temp->push_back (new DelayUser);
+#endif
         }
-
         break;
 
     case 5:
@@ -372,7 +342,7 @@ ClassCBucket::update (DelaySpec const &rate, int incr)
     /* If we aren't active, don't try to update us ! */
     assert (rate.restore_bps != -1);
 
-    for (unsigned char j = 0; j < individuals.size(); ++j)
+    for (unsigned int j = 0; j < individuals.size(); ++j)
         individuals.values[j].update (rate, incr);
 }
 
@@ -504,7 +474,6 @@ Aggregate::parse()
 }
 
 DelayIdComposite::Pointer
-
 Aggregate::id(CompositeSelectionDetails &details)
 {
     if (rate()->restore_bps != -1)
@@ -550,8 +519,7 @@ unsigned short DelayPools::pools_ (0);
 void
 DelayPools::RegisterWithCacheManager(void)
 {
-    CacheManager::GetInstance()->
-    registerAction("delay", "Delay Pool Levels", Stats, 0, 1);
+    Mgr::RegisterAction("delay", "Delay Pool Levels", Stats, 0, 1);
 }
 
 void
@@ -561,7 +529,6 @@ DelayPools::Init()
     RegisterWithCacheManager();
 }
 
-
 void
 DelayPools::InitDelayData()
 {
@@ -599,7 +566,7 @@ DelayPools::Update(void *unused)
 
     LastUpdate = squid_curtime;
 
-    Vector<Updateable *>::iterator pos = toUpdate.begin();
+    std::vector<Updateable *>::iterator pos = toUpdate.begin();
 
     while (pos != toUpdate.end()) {
         (*pos)->update(incr);
@@ -617,7 +584,7 @@ DelayPools::registerForUpdates(Updateable *anObject)
 void
 DelayPools::deregisterForUpdates (Updateable *anObject)
 {
-    Vector<Updateable *>::iterator pos = toUpdate.begin();
+    std::vector<Updateable *>::iterator pos = toUpdate.begin();
 
     while (pos != toUpdate.end() && *pos != anObject) {
         ++pos;
@@ -625,7 +592,7 @@ DelayPools::deregisterForUpdates (Updateable *anObject)
 
     if (pos != toUpdate.end()) {
         /* move all objects down one */
-        Vector<Updateable *>::iterator temp = pos;
+        std::vector<Updateable *>::iterator temp = pos;
         ++pos;
 
         while (pos != toUpdate.end()) {
@@ -638,7 +605,7 @@ DelayPools::deregisterForUpdates (Updateable *anObject)
     }
 }
 
-Vector<Updateable *> DelayPools::toUpdate;
+std::vector<Updateable *> DelayPools::toUpdate;
 
 void
 DelayPools::Stats(StoreEntry * sentry)
@@ -674,10 +641,10 @@ DelayPools::pools()
 }
 
 void
-DelayPools::pools (u_short newPools)
+DelayPools::pools(unsigned short newPools)
 {
     if (pools()) {
-        debugs(3, 0, "parse_delay_pool_count: multiple delay_pools lines, aborting all previous delay_pools config");
+        debugs(3, DBG_CRITICAL, "parse_delay_pool_count: multiple delay_pools lines, aborting all previous delay_pools config");
         FreePools();
     }
 
@@ -748,7 +715,7 @@ VectorPool::stats(StoreEntry * sentry)
 
     storeAppendPrintf(sentry, "\t\tCurrent:");
 
-    for (unsigned int i = 0; i < buckets.size(); i++) {
+    for (unsigned int i = 0; i < buckets.size(); ++i) {
         storeAppendPrintf(sentry, " %d:", buckets.key_map[i]);
         buckets.values[i].stats(sentry);
     }
@@ -800,7 +767,7 @@ unsigned char
 VectorMap<Key,Value>::findKeyIndex (Key const key) const
 {
     for (unsigned int index = 0; index < size(); ++index) {
-        assert (indexUsed (index));
+        assert(indexUsed(index));
 
         if (key_map[index] == key)
             return index;
@@ -811,20 +778,23 @@ VectorMap<Key,Value>::findKeyIndex (Key const key) const
 }
 
 DelayIdComposite::Pointer
-
 VectorPool::id(CompositeSelectionDetails &details)
 {
     if (rate()->restore_bps == -1)
         return new NullDelayId;
 
-    unsigned int key = makeKey (details.src_addr);
+    /* non-IPv4 are not able to provide IPv4-bitmask for this pool type key. */
+    if ( !details.src_addr.isIPv4() )
+        return new NullDelayId;
 
-    if (keyAllocated (key))
-        return new Id (this, buckets.findKeyIndex(key));
+    unsigned int key = makeKey(details.src_addr);
+
+    if (keyAllocated(key))
+        return new Id(this, buckets.findKeyIndex(key));
 
     unsigned char const resultIndex = buckets.insert(key);
 
-    buckets.values[resultIndex].init (*rate());
+    buckets.values[resultIndex].init(*rate());
 
     return new Id(this, resultIndex);
 }
@@ -837,13 +807,13 @@ VectorPool::Id::operator new(size_t size)
 }
 
 void
-VectorPool::Id::operator delete (void *address)
+VectorPool::Id::operator delete(void *address)
 {
     DelayPools::MemoryUsed -= sizeof (Id);
     ::operator delete (address);
 }
 
-VectorPool::Id::Id (VectorPool::Pointer aPool, int anIndex) : theVector (aPool), theIndex (anIndex)
+VectorPool::Id::Id(VectorPool::Pointer aPool, int anIndex) : theVector (aPool), theIndex (anIndex)
 {}
 
 int
@@ -859,15 +829,14 @@ VectorPool::Id::bytesIn(int qty)
 }
 
 unsigned int
-IndividualPool::makeKey (IpAddress &src_addr) const
+IndividualPool::makeKey(Ip::Address &src_addr) const
 {
-    /* FIXME INET6 : IPv6 requires a 64-128 bit result from this function */
-    if ( !src_addr.IsIPv4() )
+    /* IPv4 required for this pool */
+    if ( !src_addr.isIPv4() )
         return 1;
 
-    /* Temporary bypass for IPv4-only */
     struct in_addr host;
-    src_addr.GetInAddr(host);
+    src_addr.getInAddr(host);
     return (ntohl(host.s_addr) & 0xff);
 }
 
@@ -886,19 +855,17 @@ ClassCNetPool::operator delete (void *address)
 }
 
 unsigned int
-ClassCNetPool::makeKey (IpAddress &src_addr) const
+ClassCNetPool::makeKey(Ip::Address &src_addr) const
 {
-    /* FIXME INET6 : IPv6 requires a 64-128 bit result from this function */
-    if ( !src_addr.IsIPv4() )
+    /* IPv4 required for this pool */
+    if ( !src_addr.isIPv4() )
         return 1;
 
-    /* Temporary bypass for IPv4-only */
     struct in_addr net;
-    src_addr.GetInAddr(net);
+    src_addr.getInAddr(net);
     return ( (ntohl(net.s_addr) >> 8) & 0xff);
 }
 
-
 ClassCHostPool::ClassCHostPool()
 {
     DelayPools::registerForUpdates (this);
@@ -960,38 +927,40 @@ ClassCHostPool::keyAllocated (unsigned char const key) const
 }
 
 unsigned char
-ClassCHostPool::makeHostKey (IpAddress &src_addr) const
+ClassCHostPool::makeHostKey(Ip::Address &src_addr) const
 {
-    /* FIXME INET6 : IPv6 requires a 64-128 bit result from this function */
-    if ( !src_addr.IsIPv4() )
+    /* IPv4 required for this pool */
+    if ( !src_addr.isIPv4() )
         return 1;
 
     /* Temporary bypass for IPv4-only */
     struct in_addr host;
-    src_addr.GetInAddr(host);
+    src_addr.getInAddr(host);
     return (ntohl(host.s_addr) & 0xff);
 }
 
 unsigned int
-ClassCHostPool::makeKey (IpAddress &src_addr) const
+ClassCHostPool::makeKey(Ip::Address &src_addr) const
 {
-    /* FIXME INET6 : IPv6 requires a 64-128 bit result from this function */
-    if ( !src_addr.IsIPv4() )
+    /* IPv4 required for this pool */
+    if ( !src_addr.isIPv4() )
         return 1;
 
-    /* Temporary bypass for IPv4-only */
     struct in_addr net;
-    src_addr.GetInAddr(net);
+    src_addr.getInAddr(net);
     return ( (ntohl(net.s_addr) >> 8) & 0xff);
 }
 
 DelayIdComposite::Pointer
-
 ClassCHostPool::id(CompositeSelectionDetails &details)
 {
     if (rate()->restore_bps == -1)
         return new NullDelayId;
 
+    /* non-IPv4 are not able to provide IPv4-bitmask for this pool type key. */
+    if ( !details.src_addr.isIPv4() )
+        return new NullDelayId;
+
     unsigned int key = makeKey (details.src_addr);
 
     unsigned char host = makeHostKey (details.src_addr);
@@ -1039,5 +1008,5 @@ ClassCHostPool::Id::bytesIn(int qty)
     theClassCHost->buckets.values[theNet].individuals.values[theHost].bytesIn (qty);
 }
 
-#endif
+#endif /* USE_DELAY_POOLS */