]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Multicast Miss Stream code
authorwessels <>
Sat, 12 Dec 1998 03:06:49 +0000 (03:06 +0000)
committerwessels <>
Sat, 12 Dec 1998 03:06:49 +0000 (03:06 +0000)
src/access_log.cc
src/cf.data.pre
src/structs.h

index 7f2dd7f4aaf670396e3a299c673250adeb786214..bd9d0e1ef6d0c627346a95a76a09cb37f9db7943 100644 (file)
@@ -1,7 +1,7 @@
 
 
 /*
- * $Id: access_log.cc,v 1.44 1998/11/12 06:27:53 wessels Exp $
+ * $Id: access_log.cc,v 1.45 1998/12/11 20:06:49 wessels Exp $
  *
  * DEBUG: section 46    Access Log
  * AUTHOR: Duane Wessels
@@ -42,6 +42,12 @@ static char *log_quote(const char *header);
 static void accessLogSquid(AccessLogEntry * al, MemBuf * mb);
 static void accessLogCommon(AccessLogEntry * al, MemBuf * mb);
 
+#if MULTICAST_MISS_STREAM
+static int mcast_miss_fd = -1;
+static struct sockaddr_in mcast_miss_to;
+static void mcast_encode(unsigned int *, size_t, const unsigned int *);
+#endif
+
 const char *log_tags[] =
 {
     "NONE",
@@ -261,6 +267,25 @@ accessLogLog(AccessLogEntry * al)
     }
     file_write_mbuf(LogfileFD, -1, mb, NULL, NULL);
     safe_free(xbuf);
+#if MULTICAST_MISS_STREAM
+    if (al->cache.code != LOG_TCP_MISS)
+       (void) 0;
+    else if (al->http.method != METHOD_GET)
+       (void) 0;
+    else if (mcast_miss_fd < 0)
+       (void) 0;
+    else {
+       unsigned int ibuf[365];
+       size_t isize;
+       xstrncpy((char *) ibuf, al->url, 364 * sizeof(int));
+       isize = ((strlen(al->url) + 8) / 8) * 2;
+       mcast_encode((unsigned int *) ibuf, isize,
+               (const unsigned int *) Config.mcast_miss.encode_key);
+       comm_udp_sendto(mcast_miss_fd,
+           &mcast_miss_to, sizeof(mcast_miss_to),
+           ibuf, isize * sizeof(int));
+    }
+#endif
 }
 
 void
@@ -333,6 +358,27 @@ accessLogInit(void)
 #if FORW_VIA_DB
     fvdbInit();
 #endif
+#if MULTICAST_MISS_STREAM
+    if (Config.mcast_miss.addr.s_addr != no_addr.s_addr) {
+       memset(&mcast_miss_to, '\0', sizeof(mcast_miss_to));
+       mcast_miss_to.sin_family = AF_INET;
+       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,
+           Config.Addrs.udp_incoming,
+           Config.mcast_miss.port,
+           COMM_NONBLOCKING,
+           "Multicast Miss Stream");
+       if (mcast_miss_fd < 0)
+           fatal("Cannot open Multicast Miss Stream Socket");
+       debug(46, 1) ("Multicast Miss Stream Socket opened on FD %d\n",
+           mcast_miss_fd);
+       mcastSetTtl(mcast_miss_fd, 128);
+       if (strlen(Config.mcast_miss.encode_key) < 16)
+           fatal("mcast_encode_key is too short, must be 16 characters");
+    }
+#endif
 }
 
 const char *
@@ -436,3 +482,41 @@ fvdbClear(void)
 }
 
 #endif
+
+#if MULTICAST_MISS_STREAM
+/*
+ * From http://www.io.com/~paulhart/game/algorithms/tea.html
+ *
+ * size of 'ibuf' must be a multiple of 2.
+ * size of 'key' must be 4.
+ * 'ibuf' is modified in place, encrypted data is written in
+ * network byte order.
+ */
+static void
+mcast_encode(unsigned int *ibuf, size_t isize, const unsigned int *key)
+{
+    unsigned int y;
+    unsigned int z;
+    unsigned int sum;
+    const unsigned int delta = 0x9e3779b9;
+    unsigned int n = 32;
+    const unsigned int k0 = htonl(key[0]);
+    const unsigned int k1 = htonl(key[1]);
+    const unsigned int k2 = htonl(key[2]);
+    const unsigned int k3 = htonl(key[3]);
+    int i;
+    for (i = 0; i < isize; i += 2) {
+       y = htonl(ibuf[i]);
+       z = htonl(ibuf[i + 1]);
+       sum = 0;
+       for (n = 32; n; n--) {
+           sum += delta;
+           y += (z << 4) + (k0 ^ z) + (sum ^ (z >> 5)) + k1;
+           z += (y << 4) + (k2 ^ y) + (sum ^ (y >> 5)) + k3;
+       }
+       ibuf[i] = htonl(y);
+       ibuf[i + 1] = htonl(z);
+    }
+}
+
+#endif
index ab8b9e8aad730425fb0a907e9573e2786341f808..c5a2dbc9455a5174bfb07b88237af3386ddb854d 100644 (file)
@@ -1,6 +1,6 @@
 
 #
-# $Id: cf.data.pre,v 1.129 1998/12/10 20:10:13 wessels Exp $
+# $Id: cf.data.pre,v 1.130 1998/12/11 20:06:50 wessels Exp $
 #
 #
 # SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -2728,6 +2728,27 @@ DOC_START
 persistent_client_posts on
 DOC_END
 
+NAME: mcast_miss_addr
+IFDEF: MULTICAST_MISS_STREAM
+TYPE: address
+LOC: Config.mcast_miss.addr
+DEFAULT: 255.255.255.255
+DOC_NONE
+
+NAME: mcast_miss_port
+IFDEF: MULTICAST_MISS_STREAM
+TYPE: ushort
+LOC: Config.mcast_miss.port
+DEFAULT: 3135
+DOC_NONE
+
+NAME: mcast_miss_encode_key
+IFDEF: MULTICAST_MISS_STREAM
+TYPE: string
+LOC: Config.mcast_miss.encode_key
+DEFAULT: XXXXXXXXXXXXXXXX
+DOC_NONE
+
 NAME: prefer_direct
 TYPE: onoff
 LOC: Config.onoff.prefer_direct
index 56cd971a8fea536f1ca9c36c1afc9e7fe21c38ca..1fe89e700ddcc95dc3134f190e019ac37340625b 100644 (file)
@@ -1,7 +1,7 @@
 
 
 /*
- * $Id: structs.h,v 1.252 1998/12/09 23:01:03 wessels Exp $
+ * $Id: structs.h,v 1.253 1998/12/11 20:06:52 wessels Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -419,6 +419,13 @@ struct _SquidConfig {
     int max_open_disk_fds;
     int uri_whitespace;
     size_t rangeOffsetLimit;
+#if MULTICAST_MISS_STREAM
+    struct {
+       struct in_addr addr;
+       unsigned short port;
+       char *encode_key;
+    } mcast_miss;
+#endif
 };
 
 struct _SquidConfig2 {