]> git.ipfire.org Git - thirdparty/squid.git/blame - src/comm/Connection.h
Boilerplate: update copyright blurbs on Squid helpers
[thirdparty/squid.git] / src / comm / Connection.h
CommitLineData
ee0989f2 1/*
45906573 2 * DEBUG: section 05 Socket Functions
93ad6f77 3 * AUTHOR: Amos Jeffries
ee0989f2 4 * AUTHOR: Robert Collins
5 *
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
8 *
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
26ac0430 22 *
ee0989f2 23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
26ac0430 27 *
ee0989f2 28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 *
32 *
33 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
93ad6f77 34 * Copyright (c) 2010, Amos Jeffries <amosjeffries@squid-cache.org>
ee0989f2 35 */
36
37#ifndef _SQUIDCONNECTIONDETAIL_H_
38#define _SQUIDCONNECTIONDETAIL_H_
39
49ae8b95 40#include "comm/forward.h"
582c2af2 41#include "defines.h"
cfd66529 42#include "hier_code.h"
96d89ea0 43#include "ip/Address.h"
fd7b48b9 44#include "MemPool.h"
25b481e6 45#include "typedefs.h"
89aec9b6
AJ
46#if USE_SQUID_EUI
47#include "eui/Eui48.h"
48#include "eui/Eui64.h"
49#endif
8aec3e1b 50#include "SquidTime.h"
cc192b50 51
5c336a3b 52#include <iosfwd>
5c336a3b 53#include <ostream>
5c336a3b 54
a3c6762c 55class CachePeer;
cfd66529 56
dc49061a
A
57namespace Comm
58{
cfd66529 59
27d1f0a0
AJ
60/* TODO: make these a struct of boolean flags members in the connection instead of a bitmap.
61 * we can't do that until all non-comm code uses Commm::Connection objects to create FD
62 * currently there is code still using comm_open() and comm_openex() synchronously!!
63 */
cfd66529 64#define COMM_UNSET 0x00
40d34a62 65#define COMM_NONBLOCKING 0x01 // default flag.
cfd66529 66#define COMM_NOCLOEXEC 0x02
40d34a62
AJ
67#define COMM_REUSEADDR 0x04 // shared FD may be both accept()ing and read()ing
68#define COMM_DOBIND 0x08 // requires a bind()
69#define COMM_TRANSPARENT 0x10 // arrived via TPROXY
70#define COMM_INTERCEPTION 0x20 // arrived via NAT
62e76326 71
739b352a
AJ
72/**
73 * Store data about the physical and logical attributes of a connection.
74 *
75 * Some link state can be infered from the data, however this is not an
76 * object for state data. But a semantic equivalent for FD with easily
77 * accessible cached properties not requiring repeated complex lookups.
78 *
50847dca 79 * Connection properties may be changed until the connection is opened.
e83cc785
AJ
80 * Properties should be considered read-only outside of the Comm layer
81 * code once the connection is open.
739b352a 82 *
1c8f25bb
AJ
83 * These objects should not be passed around directly,
84 * but a Comm::ConnectionPointer should be passed instead.
739b352a 85 */
93ad6f77 86class Connection : public RefCountable
cfd66529 87{
62e76326 88public:
fd7b48b9
AJ
89 MEMPROXY_CLASS(Comm::Connection);
90
cfd66529 91 Connection();
739b352a 92
aed188fd 93 /** Clear the connection properties and close any open socket. */
cfd66529
AJ
94 ~Connection();
95
aed188fd
AJ
96 /** Copy an existing connections IP and properties.
97 * This excludes the FD. The new copy will be a closed connection.
739b352a 98 */
5ae21d99 99 ConnectionPointer copyDetails() const;
aed188fd 100
aed188fd 101 /** Close any open socket. */
55cbb02b
AJ
102 void close();
103
104 /** determine whether this object describes an active connection or not. */
d6327017 105 bool isOpen() const { return (fd >= 0); }
55cbb02b 106
7fb5be3e
AJ
107 /** Alter the stored IP address pair.
108 * WARNING: Does not ensure matching IPv4/IPv6 are supplied.
109 */
110 void setAddrs(const Ip::Address &aLocal, const Ip::Address &aRemote) {local = aLocal; remote = aRemote;}
111
a3c6762c 112 /** retrieve the CachePeer pointer for use.
5229395c
AJ
113 * The caller is responsible for all CBDATA operations regarding the
114 * used of the pointer returned.
115 */
a3c6762c 116 CachePeer * getPeer() const;
5229395c 117
a3c6762c
FC
118 /** alter the stored CachePeer pointer.
119 * Perform appropriate CBDATA operations for locking the CachePeer pointer
5229395c 120 */
a3c6762c 121 void setPeer(CachePeer * p);
5229395c 122
8aec3e1b
CT
123 /** The time the connection started */
124 time_t startTime() const {return startTime_;}
125
126 void noteStart() {startTime_ = squid_curtime;}
5229395c
AJ
127private:
128 /** These objects may not be exactly duplicated. Use copyDetails() instead. */
129 Connection(const Connection &c);
130
131 /** These objects may not be exactly duplicated. Use copyDetails() instead. */
132 Connection & operator =(const Connection &c);
133
134public:
cfd66529
AJ
135 /** Address/Port for the Squid end of a TCP link. */
136 Ip::Address local;
62e76326 137
cfd66529
AJ
138 /** Address for the Remote end of a TCP link. */
139 Ip::Address remote;
2d8c0b1a 140
cfd66529 141 /** Hierarchy code for this connection link */
5229395c 142 hier_code peerType;
cfd66529 143
e83cc785 144 /** Socket used by this connection. Negative if not open. */
cfd66529
AJ
145 int fd;
146
739b352a 147 /** Quality of Service TOS values currently sent on this connection */
b5523edc
AJ
148 tos_t tos;
149
150 /** Netfilter MARK values currently sent on this connection */
151 nfmark_t nfmark;
cfd66529
AJ
152
153 /** COMM flags set on this connection */
154 int flags;
739b352a 155
73c36fd9
AJ
156 char rfc931[USER_IDENT_SZ];
157
89aec9b6
AJ
158#if USE_SQUID_EUI
159 Eui::Eui48 remoteEui48;
160 Eui::Eui64 remoteEui64;
161#endif
162
739b352a
AJ
163private:
164 /** cache_peer data object (if any) */
a3c6762c 165 CachePeer *peer_;
8aec3e1b
CT
166
167 /** The time the connection object was created */
168 time_t startTime_;
ee0989f2 169};
170
cfd66529
AJ
171}; // namespace Comm
172
51045442 173MEMPROXY_CLASS_INLINE(Comm::Connection);
5c336a3b
AJ
174
175// NP: Order and namespace here is very important.
176// * The second define inlines the first.
177// * Stream inheritance overloading is searched in the global scope first.
178
179inline std::ostream &
180operator << (std::ostream &os, const Comm::Connection &conn)
181{
3b7a48df 182 os << "local=" << conn.local << " remote=" << conn.remote;
9815f129 183 if (conn.fd >= 0)
3b7a48df 184 os << " FD " << conn.fd;
9815f129 185 if (conn.flags != COMM_UNSET)
50847dca 186 os << " flags=" << conn.flags;
73c36fd9 187#if USE_IDENT
50847dca
AJ
188 if (*conn.rfc931)
189 os << " IDENT::" << conn.rfc931;
73c36fd9 190#endif
5c336a3b
AJ
191 return os;
192}
193
194inline std::ostream &
195operator << (std::ostream &os, const Comm::ConnectionPointer &conn)
196{
197 if (conn != NULL)
198 os << *conn;
199 return os;
200}
201
ee0989f2 202#endif