2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 26 Secure Sockets Layer Proxy */
12 #include "acl/FilledChecklist.h"
13 #include "base/CbcPointer.h"
14 #include "CachePeer.h"
16 #include "client_side.h"
17 #include "client_side_request.h"
19 #include "comm/Connection.h"
20 #include "comm/ConnOpener.h"
21 #include "comm/Read.h"
22 #include "comm/Write.h"
23 #include "errorpage.h"
28 #include "http/Stream.h"
29 #include "HttpRequest.h"
30 #include "HttpStateFlags.h"
31 #include "ip/QosConfig.h"
34 #include "PeerSelectState.h"
36 #include "SquidConfig.h"
37 #include "SquidTime.h"
38 #include "ssl/BlindPeerConnector.h"
39 #include "StatCounters.h"
42 #include "ssl/ServerBump.h"
53 * TunnelStateData is the state engine performing the tasks for
54 * setup of a TCP tunnel from an existing open client FD to a server
55 * then shuffling binary data between the resulting FD pair.
58 * TODO 1: implement a read/write API on ConnStateData to send/receive blocks
59 * of pre-formatted data. Then we can use that as the client side of the tunnel
60 * instead of re-implementing it here and occasionally getting the ConnStateData
61 * read/write state wrong.
63 * TODO 2: then convert this into a AsyncJob, possibly a child of 'Server'
67 CBDATA_CLASS(TunnelStateData
);
72 TunnelStateData(const TunnelStateData
&); // do not implement
73 TunnelStateData
&operator =(const TunnelStateData
&); // do not implement
76 static void ReadClient(const Comm::ConnectionPointer
&, char *buf
, size_t len
, Comm::Flag errcode
, int xerrno
, void *data
);
77 static void ReadServer(const Comm::ConnectionPointer
&, char *buf
, size_t len
, Comm::Flag errcode
, int xerrno
, void *data
);
78 static void WriteClientDone(const Comm::ConnectionPointer
&, char *buf
, size_t len
, Comm::Flag flag
, int xerrno
, void *data
);
79 static void WriteServerDone(const Comm::ConnectionPointer
&, char *buf
, size_t len
, Comm::Flag flag
, int xerrno
, void *data
);
81 /// Starts reading peer response to our CONNECT request.
82 void readConnectResponse();
84 /// Called when we may be done handling a CONNECT exchange with the peer.
85 void connectExchangeCheckpoint();
87 bool noConnections() const;
89 CbcPointer
<ClientHttpRequest
> http
;
90 HttpRequest::Pointer request
;
91 AccessLogEntryPointer al
;
92 Comm::ConnectionList serverDestinations
;
94 const char * getHost() const {
95 return (server
.conn
!= NULL
&& server
.conn
->getPeer() ? server
.conn
->getPeer()->host
: request
->url
.host());
98 /// Whether we are writing a CONNECT request to a peer.
99 bool waitingForConnectRequest() const { return connectReqWriting
; }
100 /// Whether we are reading a CONNECT response from a peer.
101 bool waitingForConnectResponse() const { return connectRespBuf
; }
102 /// Whether we are waiting for the CONNECT request/response exchange with the peer.
103 bool waitingForConnectExchange() const { return waitingForConnectRequest() || waitingForConnectResponse(); }
105 /// Whether the client sent a CONNECT request to us.
106 bool clientExpectsConnectResponse() const {
108 // We are bumping and we had already send "OK CONNECTED"
109 if (http
.valid() && http
->getConn() && http
->getConn()->serverBump() && http
->getConn()->serverBump()->step
> Ssl::bumpStep1
)
112 return !(request
!= NULL
&&
113 (request
->flags
.interceptTproxy
|| request
->flags
.intercepted
));
116 /// Sends "502 Bad Gateway" error response to the client,
117 /// if it is waiting for Squid CONNECT response, closing connections.
118 void informUserOfPeerError(const char *errMsg
, size_t);
124 Connection() : len (0), buf ((char *)xmalloc(SQUID_TCP_SO_RCVBUF
)), size_ptr(NULL
), delayedLoops(0),
125 readPending(NULL
), readPendingFunc(NULL
) {}
129 int bytesWanted(int lower
=0, int upper
= INT_MAX
) const;
130 void bytesIn(int const &);
133 void setDelayId(DelayId
const &);
136 void error(int const xerrno
);
137 int debugLevelForError(int const xerrno
) const;
139 void dataSent (size_t amount
);
140 /// writes 'b' buffer, setting the 'writer' member to 'callback'.
141 void write(const char *b
, int size
, AsyncCall::Pointer
&callback
, FREE
* free_func
);
144 AsyncCall::Pointer writer
; ///< pending Comm::Write callback
145 uint64_t *size_ptr
; /* pointer to size in an ConnStateData for logging */
147 Comm::ConnectionPointer conn
; ///< The currently connected connection.
148 uint8_t delayedLoops
; ///< how many times a read on this connection has been postponed.
150 // XXX: make these an AsyncCall when event API can handle them
151 TunnelStateData
*readPending
;
152 EVH
*readPendingFunc
;
161 Connection client
, server
;
162 int *status_ptr
; ///< pointer for logging HTTP status
163 LogTags
*logTag_ptr
; ///< pointer for logging Squid processing code
164 MemBuf
*connectRespBuf
; ///< accumulates peer CONNECT response when we need it
165 bool connectReqWriting
; ///< whether we are writing a CONNECT request to a peer
166 SBuf preReadClientData
;
167 time_t started
; ///< when this tunnel was initiated.
169 void copyRead(Connection
&from
, IOCB
*completion
);
171 /// continue to set up connection to a peer, going async for SSL peers
172 void connectToPeer();
176 /// Gives PeerConnector access to Answer in the TunnelStateData callback dialer.
177 class MyAnswerDialer
: public CallDialer
, public Ssl::PeerConnector::CbDialer
180 typedef void (TunnelStateData::*Method
)(Security::EncryptorAnswer
&);
182 MyAnswerDialer(Method method
, TunnelStateData
*tunnel
):
183 method_(method
), tunnel_(tunnel
), answer_() {}
186 virtual bool canDial(AsyncCall
&call
) { return tunnel_
.valid(); }
187 void dial(AsyncCall
&call
) { ((&(*tunnel_
))->*method_
)(answer_
); }
188 virtual void print(std::ostream
&os
) const {
189 os
<< '(' << tunnel_
.get() << ", " << answer_
<< ')';
192 /* Ssl::PeerConnector::CbDialer API */
193 virtual Security::EncryptorAnswer
&answer() { return answer_
; }
197 CbcPointer
<TunnelStateData
> tunnel_
;
198 Security::EncryptorAnswer answer_
;
202 /// callback handler after connection setup (including any encryption)
203 void connectedToPeer(Security::EncryptorAnswer
&answer
);
206 bool keepGoingAfterRead(size_t len
, Comm::Flag errcode
, int xerrno
, Connection
&from
, Connection
&to
);
207 void copy(size_t len
, Connection
&from
, Connection
&to
, IOCB
*);
208 void handleConnectResponse(const size_t chunkSize
);
209 void readServer(char *buf
, size_t len
, Comm::Flag errcode
, int xerrno
);
210 void readClient(char *buf
, size_t len
, Comm::Flag errcode
, int xerrno
);
211 void writeClientDone(char *buf
, size_t len
, Comm::Flag flag
, int xerrno
);
212 void writeServerDone(char *buf
, size_t len
, Comm::Flag flag
, int xerrno
);
214 static void ReadConnectResponseDone(const Comm::ConnectionPointer
&, char *buf
, size_t len
, Comm::Flag errcode
, int xerrno
, void *data
);
215 void readConnectResponseDone(char *buf
, size_t len
, Comm::Flag errcode
, int xerrno
);
216 void copyClientBytes();
219 static const char *const conn_established
= "HTTP/1.1 200 Connection established\r\n\r\n";
221 static CNCB tunnelConnectDone
;
222 static ERCB tunnelErrorComplete
;
223 static CLCB tunnelServerClosed
;
224 static CLCB tunnelClientClosed
;
225 static CTCB tunnelTimeout
;
226 static PSC tunnelPeerSelectComplete
;
227 static EVH tunnelDelayedClientRead
;
228 static EVH tunnelDelayedServerRead
;
229 static void tunnelConnected(const Comm::ConnectionPointer
&server
, void *);
230 static void tunnelRelayConnectRequest(const Comm::ConnectionPointer
&server
, void *);
233 tunnelServerClosed(const CommCloseCbParams
¶ms
)
235 TunnelStateData
*tunnelState
= (TunnelStateData
*)params
.data
;
236 debugs(26, 3, HERE
<< tunnelState
->server
.conn
);
237 tunnelState
->server
.conn
= NULL
;
238 tunnelState
->server
.writer
= NULL
;
240 if (tunnelState
->request
!= NULL
)
241 tunnelState
->request
->hier
.stopPeerClock(false);
243 if (tunnelState
->noConnections()) {
244 // ConnStateData pipeline should contain the CONNECT we are performing
245 // but it may be invalid already (bug 4392)
246 if (tunnelState
->http
.valid() && tunnelState
->http
->getConn()) {
247 auto ctx
= tunnelState
->http
->getConn()->pipeline
.front();
255 if (!tunnelState
->client
.writer
) {
256 tunnelState
->client
.conn
->close();
262 tunnelClientClosed(const CommCloseCbParams
¶ms
)
264 TunnelStateData
*tunnelState
= (TunnelStateData
*)params
.data
;
265 debugs(26, 3, HERE
<< tunnelState
->client
.conn
);
266 tunnelState
->client
.conn
= NULL
;
267 tunnelState
->client
.writer
= NULL
;
269 if (tunnelState
->noConnections()) {
270 // ConnStateData pipeline should contain the CONNECT we are performing
271 // but it may be invalid already (bug 4392)
272 if (tunnelState
->http
.valid() && tunnelState
->http
->getConn()) {
273 auto ctx
= tunnelState
->http
->getConn()->pipeline
.front();
281 if (!tunnelState
->server
.writer
) {
282 tunnelState
->server
.conn
->close();
287 TunnelStateData::TunnelStateData() :
293 connectRespBuf(NULL
),
294 connectReqWriting(false),
295 started(squid_curtime
)
297 debugs(26, 3, "TunnelStateData constructed this=" << this);
298 client
.readPendingFunc
= &tunnelDelayedClientRead
;
299 server
.readPendingFunc
= &tunnelDelayedServerRead
;
302 TunnelStateData::~TunnelStateData()
304 debugs(26, 3, "TunnelStateData destructed this=" << this);
305 assert(noConnections());
307 serverDestinations
.clear();
308 delete connectRespBuf
;
311 TunnelStateData::Connection::~Connection()
314 eventDelete(readPendingFunc
, readPending
);
320 TunnelStateData::Connection::bytesWanted(int lowerbound
, int upperbound
) const
323 return delayId
.bytesWanted(lowerbound
, upperbound
);
331 TunnelStateData::Connection::bytesIn(int const &count
)
333 debugs(26, 3, HERE
<< "len=" << len
<< " + count=" << count
);
335 delayId
.bytesIn(count
);
342 TunnelStateData::Connection::debugLevelForError(int const xerrno
) const
346 if (xerrno
== ECONNRESET
)
351 if (ignoreErrno(xerrno
))
357 /* Read from server side and queue it for writing to the client */
359 TunnelStateData::ReadServer(const Comm::ConnectionPointer
&c
, char *buf
, size_t len
, Comm::Flag errcode
, int xerrno
, void *data
)
361 TunnelStateData
*tunnelState
= (TunnelStateData
*)data
;
362 assert(cbdataReferenceValid(tunnelState
));
363 debugs(26, 3, HERE
<< c
);
365 tunnelState
->readServer(buf
, len
, errcode
, xerrno
);
369 TunnelStateData::readServer(char *, size_t len
, Comm::Flag errcode
, int xerrno
)
371 debugs(26, 3, HERE
<< server
.conn
<< ", read " << len
<< " bytes, err=" << errcode
);
372 server
.delayedLoops
=0;
375 * Bail out early on Comm::ERR_CLOSING
376 * - close handlers will tidy up for us
379 if (errcode
== Comm::ERR_CLOSING
)
384 statCounter
.server
.all
.kbytes_in
+= len
;
385 statCounter
.server
.other
.kbytes_in
+= len
;
388 if (keepGoingAfterRead(len
, errcode
, xerrno
, server
, client
))
389 copy(len
, server
, client
, WriteClientDone
);
392 /// Called when we read [a part of] CONNECT response from the peer
394 TunnelStateData::readConnectResponseDone(char *, size_t len
, Comm::Flag errcode
, int xerrno
)
396 debugs(26, 3, server
.conn
<< ", read " << len
<< " bytes, err=" << errcode
);
397 assert(waitingForConnectResponse());
399 if (errcode
== Comm::ERR_CLOSING
)
403 connectRespBuf
->appended(len
);
405 statCounter
.server
.all
.kbytes_in
+= len
;
406 statCounter
.server
.other
.kbytes_in
+= len
;
409 if (keepGoingAfterRead(len
, errcode
, xerrno
, server
, client
))
410 handleConnectResponse(len
);
414 TunnelStateData::informUserOfPeerError(const char *errMsg
, const size_t sz
)
419 *logTag_ptr
= LOG_TCP_TUNNEL
;
421 if (!clientExpectsConnectResponse()) {
422 // closing the connection is the best we can do here
423 debugs(50, 3, server
.conn
<< " closing on error: " << errMsg
);
424 server
.conn
->close();
428 // if we have no reply suitable to relay, use 502 Bad Gateway
429 if (!sz
|| sz
> static_cast<size_t>(connectRespBuf
->contentSize())) {
430 ErrorState
*err
= new ErrorState(ERR_CONNECT_FAIL
, Http::scBadGateway
, request
.getRaw());
431 *status_ptr
= Http::scBadGateway
;
432 err
->callback
= tunnelErrorComplete
;
433 err
->callback_data
= this;
434 errorSend(http
->getConn()->clientConnection
, err
);
438 // if we need to send back the server response. write its headers to the client
440 memcpy(server
.buf
, connectRespBuf
->content(), server
.len
);
441 copy(server
.len
, server
, client
, TunnelStateData::WriteClientDone
);
442 // then close the server FD to prevent any relayed keep-alive causing CVE-2015-5400
443 server
.closeIfOpen();
446 /* Read from client side and queue it for writing to the server */
448 TunnelStateData::ReadConnectResponseDone(const Comm::ConnectionPointer
&, char *buf
, size_t len
, Comm::Flag errcode
, int xerrno
, void *data
)
450 TunnelStateData
*tunnelState
= (TunnelStateData
*)data
;
451 assert (cbdataReferenceValid (tunnelState
));
453 tunnelState
->readConnectResponseDone(buf
, len
, errcode
, xerrno
);
456 /// Parses [possibly incomplete] CONNECT response and reacts to it.
457 /// If the tunnel is being closed or more response data is needed, returns false.
458 /// Otherwise, the caller should handle the remaining read data, if any.
460 TunnelStateData::handleConnectResponse(const size_t chunkSize
)
462 assert(waitingForConnectResponse());
464 // Ideally, client and server should use MemBuf or better, but current code
465 // never accumulates more than one read when shoveling data (XXX) so it does
466 // not need to deal with MemBuf complexity. To keep it simple, we use a
467 // dedicated MemBuf for accumulating CONNECT responses. TODO: When shoveling
468 // is optimized, reuse server.buf for CONNEC response accumulation instead.
470 /* mimic the basic parts of HttpStateData::processReplyHeader() */
472 Http::StatusCode parseErr
= Http::scNone
;
473 const bool eof
= !chunkSize
;
474 connectRespBuf
->terminate(); // HttpMsg::parse requires terminated string
475 const bool parsed
= rep
.parse(connectRespBuf
->content(), connectRespBuf
->contentSize(), eof
, &parseErr
);
477 if (parseErr
> 0) { // unrecoverable parsing error
478 informUserOfPeerError("malformed CONNECT response from peer", 0);
486 if (!connectRespBuf
->hasSpace()) {
487 informUserOfPeerError("huge CONNECT response from peer", 0);
492 readConnectResponse();
496 // CONNECT response was successfully parsed
497 *status_ptr
= rep
.sline
.status();
499 // we need to relay the 401/407 responses when login=PASS(THRU)
500 const char *pwd
= server
.conn
->getPeer()->login
;
501 const bool relay
= pwd
&& (strcmp(pwd
, "PASS") != 0 || strcmp(pwd
, "PASSTHRU") != 0) &&
502 (*status_ptr
== Http::scProxyAuthenticationRequired
||
503 *status_ptr
== Http::scUnauthorized
);
505 // bail if we did not get an HTTP 200 (Connection Established) response
506 if (rep
.sline
.status() != Http::scOkay
) {
507 // if we ever decide to reuse the peer connection, we must extract the error response first
508 informUserOfPeerError("unsupported CONNECT response status code", (relay
? rep
.hdr_sz
: 0));
512 if (rep
.hdr_sz
< connectRespBuf
->contentSize()) {
513 // preserve bytes that the server already sent after the CONNECT response
514 server
.len
= connectRespBuf
->contentSize() - rep
.hdr_sz
;
515 memcpy(server
.buf
, connectRespBuf
->content()+rep
.hdr_sz
, server
.len
);
517 // reset; delay pools were using this field to throttle CONNECT response
521 delete connectRespBuf
;
522 connectRespBuf
= NULL
;
523 connectExchangeCheckpoint();
527 TunnelStateData::Connection::error(int const xerrno
)
529 /* XXX fixme xstrerror and xerrno... */
532 debugs(50, debugLevelForError(xerrno
), HERE
<< conn
<< ": read/write failure: " << xstrerror());
534 if (!ignoreErrno(xerrno
))
538 /* Read from client side and queue it for writing to the server */
540 TunnelStateData::ReadClient(const Comm::ConnectionPointer
&, char *buf
, size_t len
, Comm::Flag errcode
, int xerrno
, void *data
)
542 TunnelStateData
*tunnelState
= (TunnelStateData
*)data
;
543 assert (cbdataReferenceValid (tunnelState
));
545 tunnelState
->readClient(buf
, len
, errcode
, xerrno
);
549 TunnelStateData::readClient(char *, size_t len
, Comm::Flag errcode
, int xerrno
)
551 debugs(26, 3, HERE
<< client
.conn
<< ", read " << len
<< " bytes, err=" << errcode
);
552 client
.delayedLoops
=0;
555 * Bail out early on Comm::ERR_CLOSING
556 * - close handlers will tidy up for us
559 if (errcode
== Comm::ERR_CLOSING
)
564 statCounter
.client_http
.kbytes_in
+= len
;
567 if (keepGoingAfterRead(len
, errcode
, xerrno
, client
, server
))
568 copy(len
, client
, server
, WriteServerDone
);
571 /// Updates state after reading from client or server.
572 /// Returns whether the caller should use the data just read.
574 TunnelStateData::keepGoingAfterRead(size_t len
, Comm::Flag errcode
, int xerrno
, Connection
&from
, Connection
&to
)
576 debugs(26, 3, HERE
<< "from={" << from
.conn
<< "}, to={" << to
.conn
<< "}");
578 /* I think this is to prevent free-while-in-a-callback behaviour
580 * from.conn->close() / to.conn->close() done here trigger close callbacks which may free TunnelStateData
582 const CbcPointer
<TunnelStateData
> safetyLock(this);
584 /* Bump the source connection read timeout on any activity */
585 if (Comm::IsConnOpen(from
.conn
)) {
586 AsyncCall::Pointer timeoutCall
= commCbCall(5, 4, "tunnelTimeout",
587 CommTimeoutCbPtrFun(tunnelTimeout
, this));
588 commSetConnTimeout(from
.conn
, Config
.Timeout
.read
, timeoutCall
);
591 /* Bump the dest connection read timeout on any activity */
592 /* see Bug 3659: tunnels can be weird, with very long one-way transfers */
593 if (Comm::IsConnOpen(to
.conn
)) {
594 AsyncCall::Pointer timeoutCall
= commCbCall(5, 4, "tunnelTimeout",
595 CommTimeoutCbPtrFun(tunnelTimeout
, this));
596 commSetConnTimeout(to
.conn
, Config
.Timeout
.read
, timeoutCall
);
601 else if (len
== 0 || !Comm::IsConnOpen(to
.conn
)) {
602 debugs(26, 3, HERE
<< "Nothing to write or client gone. Terminate the tunnel.");
605 /* Only close the remote end if we've finished queueing data to it */
606 if (from
.len
== 0 && Comm::IsConnOpen(to
.conn
) ) {
609 } else if (cbdataReferenceValid(this)) {
617 TunnelStateData::copy(size_t len
, Connection
&from
, Connection
&to
, IOCB
*completion
)
619 debugs(26, 3, HERE
<< "Schedule Write");
620 AsyncCall::Pointer call
= commCbCall(5,5, "TunnelBlindCopyWriteHandler",
621 CommIoCbPtrFun(completion
, this));
622 to
.write(from
.buf
, len
, call
, NULL
);
625 /* Writes data from the client buffer to the server side */
627 TunnelStateData::WriteServerDone(const Comm::ConnectionPointer
&, char *buf
, size_t len
, Comm::Flag flag
, int xerrno
, void *data
)
629 TunnelStateData
*tunnelState
= (TunnelStateData
*)data
;
630 assert (cbdataReferenceValid (tunnelState
));
631 tunnelState
->server
.writer
= NULL
;
633 tunnelState
->writeServerDone(buf
, len
, flag
, xerrno
);
637 TunnelStateData::writeServerDone(char *, size_t len
, Comm::Flag flag
, int xerrno
)
639 debugs(26, 3, HERE
<< server
.conn
<< ", " << len
<< " bytes written, flag=" << flag
);
642 if (flag
!= Comm::OK
) {
643 if (flag
!= Comm::ERR_CLOSING
) {
644 debugs(26, 4, HERE
<< "calling TunnelStateData::server.error(" << xerrno
<<")");
645 server
.error(xerrno
); // may call comm_close
652 debugs(26, 4, HERE
<< "No read input. Closing server connection.");
653 server
.conn
->close();
658 statCounter
.server
.all
.kbytes_out
+= len
;
659 statCounter
.server
.other
.kbytes_out
+= len
;
660 client
.dataSent(len
);
662 /* If the other end has closed, so should we */
663 if (!Comm::IsConnOpen(client
.conn
)) {
664 debugs(26, 4, HERE
<< "Client gone away. Shutting down server connection.");
665 server
.conn
->close();
669 const CbcPointer
<TunnelStateData
> safetyLock(this); /* ??? should be locked by the caller... */
671 if (cbdataReferenceValid(this))
675 /* Writes data from the server buffer to the client side */
677 TunnelStateData::WriteClientDone(const Comm::ConnectionPointer
&, char *buf
, size_t len
, Comm::Flag flag
, int xerrno
, void *data
)
679 TunnelStateData
*tunnelState
= (TunnelStateData
*)data
;
680 assert (cbdataReferenceValid (tunnelState
));
681 tunnelState
->client
.writer
= NULL
;
683 tunnelState
->writeClientDone(buf
, len
, flag
, xerrno
);
687 TunnelStateData::Connection::dataSent(size_t amount
)
689 debugs(26, 3, HERE
<< "len=" << len
<< " - amount=" << amount
);
690 assert(amount
== (size_t)len
);
692 /* increment total object size */
699 TunnelStateData::Connection::write(const char *b
, int size
, AsyncCall::Pointer
&callback
, FREE
* free_func
)
702 Comm::Write(conn
, b
, size
, callback
, free_func
);
706 TunnelStateData::writeClientDone(char *, size_t len
, Comm::Flag flag
, int xerrno
)
708 debugs(26, 3, HERE
<< client
.conn
<< ", " << len
<< " bytes written, flag=" << flag
);
711 if (flag
!= Comm::OK
) {
712 if (flag
!= Comm::ERR_CLOSING
) {
713 debugs(26, 4, HERE
<< "Closing client connection due to comm flags.");
714 client
.error(xerrno
); // may call comm_close
721 debugs(26, 4, HERE
<< "Closing client connection due to 0 byte read.");
722 client
.conn
->close();
727 statCounter
.client_http
.kbytes_out
+= len
;
728 server
.dataSent(len
);
730 /* If the other end has closed, so should we */
731 if (!Comm::IsConnOpen(server
.conn
)) {
732 debugs(26, 4, HERE
<< "Server has gone away. Terminating client connection.");
733 client
.conn
->close();
737 CbcPointer
<TunnelStateData
> safetyLock(this); /* ??? should be locked by the caller... */
739 if (cbdataReferenceValid(this))
740 copyRead(server
, ReadServer
);
744 tunnelTimeout(const CommTimeoutCbParams
&io
)
746 TunnelStateData
*tunnelState
= static_cast<TunnelStateData
*>(io
.data
);
747 debugs(26, 3, HERE
<< io
.conn
);
748 /* Temporary lock to protect our own feets (comm_close -> tunnelClientClosed -> Free) */
749 CbcPointer
<TunnelStateData
> safetyLock(tunnelState
);
751 tunnelState
->client
.closeIfOpen();
752 tunnelState
->server
.closeIfOpen();
756 TunnelStateData::Connection::closeIfOpen()
758 if (Comm::IsConnOpen(conn
))
763 tunnelDelayedClientRead(void *data
)
768 TunnelStateData
*tunnel
= static_cast<TunnelStateData
*>(data
);
769 tunnel
->client
.readPending
= NULL
;
770 static uint64_t counter
=0;
771 debugs(26, 7, "Client read(2) delayed " << ++counter
<< " times");
772 tunnel
->copyRead(tunnel
->client
, TunnelStateData::ReadClient
);
776 tunnelDelayedServerRead(void *data
)
781 TunnelStateData
*tunnel
= static_cast<TunnelStateData
*>(data
);
782 tunnel
->server
.readPending
= NULL
;
783 static uint64_t counter
=0;
784 debugs(26, 7, "Server read(2) delayed " << ++counter
<< " times");
785 tunnel
->copyRead(tunnel
->server
, TunnelStateData::ReadServer
);
789 TunnelStateData::copyRead(Connection
&from
, IOCB
*completion
)
791 assert(from
.len
== 0);
792 // If only the minimum permitted read size is going to be attempted
793 // then we schedule an event to try again in a few I/O cycles.
794 // Allow at least 1 byte to be read every (0.3*10) seconds.
795 int bw
= from
.bytesWanted(1, SQUID_TCP_SO_RCVBUF
);
796 if (bw
== 1 && ++from
.delayedLoops
< 10) {
797 from
.readPending
= this;
798 eventAdd("tunnelDelayedServerRead", from
.readPendingFunc
, from
.readPending
, 0.3, true);
802 AsyncCall::Pointer call
= commCbCall(5,4, "TunnelBlindCopyReadHandler",
803 CommIoCbPtrFun(completion
, this));
804 comm_read(from
.conn
, from
.buf
, bw
, call
);
808 TunnelStateData::readConnectResponse()
810 assert(waitingForConnectResponse());
812 AsyncCall::Pointer call
= commCbCall(5,4, "readConnectResponseDone",
813 CommIoCbPtrFun(ReadConnectResponseDone
, this));
814 comm_read(server
.conn
, connectRespBuf
->space(),
815 server
.bytesWanted(1, connectRespBuf
->spaceSize()), call
);
819 TunnelStateData::copyClientBytes()
821 if (preReadClientData
.length()) {
822 size_t copyBytes
= preReadClientData
.length() > SQUID_TCP_SO_RCVBUF
? SQUID_TCP_SO_RCVBUF
: preReadClientData
.length();
823 memcpy(client
.buf
, preReadClientData
.rawContent(), copyBytes
);
824 preReadClientData
.consume(copyBytes
);
825 client
.bytesIn(copyBytes
);
826 if (keepGoingAfterRead(copyBytes
, Comm::OK
, 0, client
, server
))
827 copy(copyBytes
, client
, server
, TunnelStateData::WriteServerDone
);
829 copyRead(client
, ReadClient
);
833 * Set the HTTP status for this request and sets the read handlers for client
834 * and server side connections.
837 tunnelStartShoveling(TunnelStateData
*tunnelState
)
839 assert(!tunnelState
->waitingForConnectExchange());
840 *tunnelState
->status_ptr
= Http::scOkay
;
841 if (tunnelState
->logTag_ptr
)
842 *tunnelState
->logTag_ptr
= LOG_TCP_TUNNEL
;
843 if (cbdataReferenceValid(tunnelState
)) {
845 // Shovel any payload already pushed into reply buffer by the server response
846 if (!tunnelState
->server
.len
)
847 tunnelState
->copyRead(tunnelState
->server
, TunnelStateData::ReadServer
);
849 debugs(26, DBG_DATA
, "Tunnel server PUSH Payload: \n" << Raw("", tunnelState
->server
.buf
, tunnelState
->server
.len
) << "\n----------");
850 tunnelState
->copy(tunnelState
->server
.len
, tunnelState
->server
, tunnelState
->client
, TunnelStateData::WriteClientDone
);
853 if (tunnelState
->http
.valid() && tunnelState
->http
->getConn() && !tunnelState
->http
->getConn()->inBuf
.isEmpty()) {
854 SBuf
* const in
= &tunnelState
->http
->getConn()->inBuf
;
855 debugs(26, DBG_DATA
, "Tunnel client PUSH Payload: \n" << *in
<< "\n----------");
856 tunnelState
->preReadClientData
.append(*in
);
857 in
->consume(); // ConnStateData buffer accounting after the shuffle.
859 tunnelState
->copyClientBytes();
864 * All the pieces we need to write to client and/or server connection
866 * Call the tunnelStartShoveling to start the blind pump.
869 tunnelConnectedWriteDone(const Comm::ConnectionPointer
&conn
, char *, size_t, Comm::Flag flag
, int, void *data
)
871 TunnelStateData
*tunnelState
= (TunnelStateData
*)data
;
872 debugs(26, 3, HERE
<< conn
<< ", flag=" << flag
);
873 tunnelState
->client
.writer
= NULL
;
875 if (flag
!= Comm::OK
) {
876 *tunnelState
->status_ptr
= Http::scInternalServerError
;
877 tunnelErrorComplete(conn
->fd
, data
, 0);
881 tunnelStartShoveling(tunnelState
);
884 /// Called when we are done writing CONNECT request to a peer.
886 tunnelConnectReqWriteDone(const Comm::ConnectionPointer
&conn
, char *, size_t, Comm::Flag flag
, int, void *data
)
888 TunnelStateData
*tunnelState
= (TunnelStateData
*)data
;
889 debugs(26, 3, conn
<< ", flag=" << flag
);
890 tunnelState
->server
.writer
= NULL
;
891 assert(tunnelState
->waitingForConnectRequest());
893 if (flag
!= Comm::OK
) {
894 *tunnelState
->status_ptr
= Http::scInternalServerError
;
895 tunnelErrorComplete(conn
->fd
, data
, 0);
899 tunnelState
->connectReqWriting
= false;
900 tunnelState
->connectExchangeCheckpoint();
904 TunnelStateData::connectExchangeCheckpoint()
906 if (waitingForConnectResponse()) {
907 debugs(26, 5, "still reading CONNECT response on " << server
.conn
);
908 } else if (waitingForConnectRequest()) {
909 debugs(26, 5, "still writing CONNECT request on " << server
.conn
);
911 assert(!waitingForConnectExchange());
912 debugs(26, 3, "done with CONNECT exchange on " << server
.conn
);
913 tunnelConnected(server
.conn
, this);
918 * handle the write completion from a proxy request to an upstream origin
921 tunnelConnected(const Comm::ConnectionPointer
&server
, void *data
)
923 TunnelStateData
*tunnelState
= (TunnelStateData
*)data
;
924 debugs(26, 3, HERE
<< server
<< ", tunnelState=" << tunnelState
);
926 if (!tunnelState
->clientExpectsConnectResponse())
927 tunnelStartShoveling(tunnelState
); // ssl-bumped connection, be quiet
929 AsyncCall::Pointer call
= commCbCall(5,5, "tunnelConnectedWriteDone",
930 CommIoCbPtrFun(tunnelConnectedWriteDone
, tunnelState
));
931 tunnelState
->client
.write(conn_established
, strlen(conn_established
), call
, NULL
);
936 tunnelErrorComplete(int fd
/*const Comm::ConnectionPointer &*/, void *data
, size_t)
938 TunnelStateData
*tunnelState
= (TunnelStateData
*)data
;
939 debugs(26, 3, HERE
<< "FD " << fd
);
940 assert(tunnelState
!= NULL
);
941 /* temporary lock to save our own feets (comm_close -> tunnelClientClosed -> Free) */
942 CbcPointer
<TunnelStateData
> safetyLock(tunnelState
);
944 if (Comm::IsConnOpen(tunnelState
->client
.conn
))
945 tunnelState
->client
.conn
->close();
947 if (Comm::IsConnOpen(tunnelState
->server
.conn
))
948 tunnelState
->server
.conn
->close();
952 tunnelConnectDone(const Comm::ConnectionPointer
&conn
, Comm::Flag status
, int xerrno
, void *data
)
954 TunnelStateData
*tunnelState
= (TunnelStateData
*)data
;
956 if (status
!= Comm::OK
) {
957 debugs(26, 4, HERE
<< conn
<< ", comm failure recovery.");
958 /* At this point only the TCP handshake has failed. no data has been passed.
959 * we are allowed to re-try the TCP-level connection to alternate IPs for CONNECT.
961 debugs(26, 4, "removing server 1 of " << tunnelState
->serverDestinations
.size() <<
962 " from destinations (" << tunnelState
->serverDestinations
[0] << ")");
963 tunnelState
->serverDestinations
.erase(tunnelState
->serverDestinations
.begin());
964 time_t fwdTimeout
= tunnelState
->started
+ Config
.Timeout
.forward
;
965 if (fwdTimeout
> squid_curtime
&& tunnelState
->serverDestinations
.size() > 0) {
966 // find remaining forward_timeout available for this attempt
967 fwdTimeout
-= squid_curtime
;
968 if (fwdTimeout
> Config
.Timeout
.connect
)
969 fwdTimeout
= Config
.Timeout
.connect
;
970 /* Try another IP of this destination host */
971 GetMarkingsToServer(tunnelState
->request
.getRaw(), *tunnelState
->serverDestinations
[0]);
972 debugs(26, 4, HERE
<< "retry with : " << tunnelState
->serverDestinations
[0]);
973 AsyncCall::Pointer call
= commCbCall(26,3, "tunnelConnectDone", CommConnectCbPtrFun(tunnelConnectDone
, tunnelState
));
974 Comm::ConnOpener
*cs
= new Comm::ConnOpener(tunnelState
->serverDestinations
[0], call
, fwdTimeout
);
975 cs
->setHost(tunnelState
->url
);
978 debugs(26, 4, HERE
<< "terminate with error.");
979 ErrorState
*err
= new ErrorState(ERR_CONNECT_FAIL
, Http::scServiceUnavailable
, tunnelState
->request
.getRaw());
980 *tunnelState
->status_ptr
= Http::scServiceUnavailable
;
981 err
->xerrno
= xerrno
;
982 // on timeout is this still: err->xerrno = ETIMEDOUT;
983 err
->port
= conn
->remote
.port();
984 err
->callback
= tunnelErrorComplete
;
985 err
->callback_data
= tunnelState
;
986 errorSend(tunnelState
->client
.conn
, err
);
987 if (tunnelState
->request
!= NULL
)
988 tunnelState
->request
->hier
.stopPeerClock(false);
994 /* no point using the delayIsNoDelay stuff since tunnel is nice and simple */
995 if (conn
->getPeer() && conn
->getPeer()->options
.no_delay
)
996 tunnelState
->server
.setDelayId(DelayId());
999 tunnelState
->request
->hier
.note(conn
, tunnelState
->getHost());
1001 tunnelState
->server
.conn
= conn
;
1002 tunnelState
->request
->peer_host
= conn
->getPeer() ? conn
->getPeer()->host
: NULL
;
1003 comm_add_close_handler(conn
->fd
, tunnelServerClosed
, tunnelState
);
1005 debugs(26, 4, HERE
<< "determine post-connect handling pathway.");
1006 if (conn
->getPeer()) {
1007 tunnelState
->request
->peer_login
= conn
->getPeer()->login
;
1008 tunnelState
->request
->peer_domain
= conn
->getPeer()->domain
;
1009 tunnelState
->request
->flags
.auth_no_keytab
= conn
->getPeer()->options
.auth_no_keytab
;
1010 tunnelState
->request
->flags
.proxying
= !(conn
->getPeer()->options
.originserver
);
1012 tunnelState
->request
->peer_login
= NULL
;
1013 tunnelState
->request
->peer_domain
= NULL
;
1014 tunnelState
->request
->flags
.auth_no_keytab
= false;
1015 tunnelState
->request
->flags
.proxying
= false;
1018 if (tunnelState
->request
->flags
.proxying
)
1019 tunnelState
->connectToPeer();
1021 tunnelConnected(conn
, tunnelState
);
1024 AsyncCall::Pointer timeoutCall
= commCbCall(5, 4, "tunnelTimeout",
1025 CommTimeoutCbPtrFun(tunnelTimeout
, tunnelState
));
1026 commSetConnTimeout(conn
, Config
.Timeout
.read
, timeoutCall
);
1030 tunnelStart(ClientHttpRequest
* http
)
1032 debugs(26, 3, HERE
);
1033 /* Create state structure. */
1034 TunnelStateData
*tunnelState
= NULL
;
1035 ErrorState
*err
= NULL
;
1036 HttpRequest
*request
= http
->request
;
1037 char *url
= http
->uri
;
1040 * client_addr.isNoAddr() indicates this is an "internal" request
1041 * from peer_digest.c, asn.c, netdb.c, etc and should always
1042 * be allowed. yuck, I know.
1045 if (Config
.accessList
.miss
&& !request
->client_addr
.isNoAddr()) {
1047 * Check if this host is allowed to fetch MISSES from us (miss_access)
1048 * default is to allow.
1050 ACLFilledChecklist
ch(Config
.accessList
.miss
, request
, NULL
);
1051 ch
.src_addr
= request
->client_addr
;
1052 ch
.my_addr
= request
->my_addr
;
1053 if (ch
.fastCheck() == ACCESS_DENIED
) {
1054 debugs(26, 4, HERE
<< "MISS access forbidden.");
1055 err
= new ErrorState(ERR_FORWARDING_DENIED
, Http::scForbidden
, request
);
1056 http
->al
->http
.code
= Http::scForbidden
;
1057 errorSend(http
->getConn()->clientConnection
, err
);
1062 debugs(26, 3, request
->method
<< ' ' << url
<< ' ' << request
->http_ver
);
1063 ++statCounter
.server
.all
.requests
;
1064 ++statCounter
.server
.other
.requests
;
1066 tunnelState
= new TunnelStateData
;
1068 tunnelState
->server
.setDelayId(DelayId::DelayClient(http
));
1070 tunnelState
->url
= xstrdup(url
);
1071 tunnelState
->request
= request
;
1072 tunnelState
->server
.size_ptr
= &http
->out
.size
;
1073 tunnelState
->client
.size_ptr
= &http
->al
->http
.clientRequestSz
.payloadData
;
1074 tunnelState
->status_ptr
= &http
->al
->http
.code
;
1075 tunnelState
->logTag_ptr
= &http
->logType
;
1076 tunnelState
->client
.conn
= http
->getConn()->clientConnection
;
1077 tunnelState
->http
= http
;
1078 tunnelState
->al
= http
->al
;
1079 //tunnelState->started is set in TunnelStateData ctor
1081 comm_add_close_handler(tunnelState
->client
.conn
->fd
,
1085 AsyncCall::Pointer timeoutCall
= commCbCall(5, 4, "tunnelTimeout",
1086 CommTimeoutCbPtrFun(tunnelTimeout
, tunnelState
));
1087 commSetConnTimeout(tunnelState
->client
.conn
, Config
.Timeout
.lifetime
, timeoutCall
);
1089 peerSelect(&(tunnelState
->serverDestinations
), request
, http
->al
,
1091 tunnelPeerSelectComplete
,
1096 TunnelStateData::connectToPeer()
1099 if (CachePeer
*p
= server
.conn
->getPeer()) {
1100 if (p
->secure
.encryptTransport
) {
1101 AsyncCall::Pointer callback
= asyncCall(5,4,
1102 "TunnelStateData::ConnectedToPeer",
1103 MyAnswerDialer(&TunnelStateData::connectedToPeer
, this));
1104 Ssl::BlindPeerConnector
*connector
=
1105 new Ssl::BlindPeerConnector(request
, server
.conn
, callback
);
1106 AsyncJob::Start(connector
); // will call our callback
1112 Security::EncryptorAnswer nil
;
1113 connectedToPeer(nil
);
1117 TunnelStateData::connectedToPeer(Security::EncryptorAnswer
&answer
)
1119 if (ErrorState
*error
= answer
.error
.get()) {
1120 *status_ptr
= error
->httpStatus
;
1121 error
->callback
= tunnelErrorComplete
;
1122 error
->callback_data
= this;
1123 errorSend(client
.conn
, error
);
1124 answer
.error
.clear(); // preserve error for errorSendComplete()
1128 tunnelRelayConnectRequest(server
.conn
, this);
1132 tunnelRelayConnectRequest(const Comm::ConnectionPointer
&srv
, void *data
)
1134 TunnelStateData
*tunnelState
= (TunnelStateData
*)data
;
1135 assert(!tunnelState
->waitingForConnectExchange());
1136 HttpHeader
hdr_out(hoRequest
);
1137 HttpStateFlags flags
;
1138 debugs(26, 3, HERE
<< srv
<< ", tunnelState=" << tunnelState
);
1139 memset(&flags
, '\0', sizeof(flags
));
1140 flags
.proxying
= tunnelState
->request
->flags
.proxying
;
1143 mb
.appendf("CONNECT %s HTTP/1.1\r\n", tunnelState
->url
);
1144 HttpStateData::httpBuildRequestHeader(tunnelState
->request
.getRaw(),
1145 NULL
, /* StoreEntry */
1146 tunnelState
->al
, /* AccessLogEntry */
1149 hdr_out
.packInto(&mb
);
1151 mb
.append("\r\n", 2);
1153 debugs(11, 2, "Tunnel Server REQUEST: " << tunnelState
->server
.conn
<<
1154 ":\n----------\n" << mb
.buf
<< "\n----------");
1156 AsyncCall::Pointer writeCall
= commCbCall(5,5, "tunnelConnectReqWriteDone",
1157 CommIoCbPtrFun(tunnelConnectReqWriteDone
,
1160 tunnelState
->server
.write(mb
.buf
, mb
.size
, writeCall
, mb
.freeFunc());
1161 tunnelState
->connectReqWriting
= true;
1163 tunnelState
->connectRespBuf
= new MemBuf
;
1164 // SQUID_TCP_SO_RCVBUF: we should not accumulate more than regular I/O buffer
1165 // can hold since any CONNECT response leftovers have to fit into server.buf.
1166 // 2*SQUID_TCP_SO_RCVBUF: HttpMsg::parse() zero-terminates, which uses space.
1167 tunnelState
->connectRespBuf
->init(SQUID_TCP_SO_RCVBUF
, 2*SQUID_TCP_SO_RCVBUF
);
1168 tunnelState
->readConnectResponse();
1170 assert(tunnelState
->waitingForConnectExchange());
1172 AsyncCall::Pointer timeoutCall
= commCbCall(5, 4, "tunnelTimeout",
1173 CommTimeoutCbPtrFun(tunnelTimeout
, tunnelState
));
1174 commSetConnTimeout(srv
, Config
.Timeout
.read
, timeoutCall
);
1178 tunnelPeerSelectComplete(Comm::ConnectionList
*peer_paths
, ErrorState
*err
, void *data
)
1180 TunnelStateData
*tunnelState
= (TunnelStateData
*)data
;
1182 if (peer_paths
== NULL
|| peer_paths
->size() < 1) {
1183 debugs(26, 3, HERE
<< "No paths found. Aborting CONNECT");
1185 err
= new ErrorState(ERR_CANNOT_FORWARD
, Http::scServiceUnavailable
, tunnelState
->request
.getRaw());
1187 *tunnelState
->status_ptr
= err
->httpStatus
;
1188 err
->callback
= tunnelErrorComplete
;
1189 err
->callback_data
= tunnelState
;
1190 errorSend(tunnelState
->client
.conn
, err
);
1195 GetMarkingsToServer(tunnelState
->request
.getRaw(), *tunnelState
->serverDestinations
[0]);
1197 if (tunnelState
->request
!= NULL
)
1198 tunnelState
->request
->hier
.startPeerClock();
1200 debugs(26, 3, HERE
<< "paths=" << peer_paths
->size() << ", p[0]={" << (*peer_paths
)[0] << "}, serverDest[0]={" <<
1201 tunnelState
->serverDestinations
[0] << "}");
1203 AsyncCall::Pointer call
= commCbCall(26,3, "tunnelConnectDone", CommConnectCbPtrFun(tunnelConnectDone
, tunnelState
));
1204 Comm::ConnOpener
*cs
= new Comm::ConnOpener(tunnelState
->serverDestinations
[0], call
, Config
.Timeout
.connect
);
1205 cs
->setHost(tunnelState
->url
);
1206 AsyncJob::Start(cs
);
1209 CBDATA_CLASS_INIT(TunnelStateData
);
1212 TunnelStateData::noConnections() const
1214 return !Comm::IsConnOpen(server
.conn
) && !Comm::IsConnOpen(client
.conn
);
1219 TunnelStateData::Connection::setDelayId(DelayId
const &newDelay
)
1228 switchToTunnel(HttpRequest
*request
, Comm::ConnectionPointer
&clientConn
, Comm::ConnectionPointer
&srvConn
)
1230 debugs(26,5, "Revert to tunnel FD " << clientConn
->fd
<< " with FD " << srvConn
->fd
);
1231 /* Create state structure. */
1232 TunnelStateData
*tunnelState
= NULL
;
1233 const SBuf
url(request
->effectiveRequestUri());
1235 debugs(26, 3, request
->method
<< " " << url
<< " " << request
->http_ver
);
1236 ++statCounter
.server
.all
.requests
;
1237 ++statCounter
.server
.other
.requests
;
1239 tunnelState
= new TunnelStateData
;
1240 tunnelState
->url
= SBufToCstring(url
);
1241 tunnelState
->request
= request
;
1242 tunnelState
->server
.size_ptr
= NULL
; //Set later if Http::Stream is available
1244 // Temporary static variable to store the unneeded for our case status code
1245 static int status_code
= 0;
1246 tunnelState
->status_ptr
= &status_code
;
1247 tunnelState
->client
.conn
= clientConn
;
1249 ConnStateData
*conn
;
1250 if ((conn
= request
->clientConnectionManager
.get())) {
1251 Http::StreamPointer context
= conn
->pipeline
.front();
1252 if (context
!= nullptr && context
->http
!= nullptr) {
1253 tunnelState
->logTag_ptr
= &context
->http
->logType
;
1254 tunnelState
->server
.size_ptr
= &context
->http
->out
.size
;
1257 /* no point using the delayIsNoDelay stuff since tunnel is nice and simple */
1258 if (srvConn
->getPeer() && srvConn
->getPeer()->options
.no_delay
)
1259 tunnelState
->server
.setDelayId(DelayId::DelayClient(context
->http
));
1264 comm_add_close_handler(tunnelState
->client
.conn
->fd
,
1268 AsyncCall::Pointer timeoutCall
= commCbCall(5, 4, "tunnelTimeout",
1269 CommTimeoutCbPtrFun(tunnelTimeout
, tunnelState
));
1270 commSetConnTimeout(tunnelState
->client
.conn
, Config
.Timeout
.lifetime
, timeoutCall
);
1271 fd_table
[clientConn
->fd
].read_method
= &default_read_method
;
1272 fd_table
[clientConn
->fd
].write_method
= &default_write_method
;
1274 tunnelState
->request
->hier
.note(srvConn
, tunnelState
->getHost());
1276 tunnelState
->server
.conn
= srvConn
;
1277 tunnelState
->request
->peer_host
= srvConn
->getPeer() ? srvConn
->getPeer()->host
: NULL
;
1278 comm_add_close_handler(srvConn
->fd
, tunnelServerClosed
, tunnelState
);
1280 debugs(26, 4, "determine post-connect handling pathway.");
1281 if (srvConn
->getPeer()) {
1282 tunnelState
->request
->peer_login
= srvConn
->getPeer()->login
;
1283 tunnelState
->request
->peer_domain
= srvConn
->getPeer()->domain
;
1284 tunnelState
->request
->flags
.auth_no_keytab
= srvConn
->getPeer()->options
.auth_no_keytab
;
1285 tunnelState
->request
->flags
.proxying
= !(srvConn
->getPeer()->options
.originserver
);
1287 tunnelState
->request
->peer_login
= NULL
;
1288 tunnelState
->request
->peer_domain
= NULL
;
1289 tunnelState
->request
->flags
.auth_no_keytab
= false;
1290 tunnelState
->request
->flags
.proxying
= false;
1293 timeoutCall
= commCbCall(5, 4, "tunnelTimeout",
1294 CommTimeoutCbPtrFun(tunnelTimeout
, tunnelState
));
1295 commSetConnTimeout(srvConn
, Config
.Timeout
.read
, timeoutCall
);
1296 fd_table
[srvConn
->fd
].read_method
= &default_read_method
;
1297 fd_table
[srvConn
->fd
].write_method
= &default_write_method
;
1299 auto ssl
= fd_table
[srvConn
->fd
].ssl
.get();
1301 BIO
*b
= SSL_get_rbio(ssl
);
1302 Ssl::ServerBio
*srvBio
= static_cast<Ssl::ServerBio
*>(b
->ptr
);
1303 const MemBuf
&buf
= srvBio
->rBufData();
1305 AsyncCall::Pointer call
= commCbCall(5,5, "tunnelConnectedWriteDone",
1306 CommIoCbPtrFun(tunnelConnectedWriteDone
, tunnelState
));
1307 tunnelState
->client
.write(buf
.content(), buf
.contentSize(), call
, NULL
);
1309 #endif //USE_OPENSSL