From: robertc <> Date: Fri, 14 Feb 2003 20:59:49 +0000 (+0000) Subject: Merge comms accept fix. X-Git-Tag: SQUID_3_0_PRE1~346 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ee0989f21780ad272c9c35e4cf300880db88943d;p=thirdparty%2Fsquid.git Merge comms accept fix. --- diff --git a/src/ConnectionDetail.h b/src/ConnectionDetail.h new file mode 100644 index 0000000000..272a52e0e9 --- /dev/null +++ b/src/ConnectionDetail.h @@ -0,0 +1,46 @@ +/* + * $Id: ConnectionDetail.h,v 1.1 2003/02/14 13:59:50 robertc Exp $ + * + * DEBUG: section 5 Socket Functions + * AUTHOR: Robert Collins + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + * + * Copyright (c) 2003, Robert Collins + */ + +#ifndef _SQUIDCONNECTIONDETAIL_H_ +#define _SQUIDCONNECTIONDETAIL_H_ + +class ConnectionDetail { + public: + struct sockaddr_in me; + struct sockaddr_in peer; +}; + +#endif diff --git a/src/Makefile.am b/src/Makefile.am index 2a1732d158..d16d97766f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.am,v 1.58 2003/02/13 08:07:47 robertc Exp $ +# $Id: Makefile.am,v 1.59 2003/02/14 13:59:50 robertc Exp $ # # Uncomment and customize the following to suit your needs: # @@ -191,6 +191,7 @@ squid_SOURCES = \ comm_poll.cc \ comm_kqueue.cc \ Config.h \ + ConnectionDetail.h \ debug.cc \ Debug.h \ defines.h \ diff --git a/src/client_side.cc b/src/client_side.cc index 3b4d365bcc..f848f74984 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.619 2003/02/12 06:11:00 robertc Exp $ + * $Id: client_side.cc,v 1.620 2003/02/14 13:59:49 robertc Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -67,6 +67,7 @@ #include "fde.h" #include "client_side_request.h" #include "ACLChecklist.h" +#include "ConnectionDetail.h" #if LINGERING_CLOSE #define comm_close comm_lingering_close @@ -2217,7 +2218,7 @@ connStateCreate(struct sockaddr_in *peer, struct sockaddr_in *me, int fd) /* Handle a new connection on HTTP socket. */ void -httpAccept(int sock, int newfd, struct sockaddr_in *me, struct sockaddr_in *peer, +httpAccept(int sock, int newfd, ConnectionDetail *details, comm_err_t flag, int xerrno, void *data) { int *N = &incoming_sockets_accepted; @@ -2240,22 +2241,22 @@ httpAccept(int sock, int newfd, struct sockaddr_in *me, struct sockaddr_in *peer } debug(33, 4) ("httpAccept: FD %d: accepted\n", newfd); - connState = connStateCreate(peer, me, newfd); + connState = connStateCreate(&details->peer, &details->me, newfd); comm_add_close_handler(newfd, connStateFree, connState); if (Config.onoff.log_fqdn) - fqdncache_gethostbyaddr(peer->sin_addr, FQDN_LOOKUP_IF_MISS); + fqdncache_gethostbyaddr(details->peer.sin_addr, FQDN_LOOKUP_IF_MISS); commSetTimeout(newfd, Config.Timeout.request, requestTimeout, connState); #if USE_IDENT ACLChecklist identChecklist; - identChecklist.src_addr = peer->sin_addr; - identChecklist.my_addr = me->sin_addr; - identChecklist.my_port = ntohs(me->sin_port); + identChecklist.src_addr = details->peer.sin_addr; + identChecklist.my_addr = details->me.sin_addr; + identChecklist.my_port = ntohs(details->me.sin_port); if (aclCheckFast(Config.accessList.identLookup, &identChecklist)) - identStart(me, peer, clientIdentDone, connState); + identStart(&details->me, &details->peer, clientIdentDone, connState); #endif clientReadSomeData(connState); commSetDefer(newfd, clientReadDefer, connState); - clientdbEstablished(peer->sin_addr, 1); + clientdbEstablished(details->peer.sin_addr, 1); assert(N); (*N)++; } diff --git a/src/comm.cc b/src/comm.cc index 44b72b7b09..25863e49e8 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.364 2003/02/12 06:11:02 robertc Exp $ + * $Id: comm.cc,v 1.365 2003/02/14 13:59:49 robertc Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -37,6 +37,7 @@ #include "StoreIOBuffer.h" #include "comm.h" #include "fde.h" +#include "ConnectionDetail.h" #if defined(_SQUID_CYGWIN_) #include @@ -85,6 +86,13 @@ CBDATA_TYPE(ConnectStateData); static PF comm_accept_try; +class AcceptFD { + public: + int check_delay; + IOACB *handler; + void *handler_data; +}; + struct _fdc_t { int active; int fd; @@ -104,11 +112,10 @@ struct _fdc_t { } write; struct { /* how often (in msec) to re-check if we're out of fds on an accept() */ - int check_delay; - struct sockaddr_in me; - struct sockaddr_in pn; - IOACB *handler; - void *handler_data; + struct sockaddr_in & me() {return connDetails.me;} + struct sockaddr_in & pn() {return connDetails.peer;} + AcceptFD accept; + ConnectionDetail connDetails; } accept; struct CommFiller { StoreIOBuffer requestedData; @@ -145,8 +152,7 @@ struct _CommCallbackData { comm_err_t errcode; int xerrno; int seqnum; - struct sockaddr_in me; - struct sockaddr_in pn; + ConnectionDetail details; StoreIOBuffer sb; }; typedef struct _CommCallbackData CommCallbackData; @@ -215,9 +221,9 @@ comm_addreadcallback(int fd, IOCB *callback, char *buf, size_t retval, comm_err_ } + static void -comm_addacceptcallback(int fd, int newfd, IOACB *callback, struct sockaddr_in *pn, - struct sockaddr_in *me, comm_err_t errcode, int xerrno, void *callback_data) +comm_addacceptcallback(int fd, int newfd, IOACB *callback, ConnectionDetail details, comm_err_t errcode, int xerrno, void *callback_data) { CommCallbackData *cio; @@ -235,8 +241,7 @@ comm_addacceptcallback(int fd, int newfd, IOACB *callback, struct sockaddr_in *p cio->seqnum = CommCallbackSeqnum; cio->type = COMM_CB_ACCEPT; cio->newfd = newfd; - cio->pn = *pn; - cio->me = *me; + cio->details = details; /* Add it to the end of the list */ dlinkAddTail(cio, &(cio->h_node), &CommCallbackList); @@ -325,7 +330,7 @@ comm_call_io_callback(CommCallbackData *cio) cio->callback_data); break; case COMM_CB_ACCEPT: - cio->c.a_callback(cio->fd, cio->newfd, &cio->me, &cio->pn, cio->errcode, + cio->c.a_callback(cio->fd, cio->newfd, &cio->details, cio->errcode, cio->xerrno, cio->callback_data); break; case COMM_CB_FILL: @@ -732,7 +737,7 @@ comm_accept_setcheckperiod(int fd, int mdelay) { assert(fdc_table[fd].active == 1); assert(mdelay != 0); - fdc_table[fd].accept.check_delay = mdelay; + fdc_table[fd].accept.accept.check_delay = mdelay; } /* @@ -753,7 +758,7 @@ comm_accept_check_event(void *data) last_warn = squid_curtime; } eventAdd("comm_accept_check_event", comm_accept_check_event, &fdc_table[fd], - 1000.0 / (double)(fdc_table[fd].accept.check_delay), 1); + 1000.0 / (double)(fdc_table[fd].accept.accept.check_delay), 1); } @@ -1194,18 +1199,14 @@ comm_connect_addr(int sock, const struct sockaddr_in *address) /* Wait for an incoming connection on FD. FD should be a socket returned * from comm_listen. */ -int -comm_old_accept(int fd, struct sockaddr_in *pn, struct sockaddr_in *me) +static int +comm_old_accept(int fd, ConnectionDetail &details) { - int sock; - struct sockaddr_in P; - struct sockaddr_in M; - socklen_t Slen; - fde *F = NULL; - Slen = sizeof(P); - statCounter.syscalls.sock.accepts++; PROF_start(comm_accept); - if ((sock = accept(fd, (struct sockaddr *) &P, &Slen)) < 0) { + statCounter.syscalls.sock.accepts++; + int sock; + socklen_t Slen = sizeof(details.peer); + if ((sock = accept(fd, (struct sockaddr *) &details.peer, &Slen)) < 0) { PROF_stop(comm_accept); if (ignoreErrno(errno)) { debug(50, 5) ("comm_old_accept: FD %d: %s\n", fd, xstrerror()); @@ -1218,23 +1219,19 @@ comm_old_accept(int fd, struct sockaddr_in *pn, struct sockaddr_in *me) return COMM_ERROR; } } - if (pn) - *pn = P; - Slen = sizeof(M); - memset(&M, '\0', Slen); - getsockname(sock, (struct sockaddr *) &M, &Slen); - if (me) - *me = M; + Slen = sizeof(details.me); + memset(&details.me, '\0', Slen); + getsockname(sock, (struct sockaddr *) &details.me, &Slen); commSetCloseOnExec(sock); /* fdstat update */ fd_open(sock, FD_SOCKET, "HTTP Request"); fdd_table[sock].close_file = NULL; fdd_table[sock].close_line = 0; fdc_table[sock].active = 1; - F = &fd_table[sock]; - xstrncpy(F->ipaddr, inet_ntoa(P.sin_addr), 16); - F->remote_port = htons(P.sin_port); - F->local_port = htons(M.sin_port); + fde *F = &fd_table[sock]; + xstrncpy(F->ipaddr, inet_ntoa(details.peer.sin_addr), 16); + F->remote_port = htons(details.peer.sin_port); + F->local_port = htons(details.me.sin_port); commSetNonBlocking(sock); PROF_stop(comm_accept); return sock; @@ -1361,10 +1358,10 @@ _comm_close(int fd, char *file, int line) COMM_ERR_CLOSING, 0, fdc_table[fd].read.handler_data); fdc_table[fd].read.handler = NULL; } - if (fdc_table[fd].accept.handler) { - fdc_table[fd].accept.handler(fd, -1, NULL, NULL, COMM_ERR_CLOSING, - 0, fdc_table[fd].accept.handler_data); - fdc_table[fd].accept.handler = NULL; + if (fdc_table[fd].accept.accept.handler) { + fdc_table[fd].accept.accept.handler(fd, -1, NULL, COMM_ERR_CLOSING, + 0, fdc_table[fd].accept.accept.handler_data); + fdc_table[fd].accept.accept.handler = NULL; } if (fdc_table[fd].fill.handler) { fdc_table[fd].fill.handler(fd, fdc_table[fd].fill.requestedData, COMM_ERR_CLOSING, 0, @@ -1825,11 +1822,11 @@ comm_accept_try(int fd, void *data) if (fdNFree() < RESERVED_FD) { debug(5, 3) ("comm_accept_try: we're out of fds - deferring io!\n"); eventAdd("comm_accept_check_event", comm_accept_check_event, &fdc_table[fd], - 1000.0 / (double)(fdc_table[fd].accept.check_delay), 1); + 1000.0 / (double)(fdc_table[fd].accept.accept.check_delay), 1); return; } /* Accept a new connection */ - newfd = comm_old_accept(fd, &Fc->accept.pn, &Fc->accept.me); + newfd = comm_old_accept(fd, Fc->accept.connDetails); /* Check for errors */ if (newfd < 0) { if (newfd == COMM_NOMESSAGE) { @@ -1838,20 +1835,19 @@ comm_accept_try(int fd, void *data) return; } /* A non-recoverable error - register an error callback */ - comm_addacceptcallback(fd, -1, Fc->accept.handler, &Fc->accept.pn, - &Fc->accept.me, COMM_ERROR, errno, Fc->accept.handler_data); - Fc->accept.handler = NULL; - Fc->accept.handler_data = NULL; + comm_addacceptcallback(fd, -1, Fc->accept.accept.handler, Fc->accept.connDetails, COMM_ERROR, errno, Fc->accept.accept.handler_data); + Fc->accept.accept.handler = NULL; + Fc->accept.accept.handler_data = NULL; return; } /* Try the callback! */ - hdl = Fc->accept.handler; - Fc->accept.handler = NULL; - hdl(fd, newfd, &Fc->accept.pn, &Fc->accept.me, COMM_OK, 0, Fc->accept.handler_data); + hdl = Fc->accept.accept.handler; + Fc->accept.accept.handler = NULL; + hdl(fd, newfd, &Fc->accept.connDetails, COMM_OK, 0, Fc->accept.accept.handler_data); /* If we weren't re-registed, don't bother trying again! */ - if (Fc->accept.handler == NULL) + if (Fc->accept.accept.handler == NULL) return; } } @@ -1871,12 +1867,12 @@ comm_accept(int fd, IOACB *handler, void *handler_data) assert(fdc_table[fd].active == 1); /* make sure we're not pending! */ - assert(fdc_table[fd].accept.handler == NULL); + assert(fdc_table[fd].accept.accept.handler == NULL); /* Record our details */ Fc = &fdc_table[fd]; - Fc->accept.handler = handler; - Fc->accept.handler_data = handler_data; + Fc->accept.accept.handler = handler; + Fc->accept.accept.handler_data = handler_data; /* Kick off the accept */ #if OPTIMISTIC_IO diff --git a/src/comm.h b/src/comm.h index 1339366896..67702c5469 100644 --- a/src/comm.h +++ b/src/comm.h @@ -8,6 +8,10 @@ typedef void IOWCB(int fd, char *data, size_t len, comm_err_t flag, int xerrno, /* fill sb with up to length data from fd */ extern void comm_fill_immediate(int fd, StoreIOBuffer sb, IOFCB *callback, void *data); +class ConnectionDetail; +typedef void IOACB(int fd, int nfd, ConnectionDetail *details, comm_err_t flag, int xerrno, void *data); +extern void comm_accept(int fd, IOACB *handler, void *handler_data); + extern int comm_has_pending_read_callback(int fd); extern bool comm_has_pending_read(int fd); extern void comm_read_cancel(int fd, IOCB *callback, void *data); diff --git a/src/ftp.cc b/src/ftp.cc index 336d6ecb20..ce2aa9c31d 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.340 2003/02/05 10:36:51 robertc Exp $ + * $Id: ftp.cc,v 1.341 2003/02/14 13:59:50 robertc Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -45,6 +45,7 @@ #if DELAY_POOLS #include "DelayPools.h" #endif +#include "ConnectionDetail.h" static const char *const crlf = "\r\n"; static char cbuf[1024]; @@ -1908,7 +1909,7 @@ ftpReadPort(FtpStateData * ftpState) /* "read" handler to accept data connection */ static void -ftpAcceptDataConnection(int fd, int newfd, struct sockaddr_in *me, struct sockaddr_in *my_peer, +ftpAcceptDataConnection(int fd, int newfd, ConnectionDetail *details, comm_err_t flag, int xerrno, void *data) { FtpStateData *ftpState = (FtpStateData *)data; @@ -1924,9 +1925,9 @@ ftpAcceptDataConnection(int fd, int newfd, struct sockaddr_in *me, struct sockad } if (Config.Ftp.sanitycheck) { - char *ipaddr = inet_ntoa(my_peer->sin_addr); + char *ipaddr = inet_ntoa(details->peer.sin_addr); if (strcmp(fd_table[ftpState->ctrl.fd].ipaddr, ipaddr) != 0) { - debug(9, 1) ("FTP data connection from unexpected server (%s:%d), expecting %s\n", ipaddr, (int) ntohs(my_peer->sin_port), fd_table[ftpState->ctrl.fd].ipaddr); + debug(9, 1) ("FTP data connection from unexpected server (%s:%d), expecting %s\n", ipaddr, (int) ntohs(details->peer.sin_port), fd_table[ftpState->ctrl.fd].ipaddr); comm_close(newfd); comm_accept(ftpState->data.fd, ftpAcceptDataConnection, ftpState); return; @@ -1943,8 +1944,8 @@ ftpAcceptDataConnection(int fd, int newfd, struct sockaddr_in *me, struct sockad comm_close(ftpState->data.fd); debug(9, 3) ("ftpAcceptDataConnection: Connected data socket on FD %d\n", newfd); ftpState->data.fd = newfd; - ftpState->data.port = ntohs(my_peer->sin_port); - ftpState->data.host = xstrdup(inet_ntoa(my_peer->sin_addr)); + ftpState->data.port = ntohs(details->peer.sin_port); + ftpState->data.host = xstrdup(inet_ntoa(details->peer.sin_addr)); commSetTimeout(ftpState->ctrl.fd, -1, NULL, NULL); commSetTimeout(ftpState->data.fd, Config.Timeout.read, ftpTimeout, ftpState); diff --git a/src/protos.h b/src/protos.h index 035c0c915d..35fa1bc575 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.464 2003/02/12 06:11:04 robertc Exp $ + * $Id: protos.h,v 1.465 2003/02/14 13:59:50 robertc Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -124,12 +124,10 @@ extern int comm_existsiocallback(void); extern void comm_calliocallback(void); extern void comm_read(int fd, char *buf, int len, IOCB *handler, void *data); -extern void comm_accept(int fd, IOACB *handler, void *handler_data); extern int comm_listen(int fd); SQUIDCEXTERN int commSetNonBlocking(int fd); SQUIDCEXTERN int commUnsetNonBlocking(int fd); SQUIDCEXTERN void commSetCloseOnExec(int fd); -extern int comm_old_accept(int fd, struct sockaddr_in *, struct sockaddr_in *); extern void _comm_close(int fd, char *file, int line); #define comm_close(fd) (_comm_close((fd), __FILE__, __LINE__)) SQUIDCEXTERN void comm_reset_close(int fd); diff --git a/src/typedefs.h b/src/typedefs.h index 5c258c578a..23f3a84591 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.150 2003/02/12 06:11:05 robertc Exp $ + * $Id: typedefs.h,v 1.151 2003/02/14 13:59:50 robertc Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -173,8 +173,6 @@ typedef struct _snmp_request_t snmp_request_t; typedef void CWCB(int fd, char *, size_t size, comm_err_t flag, void *data); typedef void CNCB(int fd, comm_err_t status, void *); typedef void IOCB(int fd, char *, size_t size, comm_err_t flag, int xerrno, void *data); -typedef void IOACB(int fd, int nfd, struct sockaddr_in *me, struct sockaddr_in - *pn, comm_err_t flag, int xerrno, void *data); typedef void FREE(void *); typedef void CBDUNL(void *);