]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Throw, not self_destruct(), on qos_flow configuration errors (#1644)
authorAlexey <bigalex934@gmail.com>
Thu, 1 Feb 2024 09:37:30 +0000 (09:37 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Thu, 1 Feb 2024 09:37:35 +0000 (09:37 +0000)
src/ip/QosConfig.cc

index 20800da3dd2b33adbe62b8a4baafcfdca38ec996..ad32975f6b8d3c9b84ebbcea72f17716cb727fbe 100644 (file)
@@ -10,6 +10,7 @@
 #include "acl/Gadgets.h"
 #include "base/IoManip.h"
 #include "base/PackableStream.h"
+#include "base/TextException.h"
 #include "cache_cf.h"
 #include "comm/Connection.h"
 #include "compat/cmsg.h"
@@ -20,6 +21,7 @@
 #include "ip/QosConfig.h"
 #include "ip/tools.h"
 #include "Parsing.h"
+#include "sbuf/Stream.h"
 #include "Store.h"
 
 #include <cerrno>
@@ -305,8 +307,7 @@ Ip::Qos::Config::parseConfigLine()
     /* Assume preserve is true. We don't set at initialisation as this affects isHitTosActive().
        We have to do this now, as we may never match the 'tos' parameter below */
 #if !USE_QOS_TOS
-    debugs(3, DBG_CRITICAL, "ERROR: Invalid option 'qos_flows'. QOS features not enabled in this build");
-    self_destruct();
+    throw TextException(ToSBuf("Invalid option 'qos_flows'. QOS features not enabled in this build"), Here());
 #endif
 
     while ( (token = ConfigParser::NextToken()) ) {
@@ -325,13 +326,11 @@ Ip::Qos::Config::parseConfigLine()
                        << "Netfilter mark preservation not available.");
 #endif // USE_LIBNETFILTERCONNTRACK
 #elif SO_MARK // SO_MARK && USE_LIBCAP
-                debugs(3, DBG_CRITICAL, "ERROR: Invalid parameter 'mark' in qos_flows option. "
-                       << "Linux Netfilter marking not available without LIBCAP support.");
-                self_destruct();
+                throw TextException(ToSBuf("Invalid parameter 'mark' in qos_flows option. ",
+                                           "Linux Netfilter marking not available on this platform."), Here());
 #else // SO_MARK && USE_LIBCAP
-                debugs(3, DBG_CRITICAL, "ERROR: Invalid parameter 'mark' in qos_flows option. "
-                       << "Linux Netfilter marking not available on this platform.");
-                self_destruct();
+                throw TextException(ToSBuf("Invalid parameter 'mark' in qos_flows option. ",
+                                           "Linux Netfilter marking not available on this platform."), Here());
 #endif // SO_MARK && USE_LIBCAP
             } else if (strncmp(token, "tos",3) == 0) {
                 preserveMissTos = true;
@@ -346,14 +345,12 @@ Ip::Qos::Config::parseConfigLine()
 
             if (mark) {
                 if (!xstrtoui(&token[10], nullptr, &markLocalHit, 0, std::numeric_limits<nfmark_t>::max())) {
-                    debugs(3, DBG_CRITICAL, "ERROR: Bad mark local-hit value " << &token[10]);
-                    self_destruct();
+                    throw TextException(ToSBuf("Bad mark local-hit value ", &token[10]), Here());
                 }
             } else {
                 unsigned int v = 0;
                 if (!xstrtoui(&token[10], nullptr, &v, 0, std::numeric_limits<tos_t>::max())) {
-                    debugs(3, DBG_CRITICAL, "ERROR: Bad TOS local-hit value " << &token[10]);
-                    self_destruct();
+                    throw TextException(ToSBuf("Bad TOS local-hit value ", &token[10]), Here());
                 }
                 tosLocalHit = (tos_t)v;
             }
@@ -362,14 +359,12 @@ Ip::Qos::Config::parseConfigLine()
 
             if (mark) {
                 if (!xstrtoui(&token[12], nullptr, &markSiblingHit, 0, std::numeric_limits<nfmark_t>::max())) {
-                    debugs(3, DBG_CRITICAL, "ERROR: Bad mark sibling-hit value " << &token[12]);
-                    self_destruct();
+                    throw TextException(ToSBuf("Bad mark sibling-hit value ", &token[12]), Here());
                 }
             } else {
                 unsigned int v = 0;
                 if (!xstrtoui(&token[12], nullptr, &v, 0, std::numeric_limits<tos_t>::max())) {
-                    debugs(3, DBG_CRITICAL, "ERROR: Bad TOS sibling-hit value " << &token[12]);
-                    self_destruct();
+                    throw TextException(ToSBuf("Bad TOS sibling-hit value ", &token[12]), Here());
                 }
                 tosSiblingHit = (tos_t)v;
             }
@@ -378,14 +373,12 @@ Ip::Qos::Config::parseConfigLine()
 
             if (mark) {
                 if (!xstrtoui(&token[11], nullptr, &markParentHit, 0, std::numeric_limits<nfmark_t>::max())) {
-                    debugs(3, DBG_CRITICAL, "ERROR: Bad mark parent-hit value " << &token[11]);
-                    self_destruct();
+                    throw TextException(ToSBuf("Bad mark parent-hit value ", &token[11]), Here());
                 }
             } else {
                 unsigned int v = 0;
                 if (!xstrtoui(&token[11], nullptr, &v, 0, std::numeric_limits<tos_t>::max())) {
-                    debugs(3, DBG_CRITICAL, "ERROR: Bad TOS parent-hit value " << &token[11]);
-                    self_destruct();
+                    throw TextException(ToSBuf("Bad TOS parent-hit value ", &token[11]), Here());
                 }
                 tosParentHit = (tos_t)v;
             }
@@ -395,8 +388,7 @@ Ip::Qos::Config::parseConfigLine()
             char *end;
             if (mark) {
                 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();
+                    throw TextException(ToSBuf("Bad mark miss value ", &token[5]), Here());
                 }
                 if (*end == '/') {
                     if (!xstrtoui(end + 1, nullptr, &markMissMask, 0, std::numeric_limits<nfmark_t>::max())) {
@@ -409,8 +401,7 @@ Ip::Qos::Config::parseConfigLine()
             } else {
                 unsigned int v = 0;
                 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();
+                    throw TextException(ToSBuf("Bad TOS miss value ", &token[5]), Here());
                 }
                 tosMiss = (tos_t)v;
                 if (*end == '/') {
@@ -427,8 +418,7 @@ Ip::Qos::Config::parseConfigLine()
         } else if (strcmp(token, "disable-preserve-miss") == 0) {
 
             if (preserveMissTosMask!=0xFFU || preserveMissMarkMask!=0xFFFFFFFFU) {
-                debugs(3, DBG_CRITICAL, "ERROR: miss-mask feature cannot be set with disable-preserve-miss");
-                self_destruct();
+                throw TextException(ToSBuf("miss-mask feature cannot be set with disable-preserve-miss"), Here());
             }
             if (mark) {
                 preserveMissMark = false;
@@ -442,19 +432,16 @@ Ip::Qos::Config::parseConfigLine()
 
             if (mark && preserveMissMark) {
                 if (!xstrtoui(&token[10], nullptr, &preserveMissMarkMask, 0, std::numeric_limits<nfmark_t>::max())) {
-                    debugs(3, DBG_CRITICAL, "ERROR: Bad mark miss-mark value " << &token[10]);
-                    self_destruct();
+                    throw TextException(ToSBuf("Bad mark miss-mark value ", &token[10]), Here());
                 }
             } else if (preserveMissTos) {
                 unsigned int v = 0;
                 if (!xstrtoui(&token[10], nullptr, &v, 0, std::numeric_limits<tos_t>::max())) {
-                    debugs(3, DBG_CRITICAL, "ERROR: Bad TOS miss-mark value " << &token[10]);
-                    self_destruct();
+                    throw TextException(ToSBuf("Bad TOS miss-mark value ", &token[10]), Here());
                 }
                 preserveMissTosMask = (tos_t)v;
             } else {
-                debugs(3, DBG_CRITICAL, "ERROR: miss-mask feature cannot be set without miss-preservation enabled");
-                self_destruct();
+                throw TextException(ToSBuf("miss-mask feature cannot be set without miss-preservation enabled"), Here());
             }
 
         }