PortCfg.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #include "squid.h"
10 #include "anyp/PortCfg.h"
11 #include "anyp/UriScheme.h"
12 #include "comm.h"
13 #include "fatal.h"
14 #include "security/PeerOptions.h"
15 #if USE_OPENSSL
16 #include "ssl/support.h"
17 #endif
18 
19 #include <cstring>
20 #include <limits>
21 
24 
25 int NHttpSockets = 0;
27 
29  next(),
30  s(),
31  transport(AnyP::PROTO_HTTP,1,1), // "Squid is an HTTP proxy", etc.
32  name(nullptr),
33  defaultsite(nullptr),
34  flags(),
35  allow_direct(false),
36  vhost(false),
37  actAsOrigin(false),
38  ignore_cc(false),
39  connection_auth_disabled(false),
40  ftp_track_dirs(false),
41  vport(0),
42  disable_pmtu_discovery(0),
43  workerQueues(false),
44  listenConn()
45 {
46 }
47 
49 {
50  if (Comm::IsConnOpen(listenConn)) {
51  listenConn->close();
52  listenConn = nullptr;
53  }
54 
55  safe_free(name);
56  safe_free(defaultsite);
57 }
58 
60  next(), // special case; see assert() below
61  s(other.s),
62  transport(other.transport),
63  name(other.name ? xstrdup(other.name) : nullptr),
64  defaultsite(other.defaultsite ? xstrdup(other.defaultsite) : nullptr),
65  flags(other.flags),
66  allow_direct(other.allow_direct),
67  vhost(other.vhost),
68  actAsOrigin(other.actAsOrigin),
69  ignore_cc(other.ignore_cc),
70  connection_auth_disabled(other.connection_auth_disabled),
71  ftp_track_dirs(other.ftp_track_dirs),
72  vport(other.vport),
73  disable_pmtu_discovery(other.disable_pmtu_discovery),
74  workerQueues(other.workerQueues),
75  tcp_keepalive(other.tcp_keepalive),
76  listenConn(), // special case; see assert() below
77  secure(other.secure)
78 {
79  // to simplify, we only support port copying during parsing
80  assert(!other.next);
81  assert(!other.listenConn);
82 }
83 
86 {
87  const auto clone = new PortCfg(*this);
88  clone->s.setIPv4();
89  debugs(3, 3, AnyP::UriScheme(transport.protocol).image() << "_port: " <<
90  "cloned wildcard address for split-stack: " << s << " and " << clone->s);
91  return clone;
92 }
93 
96 {
97  // Unfortunately, .name lifetime is too short in FTP use cases.
98  // TODO: Consider adding InstanceId<uint32_t> to all RefCountable classes.
99  return ScopedId("port");
100 }
101 
102 std::ostream &
103 AnyP::PortCfg::detailCodeContext(std::ostream &os) const
104 {
105  // parsePortSpecification() defaults optional port name to the required
106  // listening address so we cannot easily distinguish one from the other.
107  if (name)
108  os << Debug::Extra << "listening port: " << name;
109  else if (s.port())
110  os << Debug::Extra << "listening port address: " << s;
111  return os;
112 }
113 
~PortCfg() override
Definition: PortCfg.cc:48
ScopedId codeContextGist() const override
Definition: PortCfg.cc:95
AnyP::PortCfgPointer HttpPortList
list of Squid http(s)_port configured
Definition: PortCfg.cc:22
std::ostream & detailCodeContext(std::ostream &os) const override
appends human-friendly context description line(s) to a cache.log record
Definition: PortCfg.cc:103
#define xstrdup
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:27
int HttpSockets[MAXTCPLISTENPORTS]
Definition: PortCfg.cc:26
Definition: forward.h:14
PortCfg * ipV4clone() const
creates the same port configuration but listening on any IPv4 address
Definition: PortCfg.cc:85
#define safe_free(x)
Definition: xalloc.h:73
AnyP::PortCfgPointer FtpPortList
list of Squid ftp_port configured
Definition: PortCfg.cc:23
#define assert(EX)
Definition: assert.h:17
SBuf image() const
Definition: UriScheme.h:57
static std::ostream & Extra(std::ostream &)
Definition: debug.cc:1316
@ PROTO_HTTP
Definition: ProtocolType.h:25
Comm::ConnectionPointer listenConn
Definition: PortCfg.h:67
PortCfgPointer next
Definition: PortCfg.h:38
int NHttpSockets
Definition: PortCfg.cc:25
#define MAXTCPLISTENPORTS
Definition: PortCfg.h:86
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192

 

Introduction

Documentation

Support

Miscellaneous