]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Summary: More Windows Merges.
authorrobertc <>
Sun, 23 Feb 2003 07:08:03 +0000 (07:08 +0000)
committerrobertc <>
Sun, 23 Feb 2003 07:08:03 +0000 (07:08 +0000)
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

14 files changed:
src/access_log.cc
src/client_side.cc
src/dns_internal.cc
src/forward.cc
src/ftp.cc
src/htcp.cc
src/icp_v2.cc
src/ident.cc
src/neighbors.cc
src/pinger.cc
src/snmp_core.cc
src/squid.h
src/tunnel.cc
src/wccp.cc

index 34862558f3306e9fbc987cc1b19ece98ab54fc02..8c481e4b8cef7df451908a32dbe6d7bc1b6a0eef 100644 (file)
@@ -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,
index ca0a40902add51bceac51629cbc6995b851d5f3a..47462d88b67be80790b113b35fbd880c0197cd6c 100644 (file)
@@ -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();
index 3101f7b083b5af8b6078c819c7dcedfa26e55a5c..2636eb38697e4dee3ac09d28b6c9f07fc2466048 100644 (file)
@@ -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,
index ad3e257fc131a476d0d7ea692497e7ac832684fd..b4c2bb7de0969d3214f8013f6c01dd49fffefc97 100644 (file)
@@ -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,
index 948b9c096575d00255721cd77a1a52e62a4b756b..7010a4bdd08fd3ffc68ccb8d0381c17e6150dce1 100644 (file)
@@ -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),
index 66c6baecd41298af71dbf6399c73bd5b0bea3f01..85fca8bbddcb56e7c7d4dc8c44a969df819c5f37 100644 (file)
@@ -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,
index 882a58d68ed1daf6d4bd585701a6d50dac69fb47..36486f3d7538a1e2d3392905ef292343708bc47d 100644 (file)
@@ -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,
index 1180e34525e25fe32c234293f9040ae5a326a1d4..41790e94bb79b38d32c19296f05ef0547e1a56d8 100644 (file)
@@ -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,
index 1b7364fa29d30c45117f2c524c603b10e1ed5c58..2058a03a3c723b9847b50111949f49dcd3d014ba 100644 (file)
@@ -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)
index 96bfeee92a375f2fbc7dcea4e877b13af6cdf4ce..dbc1c3c8943d2c0ff361de409b6a222022844092 100644 (file)
@@ -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
 
 #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 <netinet/in_systm.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <netinet/ip_icmp.h>
+
+#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 <winsock2.h>
+#include <process.h>
+
+#define PINGER_TIMEOUT 5
+
+static int socket_to_squid = -1;
+#define socket_from_squid socket_to_squid
+
+#else /* _SQUID_CYGWIN_ */
+
 #include <netinet/in_systm.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
 #include <netinet/ip_icmp.h>
 
+#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
index dfa8f1572cfd7baa05e4e44eb0102f1d562a7da6..5d676cc520c5a0292ffefa3fe3f7d31bd36721a4 100644 (file)
@@ -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,
index d0e2e7c923d3f0d3a0e8a590869ee8685f839a97..6822479d5ca52ba4a2ba653acfb7d7bb8aa70a64 100644 (file)
@@ -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 */
index 8cbbf1d0e9d9d40581991d9bfd4d95ef90c0bb35..f676149400fc2799ad559d49c027788f51c87427 100644 (file)
@@ -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,
index 93b19c14e7c6e6ec57f60e6e033845c5c7e475fa..f5c99f5825dad1096948acb753e2b4a1f81f7a24 100644 (file)
@@ -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,