]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/Connection.h
2 * Copyright (C) 1996-2014 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"
16 #include "hier_code.h"
17 #include "ip/Address.h"
18 #include "mem/forward.h"
21 #include "eui/Eui48.h"
22 #include "eui/Eui64.h"
24 #include "SquidTime.h"
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!!
38 #define COMM_UNSET 0x00
39 #define COMM_NONBLOCKING 0x01 // default flag.
40 #define COMM_NOCLOEXEC 0x02
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
47 * Store data about the physical and logical attributes of a connection.
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.
53 * Connection properties may be changed until the connection is opened.
54 * Properties should be considered read-only outside of the Comm layer
55 * code once the connection is open.
57 * These objects should not be passed around directly,
58 * but a Comm::ConnectionPointer should be passed instead.
60 class Connection
: public RefCountable
62 MEMPROXY_CLASS(Comm::Connection
);
67 /** Clear the connection properties and close any open socket. */
70 /** Copy an existing connections IP and properties.
71 * This excludes the FD. The new copy will be a closed connection.
73 ConnectionPointer
copyDetails() const;
75 /** Close any open socket. */
78 /** determine whether this object describes an active connection or not. */
79 bool isOpen() const { return (fd
>= 0); }
81 /** Alter the stored IP address pair.
82 * WARNING: Does not ensure matching IPv4/IPv6 are supplied.
84 void setAddrs(const Ip::Address
&aLocal
, const Ip::Address
&aRemote
) {local
= aLocal
; remote
= aRemote
;}
86 /** retrieve the CachePeer pointer for use.
87 * The caller is responsible for all CBDATA operations regarding the
88 * used of the pointer returned.
90 CachePeer
* getPeer() const;
92 /** alter the stored CachePeer pointer.
93 * Perform appropriate CBDATA operations for locking the CachePeer pointer
95 void setPeer(CachePeer
* p
);
97 /** The time the connection started */
98 time_t startTime() const {return startTime_
;}
100 void noteStart() {startTime_
= squid_curtime
;}
102 /** These objects may not be exactly duplicated. Use copyDetails() instead. */
103 Connection(const Connection
&c
);
105 /** These objects may not be exactly duplicated. Use copyDetails() instead. */
106 Connection
& operator =(const Connection
&c
);
109 /** Address/Port for the Squid end of a TCP link. */
112 /** Address for the Remote end of a TCP link. */
115 /** Hierarchy code for this connection link */
118 /** Socket used by this connection. Negative if not open. */
121 /** Quality of Service TOS values currently sent on this connection */
124 /** Netfilter MARK values currently sent on this connection */
127 /** COMM flags set on this connection */
130 char rfc931
[USER_IDENT_SZ
];
133 Eui::Eui48 remoteEui48
;
134 Eui::Eui64 remoteEui64
;
138 /** cache_peer data object (if any) */
141 /** The time the connection object was created */
147 // NP: Order and namespace here is very important.
148 // * The second define inlines the first.
149 // * Stream inheritance overloading is searched in the global scope first.
151 inline std::ostream
&
152 operator << (std::ostream
&os
, const Comm::Connection
&conn
)
154 os
<< "local=" << conn
.local
<< " remote=" << conn
.remote
;
156 os
<< " FD " << conn
.fd
;
157 if (conn
.flags
!= COMM_UNSET
)
158 os
<< " flags=" << conn
.flags
;
161 os
<< " IDENT::" << conn
.rfc931
;
166 inline std::ostream
&
167 operator << (std::ostream
&os
, const Comm::ConnectionPointer
&conn
)