]> git.ipfire.org Git - thirdparty/squid.git/blame - src/comm/Connection.h
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / comm / Connection.h
CommitLineData
ee0989f2 1/*
5b74111a 2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
ee0989f2 3 *
bbc27441
AJ
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.
ee0989f2 7 */
8
bbc27441
AJ
9/* DEBUG: section 05 Socket Functions */
10
ee0989f2 11#ifndef _SQUIDCONNECTIONDETAIL_H_
12#define _SQUIDCONNECTIONDETAIL_H_
13
49ae8b95 14#include "comm/forward.h"
582c2af2 15#include "defines.h"
89aec9b6
AJ
16#if USE_SQUID_EUI
17#include "eui/Eui48.h"
18#include "eui/Eui64.h"
19#endif
d35851f1
FC
20#include "hier_code.h"
21#include "ip/Address.h"
22#include "ip/forward.h"
23#include "mem/forward.h"
8aec3e1b 24#include "SquidTime.h"
cc192b50 25
5c336a3b 26#include <iosfwd>
5c336a3b 27#include <ostream>
5c336a3b 28
a3c6762c 29class CachePeer;
cfd66529 30
2bcab852
CT
31namespace Security
32{
33class NegotiationHistory;
34};
35
dc49061a
A
36namespace Comm
37{
cfd66529 38
27d1f0a0
AJ
39/* TODO: make these a struct of boolean flags members in the connection instead of a bitmap.
40 * we can't do that until all non-comm code uses Commm::Connection objects to create FD
41 * currently there is code still using comm_open() and comm_openex() synchronously!!
42 */
cfd66529 43#define COMM_UNSET 0x00
40d34a62 44#define COMM_NONBLOCKING 0x01 // default flag.
cfd66529 45#define COMM_NOCLOEXEC 0x02
40d34a62
AJ
46#define COMM_REUSEADDR 0x04 // shared FD may be both accept()ing and read()ing
47#define COMM_DOBIND 0x08 // requires a bind()
48#define COMM_TRANSPARENT 0x10 // arrived via TPROXY
49#define COMM_INTERCEPTION 0x20 // arrived via NAT
62e76326 50
739b352a
AJ
51/**
52 * Store data about the physical and logical attributes of a connection.
53 *
54 * Some link state can be infered from the data, however this is not an
55 * object for state data. But a semantic equivalent for FD with easily
56 * accessible cached properties not requiring repeated complex lookups.
57 *
50847dca 58 * Connection properties may be changed until the connection is opened.
e83cc785
AJ
59 * Properties should be considered read-only outside of the Comm layer
60 * code once the connection is open.
739b352a 61 *
1c8f25bb
AJ
62 * These objects should not be passed around directly,
63 * but a Comm::ConnectionPointer should be passed instead.
739b352a 64 */
93ad6f77 65class Connection : public RefCountable
cfd66529 66{
fd7b48b9
AJ
67 MEMPROXY_CLASS(Comm::Connection);
68
741c2986 69public:
cfd66529 70 Connection();
739b352a 71
aed188fd 72 /** Clear the connection properties and close any open socket. */
cfd66529
AJ
73 ~Connection();
74
aed188fd
AJ
75 /** Copy an existing connections IP and properties.
76 * This excludes the FD. The new copy will be a closed connection.
739b352a 77 */
5ae21d99 78 ConnectionPointer copyDetails() const;
aed188fd 79
aed188fd 80 /** Close any open socket. */
55cbb02b
AJ
81 void close();
82
b54a7c5a
CT
83 /** Synchronize with Comm: Somebody closed our connection. */
84 void noteClosure();
85
55cbb02b 86 /** determine whether this object describes an active connection or not. */
d6327017 87 bool isOpen() const { return (fd >= 0); }
55cbb02b 88
7fb5be3e
AJ
89 /** Alter the stored IP address pair.
90 * WARNING: Does not ensure matching IPv4/IPv6 are supplied.
91 */
92 void setAddrs(const Ip::Address &aLocal, const Ip::Address &aRemote) {local = aLocal; remote = aRemote;}
93
a3c6762c 94 /** retrieve the CachePeer pointer for use.
5229395c
AJ
95 * The caller is responsible for all CBDATA operations regarding the
96 * used of the pointer returned.
97 */
a3c6762c 98 CachePeer * getPeer() const;
5229395c 99
a3c6762c
FC
100 /** alter the stored CachePeer pointer.
101 * Perform appropriate CBDATA operations for locking the CachePeer pointer
5229395c 102 */
a3c6762c 103 void setPeer(CachePeer * p);
5229395c 104
8aec3e1b
CT
105 /** The time the connection started */
106 time_t startTime() const {return startTime_;}
107
c5c06f02
CT
108 /** The connection lifetime */
109 time_t lifeTime() const {return squid_curtime - startTime_;}
110
111 /** The time left for this connection*/
112 time_t timeLeft(const time_t idleTimeout) const;
113
0ce8e93b
EB
114 /// Connection establishment timeout for callers that have already decided
115 /// to connect(2), either for the first time or after checking
116 /// EnoughTimeToReForward() during any re-forwarding attempts.
117 /// \returns the time left for this connection to become connected
118 /// \param fwdStart The start time of the peer selection/connection process.
119 time_t connectTimeout(const time_t fwdStart) const;
120
8aec3e1b 121 void noteStart() {startTime_ = squid_curtime;}
2bcab852
CT
122
123 Security::NegotiationHistory *tlsNegotiations();
124 const Security::NegotiationHistory *hasTlsNegotiations() const {return tlsHistory;}
125
5229395c
AJ
126private:
127 /** These objects may not be exactly duplicated. Use copyDetails() instead. */
128 Connection(const Connection &c);
129
130 /** These objects may not be exactly duplicated. Use copyDetails() instead. */
131 Connection & operator =(const Connection &c);
132
133public:
cfd66529
AJ
134 /** Address/Port for the Squid end of a TCP link. */
135 Ip::Address local;
62e76326 136
cfd66529
AJ
137 /** Address for the Remote end of a TCP link. */
138 Ip::Address remote;
2d8c0b1a 139
cfd66529 140 /** Hierarchy code for this connection link */
5229395c 141 hier_code peerType;
cfd66529 142
e83cc785 143 /** Socket used by this connection. Negative if not open. */
cfd66529
AJ
144 int fd;
145
739b352a 146 /** Quality of Service TOS values currently sent on this connection */
b5523edc
AJ
147 tos_t tos;
148
149 /** Netfilter MARK values currently sent on this connection */
150 nfmark_t nfmark;
cfd66529
AJ
151
152 /** COMM flags set on this connection */
153 int flags;
739b352a 154
73c36fd9
AJ
155 char rfc931[USER_IDENT_SZ];
156
89aec9b6
AJ
157#if USE_SQUID_EUI
158 Eui::Eui48 remoteEui48;
159 Eui::Eui64 remoteEui64;
160#endif
161
739b352a
AJ
162private:
163 /** cache_peer data object (if any) */
a3c6762c 164 CachePeer *peer_;
8aec3e1b
CT
165
166 /** The time the connection object was created */
167 time_t startTime_;
2bcab852
CT
168
169 /** TLS connection details*/
170 Security::NegotiationHistory *tlsHistory;
ee0989f2 171};
172
cfd66529
AJ
173}; // namespace Comm
174
6043e368 175std::ostream &operator << (std::ostream &os, const Comm::Connection &conn);
5c336a3b
AJ
176
177inline std::ostream &
178operator << (std::ostream &os, const Comm::ConnectionPointer &conn)
179{
180 if (conn != NULL)
181 os << *conn;
182 return os;
183}
184
ee0989f2 185#endif
f53969cc 186