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 
31 class CachePeer;
32 
33 namespace Security
34 {
35 class NegotiationHistory;
36 };
37 
38 namespace 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
53 #define COMM_ORPHANED 0x80
55 #define COMM_DOBIND_PORT_LATER 0x100
57 
72 class Connection: public CodeContext
73 {
75 
76 public:
77  Connection();
78 
80  ~Connection() override;
81 
84  Connection(const Connection &&) = delete;
85 
88 
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 
147 public:
150 
153 
156 
158  int fd;
159 
162 
167 
175 
177  int flags;
178 
179 #if USE_SQUID_EUI
182 #endif
183 
185 
186 private:
189 
191  time_t startTime_;
192 
195 };
196 
197 std::ostream &operator <<(std::ostream &, const Connection &);
198 
199 inline std::ostream &
200 operator <<(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 
hier_code peerType
Definition: Connection.h:155
MEMPROXY_CLASS(Comm::Connection)
void enterOrphanage()
close the still-open connection when its last reference is gone
Definition: Connection.h:90
~Connection() override
Definition: Connection.cc:43
Eui::Eui64 remoteEui64
Definition: Connection.h:181
void setAddrs(const Ip::Address &aLocal, const Ip::Address &aRemote)
Definition: Connection.h:106
InstanceId< Connection, uint64_t > id
Definition: Connection.h:184
bool toGoneCachePeer() const
whether this is a connection to a cache_peer that was removed during reconfiguration
Definition: Connection.cc:143
Abstraction layer for TCP, UDP, TLS, UDS and filedescriptor sockets.
Definition: AcceptLimiter.h:16
unsigned char tos_t
Definition: forward.h:27
time_t startTime() const
Definition: Connection.h:123
std::ostream & operator<<(std::ostream &, const Connection &)
Definition: Connection.cc:198
time_t connectTimeout(const time_t fwdStart) const
Definition: Connection.cc:167
void leaveOrphanage()
resume relying on owner(s) to initiate an explicit connection closure
Definition: Connection.h:92
ConnectionPointer cloneProfile() const
Create a new closed Connection with the same configuration as this one.
Definition: Connection.cc:62
time_t timeLeft(const time_t idleTimeout) const
Definition: Connection.cc:149
const Security::NegotiationHistory * hasTlsNegotiations() const
Definition: Connection.h:141
Ip::Address local
Definition: Connection.h:149
CachePeer * getPeer() const
Definition: Connection.cc:121
ScopedId codeContextGist() const override
Definition: Connection.cc:187
Ip::Address remote
Definition: Connection.h:152
uint32_t nfmark_t
Definition: forward.h:26
nfmark_t nfConnmark
Definition: Connection.h:174
Eui::Eui48 remoteEui48
Definition: Connection.h:180
CachePeer * peer_
Definition: Connection.h:188
time_t squid_curtime
Definition: stub_libtime.cc:20
Security::NegotiationHistory * tlsHistory
Definition: Connection.h:194
time_t lifeTime() const
Definition: Connection.h:126
std::ostream & detailCodeContext(std::ostream &os) const override
appends human-friendly context description line(s) to a cache.log record
Definition: Connection.cc:192
hier_code
Definition: hier_code.h:12
void setPeer(CachePeer *p)
Definition: Connection.cc:130
bool isOpen() const
Definition: Connection.h:101
Network/connection security abstraction layer.
Definition: Connection.h:33
Security::NegotiationHistory * tlsNegotiations()
Definition: Connection.cc:159
nfmark_t nfmark
Definition: Connection.h:166
#define COMM_ORPHANED
not registered with Comm and not owned by any connection-closing code
Definition: Connection.h:54

 

Introduction

Documentation

Support

Miscellaneous