]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fde.h
Various audit updates
[thirdparty/squid.git] / src / fde.h
1 /*
2 * SQUID Web Proxy Cache http://www.squid-cache.org/
3 * ----------------------------------------------------------
4 *
5 * Squid is the result of efforts by numerous individuals from
6 * the Internet community; see the CONTRIBUTORS file for full
7 * details. Many organizations have provided support for Squid's
8 * development; see the SPONSORS file for full details. Squid is
9 * Copyrighted (C) 2001 by the Regents of the University of
10 * California; see the COPYRIGHT file for full details. Squid
11 * incorporates software developed and/or copyrighted by other
12 * sources; see the CREDITS file for full details.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 *
28 */
29
30 #ifndef SQUID_FDE_H
31 #define SQUID_FDE_H
32
33 #include "comm.h"
34 #include "defines.h"
35 #include "ip/Address.h"
36
37 #if HAVE_OPENSSL_SSL_H
38 #include <openssl/ssl.h>
39 #endif
40
41 #if USE_DELAY_POOLS
42 class ClientInfo;
43 #endif
44
45 class dwrite_q;
46 class _fde_disk
47 {
48 public:
49 DWCB *wrt_handle;
50 void *wrt_handle_data;
51 dwrite_q *write_q;
52 dwrite_q *write_q_tail;
53 off_t offset;
54 _fde_disk() { memset(this, 0, sizeof(_fde_disk)); }
55 };
56
57 class fde
58 {
59
60 public:
61 fde() { clear(); };
62
63 /// True if comm_close for this fd has been called
64 bool closing() { return flags.close_request; }
65
66 /* NOTE: memset is used on fdes today. 20030715 RBC */
67 static void DumpStats (StoreEntry *);
68
69 char const *remoteAddr() const;
70 void dumpStats (StoreEntry &, int);
71 bool readPending(int);
72 void noteUse();
73
74 public:
75
76 /// global table of FD and their state.
77 static fde* Table;
78
79 unsigned int type;
80 unsigned short remote_port;
81
82 Ip::Address local_addr;
83 tos_t tosToServer; /**< The TOS value for packets going towards the server.
84 See also tosFromServer. */
85 nfmark_t nfmarkToServer; /**< The netfilter mark for packets going towards the server.
86 See also nfmarkFromServer. */
87 int sock_family;
88 char ipaddr[MAX_IPSTRLEN]; /* dotted decimal address of peer */
89 char desc[FD_DESC_SZ];
90
91 struct _fde_flags {
92 bool open;
93 bool close_request; ///< true if file_ or comm_close has been called
94 bool write_daemon;
95 bool socket_eof;
96 bool nolinger;
97 bool nonblocking;
98 bool ipc;
99 bool called_connect;
100 bool nodelay;
101 bool close_on_exec;
102 bool read_pending;
103 //bool write_pending; //XXX seems not to be used
104 bool transparent;
105 } flags;
106
107 int64_t bytes_read;
108 int64_t bytes_written;
109
110 struct {
111 int uses; /* ie # req's over persistent conn */
112 } pconn;
113
114 #if USE_DELAY_POOLS
115 ClientInfo * clientInfo;/* pointer to client info used in client write limiter or NULL if not present */
116 #endif
117 unsigned epoll_state;
118
119 _fde_disk disk;
120 PF *read_handler;
121 void *read_data;
122 PF *write_handler;
123 void *write_data;
124 AsyncCall::Pointer timeoutHandler;
125 time_t timeout;
126 time_t writeStart;
127 void *lifetime_data;
128 AsyncCall::Pointer closeHandler;
129 AsyncCall::Pointer halfClosedReader; /// read handler for half-closed fds
130 CommWriteStateData *wstate; /* State data for comm_write */
131 READ_HANDLER *read_method;
132 WRITE_HANDLER *write_method;
133 #if USE_OPENSSL
134 SSL *ssl;
135 SSL_CTX *dynamicSslContext; ///< cached and then freed when fd is closed
136 #endif
137 #if _SQUID_WINDOWS_
138 struct {
139 long handle;
140 } win32;
141 #endif
142 tos_t tosFromServer; /**< Stores the TOS flags of the packets from the remote server.
143 See FwdState::dispatch(). Note that this differs to
144 tosToServer in that this is the value we *receive* from the,
145 connection, whereas tosToServer is the value to set on packets
146 *leaving* Squid. */
147 unsigned int nfmarkFromServer; /**< Stores the Netfilter mark value of the connection from the remote
148 server. See FwdState::dispatch(). Note that this differs to
149 nfmarkToServer in that this is the value we *receive* from the,
150 connection, whereas nfmarkToServer is the value to set on packets
151 *leaving* Squid. */
152
153 private:
154 /** Clear the fde class back to NULL equivalent. */
155 inline void clear() {
156 type = 0;
157 remote_port = 0;
158 local_addr.setEmpty();
159 tosToServer = '\0';
160 nfmarkToServer = 0;
161 sock_family = 0;
162 memset(ipaddr, '\0', MAX_IPSTRLEN);
163 memset(desc,'\0',FD_DESC_SZ);
164 memset(&flags,0,sizeof(_fde_flags));
165 bytes_read = 0;
166 bytes_written = 0;
167 pconn.uses = 0;
168 #if USE_DELAY_POOLS
169 clientInfo = NULL;
170 #endif
171 epoll_state = 0;
172 read_handler = NULL;
173 read_data = NULL;
174 write_handler = NULL;
175 write_data = NULL;
176 timeoutHandler = NULL;
177 timeout = 0;
178 writeStart = 0;
179 lifetime_data = NULL;
180 closeHandler = NULL;
181 halfClosedReader = NULL;
182 wstate = NULL;
183 read_method = NULL;
184 write_method = NULL;
185 #if USE_OPENSSL
186 ssl = NULL;
187 dynamicSslContext = NULL;
188 #endif
189 #if _SQUID_WINDOWS_
190 win32.handle = NULL;
191 #endif
192 tosFromServer = '\0';
193 nfmarkFromServer = 0;
194 }
195 };
196
197 #define fd_table fde::Table
198
199 int fdNFree(void);
200
201 #define FD_READ_METHOD(fd, buf, len) (*fd_table[fd].read_method)(fd, buf, len)
202 #define FD_WRITE_METHOD(fd, buf, len) (*fd_table[fd].write_method)(fd, buf, len)
203
204 #endif /* SQUID_FDE_H */