]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/Connection.h
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 05 Socket Functions */
11 #ifndef _SQUIDCONNECTIONDETAIL_H_
12 #define _SQUIDCONNECTIONDETAIL_H_
14 #include "comm/forward.h"
17 #include "eui/Eui48.h"
18 #include "eui/Eui64.h"
20 #include "hier_code.h"
21 #include "ip/Address.h"
22 #include "ip/forward.h"
23 #include "mem/forward.h"
24 #include "SquidTime.h"
33 class NegotiationHistory
;
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!!
43 #define COMM_UNSET 0x00
44 #define COMM_NONBLOCKING 0x01 // default flag.
45 #define COMM_NOCLOEXEC 0x02
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
52 * Store data about the physical and logical attributes of a connection.
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.
58 * Connection properties may be changed until the connection is opened.
59 * Properties should be considered read-only outside of the Comm layer
60 * code once the connection is open.
62 * These objects should not be passed around directly,
63 * but a Comm::ConnectionPointer should be passed instead.
65 class Connection
: public RefCountable
67 MEMPROXY_CLASS(Comm::Connection
);
72 /** Clear the connection properties and close any open socket. */
75 /** Copy an existing connections IP and properties.
76 * This excludes the FD. The new copy will be a closed connection.
78 ConnectionPointer
copyDetails() const;
80 /** Close any open socket. */
83 /** Synchronize with Comm: Somebody closed our connection. */
86 /** determine whether this object describes an active connection or not. */
87 bool isOpen() const { return (fd
>= 0); }
89 /** Alter the stored IP address pair.
90 * WARNING: Does not ensure matching IPv4/IPv6 are supplied.
92 void setAddrs(const Ip::Address
&aLocal
, const Ip::Address
&aRemote
) {local
= aLocal
; remote
= aRemote
;}
94 /** retrieve the CachePeer pointer for use.
95 * The caller is responsible for all CBDATA operations regarding the
96 * used of the pointer returned.
98 CachePeer
* getPeer() const;
100 /** alter the stored CachePeer pointer.
101 * Perform appropriate CBDATA operations for locking the CachePeer pointer
103 void setPeer(CachePeer
* p
);
105 /** The time the connection started */
106 time_t startTime() const {return startTime_
;}
108 /** The connection lifetime */
109 time_t lifeTime() const {return squid_curtime
- startTime_
;}
111 /** The time left for this connection*/
112 time_t timeLeft(const time_t idleTimeout
) const;
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;
121 void noteStart() {startTime_
= squid_curtime
;}
123 Security::NegotiationHistory
*tlsNegotiations();
124 const Security::NegotiationHistory
*hasTlsNegotiations() const {return tlsHistory
;}
127 /** These objects may not be exactly duplicated. Use copyDetails() instead. */
128 Connection(const Connection
&c
);
130 /** These objects may not be exactly duplicated. Use copyDetails() instead. */
131 Connection
& operator =(const Connection
&c
);
134 /** Address/Port for the Squid end of a TCP link. */
137 /** Address for the Remote end of a TCP link. */
140 /** Hierarchy code for this connection link */
143 /** Socket used by this connection. Negative if not open. */
146 /** Quality of Service TOS values currently sent on this connection */
149 /** Netfilter MARK values currently sent on this connection */
152 /** COMM flags set on this connection */
155 char rfc931
[USER_IDENT_SZ
];
158 Eui::Eui48 remoteEui48
;
159 Eui::Eui64 remoteEui64
;
163 /** cache_peer data object (if any) */
166 /** The time the connection object was created */
169 /** TLS connection details*/
170 Security::NegotiationHistory
*tlsHistory
;
175 std::ostream
&operator << (std::ostream
&os
, const Comm::Connection
&conn
);
177 inline std::ostream
&
178 operator << (std::ostream
&os
, const Comm::ConnectionPointer
&conn
)