]> git.ipfire.org Git - thirdparty/squid.git/blame - src/comm/Connection.h
Removed squid-old.h
[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"
93ad6f77 45#include "RefCount.h"
25b481e6 46#include "typedefs.h"
89aec9b6
AJ
47#if USE_SQUID_EUI
48#include "eui/Eui48.h"
49#include "eui/Eui64.h"
50#endif
cc192b50 51
5c336a3b
AJ
52#if HAVE_IOSFWD
53#include <iosfwd>
54#endif
55#if HAVE_OSTREAM
56#include <ostream>
57#endif
58
739b352a 59struct peer;
cfd66529 60
dc49061a
A
61namespace Comm
62{
cfd66529 63
27d1f0a0
AJ
64/* TODO: make these a struct of boolean flags members in the connection instead of a bitmap.
65 * we can't do that until all non-comm code uses Commm::Connection objects to create FD
66 * currently there is code still using comm_open() and comm_openex() synchronously!!
67 */
cfd66529 68#define COMM_UNSET 0x00
40d34a62 69#define COMM_NONBLOCKING 0x01 // default flag.
cfd66529 70#define COMM_NOCLOEXEC 0x02
40d34a62
AJ
71#define COMM_REUSEADDR 0x04 // shared FD may be both accept()ing and read()ing
72#define COMM_DOBIND 0x08 // requires a bind()
73#define COMM_TRANSPARENT 0x10 // arrived via TPROXY
74#define COMM_INTERCEPTION 0x20 // arrived via NAT
62e76326 75
739b352a
AJ
76/**
77 * Store data about the physical and logical attributes of a connection.
78 *
79 * Some link state can be infered from the data, however this is not an
80 * object for state data. But a semantic equivalent for FD with easily
81 * accessible cached properties not requiring repeated complex lookups.
82 *
50847dca 83 * Connection properties may be changed until the connection is opened.
e83cc785
AJ
84 * Properties should be considered read-only outside of the Comm layer
85 * code once the connection is open.
739b352a 86 *
1c8f25bb
AJ
87 * These objects should not be passed around directly,
88 * but a Comm::ConnectionPointer should be passed instead.
739b352a 89 */
93ad6f77 90class Connection : public RefCountable
cfd66529 91{
62e76326 92public:
fd7b48b9
AJ
93 MEMPROXY_CLASS(Comm::Connection);
94
cfd66529 95 Connection();
739b352a 96
aed188fd 97 /** Clear the connection properties and close any open socket. */
cfd66529
AJ
98 ~Connection();
99
aed188fd
AJ
100 /** Copy an existing connections IP and properties.
101 * This excludes the FD. The new copy will be a closed connection.
739b352a 102 */
5ae21d99 103 ConnectionPointer copyDetails() const;
aed188fd 104
aed188fd 105 /** Close any open socket. */
55cbb02b
AJ
106 void close();
107
108 /** determine whether this object describes an active connection or not. */
d6327017 109 bool isOpen() const { return (fd >= 0); }
55cbb02b 110
5229395c
AJ
111 /** retrieve the peer pointer for use.
112 * The caller is responsible for all CBDATA operations regarding the
113 * used of the pointer returned.
114 */
743c8e20 115 peer * getPeer() const;
5229395c
AJ
116
117 /** alter the stored peer pointer.
118 * Perform appropriate CBDATA operations for locking the peer pointer
119 */
120 void setPeer(peer * p);
121
122private:
123 /** These objects may not be exactly duplicated. Use copyDetails() instead. */
124 Connection(const Connection &c);
125
126 /** These objects may not be exactly duplicated. Use copyDetails() instead. */
127 Connection & operator =(const Connection &c);
128
129public:
cfd66529
AJ
130 /** Address/Port for the Squid end of a TCP link. */
131 Ip::Address local;
62e76326 132
cfd66529
AJ
133 /** Address for the Remote end of a TCP link. */
134 Ip::Address remote;
2d8c0b1a 135
cfd66529 136 /** Hierarchy code for this connection link */
5229395c 137 hier_code peerType;
cfd66529 138
e83cc785 139 /** Socket used by this connection. Negative if not open. */
cfd66529
AJ
140 int fd;
141
739b352a 142 /** Quality of Service TOS values currently sent on this connection */
b5523edc
AJ
143 tos_t tos;
144
145 /** Netfilter MARK values currently sent on this connection */
146 nfmark_t nfmark;
cfd66529
AJ
147
148 /** COMM flags set on this connection */
149 int flags;
739b352a 150
73c36fd9
AJ
151 char rfc931[USER_IDENT_SZ];
152
89aec9b6
AJ
153#if USE_SQUID_EUI
154 Eui::Eui48 remoteEui48;
155 Eui::Eui64 remoteEui64;
156#endif
157
739b352a 158private:
418b3087
AJ
159 // XXX: we need to call this member peer_ but the struct peer_ global type
160 // behind peer* clashes despite our private Comm:: namespace
161 // (it being global gets inherited here too).
162
739b352a
AJ
163 /** cache_peer data object (if any) */
164 peer *_peer;
ee0989f2 165};
166
cfd66529
AJ
167}; // namespace Comm
168
51045442 169MEMPROXY_CLASS_INLINE(Comm::Connection);
5c336a3b
AJ
170
171// NP: Order and namespace here is very important.
172// * The second define inlines the first.
173// * Stream inheritance overloading is searched in the global scope first.
174
175inline std::ostream &
176operator << (std::ostream &os, const Comm::Connection &conn)
177{
3b7a48df 178 os << "local=" << conn.local << " remote=" << conn.remote;
9815f129 179 if (conn.fd >= 0)
3b7a48df 180 os << " FD " << conn.fd;
9815f129 181 if (conn.flags != COMM_UNSET)
50847dca 182 os << " flags=" << conn.flags;
73c36fd9 183#if USE_IDENT
50847dca
AJ
184 if (*conn.rfc931)
185 os << " IDENT::" << conn.rfc931;
73c36fd9 186#endif
5c336a3b
AJ
187 return os;
188}
189
190inline std::ostream &
191operator << (std::ostream &os, const Comm::ConnectionPointer &conn)
192{
193 if (conn != NULL)
194 os << *conn;
195 return os;
196}
197
ee0989f2 198#endif