The -a option was broken by some config updates early in the 3.x cycles which reset SquidConfig prior to parsing but after opening the -a provided port.

This patch preserves the documented -a behaviour of opening an HTTP listener port from the command line. It also adds the double port opening for split-stack systems, preserving consistency with wildcard http_port entries in the config.


Overall, I'm not sure we actually need the -a option. Especially given that it appears to have been a few years before anyone noticed its being broken. What are peoples thoughts on deprecating it for removal in 3.3?

Amos
--
Please be using
  Current Stable Squid 2.7.STABLE9 or 3.1.9
  Beta testers wanted for 3.2.0.3
=== modified file 'src/cache_cf.cc'
--- src/cache_cf.cc	2010-10-29 00:12:28 +0000
+++ src/cache_cf.cc	2010-11-14 03:38:32 +0000
@@ -174,6 +174,8 @@
 #endif /* CURRENTLY_UNUSED */
 #endif /* USE_WCCPv2 */
 
+
+static void add_http_port(const char *portspec);
 static void parse_http_port_list(http_port_list **);
 static void dump_http_port_list(StoreEntry *, const char *, const http_port_list *);
 static void free_http_port_list(http_port_list **);
@@ -544,6 +546,11 @@
     ACLMethodData::ThePurgeCount = 0;
     default_all();
 
+    // Check for comand-line -a port spec
+    if (Config2.opt_extra_http_port) {
+        add_http_port(Config2.opt_extra_http_port);
+    }
+
     err_count = parseOneConfigFile(file_name, 0);
 
     defaults_if_none();
@@ -3324,11 +3331,12 @@
 CBDATA_CLASS_INIT(http_port_list);
 
 static void
-parse_http_port_specification(http_port_list * s, char *token)
+parse_http_port_specification(http_port_list * s, const char *token)
 {
     char *host = NULL;
     unsigned short port = 0;
     char *t = NULL;
+    const char *tc = NULL;
     char *junk = NULL;
 
     s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
@@ -3337,7 +3345,7 @@
 
     if (*token == '[') {
         /* [ipv6]:port */
-        host = token + 1;
+        host = xstrdup(token + 1);
         t = strchr(host, ']');
         if (!t) {
             debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token);
@@ -3353,12 +3361,12 @@
             self_destruct();
         }
         port = xatos(t + 1);
-    } else if ((t = strchr(token, ':'))) {
+    } else if ((tc = strchr(token, ':'))) {
         /* host:port */
         /* ipv4:port */
-        host = token;
-        *t = '\0';
-        port = xatos(t + 1);
+        host = xstrdup(token);
+        host[(tc - token)] = '\0';
+        port = xatos(tc + 1);
 
     } else if ((port = strtol(token, &junk, 10)), !*junk) {
         /* port */
@@ -3580,7 +3588,7 @@
 }
 
 static http_port_list *
-create_http_port(char *portspec)
+create_http_port(const char *portspec)
 {
     http_port_list *s = new http_port_list("http");
     parse_http_port_specification(s, portspec);
@@ -3588,13 +3596,22 @@
 }
 
 void
-add_http_port(char *portspec)
+add_http_port(const char *portspec)
 {
     http_port_list *s = create_http_port(portspec);
     // we may need to merge better of the above returns a list with clones
     assert(s->next == NULL);
     s->next = Config.Sockaddr.http;
     Config.Sockaddr.http = s;
+
+    if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK) {
+        // clone the port options from *s to *(s->next)
+        http_port_list *s2 = create_http_port(portspec);
+        s2->s.SetIPv4();
+        debugs(3, 3, "http(s)_port: clone wildcard address for split-stack: " << s->s << " and " << s2->s);
+        s2->next = s;
+        Config.Sockaddr.http = s2;
+    }
 }
 
 http_port_list *
=== modified file 'src/main.cc'
--- src/main.cc	2010-11-01 05:44:28 +0000
+++ src/main.cc	2010-11-13 15:06:00 +0000
@@ -381,7 +381,7 @@
         case 'a':
             /** \par a
              * Add optional HTTP port as given following the option */
-            add_http_port(optarg);
+            Config2.opt_extra_http_port = xstrdup(optarg);
             break;
 
         case 'd':

=== modified file 'src/protos.h'
--- src/protos.h	2010-11-01 05:44:28 +0000
+++ src/protos.h	2010-11-14 01:25:31 +0000
@@ -67,7 +67,6 @@
 class MemBuf;
 SQUIDCEXTERN void wordlistCat(const wordlist *, MemBuf * mb);
 SQUIDCEXTERN void self_destruct(void);
-SQUIDCEXTERN void add_http_port(char *portspec);
 extern int xatoi(const char *token);
 extern long xatol(const char *token);
 

=== modified file 'src/structs.h'
--- src/structs.h	2010-10-28 18:52:59 +0000
+++ src/structs.h	2010-11-14 00:09:22 +0000
@@ -640,6 +640,7 @@
     } onoff;
     uid_t effectiveUserID;
     gid_t effectiveGroupID;
+    const char *opt_extra_http_port;
 };
 
 SQUIDCEXTERN SquidConfig2 Config2;

Reply via email to