Connection.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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 "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:
77 Connection();
78
80 virtual ~Connection();
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 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 virtual ScopedId codeContextGist() const override;
142 virtual std::ostream &detailCodeContext(std::ostream &os) const override;
143
144public:
147
150
153
155 int fd;
156
159
164
172
174 int flags;
175
177
178#if USE_SQUID_EUI
181#endif
182
184
185private:
188
191
194};
195
196}; // namespace Comm
197
198std::ostream &operator << (std::ostream &os, const Comm::Connection &conn);
199
200inline std::ostream &
201operator << (std::ostream &os, const Comm::ConnectionPointer &conn)
202{
203 if (conn != nullptr)
204 os << *conn;
205 return os;
206}
207
208#endif
209
#define COMM_ORPHANED
not registered with Comm and not owned by any connection-closing code
Definition: Connection.h:54
std::ostream & operator<<(std::ostream &os, const Comm::Connection &conn)
Definition: Connection.cc:195
time_t squid_curtime
Definition: stub_libtime.cc:20
int conn
the current server connection FD
Definition: Transport.cc:26
Eui::Eui64 remoteEui64
Definition: Connection.h:180
bool isOpen() const
Definition: Connection.h:101
InstanceId< Connection, uint64_t > id
Definition: Connection.h:183
hier_code peerType
Definition: Connection.h:152
const Security::NegotiationHistory * hasTlsNegotiations() const
Definition: Connection.h:138
time_t timeLeft(const time_t idleTimeout) const
Definition: Connection.cc:146
CachePeer * getPeer() const
Definition: Connection.cc:124
nfmark_t nfmark
Definition: Connection.h:163
Ip::Address remote
Definition: Connection.h:149
void setAddrs(const Ip::Address &aLocal, const Ip::Address &aRemote)
Definition: Connection.h:106
char rfc931[USER_IDENT_SZ]
Definition: Connection.h:176
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
void leaveOrphanage()
resume relying on owner(s) to initiate an explicit connection closure
Definition: Connection.h:92
Security::NegotiationHistory * tlsHistory
Definition: Connection.h:193
CachePeer * peer_
Definition: Connection.h:187
Ip::Address local
Definition: Connection.h:146
void enterOrphanage()
close the still-open connection when its last reference is gone
Definition: Connection.h:90
nfmark_t nfConnmark
Definition: Connection.h:171
time_t lifeTime() const
Definition: Connection.h:123
Connection(const Connection &&)=delete
Eui::Eui48 remoteEui48
Definition: Connection.h:179
time_t startTime() const
Definition: Connection.h:120
MEMPROXY_CLASS(Comm::Connection)
virtual ~Connection()
Definition: Connection.cc:45
time_t connectTimeout(const time_t fwdStart) const
Definition: Connection.cc:164
Security::NegotiationHistory * tlsNegotiations()
Definition: Connection.cc:156
ConnectionPointer cloneProfile() const
Create a new closed Connection with the same configuration as this one.
Definition: Connection.cc:64
virtual ScopedId codeContextGist() const override
Definition: Connection.cc:184
void setPeer(CachePeer *p)
Definition: Connection.cc:133
#define USER_IDENT_SZ
Definition: defines.h:37
hier_code
Definition: hier_code.h:12
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.
Definition: AcceptLimiter.h:17
Network/connection security abstraction layer.
Definition: Connection.h:34

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors