Connection.h
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 /* 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  time_t startTime() const {return startTime_;}
121 
123  time_t lifeTime() const {return squid_curtime - startTime_;}
124 
126  time_t timeLeft(const time_t idleTimeout) const;
127 
133  time_t connectTimeout(const time_t fwdStart) const;
134 
136 
139 
140  /* CodeContext API */
141  ScopedId codeContextGist() const override;
142  std::ostream &detailCodeContext(std::ostream &os) const override;
143 
144 public:
147 
150 
153 
155  int fd;
156 
159 
164 
172 
174  int flags;
175 
176 #if USE_SQUID_EUI
179 #endif
180 
182 
183 private:
186 
188  time_t startTime_;
189 
192 };
193 
194 std::ostream &operator <<(std::ostream &, const Connection &);
195 
196 inline std::ostream &
197 operator <<(std::ostream &os, const ConnectionPointer &conn)
198 {
199  if (conn != nullptr)
200  os << *conn;
201  return os;
202 }
203 
204 } // namespace Comm
205 
206 #endif /* SQUID_SRC_COMM_CONNECTION_H */
207 
hier_code peerType
Definition: Connection.h:152
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:178
void setAddrs(const Ip::Address &aLocal, const Ip::Address &aRemote)
Definition: Connection.h:106
InstanceId< Connection, uint64_t > id
Definition: Connection.h:181
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:120
std::ostream & operator<<(std::ostream &, const Connection &)
Definition: Connection.cc:192
time_t connectTimeout(const time_t fwdStart) const
Definition: Connection.cc:161
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:143
const Security::NegotiationHistory * hasTlsNegotiations() const
Definition: Connection.h:138
Ip::Address local
Definition: Connection.h:146
CachePeer * getPeer() const
Definition: Connection.cc:121
ScopedId codeContextGist() const override
Definition: Connection.cc:181
Ip::Address remote
Definition: Connection.h:149
uint32_t nfmark_t
Definition: forward.h:26
nfmark_t nfConnmark
Definition: Connection.h:171
Eui::Eui48 remoteEui48
Definition: Connection.h:177
CachePeer * peer_
Definition: Connection.h:185
time_t squid_curtime
Definition: stub_libtime.cc:20
Security::NegotiationHistory * tlsHistory
Definition: Connection.h:191
time_t lifeTime() const
Definition: Connection.h:123
std::ostream & detailCodeContext(std::ostream &os) const override
appends human-friendly context description line(s) to a cache.log record
Definition: Connection.cc:186
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:153
nfmark_t nfmark
Definition: Connection.h:163
#define COMM_ORPHANED
not registered with Comm and not owned by any connection-closing code
Definition: Connection.h:54

 

Introduction

Documentation

Support

Miscellaneous