]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Delay pools 64-bit buckets and IPv6-polish
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 28 Jun 2009 08:34:50 +0000 (20:34 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 28 Jun 2009 08:34:50 +0000 (20:34 +1200)
This patch adds some polish and minor unfinished business in IPv6
support vs delay pools.

Also updates the bucket size to 64-bytes to allow for >4MB traffic caps.

TODO: Bump up the refresh size for >4MB/sec flows and check that nothing
      gets broken by it.

src/DelaySpec.cc
src/DelaySpec.h
src/Parsing.cc
src/Parsing.h
src/cf.data.pre
src/delay_pools.cc

index c91118650a90f422619056290f9208bb34a98116..2718eb23ab44f562509f30c286ef48afe2ce3c3f 100644 (file)
@@ -57,35 +57,32 @@ DelaySpec::stats (StoreEntry * sentry, char const *label) const
     }
 
     storeAppendPrintf(sentry, "\t%s:\n", label);
-    storeAppendPrintf(sentry, "\t\tMax: %d\n", max_bytes);
+    storeAppendPrintf(sentry, "\t\tMax: %"PRId64"\n", max_bytes);
     storeAppendPrintf(sentry, "\t\tRestore: %d\n", restore_bps);
 }
 
 void
 DelaySpec::dump (StoreEntry *entry) const
 {
-    storeAppendPrintf(entry, " %d/%d", restore_bps, max_bytes);
+    storeAppendPrintf(entry, " %d/%"PRId64"", restore_bps, max_bytes);
 }
 
 void
 DelaySpec::parse()
 {
-    int i;
+    int r;
     char *token;
     token = strtok(NULL, "/");
 
     if (token == NULL)
         self_destruct();
 
-    if (sscanf(token, "%d", &i) != 1)
+    if (sscanf(token, "%d", &r) != 1)
         self_destruct();
 
-    restore_bps = i;
+    restore_bps = r;
 
-    i = GetInteger();
-
-    max_bytes = i;
+    max_bytes = GetInteger64();
 }
 
 #endif
-
index 35c58c1894b92d86c5edf91821a37434ba5aa196..a03d0c045e4162b20cd3c5520d2dac27fe2ef666 100644 (file)
@@ -32,6 +32,9 @@
 #ifndef SQUID_DELAYSPEC_H
 #define SQUID_DELAYSPEC_H
 
+/* for int64_t definition */
+#include "config.h"
+
 class StoreEntry;
 
 /// \ingroup DelyPoolsAPI
@@ -44,7 +47,7 @@ public:
     void dump(StoreEntry *) const;
     void parse();
     int restore_bps;
-    int max_bytes;
+    int64_t max_bytes;
 };
 
 #endif /* SQUID_DELAYSPEC_H */
index 6bf9c65e59cb5f7cce3cc3d72571458b5f4a7f21..57656174a7a78cc8217b8b29148a0fa0841034de 100644 (file)
@@ -80,6 +80,20 @@ xatos(const char *token)
     return port;
 }
 
+int64_t
+GetInteger64(void)
+{
+    char *token = strtok(NULL, w_space);
+    int i;
+
+    if (token == NULL)
+        self_destruct();
+
+    i = strtoll(token, NULL, 10);
+
+    return i;
+}
+
 int
 GetInteger(void)
 {
index 689dfed910d8c12b321b8e70f4be1863174b70a3..b18dc5e4361845eed985b4e1b60b0d3d630525cb 100644 (file)
@@ -42,7 +42,18 @@ extern double xatof(const char *token);
 extern int xatoi(const char *token);
 extern long xatol(const char *token);
 extern unsigned short xatos(const char *token);
+
+/**
+ * Parse a 64-bit integer value.
+ */
+extern int64_t GetInteger64(void);
+
+/**
+ * Parses an integer value.
+ * Uses a method that obeys hexadecimal 0xN syntax needed for certain bitmasks.
+ */
 extern int GetInteger(void);
+
 extern u_short GetShort(void);
 
 // on success, returns true and sets *p (if any) to the end of the integer
index e4fc7be80a627f330e720fea1ebd0a1ed6f3e653..7f42fccdcc5b486649aeec1c12c6bed91a1cfe90 100644 (file)
@@ -3940,12 +3940,12 @@ DOC_START
        delay pools, one of class 2 and one of class 3, the settings above
        and here would be:
 
-Example:
- delay_pools 4      # 4 delay pools
- delay_class 1 2    # pool 1 is a class 2 pool
- delay_class 2 3    # pool 2 is a class 3 pool
- delay_class 3 4    # pool 3 is a class 4 pool
- delay_class 4 5    # pool 4 is a class 5 pool
+       Example:
          delay_pools 4      # 4 delay pools
          delay_class 1 2    # pool 1 is a class 2 pool
          delay_class 2 3    # pool 2 is a class 3 pool
          delay_class 3 4    # pool 3 is a class 4 pool
          delay_class 4 5    # pool 4 is a class 5 pool
 
        The delay pool classes are:
 
@@ -3954,13 +3954,13 @@ Example:
 
                class 2         Everything is limited by a single aggregate
                                bucket as well as an "individual" bucket chosen
-                               from bits 25 through 32 of the IP address.
+                               from bits 25 through 32 of the IPv4 address.
 
                class 3         Everything is limited by a single aggregate
                                bucket as well as a "network" bucket chosen
                                from bits 17 through 24 of the IP address and a
                                "individual" bucket chosen from bits 17 through
-                               32 of the IP address.
+                               32 of the IPv4 address.
 
                class 4         Everything in a class 3 delay pool, with an
                                additional limit on a per user basis. This
@@ -3975,6 +3975,9 @@ Example:
                -> bits 25 through 32 are "d"
                -> bits 17 through 24 are "c"
                -> bits 17 through 32 are "c * 256 + d"
+
+       NOTE-2: Due to the use of bitmasks in class 2,3,4 pools they only apply to
+               IPv4 traffic. Class 1 and 5 pools may be used with IPv6 traffic.
 DOC_END
 
 NAME: delay_access
index befd7bb9285caee57b2a7733feba7389dd52c08e..8c6d8722873973746b789cc3d4aa86c3732b07d9 100644 (file)
@@ -159,7 +159,7 @@ protected:
 
     virtual char const *label() const = 0;
 
-    virtual unsigned int makeKey (IpAddress &src_addr) const = 0;
+    virtual unsigned int makeKey(IpAddress &src_addr) const = 0;
 
     DelaySpec spec;
 
@@ -186,13 +186,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(IpAddress &src_addr) const;
 };
 
 /// \ingroup DelayPoolsInternal
@@ -205,7 +203,6 @@ public:
 
 protected:
     virtual char const *label() const {return "Network";}
-
     virtual unsigned int makeKey (IpAddress &src_addr) const;
 };
 
@@ -293,10 +290,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 +319,6 @@ CommonPool::Factory(unsigned char _class, CompositePoolNode::Pointer& compositeC
             temp->push_back (new Aggregate);
             temp->push_back(new IndividualPool);
         }
-
         break;
 
     case 3:
@@ -334,7 +330,6 @@ CommonPool::Factory(unsigned char _class, CompositePoolNode::Pointer& compositeC
             temp->push_back (new ClassCNetPool);
             temp->push_back (new ClassCHostPool);
         }
-
         break;
 
     case 4:
@@ -347,7 +342,6 @@ CommonPool::Factory(unsigned char _class, CompositePoolNode::Pointer& compositeC
             temp->push_back (new ClassCHostPool);
             temp->push_back (new DelayUser);
         }
-
         break;
 
     case 5:
@@ -504,7 +498,6 @@ Aggregate::parse()
 }
 
 DelayIdComposite::Pointer
-
 Aggregate::id(CompositeSelectionDetails &details)
 {
     if (rate()->restore_bps != -1)
@@ -800,7 +793,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 +804,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 +833,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
@@ -861,11 +857,10 @@ VectorPool::Id::bytesIn(int qty)
 unsigned int
 IndividualPool::makeKey (IpAddress &src_addr) const
 {
-    /* FIXME INET6 : IPv6 requires a 64-128 bit result from this function */
+    /* IPv4 required for this pool */
     if ( !src_addr.IsIPv4() )
         return 1;
 
-    /* Temporary bypass for IPv4-only */
     struct in_addr host;
     src_addr.GetInAddr(host);
     return (ntohl(host.s_addr) & 0xff);
@@ -888,11 +883,10 @@ ClassCNetPool::operator delete (void *address)
 unsigned int
 ClassCNetPool::makeKey (IpAddress &src_addr) const
 {
-    /* FIXME INET6 : IPv6 requires a 64-128 bit result from this function */
+    /* IPv4 required for this pool */
     if ( !src_addr.IsIPv4() )
         return 1;
 
-    /* Temporary bypass for IPv4-only */
     struct in_addr net;
     src_addr.GetInAddr(net);
     return ( (ntohl(net.s_addr) >> 8) & 0xff);
@@ -962,7 +956,7 @@ ClassCHostPool::keyAllocated (unsigned char const key) const
 unsigned char
 ClassCHostPool::makeHostKey (IpAddress &src_addr) const
 {
-    /* FIXME INET6 : IPv6 requires a 64-128 bit result from this function */
+    /* IPv4 required for this pool */
     if ( !src_addr.IsIPv4() )
         return 1;
 
@@ -975,23 +969,25 @@ ClassCHostPool::makeHostKey (IpAddress &src_addr) const
 unsigned int
 ClassCHostPool::makeKey (IpAddress &src_addr) const
 {
-    /* FIXME INET6 : IPv6 requires a 64-128 bit result from this function */
+    /* IPv4 required for this pool */
     if ( !src_addr.IsIPv4() )
         return 1;
 
-    /* Temporary bypass for IPv4-only */
     struct in_addr 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);