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