Squid Web Cache master
Loading...
Searching...
No Matches
Connection.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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/* DEBUG: section 05 Socket Functions */
10
11#ifndef SQUID_SRC_COMM_CONNECTION_H
12#define SQUID_SRC_COMM_CONNECTION_H
13
14#include "base/CodeContext.h"
15#include "base/InstanceId.h"
16#include "comm/forward.h"
17#include "defines.h"
18#if USE_SQUID_EUI
19#include "eui/Eui48.h"
20#include "eui/Eui64.h"
21#endif
22#include "hier_code.h"
23#include "ip/Address.h"
24#include "ip/forward.h"
25#include "mem/forward.h"
26#include "time/gadgets.h"
27
28#include <iosfwd>
29#include <ostream>
30
31class CachePeer;
32
33namespace Security
34{
36};
37
38namespace Comm
39{
40
41/* TODO: make these a struct of boolean flags members in the connection instead of a bitmap.
42 * we can't do that until all non-comm code uses Commm::Connection objects to create FD
43 * currently there is code still using comm_open() and comm_openex() synchronously!!
44 */
45#define COMM_UNSET 0x00
46#define COMM_NONBLOCKING 0x01 // default flag.
47#define COMM_NOCLOEXEC 0x02
48#define COMM_REUSEADDR 0x04 // shared FD may be both accept()ing and read()ing
49#define COMM_DOBIND 0x08 // requires a bind()
50#define COMM_TRANSPARENT 0x10 // arrived via TPROXY
51#define COMM_INTERCEPTION 0x20 // arrived via NAT
52#define COMM_REUSEPORT 0x40 //< needs SO_REUSEPORT
54#define COMM_ORPHANED 0x80
56#define COMM_DOBIND_PORT_LATER 0x100
57
73{
75
76public:
78
80 ~Connection() override;
81
84 Connection(const Connection &&) = delete;
85
88
92 void leaveOrphanage() { flags &= ~COMM_ORPHANED; }
93
95 void close();
96
98 void noteClosure();
99
101 bool isOpen() const { return (fd >= 0); }
102
106 void setAddrs(const Ip::Address &aLocal, const Ip::Address &aRemote) {local = aLocal; remote = aRemote;}
107
112 CachePeer * getPeer() const;
113
117 void setPeer(CachePeer * p);
118
120 bool toGoneCachePeer() const;
121
123 time_t startTime() const {return startTime_;}
124
126 time_t lifeTime() const {return squid_curtime - startTime_;}
127
129 time_t timeLeft(const time_t idleTimeout) const;
130
136 time_t connectTimeout(const time_t fwdStart) const;
137
139
142
143 /* CodeContext API */
144 ScopedId codeContextGist() const override;
145 std::ostream &detailCodeContext(std::ostream &os) const override;
146
147public:
150
153
156
158 int fd = -1;
159
162
167
175
178
179#if USE_SQUID_EUI
182#endif
183
185
186private:
188 CachePeer *peer_ = nullptr;
189
192
195};
196
197std::ostream &operator <<(std::ostream &, const Connection &);
198
199inline std::ostream &
200operator <<(std::ostream &os, const ConnectionPointer &conn)
201{
202 if (conn != nullptr)
203 os << *conn;
204 return os;
205}
206
207} // namespace Comm
208
209#endif /* SQUID_SRC_COMM_CONNECTION_H */
210
#define COMM_ORPHANED
not registered with Comm and not owned by any connection-closing code
Definition Connection.h:54
#define COMM_NONBLOCKING
Definition Connection.h:46
time_t squid_curtime
Eui::Eui64 remoteEui64
Definition Connection.h:181
bool isOpen() const
Definition Connection.h:101
InstanceId< Connection, uint64_t > id
Definition Connection.h:184
hier_code peerType
Definition Connection.h:155
const Security::NegotiationHistory * hasTlsNegotiations() const
Definition Connection.h:141
time_t timeLeft(const time_t idleTimeout) const
CachePeer * getPeer() const
Ip::Address remote
Definition Connection.h:152
void setAddrs(const Ip::Address &aLocal, const Ip::Address &aRemote)
Definition Connection.h:106
std::ostream & detailCodeContext(std::ostream &os) const override
appends human-friendly context description line(s) to a cache.log record
void leaveOrphanage()
resume relying on owner(s) to initiate an explicit connection closure
Definition Connection.h:92
Security::NegotiationHistory * tlsHistory
Definition Connection.h:194
CachePeer * peer_
Definition Connection.h:188
Ip::Address local
Definition Connection.h:149
void enterOrphanage()
close the still-open connection when its last reference is gone
Definition Connection.h:90
nfmark_t nfConnmark
Definition Connection.h:174
time_t lifeTime() const
Definition Connection.h:126
Connection(const Connection &&)=delete
Eui::Eui48 remoteEui48
Definition Connection.h:180
bool toGoneCachePeer() const
whether this is a connection to a cache_peer that was removed during reconfiguration
~Connection() override
Definition Connection.cc:32
time_t startTime() const
Definition Connection.h:123
MEMPROXY_CLASS(Comm::Connection)
time_t connectTimeout(const time_t fwdStart) const
Security::NegotiationHistory * tlsNegotiations()
ConnectionPointer cloneProfile() const
Create a new closed Connection with the same configuration as this one.
Definition Connection.cc:51
ScopedId codeContextGist() const override
void setPeer(CachePeer *p)
hier_code
Definition hier_code.h:12
@ HIER_NONE
Definition hier_code.h:13
unsigned char tos_t
Definition forward.h:27
uint32_t nfmark_t
Definition forward.h:26
Abstraction layer for TCP, UDP, TLS, UDS and filedescriptor sockets.
std::ostream & operator<<(std::ostream &, const Connection &)
Network/connection security abstraction layer.
Definition Connection.h:34