]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
bf95c10a | 2 | * Copyright (C) 1996-2022 The Squid Software Foundation and contributors |
bbc27441 AJ |
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 | ||
f7f3304a | 9 | #include "squid.h" |
65d448bc | 10 | #include "anyp/PortCfg.h" |
7801cce9 | 11 | #include "anyp/UriScheme.h" |
cbff89ba | 12 | #include "comm.h" |
eb6ac808 | 13 | #include "fatal.h" |
6bd62757 | 14 | #include "security/PeerOptions.h" |
cb4f4424 | 15 | #if USE_OPENSSL |
f4e4d4d6 CT |
16 | #include "ssl/support.h" |
17 | #endif | |
1b26be8f | 18 | |
eb6ac808 | 19 | #include <cstring> |
eb6ac808 | 20 | #include <limits> |
eb6ac808 | 21 | |
fa720bfb | 22 | AnyP::PortCfgPointer HttpPortList; |
8ea0d847 | 23 | AnyP::PortCfgPointer FtpPortList; |
65d448bc AJ |
24 | |
25 | int NHttpSockets = 0; | |
26 | int HttpSockets[MAXTCPLISTENPORTS]; | |
27 | ||
eb6ac808 | 28 | AnyP::PortCfg::PortCfg() : |
f53969cc SM |
29 | next(), |
30 | s(), | |
31 | transport(AnyP::PROTO_HTTP,1,1), // "Squid is an HTTP proxy", etc. | |
aee3523a AR |
32 | name(nullptr), |
33 | defaultsite(nullptr), | |
f53969cc SM |
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), | |
7d17a6a6 | 43 | workerQueues(false), |
f53969cc | 44 | listenConn() |
a97126cc | 45 | { |
a97126cc | 46 | } |
1b26be8f | 47 | |
65d448bc | 48 | AnyP::PortCfg::~PortCfg() |
1b26be8f | 49 | { |
8bbb16e3 | 50 | if (Comm::IsConnOpen(listenConn)) { |
00406b24 | 51 | listenConn->close(); |
aee3523a | 52 | listenConn = nullptr; |
cbff89ba | 53 | } |
04f55905 | 54 | |
1b26be8f | 55 | safe_free(name); |
56 | safe_free(defaultsite); | |
1b26be8f | 57 | } |
f4e4d4d6 | 58 | |
7801cce9 EB |
59 | AnyP::PortCfg::PortCfg(const PortCfg &other): |
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) | |
65d448bc | 78 | { |
7801cce9 EB |
79 | // to simplify, we only support port copying during parsing |
80 | assert(!other.next); | |
81 | assert(!other.listenConn); | |
82 | } | |
65d448bc | 83 | |
7801cce9 EB |
84 | AnyP::PortCfg * |
85 | AnyP::PortCfg::ipV4clone() const | |
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; | |
65d448bc | 92 | } |
5ae65581 | 93 | |
ccfbe8f4 AR |
94 | ScopedId |
95 | AnyP::PortCfg::codeContextGist() const | |
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 |