Connection.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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 _SQUIDCONNECTIONDETAIL_H_
12 #define _SQUIDCONNECTIONDETAIL_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 "SquidTime.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 0x40
55 
70 class Connection: public CodeContext
71 {
73 
74 public:
75  Connection();
76 
78  virtual ~Connection();
79 
82  Connection(const Connection &&) = delete;
83 
86 
91 
93  void close();
94 
96  void noteClosure();
97 
99  bool isOpen() const { return (fd >= 0); }
100 
104  void setAddrs(const Ip::Address &aLocal, const Ip::Address &aRemote) {local = aLocal; remote = aRemote;}
105 
110  CachePeer * getPeer() const;
111 
115  void setPeer(CachePeer * p);
116 
118  time_t startTime() const {return startTime_;}
119 
121  time_t lifeTime() const {return squid_curtime - startTime_;}
122 
124  time_t timeLeft(const time_t idleTimeout) const;
125 
131  time_t connectTimeout(const time_t fwdStart) const;
132 
134 
137 
138  /* CodeContext API */
139  virtual ScopedId codeContextGist() const override;
140  virtual std::ostream &detailCodeContext(std::ostream &os) const override;
141 
142 public:
145 
148 
151 
153  int fd;
154 
157 
162 
170 
172  int flags;
173 
175 
176 #if USE_SQUID_EUI
179 #endif
180 
182 
183 private:
186 
188  time_t startTime_;
189 
192 };
193 
194 }; // namespace Comm
195 
196 std::ostream &operator << (std::ostream &os, const Comm::Connection &conn);
197 
198 inline std::ostream &
199 operator << (std::ostream &os, const Comm::ConnectionPointer &conn)
200 {
201  if (conn != NULL)
202  os << *conn;
203  return os;
204 }
205 
206 #endif
207 
#define USER_IDENT_SZ
Definition: defines.h:37
hier_code peerType
Definition: Connection.h:150
MEMPROXY_CLASS(Comm::Connection)
void enterOrphanage()
close the still-open connection when its last reference is gone
Definition: Connection.h:88
Eui::Eui64 remoteEui64
Definition: Connection.h:178
void setAddrs(const Ip::Address &aLocal, const Ip::Address &aRemote)
Definition: Connection.h:104
InstanceId< Connection, uint64_t > id
Definition: Connection.h:181
Abstraction layer for TCP, UDP, TLS, UDS and filedescriptor sockets.
Definition: AcceptLimiter.h:17
unsigned char tos_t
Definition: forward.h:27
time_t startTime() const
Definition: Connection.h:118
char rfc931[USER_IDENT_SZ]
Definition: Connection.h:174
time_t connectTimeout(const time_t fwdStart) const
Definition: Connection.cc:164
void leaveOrphanage()
resume relying on owner(s) to initiate an explicit connection closure
Definition: Connection.h:90
#define NULL
Definition: types.h:166
virtual ~Connection()
Definition: Connection.cc:45
ConnectionPointer cloneProfile() const
Create a new closed Connection with the same configuration as this one.
Definition: Connection.cc:64
time_t timeLeft(const time_t idleTimeout) const
Definition: Connection.cc:146
const Security::NegotiationHistory * hasTlsNegotiations() const
Definition: Connection.h:136
Ip::Address local
Definition: Connection.h:144
CachePeer * getPeer() const
Definition: Connection.cc:124
Connection(const Connection &&)=delete
virtual ScopedId codeContextGist() const override
Definition: Connection.cc:184
Ip::Address remote
Definition: Connection.h:147
int conn
the current server connection FD
Definition: Transport.cc:26
uint32_t nfmark_t
Definition: forward.h:26
nfmark_t nfConnmark
Definition: Connection.h:169
Eui::Eui48 remoteEui48
Definition: Connection.h:177
CachePeer * peer_
Definition: Connection.h:185
time_t squid_curtime
Definition: stub_time.cc:17
Security::NegotiationHistory * tlsHistory
Definition: Connection.h:191
time_t lifeTime() const
Definition: Connection.h:121
virtual std::ostream & detailCodeContext(std::ostream &os) const override
appends human-friendly context description line(s) to a cache.log record
Definition: Connection.cc:189
hier_code
Definition: hier_code.h:12
void setPeer(CachePeer *p)
Definition: Connection.cc:133
bool isOpen() const
Definition: Connection.h:99
std::ostream & operator<<(std::ostream &os, const Comm::Connection &conn)
Definition: Connection.cc:195
Network/connection security abstraction layer.
Definition: Connection.h:34
Security::NegotiationHistory * tlsNegotiations()
Definition: Connection.cc:156
nfmark_t nfmark
Definition: Connection.h:161
#define COMM_ORPHANED
not registered with Comm and not owned by any connection-closing code
Definition: Connection.h:54

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors