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