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 
83 
87 
92 
94  void close();
95 
97  void noteClosure();
98 
100  bool isOpen() const { return (fd >= 0); }
101 
105  void setAddrs(const Ip::Address &aLocal, const Ip::Address &aRemote) {local = aLocal; remote = aRemote;}
106 
111  CachePeer * getPeer() const;
112 
116  void setPeer(CachePeer * p);
117 
119  time_t startTime() const {return startTime_;}
120 
122  time_t lifeTime() const {return squid_curtime - startTime_;}
123 
125  time_t timeLeft(const time_t idleTimeout) const;
126 
132  time_t connectTimeout(const time_t fwdStart) const;
133 
135 
138 
139  /* CodeContext API */
140  virtual ScopedId codeContextGist() const override;
141  virtual std::ostream &detailCodeContext(std::ostream &os) const override;
142 
143 private:
148 
153 
154 public:
157 
160 
163 
165  int fd;
166 
169 
174 
182 
184  int flags;
185 
187 
188 #if USE_SQUID_EUI
191 #endif
192 
194 
195 private:
198 
200  time_t startTime_;
201 
204 };
205 
206 }; // namespace Comm
207 
208 std::ostream &operator << (std::ostream &os, const Comm::Connection &conn);
209 
210 inline std::ostream &
211 operator << (std::ostream &os, const Comm::ConnectionPointer &conn)
212 {
213  if (conn != NULL)
214  os << *conn;
215  return os;
216 }
217 
218 #endif
219 
#define USER_IDENT_SZ
Definition: defines.h:60
hier_code peerType
Definition: Connection.h:162
MEMPROXY_CLASS(Comm::Connection)
void enterOrphanage()
close the still-open connection when its last reference is gone
Definition: Connection.h:89
void noteClosure()
Definition: Connection.cc:95
Eui::Eui64 remoteEui64
Definition: Connection.h:190
void setAddrs(const Ip::Address &aLocal, const Ip::Address &aRemote)
Definition: Connection.h:105
InstanceId< Connection, uint64_t > id
Definition: Connection.h:193
Abstraction layer for TCP, UDP, TLS, UDS and filedescriptor sockets.
Definition: AcceptLimiter.h:17
unsigned char tos_t
Definition: forward.h:26
time_t startTime() const
Definition: Connection.h:119
Connection & operator=(const Connection &c)
char rfc931[USER_IDENT_SZ]
Definition: Connection.h:186
Connection(const Connection &c)
time_t connectTimeout(const time_t fwdStart) const
Definition: Connection.cc:145
void leaveOrphanage()
resume relying on owner(s) to initiate an explicit connection closure
Definition: Connection.h:91
#define NULL
Definition: types.h:166
virtual ~Connection()
Definition: Connection.cc:44
time_t timeLeft(const time_t idleTimeout) const
Definition: Connection.cc:127
const Security::NegotiationHistory * hasTlsNegotiations() const
Definition: Connection.h:137
Ip::Address local
Definition: Connection.h:156
CachePeer * getPeer() const
Definition: Connection.cc:105
virtual ScopedId codeContextGist() const override
Definition: Connection.cc:165
Ip::Address remote
Definition: Connection.h:159
int conn
the current server connection FD
Definition: Transport.cc:26
uint32_t nfmark_t
Definition: forward.h:25
nfmark_t nfConnmark
Definition: Connection.h:181
Eui::Eui48 remoteEui48
Definition: Connection.h:189
CachePeer * peer_
Definition: Connection.h:197
time_t squid_curtime
Definition: stub_time.cc:17
ConnectionPointer cloneDestinationDetails() const
Definition: Connection.cc:63
Security::NegotiationHistory * tlsHistory
Definition: Connection.h:203
time_t lifeTime() const
Definition: Connection.h:122
virtual std::ostream & detailCodeContext(std::ostream &os) const override
appends human-friendly context description line(s) to a cache.log record
Definition: Connection.cc:170
hier_code
Definition: hier_code.h:12
void setPeer(CachePeer *p)
Definition: Connection.cc:114
ConnectionPointer cloneIdentDetails() const
Definition: Connection.cc:75
bool isOpen() const
Definition: Connection.h:100
std::ostream & operator<<(std::ostream &os, const Comm::Connection &conn)
Definition: Connection.cc:176
Network/connection security abstraction layer.
Definition: Connection.h:34
Security::NegotiationHistory * tlsNegotiations()
Definition: Connection.cc:137
nfmark_t nfmark
Definition: Connection.h:173
#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