]> git.ipfire.org Git - thirdparty/squid.git/blame - src/comm/Connection.h
Windows: fix getaddrinfo, getnameinfo, inet_ntop and inet_pton detection
[thirdparty/squid.git] / src / comm / Connection.h
CommitLineData
ee0989f2 1/*
bbc27441 2 * Copyright (C) 1996-2014 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"
cfd66529 16#include "hier_code.h"
96d89ea0 17#include "ip/Address.h"
ed6e9fb9 18#include "mem/forward.h"
25b481e6 19#include "typedefs.h"
89aec9b6
AJ
20#if USE_SQUID_EUI
21#include "eui/Eui48.h"
22#include "eui/Eui64.h"
23#endif
8aec3e1b 24#include "SquidTime.h"
cc192b50 25
5c336a3b 26#include <iosfwd>
5c336a3b 27#include <ostream>
5c336a3b 28
a3c6762c 29class CachePeer;
cfd66529 30
dc49061a
A
31namespace 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 60class Connection : public RefCountable
cfd66529 61{
fd7b48b9
AJ
62 MEMPROXY_CLASS(Comm::Connection);
63
741c2986 64public:
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
78 /** determine whether this object describes an active connection or not. */
d6327017 79 bool isOpen() const { return (fd >= 0); }
55cbb02b 80
7fb5be3e
AJ
81 /** Alter the stored IP address pair.
82 * WARNING: Does not ensure matching IPv4/IPv6 are supplied.
83 */
84 void setAddrs(const Ip::Address &aLocal, const Ip::Address &aRemote) {local = aLocal; remote = aRemote;}
85
a3c6762c 86 /** retrieve the CachePeer pointer for use.
5229395c
AJ
87 * The caller is responsible for all CBDATA operations regarding the
88 * used of the pointer returned.
89 */
a3c6762c 90 CachePeer * getPeer() const;
5229395c 91
a3c6762c
FC
92 /** alter the stored CachePeer pointer.
93 * Perform appropriate CBDATA operations for locking the CachePeer pointer
5229395c 94 */
a3c6762c 95 void setPeer(CachePeer * p);
5229395c 96
8aec3e1b
CT
97 /** The time the connection started */
98 time_t startTime() const {return startTime_;}
99
100 void noteStart() {startTime_ = squid_curtime;}
5229395c
AJ
101private:
102 /** These objects may not be exactly duplicated. Use copyDetails() instead. */
103 Connection(const Connection &c);
104
105 /** These objects may not be exactly duplicated. Use copyDetails() instead. */
106 Connection & operator =(const Connection &c);
107
108public:
cfd66529
AJ
109 /** Address/Port for the Squid end of a TCP link. */
110 Ip::Address local;
62e76326 111
cfd66529
AJ
112 /** Address for the Remote end of a TCP link. */
113 Ip::Address remote;
2d8c0b1a 114
cfd66529 115 /** Hierarchy code for this connection link */
5229395c 116 hier_code peerType;
cfd66529 117
e83cc785 118 /** Socket used by this connection. Negative if not open. */
cfd66529
AJ
119 int fd;
120
739b352a 121 /** Quality of Service TOS values currently sent on this connection */
b5523edc
AJ
122 tos_t tos;
123
124 /** Netfilter MARK values currently sent on this connection */
125 nfmark_t nfmark;
cfd66529
AJ
126
127 /** COMM flags set on this connection */
128 int flags;
739b352a 129
73c36fd9
AJ
130 char rfc931[USER_IDENT_SZ];
131
89aec9b6
AJ
132#if USE_SQUID_EUI
133 Eui::Eui48 remoteEui48;
134 Eui::Eui64 remoteEui64;
135#endif
136
739b352a
AJ
137private:
138 /** cache_peer data object (if any) */
a3c6762c 139 CachePeer *peer_;
8aec3e1b
CT
140
141 /** The time the connection object was created */
142 time_t startTime_;
ee0989f2 143};
144
cfd66529
AJ
145}; // namespace Comm
146
5c336a3b
AJ
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.
150
151inline std::ostream &
152operator << (std::ostream &os, const Comm::Connection &conn)
153{
3b7a48df 154 os << "local=" << conn.local << " remote=" << conn.remote;
9815f129 155 if (conn.fd >= 0)
3b7a48df 156 os << " FD " << conn.fd;
9815f129 157 if (conn.flags != COMM_UNSET)
50847dca 158 os << " flags=" << conn.flags;
73c36fd9 159#if USE_IDENT
50847dca
AJ
160 if (*conn.rfc931)
161 os << " IDENT::" << conn.rfc931;
73c36fd9 162#endif
5c336a3b
AJ
163 return os;
164}
165
166inline std::ostream &
167operator << (std::ostream &os, const Comm::ConnectionPointer &conn)
168{
169 if (conn != NULL)
170 os << *conn;
171 return os;
172}
173
ee0989f2 174#endif
f53969cc 175