]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add a mask on the qos_flows miss configuration value.
authorAndrew Beverley <andy@andybev.com>
Sat, 5 Nov 2011 05:21:11 +0000 (18:21 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 5 Nov 2011 05:21:11 +0000 (18:21 +1300)
The reason for this is to allow the preserved mark/TOS value from the
server to be altered slightly rather than overwritten completely.

Example usage. The following will preserve the netfilter mark, but will
ensure that the (9th) bit specified in the miss value will be set to 1
in the preserved mark:

  qos_flows mark miss=0x100/0xF00

src/cf.data.pre
src/ip/QosConfig.cc
src/ip/QosConfig.h

index 6388d9cf3d5ba052df952ddcd021eaf791c708ae..f55fc9c881fe3e56b31a8e06195f55ecbffd0129 100644 (file)
@@ -1699,8 +1699,10 @@ DOC_START
 
        parent-hit=0xFF         Value to mark hits from parent peers.
 
-       miss=0xFF               Value to mark cache misses. Takes precedence
-                               over the preserve-miss feature (see below).
+       miss=0xFF[/mask]        Value to mark cache misses. Takes precedence
+                               over the preserve-miss feature (see below), unless
+                               mask is specified, in which case only the bits
+                               specified in the mask are written.
 
        The TOS variant of the following features are only possible on Linux
        and require your kernel to be patched with the TOS preserving ZPH
index 18673f937b9120c72b5b2c32e0a094ceafc6d6f9..cae27f180000cff300f2d6bb9aea6ce3ae6845fd 100644 (file)
@@ -128,12 +128,13 @@ Ip::Qos::doTosLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hie
     } else if (Ip::Qos::TheConfig.tosParentHit && hierCode==PARENT_HIT) {
         tos = Ip::Qos::TheConfig.tosParentHit;
         debugs(33, 2, "QOS: Parent Peer hit with hier code=" << hierCode << ", TOS=" << int(tos));
-    } else if (Ip::Qos::TheConfig.tosMiss) {
-        tos = Ip::Qos::TheConfig.tosMiss;
-        debugs(33, 2, "QOS: Cache miss, setting TOS=" << int(tos));
-    } else if (Ip::Qos::TheConfig.preserveMissTos && Ip::Qos::TheConfig.preserveMissTosMask) {
+    } else if (Ip::Qos::TheConfig.preserveMissTos) {
         tos = fd_table[conn->fd].tosFromServer & Ip::Qos::TheConfig.preserveMissTosMask;
+        tos = (tos & ~Ip::Qos::TheConfig.tosMissMask) | (Ip::Qos::TheConfig.tosMiss & Ip::Qos::TheConfig.tosMissMask);
         debugs(33, 2, "QOS: Preserving TOS on miss, TOS=" << int(tos));
+    } else if (Ip::Qos::TheConfig.tosMiss) {
+        tos = Ip::Qos::TheConfig.tosMiss & Ip::Qos::TheConfig.tosMissMask;
+        debugs(33, 2, "QOS: Cache miss, setting TOS=" << int(tos));
     }
     return setSockTos(conn, tos);
 }
@@ -148,12 +149,13 @@ Ip::Qos::doNfmarkLocalMiss(const Comm::ConnectionPointer &conn, const hier_code
     } else if (Ip::Qos::TheConfig.markParentHit && hierCode==PARENT_HIT) {
         mark = Ip::Qos::TheConfig.markParentHit;
         debugs(33, 2, "QOS: Parent Peer hit with hier code=" << hierCode << ", Mark=" << mark);
-    } else if (Ip::Qos::TheConfig.markMiss) {
-        mark = Ip::Qos::TheConfig.markMiss;
-        debugs(33, 2, "QOS: Cache miss, setting Mark=" << mark);
     } else if (Ip::Qos::TheConfig.preserveMissMark) {
         mark = fd_table[conn->fd].nfmarkFromServer & Ip::Qos::TheConfig.preserveMissMarkMask;
+        mark = (mark & ~Ip::Qos::TheConfig.markMissMask) | (Ip::Qos::TheConfig.markMiss & Ip::Qos::TheConfig.markMissMask);
         debugs(33, 2, "QOS: Preserving mark on miss, Mark=" << mark);
+    } else if (Ip::Qos::TheConfig.markMiss) {
+        mark = Ip::Qos::TheConfig.markMiss & Ip::Qos::TheConfig.markMissMask;
+        debugs(33, 2, "QOS: Cache miss, setting Mark=" << mark);
     }
     return setSockNfmark(conn, mark);
 }
@@ -182,12 +184,14 @@ Ip::Qos::Config::Config()
     tosSiblingHit = 0;
     tosParentHit = 0;
     tosMiss = 0;
+    tosMissMask = 0;
     preserveMissTos = false;
     preserveMissTosMask = 0xFF;
     markLocalHit = 0;
     markSiblingHit = 0;
     markParentHit = 0;
     markMiss = 0;
+    markMissMask = 0;
     preserveMissMark = false;
     preserveMissMarkMask = 0xFFFFFFFF;
 }
@@ -290,18 +294,36 @@ Ip::Qos::Config::parseConfigLine()
 
         } else if (strncmp(token, "miss=",5) == 0) {
 
+            char *end;
             if (mark) {
-                if (!xstrtoui(&token[5], NULL, &markMiss, 0, std::numeric_limits<nfmark_t>::max())) {
+                if (!xstrtoui(&token[5], &end, &markMiss, 0, std::numeric_limits<nfmark_t>::max())) {
                     debugs(3, DBG_CRITICAL, "ERROR: Bad mark miss value " << &token[5]);
                     self_destruct();
                 }
+                if (*end == '/') {
+                    if (!xstrtoui(end + 1, NULL, &markMissMask, 0, std::numeric_limits<nfmark_t>::max())) {
+                        debugs(3, DBG_CRITICAL, "ERROR: Bad mark miss mask value " << (end + 1) << ". Using 0xFFFFFFFF instead.");
+                        markMissMask = 0xFFFFFFFF;
+                    }
+                } else {
+                    markMissMask = 0xFFFFFFFF;
+                }
             } else {
                 unsigned int v = 0;
-                if (!xstrtoui(&token[5], NULL, &v, 0, std::numeric_limits<tos_t>::max())) {
+                if (!xstrtoui(&token[5], &end, &v, 0, std::numeric_limits<tos_t>::max())) {
                     debugs(3, DBG_CRITICAL, "ERROR: Bad TOS miss value " << &token[5]);
                     self_destruct();
                 }
                 tosMiss = (tos_t)v;
+                if (*end == '/') {
+                    if (!xstrtoui(end + 1, NULL, &v, 0, std::numeric_limits<tos_t>::max())) {
+                        debugs(3, DBG_CRITICAL, "ERROR: Bad TOS miss mask value " << (end + 1) << ". Using 0xFF instead.");
+                        tosMissMask = 0xFF;
+                    } else
+                        tosMissMask = (tos_t)v;
+                } else {
+                    tosMissMask = 0xFF;
+                }
             }
 
         } else if (strcmp(token, "disable-preserve-miss") == 0) {
@@ -366,6 +388,9 @@ Ip::Qos::Config::dumpConfigLine(char *entry, const char *name) const
         }
         if (tosMiss > 0) {
             p += snprintf(p, 11, " miss=0x%02X", tosMiss);
+            if (tosMissMask!=0xFFU) {
+                p += snprintf(p, 6, "/0x%02X", markMissMask);
+            }
         }
         if (preserveMissTos == 0) {
             p += snprintf(p, 23, " disable-preserve-miss");
@@ -391,6 +416,9 @@ Ip::Qos::Config::dumpConfigLine(char *entry, const char *name) const
         }
         if (markMiss > 0) {
             p += snprintf(p, 17, " miss=0x%02X", markMiss);
+            if (markMissMask!=0xFFFFFFFFU) {
+                p += snprintf(p, 12, "/0x%02X", markMissMask);
+            }
         }
         if (preserveMissMark == false) {
             p += snprintf(p, 23, " disable-preserve-miss");
index b8df06c196bdf37f7da6b04235f3091d6b248471..3a3589d486db52b992ddf69cc481e054e9f229b6 100644 (file)
@@ -158,15 +158,17 @@ public:
     tos_t tosSiblingHit;                ///< TOS value to apply to hits from siblings
     tos_t tosParentHit;                 ///< TOS value to apply to hits from parent
     tos_t tosMiss;                      ///< TOS value to apply to cache misses
+    tos_t tosMissMask;                  ///< Mask for TOS value to apply to cache misses. Applied to the tosMiss value.
     bool preserveMissTos;               ///< Whether to preserve the TOS value of the inbound packet for misses
-    tos_t preserveMissTosMask;          ///< The mask to apply when preserving the TOS of misses
+    tos_t preserveMissTosMask;          ///< The mask to apply when preserving the TOS of misses. Applies to preserved value from upstream.
 
     nfmark_t markLocalHit;              ///< Netfilter mark value to apply to local cache hits
     nfmark_t markSiblingHit;            ///< Netfilter mark value to apply to hits from siblings
     nfmark_t markParentHit;             ///< Netfilter mark value to apply to hits from parent
     nfmark_t markMiss;                  ///< Netfilter mark value to apply to cache misses
+    nfmark_t markMissMask;              ///< Mask for netfilter mark value to apply to cache misses. Applied to the markMiss value.
     bool preserveMissMark;              ///< Whether to preserve netfilter mark value of inbound connection
-    nfmark_t preserveMissMarkMask;      ///< The mask to apply when preserving the netfilter mark of misses
+    nfmark_t preserveMissMarkMask;      ///< The mask to apply when preserving the netfilter mark of misses. Applied to preserved value from upstream.
 
     acl_tos *tosToServer;               ///< The TOS that packets to the web server should be marked with, based on ACL
     acl_tos *tosToClient;               ///< The TOS that packets to the client should be marked with, based on ACL