From: robertc <> Date: Sun, 23 Feb 2003 07:08:03 +0000 (+0000) Subject: Summary: More Windows Merges. X-Git-Tag: SQUID_3_0_PRE1~316 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bdb741f46a2048883aa70c3491617262b9b5a65e;p=thirdparty%2Fsquid.git Summary: More Windows Merges. Keywords: Hi, This is the 5th of some splitted native Windows patches grouped by functionality. Native Windows port enhancements: - Added native Windows and Cygwin support to pinger.cc - Introduced the use of IPPROTO_TCP and IPPROTO_UDP defines instead of '0' on comm_open, needed by Winsocket. See this old squid-dev thread about: http://www.squid-cache.org/mail-archive/squid-dev/200108/0162.html Regards Guido --- diff --git a/src/access_log.cc b/src/access_log.cc index 34862558f3..8c481e4b8c 100644 --- a/src/access_log.cc +++ b/src/access_log.cc @@ -1,6 +1,6 @@ /* - * $Id: access_log.cc,v 1.80 2003/02/21 22:50:06 robertc Exp $ + * $Id: access_log.cc,v 1.81 2003/02/23 00:08:03 robertc Exp $ * * DEBUG: section 46 Access Log * AUTHOR: Duane Wessels @@ -472,7 +472,7 @@ accessLogInit(void) mcast_miss_to.sin_port = htons(Config.mcast_miss.port); mcast_miss_to.sin_addr.s_addr = Config.mcast_miss.addr.s_addr; mcast_miss_fd = comm_open(SOCK_DGRAM, - 0, + IPPROTO_UDP, Config.Addrs.udp_incoming, Config.mcast_miss.port, COMM_NONBLOCKING, diff --git a/src/client_side.cc b/src/client_side.cc index ca0a40902a..47462d88b6 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.625 2003/02/22 14:59:34 hno Exp $ + * $Id: client_side.cc,v 1.626 2003/02/23 00:08:03 robertc Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -2796,7 +2796,7 @@ clientHttpConnectionsOpen(void) enter_suid(); fd = comm_open(SOCK_STREAM, - 0, + IPPROTO_TCP, s->s.sin_addr, ntohs(s->s.sin_port), COMM_NONBLOCKING, "HTTP Socket"); leave_suid(); @@ -2837,7 +2837,7 @@ clientHttpsConnectionsOpen(void) enter_suid(); fd = comm_open(SOCK_STREAM, - 0, + IPPROTO_TCP, s->http.s.sin_addr, ntohs(s->http.s.sin_port), COMM_NONBLOCKING, "HTTPS Socket"); leave_suid(); diff --git a/src/dns_internal.cc b/src/dns_internal.cc index 3101f7b083..2636eb3869 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -1,6 +1,6 @@ /* - * $Id: dns_internal.cc,v 1.53 2003/02/21 22:50:08 robertc Exp $ + * $Id: dns_internal.cc,v 1.54 2003/02/23 00:08:03 robertc Exp $ * * DEBUG: section 78 DNS lookups; interacts with lib/rfc1035.c * AUTHOR: Duane Wessels @@ -761,7 +761,7 @@ idnsInit(void) addr = Config.Addrs.udp_incoming; DnsSocket = comm_open(SOCK_DGRAM, - 0, + IPPROTO_UDP, addr, 0, COMM_NONBLOCKING, diff --git a/src/forward.cc b/src/forward.cc index ad3e257fc1..b4c2bb7de0 100644 --- a/src/forward.cc +++ b/src/forward.cc @@ -1,6 +1,6 @@ /* - * $Id: forward.cc,v 1.97 2003/02/21 22:50:08 robertc Exp $ + * $Id: forward.cc,v 1.98 2003/02/23 00:08:04 robertc Exp $ * * DEBUG: section 17 Request Forwarding * AUTHOR: Duane Wessels @@ -555,7 +555,7 @@ fwdConnectStart(void *data) inet_ntoa(outgoing), tos); fd = comm_openex(SOCK_STREAM, - 0, + IPPROTO_TCP, outgoing, 0, COMM_NONBLOCKING, diff --git a/src/ftp.cc b/src/ftp.cc index 948b9c0965..7010a4bdd0 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.342 2003/02/21 22:50:08 robertc Exp $ + * $Id: ftp.cc,v 1.343 2003/02/23 00:08:04 robertc Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -2086,7 +2086,7 @@ ftpSendPasv(FtpStateData * ftpState) /* Open data channel with the same local address as control channel */ fd = comm_open(SOCK_STREAM, - 0, + IPPROTO_TCP, addr.sin_addr, 0, COMM_NONBLOCKING, @@ -2262,7 +2262,7 @@ ftpOpenListenSocket(FtpStateData * ftpState, int fallback) } fd = comm_open(SOCK_STREAM, - 0, + IPPROTO_TCP, addr.sin_addr, port, COMM_NONBLOCKING | (fallback ? COMM_REUSEADDR : 0), diff --git a/src/htcp.cc b/src/htcp.cc index 66c6baecd4..85fca8bbdd 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -1,6 +1,6 @@ /* - * $Id: htcp.cc,v 1.51 2003/02/21 22:50:09 robertc Exp $ + * $Id: htcp.cc,v 1.52 2003/02/23 00:08:04 robertc Exp $ * * DEBUG: section 31 Hypertext Caching Protocol * AUTHOR: Duane Wesssels @@ -1149,7 +1149,7 @@ htcpInit(void) enter_suid(); htcpInSocket = comm_open(SOCK_DGRAM, - 0, + IPPROTO_UDP, Config.Addrs.udp_incoming, Config.Port.htcp, COMM_NONBLOCKING, @@ -1167,7 +1167,7 @@ htcpInit(void) if (Config.Addrs.udp_outgoing.s_addr != no_addr.s_addr) { enter_suid(); htcpOutSocket = comm_open(SOCK_DGRAM, - 0, + IPPROTO_UDP, Config.Addrs.udp_outgoing, Config.Port.htcp, COMM_NONBLOCKING, diff --git a/src/icp_v2.cc b/src/icp_v2.cc index 882a58d68e..36486f3d75 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -1,6 +1,6 @@ /* - * $Id: icp_v2.cc,v 1.78 2003/02/21 22:50:09 robertc Exp $ + * $Id: icp_v2.cc,v 1.79 2003/02/23 00:08:04 robertc Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -673,7 +673,7 @@ icpConnectionsOpen(void) enter_suid(); theInIcpConnection = comm_open(SOCK_DGRAM, - 0, + IPPROTO_UDP, Config.Addrs.udp_incoming, port, COMM_NONBLOCKING, @@ -700,7 +700,7 @@ icpConnectionsOpen(void) if ((addr = Config.Addrs.udp_outgoing).s_addr != no_addr.s_addr) { enter_suid(); theOutIcpConnection = comm_open(SOCK_DGRAM, - 0, + IPPROTO_UDP, addr, port, COMM_NONBLOCKING, diff --git a/src/ident.cc b/src/ident.cc index 1180e34525..41790e94bb 100644 --- a/src/ident.cc +++ b/src/ident.cc @@ -1,6 +1,6 @@ /* - * $Id: ident.cc,v 1.66 2003/02/21 22:50:09 robertc Exp $ + * $Id: ident.cc,v 1.67 2003/02/23 00:08:04 robertc Exp $ * * DEBUG: section 30 Ident (RFC 931) * AUTHOR: Duane Wessels @@ -232,7 +232,7 @@ identStart(struct sockaddr_in *me, struct sockaddr_in *my_peer, IDCB * callback, } fd = comm_open(SOCK_STREAM, - 0, + IPPROTO_TCP, me->sin_addr, 0, COMM_NONBLOCKING, diff --git a/src/neighbors.cc b/src/neighbors.cc index 1b7364fa29..2058a03a3c 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1,6 +1,6 @@ /* - * $Id: neighbors.cc,v 1.317 2003/02/21 22:50:10 robertc Exp $ + * $Id: neighbors.cc,v 1.318 2003/02/23 00:08:04 robertc Exp $ * * DEBUG: section 15 Neighbor Routines * AUTHOR: Harvest Derived @@ -1391,7 +1391,7 @@ peerProbeConnect(peer * p) if (squid_curtime - p->stats.last_connect_probe < 1) return; /* don't probe to often */ - fd = comm_open(SOCK_STREAM, 0, getOutgoingAddr(NULL), + fd = comm_open(SOCK_STREAM, IPPROTO_TCP, getOutgoingAddr(NULL), 0, COMM_NONBLOCKING, p->host); if (fd < 0) diff --git a/src/pinger.cc b/src/pinger.cc index 96bfeee92a..dbc1c3c894 100644 --- a/src/pinger.cc +++ b/src/pinger.cc @@ -1,6 +1,6 @@ /* - * $Id: pinger.cc,v 1.50 2003/02/21 22:50:10 robertc Exp $ + * $Id: pinger.cc,v 1.51 2003/02/23 00:08:04 robertc Exp $ * * DEBUG: section 42 ICMP Pinger program * AUTHOR: Duane Wessels @@ -37,19 +37,99 @@ #if USE_ICMP +/* Native Windows port doesn't have netinet support, so we emulate it. + At this time, Cygwin lacks icmp support in its include files, so we need + to use the native Windows port definitions. + */ + +#if !defined(_SQUID_MSWIN_) && !defined(_SQUID_CYGWIN_) + +#include +#include +#include +#include + +#define PINGER_TIMEOUT 10 + +static int socket_from_squid = 0; +static int socket_to_squid = 1; + +#else /* _SQUID_MSWIN_ or _SQUID_CYGWIN_ */ + +#ifdef _SQUID_MSWIN_ + +#include +#include + +#define PINGER_TIMEOUT 5 + +static int socket_to_squid = -1; +#define socket_from_squid socket_to_squid + +#else /* _SQUID_CYGWIN_ */ + #include #include #include #include +#define PINGER_TIMEOUT 10 + +static int socket_from_squid = 0; +static int socket_to_squid = 1; + +#endif + +#define ICMP_ECHO 8 +#define ICMP_ECHOREPLY 0 + +typedef struct iphdr +{ + +u_int8_t ip_vhl: + 4; /* Length of the header in dwords */ + +u_int8_t version: + 4; /* Version of IP */ + u_int8_t tos; /* Type of service */ + u_int16_t total_len; /* Length of the packet in dwords */ + u_int16_t ident; /* unique identifier */ + u_int16_t flags; /* Flags */ + u_int8_t ip_ttl; /* Time to live */ + u_int8_t proto; /* Protocol number (TCP, UDP etc) */ + u_int16_t checksum; /* IP checksum */ + u_int32_t source_ip; + u_int32_t dest_ip; +} + +iphdr; + +/* ICMP header */ + +typedef struct icmphdr +{ + u_int8_t icmp_type; /* ICMP packet type */ + u_int8_t icmp_code; /* Type sub code */ + u_int16_t icmp_cksum; + u_int16_t icmp_id; + u_int16_t icmp_seq; + u_int32_t timestamp; /* not part of ICMP, but we need it */ +} + +icmphdr; + +#endif /* _SQUID_MSWIN_ */ + #ifndef _SQUID_LINUX_ #ifndef _SQUID_CYGWIN_ +#ifndef _SQUID_MSWIN_ #define icmphdr icmp #define iphdr ip #endif #endif +#endif -#if defined (_SQUID_LINUX_) || defined (_SQUID_CYGWIN_) +#if defined (_SQUID_LINUX_) #ifdef icmp_id #undef icmp_id #endif @@ -123,12 +203,52 @@ static void pingerRecv(void); static void pingerLog(struct icmphdr *, struct in_addr, int, int); static int ipHops(int ttl); static void pingerSendtoSquid(pingerReplyData * preply); +static void pingerOpen(void); +static void pingerClose(void); void pingerOpen(void) { struct protoent *proto = NULL; +#ifdef _SQUID_MSWIN_ + + WSADATA wsaData; + WSAPROTOCOL_INFO wpi; + char buf[sizeof(wpi)]; + int x; + + struct sockaddr_in PS; + + WSAStartup(2, &wsaData); + + getCurrentTime(); + _db_init(NULL, "ALL,1"); + setmode(0, O_BINARY); + setmode(1, O_BINARY); + x = read(0, buf, sizeof(wpi)); + + if (x < (int)sizeof(wpi)) { + getCurrentTime(); + debug(42, 0) ("pingerOpen: read: FD 0: %s\n", xstrerror()); + write(1, "ERR\n", 4); + exit(1); + } + + xmemcpy(&wpi, buf, sizeof(wpi)); + + write(1, "OK\n", 3); + x = read(0, buf, sizeof(PS)); + + if (x < (int)sizeof(PS)) { + getCurrentTime(); + debug(42, 0) ("pingerOpen: read: FD 0: %s\n", xstrerror()); + write(1, "ERR\n", 4); + exit(1); + } + + xmemcpy(&PS, buf, sizeof(PS)); +#endif if ((proto = getprotobyname("icmp")) == 0) { debug(42, 0) ("pingerOpen: unknown protocol: icmp\n"); @@ -144,12 +264,60 @@ pingerOpen(void) icmp_ident = getpid() & 0xffff; debug(42, 0) ("pinger: ICMP socket opened\n"); +#ifdef _SQUID_MSWIN_ + + socket_to_squid = + WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, + &wpi, 0, 0); + + if (socket_to_squid == -1) { + getCurrentTime(); + debug(42, 0) ("pingerOpen: WSASocket: %s\n", xstrerror()); + write(1, "ERR\n", 4); + exit(1); + } + + x = connect(socket_to_squid, (struct sockaddr *) &PS, sizeof(PS)); + + if (SOCKET_ERROR == x) { + getCurrentTime(); + debug(42, 0) ("pingerOpen: connect: %s\n", xstrerror()); + write(1, "ERR\n", 4); + exit(1); + } + + write(1, "OK\n", 3); + memset(buf, 0, sizeof(buf)); + x = recv(socket_to_squid, buf, sizeof(buf), 0); + + if (x < 3) { + debug(42, 0) ("icmpOpen: recv: %s\n", xstrerror()); + exit(1); + } + + x = send(socket_to_squid, buf, strlen(buf), 0); + + if (x < 3 || strncmp("OK\n", buf, 3)) { + debug(42, 0) ("icmpOpen: recv: %s\n", xstrerror()); + exit(1); + } + + getCurrentTime(); + debug(42, 0) ("pinger: Squid socket opened\n"); +#endif } void pingerClose(void) { close(icmp_sock); +#ifdef _SQUID_MSWIN_ + + shutdown(socket_to_squid, SD_BOTH); + close(socket_to_squid); + socket_to_squid = -1; +#endif + icmp_sock = -1; icmp_ident = 0; } @@ -327,7 +495,7 @@ in_cksum(unsigned short *ptr, int size) sum = (sum >> 16) + (sum & 0xffff); sum += (sum >> 16); - answer = ~sum; + answer = (unsigned short) ~sum; return (answer); } @@ -373,7 +541,7 @@ pingerReadRequest(void) int n; int guess_size; memset(&pecho, '\0', sizeof(pecho)); - n = recv(0, (char *) &pecho, sizeof(pecho), 0); + n = recv(socket_from_squid, (char *) &pecho, sizeof(pecho), 0); if (n < 0) return n; @@ -406,8 +574,9 @@ pingerSendtoSquid(pingerReplyData * preply) { int len = sizeof(pingerReplyData) - MAX_PKT_SZ + preply->psize; - if (send(1, (char *) preply, len, 0) < 0) { + if (send(socket_to_squid, (char *) preply, len, 0) < 0) { debug(50, 0) ("pinger: send: %s\n", xstrerror()); + pingerClose(); exit(1); } } @@ -453,35 +622,41 @@ main(int argc, char *argv[]) _db_init(NULL, debug_args); for (;;) { - tv.tv_sec = 10; + tv.tv_sec = PINGER_TIMEOUT; tv.tv_usec = 0; FD_ZERO(&R); - FD_SET(0, &R); + FD_SET(socket_from_squid, &R); FD_SET(icmp_sock, &R); x = select(icmp_sock + 1, &R, NULL, NULL, &tv); getCurrentTime(); - if (x < 0) + if (x < 0) { + pingerClose(); exit(1); + } - if (FD_ISSET(0, &R)) + if (FD_ISSET(socket_from_squid, &R)) if (pingerReadRequest() < 0) { debug(42, 0) ("Pinger exiting.\n"); + pingerClose(); exit(1); } if (FD_ISSET(icmp_sock, &R)) pingerRecv(); - if (10 + last_check_time < squid_curtime) { - if (send(1, (char *) &tv, 0, 0) < 0) + if (PINGER_TIMEOUT + last_check_time < squid_curtime) { + if (send(socket_to_squid, (char *) &tv, 0, 0) < 0) { + pingerClose(); exit(1); + } last_check_time = squid_curtime; } } /* NOTREACHED */ + return 0; } #else diff --git a/src/snmp_core.cc b/src/snmp_core.cc index dfa8f1572c..5d676cc520 100644 --- a/src/snmp_core.cc +++ b/src/snmp_core.cc @@ -1,6 +1,6 @@ /* - * $Id: snmp_core.cc,v 1.62 2003/02/21 22:50:10 robertc Exp $ + * $Id: snmp_core.cc,v 1.63 2003/02/23 00:08:04 robertc Exp $ * * DEBUG: section 49 SNMP support * AUTHOR: Glenn Chisholm @@ -363,7 +363,7 @@ snmpConnectionOpen(void) if ((port = Config.Port.snmp) > (u_short) 0) { enter_suid(); theInSnmpConnection = comm_open(SOCK_DGRAM, - 0, + IPPROTO_UDP, Config.Addrs.snmp_incoming, port, COMM_NONBLOCKING, @@ -381,7 +381,7 @@ snmpConnectionOpen(void) if (Config.Addrs.snmp_outgoing.s_addr != no_addr.s_addr) { enter_suid(); theOutSnmpConnection = comm_open(SOCK_DGRAM, - 0, + IPPROTO_UDP, Config.Addrs.snmp_outgoing, port, COMM_NONBLOCKING, diff --git a/src/squid.h b/src/squid.h index d0e2e7c923..6822479d5c 100644 --- a/src/squid.h +++ b/src/squid.h @@ -1,6 +1,6 @@ /* - * $Id: squid.h,v 1.230 2003/02/21 22:50:10 robertc Exp $ + * $Id: squid.h,v 1.231 2003/02/23 00:08:04 robertc Exp $ * * AUTHOR: Duane Wessels * @@ -423,4 +423,12 @@ extern "C" #define FD_READ_METHOD(fd, buf, len) (*fd_table[fd].read_method)(fd, buf, len) #define FD_WRITE_METHOD(fd, buf, len) (*fd_table[fd].write_method)(fd, buf, len) +#ifndef IPPROTO_UDP +#define IPPROTO_UDP 0 +#endif + +#ifndef IPPROTO_TCP +#define IPPROTO_TCP 0 +#endif + #endif /* SQUID_H */ diff --git a/src/tunnel.cc b/src/tunnel.cc index 8cbbf1d0e9..f676149400 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -1,6 +1,6 @@ /* - * $Id: tunnel.cc,v 1.136 2003/02/21 22:50:12 robertc Exp $ + * $Id: tunnel.cc,v 1.137 2003/02/23 00:08:04 robertc Exp $ * * DEBUG: section 26 Secure Sockets Layer Proxy * AUTHOR: Duane Wessels @@ -535,7 +535,7 @@ sslStart(clientHttpRequest * http, size_t * size_ptr, int *status_ptr) statCounter.server.other.requests++; /* Create socket. */ sock = comm_openex(SOCK_STREAM, - 0, + IPPROTO_TCP, getOutgoingAddr(request), 0, COMM_NONBLOCKING, diff --git a/src/wccp.cc b/src/wccp.cc index 93b19c14e7..f5c99f5825 100644 --- a/src/wccp.cc +++ b/src/wccp.cc @@ -1,6 +1,6 @@ /* - * $Id: wccp.cc,v 1.33 2003/02/21 22:50:13 robertc Exp $ + * $Id: wccp.cc,v 1.34 2003/02/23 00:08:04 robertc Exp $ * * DEBUG: section 80 WCCP Support * AUTHOR: Glenn Chisholm @@ -142,7 +142,7 @@ wccpConnectionOpen(void) } theInWccpConnection = comm_open(SOCK_DGRAM, - 0, + IPPROTO_UDP, Config.Wccp.incoming, port, COMM_NONBLOCKING, @@ -162,7 +162,7 @@ wccpConnectionOpen(void) if (Config.Wccp.outgoing.s_addr != no_addr.s_addr) { theOutWccpConnection = comm_open(SOCK_DGRAM, - 0, + IPPROTO_UDP, Config.Wccp.outgoing, port, COMM_NONBLOCKING,