[squid-dev] [PATCH] Refactor IcmpConfig
Amos Jeffries
squid3 at treenet.co.nz
Fri May 8 08:23:08 UTC 2015
Pull the IcmpConfig object out of the global SquidConfig structure and
updates it to processing its own parse logics. Bringing it inline with
the per-component configuration design in SourceLayout and HotConf projects.
This allows us to use SBuf for storing the pinger program details and
avoid valgrind complaints about some malloc.
It will also allow lazy re-starting of the helper to be implemented later.
Amos
-------------- next part --------------
=== modified file 'src/SquidConfig.h'
--- src/SquidConfig.h 2015-02-26 10:25:12 +0000
+++ src/SquidConfig.h 2015-04-24 09:13:40 +0000
@@ -1,38 +1,37 @@
/*
* Copyright (C) 1996-2015 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
* Please see the COPYING and CONTRIBUTORS files for details.
*/
#ifndef SQUID_SQUIDCONFIG_H_
#define SQUID_SQUIDCONFIG_H_
#include "acl/forward.h"
#include "base/RefCount.h"
#include "ClientDelayConfig.h"
#include "DelayConfig.h"
#include "helper/ChildConfig.h"
#include "HttpHeaderTools.h"
-#include "icmp/IcmpConfig.h"
#include "ip/Address.h"
#include "Notes.h"
#include "YesNoNone.h"
#if USE_OPENSSL
#if HAVE_OPENSSL_SSL_H
#include <openssl/ssl.h>
#endif
class sslproxy_cert_sign;
class sslproxy_cert_adapt;
#endif
namespace Mgr
{
class ActionPasswordList;
} // namespace Mgr
class CustomLog;
class CpuAffinityMap;
class external_acl;
@@ -131,44 +130,40 @@
struct {
Ip::Address router;
Ip::Address address;
int version;
} Wccp;
#endif
#if USE_WCCPv2
struct {
Ip::Address_list *router;
Ip::Address address;
int forwarding_method;
int return_method;
int assignment_method;
int weight;
int rebuildwait;
void *info;
} Wccp2;
#endif
-#if USE_ICMP
- IcmpConfig pinger;
-#endif
-
char *as_whois_server;
struct {
char *store;
char *swap;
CustomLog *accesslogs;
#if ICAP_CLIENT
CustomLog *icaplogs;
#endif
int rotateNumber;
} Log;
char *adminEmail;
char *EmailFrom;
char *EmailProgram;
char *effectiveUser;
char *visible_appname_string;
char *effectiveGroup;
struct {
wordlist *redirect;
=== modified file 'src/cache_cf.cc'
--- src/cache_cf.cc 2015-02-26 10:25:12 +0000
+++ src/cache_cf.cc 2015-04-26 04:15:23 +0000
@@ -15,40 +15,41 @@
#include "acl/AclSizeLimit.h"
#include "acl/Address.h"
#include "acl/Gadgets.h"
#include "acl/MethodData.h"
#include "acl/Tree.h"
#include "anyp/PortCfg.h"
#include "anyp/UriScheme.h"
#include "AuthReg.h"
#include "base/RunnersRegistry.h"
#include "cache_cf.h"
#include "CachePeer.h"
#include "ConfigParser.h"
#include "CpuAffinityMap.h"
#include "DiskIO/DiskIOModule.h"
#include "eui/Config.h"
#include "ExternalACL.h"
#include "format/Format.h"
#include "ftp/Elements.h"
#include "globals.h"
#include "HttpHeaderTools.h"
+#include "icmp/IcmpConfig.h"
#include "ident/Config.h"
#include "ip/Intercept.h"
#include "ip/QosConfig.h"
#include "ip/tools.h"
#include "ipc/Kids.h"
#include "log/Config.h"
#include "log/CustomLog.h"
#include "MemBuf.h"
#include "mgr/ActionPasswordList.h"
#include "mgr/Registration.h"
#include "neighbors.h"
#include "NeighborTypeDomainList.h"
#include "Parsing.h"
#include "pconn.h"
#include "PeerDigest.h"
#include "PeerPoolMgr.h"
#include "redirect.h"
#include "RefreshPattern.h"
#include "rfc1738.h"
#include "SBufList.h"
=== modified file 'src/cf.data.depend'
--- src/cf.data.depend 2015-02-26 10:25:12 +0000
+++ src/cf.data.depend 2015-04-24 09:25:25 +0000
@@ -31,40 +31,41 @@
delay_pool_rates delay_class
client_delay_pool_access acl
client_delay_pool_count
client_delay_pool_rates
denyinfo acl
eol
externalAclHelper auth_param
HelperChildConfig
hostdomain cache_peer
hostdomaintype cache_peer
http_header_access acl
http_header_replace
HeaderWithAclList acl
adaptation_access_type adaptation_service_set adaptation_service_chain acl icap_service icap_class
adaptation_service_set_type icap_service ecap_service
adaptation_service_chain_type icap_service ecap_service
icap_access_type icap_class acl
icap_class_type icap_service
icap_service_type
icap_service_failure_limit
+icmp
ecap_service_type
int
kb_int64_t
kb_size_t
logformat
YesNoNone
memcachemode
note acl
obsolete
onoff
on_unsupported_protocol acl
peer
peer_access cache_peer acl
pipelinePrefetch
PortCfg
QosConfig
TokenOrQuotedString
refreshpattern
removalpolicy
securePeerOptions
=== modified file 'src/cf.data.pre'
--- src/cf.data.pre 2015-05-05 09:09:27 +0000
+++ src/cf.data.pre 2015-05-08 08:06:24 +0000
@@ -4869,52 +4869,52 @@
NAME: diskd_program
TYPE: string
DEFAULT: @DEFAULT_DISKD@
LOC: Config.Program.diskd
DOC_START
Specify the location of the diskd executable.
Note this is only useful if you have compiled in
diskd as one of the store io modules.
DOC_END
NAME: unlinkd_program
IFDEF: USE_UNLINKD
TYPE: string
DEFAULT: @DEFAULT_UNLINKD@
LOC: Config.Program.unlinkd
DOC_START
Specify the location of the executable for file deletion process.
DOC_END
NAME: pinger_program
-TYPE: string
-DEFAULT: @DEFAULT_PINGER@
-LOC: Config.pinger.program
IFDEF: USE_ICMP
+TYPE: icmp
+DEFAULT: @DEFAULT_PINGER@
+LOC: IcmpCfg
DOC_START
Specify the location of the executable for the pinger process.
DOC_END
NAME: pinger_enable
TYPE: onoff
DEFAULT: on
-LOC: Config.pinger.enable
+LOC: IcmpCfg.enable
IFDEF: USE_ICMP
DOC_START
Control whether the pinger is active at run-time.
Enables turning ICMP pinger on and off with a simple
squid -k reconfigure.
DOC_END
COMMENT_START
OPTIONS FOR URL REWRITING
-----------------------------------------------------------------------------
COMMENT_END
NAME: url_rewrite_program redirect_program
TYPE: wordlist
LOC: Config.Program.redirect
DEFAULT: none
DOC_START
Specify the location of the executable URL rewriter to use.
Since they can perform almost any function there isn't one included.
=== added file 'src/icmp/IcmpConfig.cc'
--- src/icmp/IcmpConfig.cc 1970-01-01 00:00:00 +0000
+++ src/icmp/IcmpConfig.cc 2015-04-26 07:58:48 +0000
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * 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 03 Configuration Settings */
+
+#include "squid.h"
+
+#if USE_ICMP
+#include "ConfigParser.h"
+#include "IcmpConfig.h"
+
+IcmpConfig IcmpCfg;
+
+void
+IcmpConfig::parse()
+{
+ if (char *token = ConfigParser::NextQuotedOrToEol()) {
+ program.clear();
+ program.append(token);
+ } else
+ self_destruct();
+}
+
+#endif /* USE_ICMP */
+
=== modified file 'src/icmp/IcmpConfig.h'
--- src/icmp/IcmpConfig.h 2015-01-13 07:25:36 +0000
+++ src/icmp/IcmpConfig.h 2015-04-26 07:58:16 +0000
@@ -1,43 +1,53 @@
/*
* Copyright (C) 1996-2015 The Squid Software Foundation and contributors
*
* 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 03 Configuration Settings */
#ifndef ICMPCONFIG_H
#define ICMPCONFIG_H
+#if USE_ICMP
+
+#include "cache_cf.h"
+#include "SBuf.h"
+
/**
* Squid pinger Configuration settings
- *
- \par
- * This structure is included as a child field of the global Config
- * such that if ICMP is built it can be accessed as Config.pinger.*
*/
class IcmpConfig
{
-
public:
+ IcmpConfig() : enable(0) {}
+ ~IcmpConfig() {}
- /** \todo These methods should really be defined in an ICMPConfig.cc file
- * alongside any custom parsing routines needed for this component.
- * First though, the whole global Config dependancy tree needs fixing */
- IcmpConfig() : program(NULL), enable(0) {};
- ~IcmpConfig() { if (program) delete program; program = NULL; };
-
- /* variables */
+ void clear() {enable=0; program.clear();}
+ void parse();
/** pinger helper application path */
- char *program;
+ SBuf program;
/** Whether the pinger helper is enabled for use or not */
- /** \todo make this much more memory efficient for a boolean */
int enable;
};
+extern IcmpConfig IcmpCfg;
+
+/* wrappers for the legacy squid.conf parser */
+#define dump_icmp(e,n,v) \
+ if (!(v).program.isEmpty()) { \
+ (e)->append((n), strlen((n))); \
+ (e)->append(" ", 1); \
+ (e)->append((v).program.rawContent(), (v).program.length()); \
+ (e)->append("\n", 1); \
+ } else {}
+#define parse_icmp(v) (v)->parse()
+#define free_icmp(x) (x)->clear()
+
+#endif /* USE_ICMP */
#endif /* ICMPCONFIG_H */
=== modified file 'src/icmp/IcmpSquid.cc'
--- src/icmp/IcmpSquid.cc 2015-01-13 07:25:36 +0000
+++ src/icmp/IcmpSquid.cc 2015-04-25 15:58:56 +0000
@@ -1,35 +1,36 @@
/*
* Copyright (C) 1996-2015 The Squid Software Foundation and contributors
*
* 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 37 ICMP Routines */
#include "squid.h"
#include "comm.h"
#include "comm/Loops.h"
#include "defines.h"
#include "fd.h"
+#include "icmp/IcmpConfig.h"
#include "icmp/IcmpSquid.h"
#include "icmp/net_db.h"
#include "ip/tools.h"
#include "SquidConfig.h"
#include "SquidIpc.h"
#include "SquidTime.h"
#include <cerrno>
// Instance global to be available in main() and elsewhere.
IcmpSquid icmpEngine;
#if USE_ICMP
#define S_ICMP_ECHO 1
#define S_ICMP_DOM 3
static void * hIpc;
static pid_t pid;
@@ -176,56 +177,56 @@
void
IcmpSquid::DomainPing(Ip::Address &to, const char *domain)
{
#if USE_ICMP
debugs(37, 4, HERE << "'" << domain << "' (" << to << ")");
SendEcho(to, S_ICMP_DOM, domain, 0);
#endif
}
int
IcmpSquid::Open(void)
{
#if USE_ICMP
const char *args[2];
int rfd;
int wfd;
Ip::Address localhost;
/* User configured disabled. */
- if (!Config.pinger.enable) {
+ if (!IcmpCfg.enable) {
Close();
return -1;
}
args[0] = "(pinger)";
args[1] = NULL;
localhost.setLocalhost();
/*
* Do NOT use IPC_DGRAM (=IPC_UNIX_DGRAM) here because you can't
* send() more than 4096 bytes on a socketpair() socket (at
* least on FreeBSD).
*/
pid = ipcCreate(IPC_UDP_SOCKET,
- Config.pinger.program,
+ IcmpCfg.program.c_str(),
args,
"Pinger Socket",
localhost,
&rfd,
&wfd,
&hIpc);
if (pid < 0)
return -1;
assert(rfd == wfd);
icmp_sock = rfd;
fd_note(icmp_sock, "pinger");
Comm::SetSelect(icmp_sock, COMM_SELECT_READ, icmpSquidRecv, NULL, 0);
commUnsetFdTimeout(icmp_sock);
=== modified file 'src/icmp/Makefile.am'
--- src/icmp/Makefile.am 2015-02-03 11:21:26 +0000
+++ src/icmp/Makefile.am 2015-04-26 07:59:03 +0000
@@ -33,40 +33,41 @@
$(top_srcdir)/src/base/CharacterSet.h \
$(top_srcdir)/src/SBuf.h \
$(top_srcdir)/src/SBuf.cc \
$(top_srcdir)/src/MemBlob.h \
$(top_srcdir)/src/MemBlob.cc \
$(top_srcdir)/src/OutOfBoundsException.h \
$(top_srcdir)/src/SBufExceptions.h \
$(top_srcdir)/src/SBufExceptions.cc \
$(top_srcdir)/src/String.cc \
$(top_srcdir)/src/SquidString.h \
$(top_srcdir)/src/base/TextException.h \
$(top_srcdir)/src/base/TextException.cc
# ICMP API definition ...
libicmp_core_la_SOURCES = \
Icmp.h \
Icmp.cc
# Squid Internal ICMP helper interface
libicmp_la_SOURCES = \
+ IcmpConfig.cc \
IcmpConfig.h \
IcmpSquid.h \
IcmpSquid.cc \
net_db.h \
net_db.cc
# ICMP lookup helper
pinger_SOURCES = \
Icmp.h \
IcmpPinger.h \
IcmpPinger.cc \
Icmp4.h \
Icmp4.cc \
Icmp6.h \
Icmp6.cc \
pinger.cc
# depends on these but install/dist is done elsewhere.
# TODO: remove when these are cleaned up in their own way.
nodist_pinger_SOURCES = \
More information about the squid-dev
mailing list