#
# Makefile for the Squid Object Cache server
#
-# $Id: Makefile.in,v 1.74 1997/06/04 05:50:26 wessels Exp $
+# $Id: Makefile.in,v 1.75 1997/06/16 22:01:42 wessels Exp $
#
# Uncomment and customize the following to suit your needs:
#
ipcache.o \
main.o \
mime.o \
+ multicast.o \
neighbors.o \
net_db.o \
objcache.o \
/*
- * $Id: acl.cc,v 1.96 1997/06/04 06:15:44 wessels Exp $
+ * $Id: acl.cc,v 1.97 1997/06/16 22:01:43 wessels Exp $
*
* DEBUG: section 28 Access Control
* AUTHOR: Duane Wessels
if (checklist->state[ACL_DST_IP] == ACL_LOOKUP_NEEDED) {
checklist->state[ACL_DST_IP] = ACL_LOOKUP_PENDING;
ipcache_nbgethostbyname(checklist->request->host,
- -1,
aclLookupDstIPDone,
checklist);
return;
}
static void
-aclLookupDstIPDone(int fd, const ipcache_addrs * ia, void *data)
+aclLookupDstIPDone(const ipcache_addrs * ia, void *data)
{
aclCheck_t *checklist = data;
checklist->state[ACL_DST_IP] = ACL_LOOKUP_DONE;
/*
- * $Id: comm.cc,v 1.161 1997/06/04 07:02:55 wessels Exp $
+ * $Id: comm.cc,v 1.162 1997/06/16 22:01:44 wessels Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
int tries;
struct in_addr in_addr;
int locks;
+ int fd;
} ConnectStateData;
/* GLOBAL */
#endif
static void commSetTcpRcvbuf _PARAMS((int, int));
static PF commConnectFree;
-static void commConnectHandle _PARAMS((int fd, void *data));
-static void commHandleWrite _PARAMS((int fd, void *data));
+static PF commConnectHandle;
+static PF commHandleWrite;
static int fdIsHttpOrIcp _PARAMS((int fd));
static IPH commConnectDnsHandle;
-static void commConnectCallback _PARAMS((int fd, ConnectStateData * cs, int status));
+static void commConnectCallback _PARAMS((ConnectStateData * cs, int status));
static struct timeval zero_tv;
commConnectStart(int fd, const char *host, u_short port, CNCB * callback, void *data)
{
ConnectStateData *cs = xcalloc(1, sizeof(ConnectStateData));
+ cs->fd = fd;
cs->host = xstrdup(host);
cs->port = port;
cs->callback = callback;
cs->data = data;
comm_add_close_handler(fd, commConnectFree, cs);
cs->locks++;
- ipcache_nbgethostbyname(host, fd, commConnectDnsHandle, cs);
+ ipcache_nbgethostbyname(host, commConnectDnsHandle, cs);
}
static void
-commConnectDnsHandle(int fd, const ipcache_addrs * ia, void *data)
+commConnectDnsHandle(const ipcache_addrs * ia, void *data)
{
ConnectStateData *cs = data;
assert(cs->locks == 1);
cs->locks--;
if (ia == NULL) {
debug(5, 3) ("commConnectDnsHandle: Unknown host: %s\n", cs->host);
- commConnectCallback(fd, cs, COMM_ERR_DNS);
+ commConnectCallback(cs, COMM_ERR_DNS);
return;
}
cs->in_addr = ia->in_addrs[ia->cur];
- commConnectHandle(fd, cs);
+ commConnectHandle(cs->fd, cs);
}
static void
-commConnectCallback(int fd, ConnectStateData * cs, int status)
+commConnectCallback(ConnectStateData * cs, int status)
{
CNCB *callback = cs->callback;
void *data = cs->data;
+ int fd = cs->fd;
comm_remove_close_handler(fd, commConnectFree, cs);
commConnectFree(fd, cs);
callback(fd, status, data);
}
static void
-commConnectFree(int fd, void *data)
+commConnectFree(int fdunused, void *data)
{
ConnectStateData *cs = data;
if (cs->locks)
if (vizSock > -1)
vizHackSendPkt(&cs->S, 2);
ipcacheCycleAddr(cs->host);
- commConnectCallback(fd, cs, COMM_OK);
+ commConnectCallback(cs, COMM_OK);
break;
default:
if (commRetryConnect(fd, cs)) {
cs->S.sin_addr.s_addr = 0;
ipcacheCycleAddr(cs->host);
cs->locks++;
- ipcache_nbgethostbyname(cs->host, fd, commConnectDnsHandle, cs);
+ ipcache_nbgethostbyname(cs->host, commConnectDnsHandle, cs);
} else {
ipcacheRemoveBadAddr(cs->host, cs->S.sin_addr);
- commConnectCallback(fd, cs, COMM_ERR_CONNECT);
+ commConnectCallback(cs, COMM_ERR_CONNECT);
}
break;
}
safe_free(p);
}
-int
-comm_set_mcast_ttl(int fd, int mcast_ttl)
-{
-#ifdef IP_MULTICAST_TTL
- char ttl = (char) mcast_ttl;
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, 1) < 0)
- debug(50, 1) ("comm_set_mcast_ttl: FD %d, TTL: %d: %s\n",
- fd, mcast_ttl, xstrerror());
-#endif
- return 0;
-}
-
-void
-comm_join_mcast_groups(int fd, const ipcache_addrs * ia, void *data)
-{
-#ifdef IP_MULTICAST_TTL
- struct ip_mreq mr;
- int i;
- int x;
- char c = 0;
- if (ia == NULL) {
- debug(5, 0) ("comm_join_mcast_groups: Unknown host\n");
- return;
- }
- for (i = 0; i < (int) ia->count; i++) {
- debug(5, 10) ("Listening for ICP requests on %s\n",
- inet_ntoa(*(ia->in_addrs + i)));
- mr.imr_multiaddr.s_addr = (ia->in_addrs + i)->s_addr;
- mr.imr_interface.s_addr = INADDR_ANY;
- x = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
- (char *) &mr, sizeof(struct ip_mreq));
- if (x < 0)
- debug(5, 1) ("comm_join_mcast_groups: FD %d, [%s]\n",
- fd, inet_ntoa(*(ia->in_addrs + i)));
- x = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &c, 1);
- if (x < 0)
- debug(5, 1) ("Can't disable multicast loopback: %s\n", xstrerror());
- }
-#endif
-}
-
static void
commSetNoLinger(int fd)
{
/*
- * $Id: ftp.cc,v 1.121 1997/06/06 06:16:19 wessels Exp $
+ * $Id: ftp.cc,v 1.122 1997/06/16 22:01:45 wessels Exp $
*
* DEBUG: section 9 File Transfer Protocol (FTP)
* AUTHOR: Harvest Derived
FTP_REST_SUPPORTED,
FTP_PASV_ONLY,
FTP_AUTHENTICATED,
- FTP_IP_LOOKUP_PENDING,
FTP_HTTP_HEADER_SENT,
FTP_TRIED_NLST,
FTP_USE_BASE,
/* Local functions */
static CNCB ftpConnectDone;
static CNCB ftpPasvCallback;
-static IPH ftpConnect;
static PF ftpReadData;
static PF ftpStateFree;
static PF ftpTimeout;
ftpState->ctrl.fd = fd;
comm_add_close_handler(fd, ftpStateFree, ftpState);
commSetTimeout(fd, Config.Timeout.connect, ftpTimeout, ftpState);
- storeRegisterAbort(entry, ftpAbort, ftpState);
- ipcache_nbgethostbyname(request->host, fd, ftpConnect, ftpState);
-}
-
-static void
-ftpConnect(int fd, const ipcache_addrs * ia, void *data)
-{
- FtpStateData *ftpState = data;
- request_t *request = ftpState->request;
- StoreEntry *entry = ftpState->entry;
- EBIT_RESET(ftpState->flags, FTP_IP_LOOKUP_PENDING);
- assert(fd == ftpState->ctrl.fd);
- if (ia == NULL) {
- debug(9, 4) ("ftpConnect: Unknown host: %s\n", request->host);
- squid_error_entry(entry, ERR_DNS_FAIL, dns_error_message);
- comm_close(fd);
- return;
- }
- debug(9, 3) ("ftpConnect: %s is %s\n", request->host,
- inet_ntoa(ia->in_addrs[0]));
- /* Open connection. */
- commSetTimeout(fd, Config.Timeout.connect, ftpTimeout, ftpState);
commConnectStart(ftpState->ctrl.fd,
request->host,
request->port,
ftpState->data.buf = xmalloc(SQUID_TCP_SO_RCVBUF);
ftpState->data.size = SQUID_TCP_SO_RCVBUF;
ftpState->data.freefunc = xfree;
+ storeRegisterAbort(ftpState->entry, ftpAbort, ftpState);
commSetSelect(fd, COMM_SELECT_READ, ftpReadControlReply, ftpState, 0);
}
/*
- * $Id: ipcache.cc,v 1.120 1997/06/04 06:16:01 wessels Exp $
+ * $Id: ipcache.cc,v 1.121 1997/06/16 22:01:48 wessels Exp $
*
* DEBUG: section 14 IP Cache
* AUTHOR: Harvest Derived
#include "squid.h"
struct _ip_pending {
- int fd;
IPH *handler;
void *handlerData;
struct _ip_pending *next;
static ipcache_entry *ipcache_get _PARAMS((const char *));
static IPH dummy_handler;
static int ipcacheExpiredEntry _PARAMS((ipcache_entry *));
-static void ipcacheAddPending _PARAMS((ipcache_entry *, int fd, IPH *, void *));
+static void ipcacheAddPending _PARAMS((ipcache_entry *, IPH *, void *));
static void ipcacheEnqueue _PARAMS((ipcache_entry *));
static void *ipcacheDequeue _PARAMS((void));
static void ipcache_dnsDispatch _PARAMS((dnsserver_t *, ipcache_entry *));
if (p->handler) {
nhandler++;
dns_error_message = i->error_message;
- p->handler(p->fd,
- i->status == IP_CACHED ? &i->addrs : NULL,
+ p->handler(i->status == IP_CACHED ? &i->addrs : NULL,
p->handlerData);
}
safe_free(p);
}
static void
-ipcacheAddPending(ipcache_entry * i, int fd, IPH * handler, void *handlerData)
+ipcacheAddPending(ipcache_entry * i, IPH * handler, void *handlerData)
{
struct _ip_pending *pending = xcalloc(1, sizeof(struct _ip_pending));
struct _ip_pending **I = NULL;
i->lastref = squid_curtime;
- pending->fd = fd;
pending->handler = handler;
pending->handlerData = handlerData;
for (I = &(i->pending_head); *I; I = &((*I)->next));
}
void
-ipcache_nbgethostbyname(const char *name, int fd, IPH * handler, void *handlerData)
+ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData)
{
ipcache_entry *i = NULL;
dnsserver_t *dnsData = NULL;
if (!handler)
fatal_dump("ipcache_nbgethostbyname: NULL handler");
- debug(14, 4) ("ipcache_nbgethostbyname: FD %d: Name '%s'.\n", fd, name);
+ debug(14, 4) ("ipcache_nbgethostbyname: Name '%s'.\n", name);
IpcacheStats.requests++;
if (name == NULL || name[0] == '\0') {
debug(14, 4) ("ipcache_nbgethostbyname: Invalid name!\n");
- handler(fd, NULL, handlerData);
+ handler(NULL, handlerData);
return;
}
if ((addrs = ipcacheCheckNumeric(name))) {
- handler(fd, addrs, handlerData);
+ handler(addrs, handlerData);
return;
}
if ((i = ipcache_get(name))) {
debug(14, 5) ("ipcache_nbgethostbyname: MISS for '%s'\n", name);
IpcacheStats.misses++;
i = ipcacheAddNew(name, NULL, IP_PENDING);
- ipcacheAddPending(i, fd, handler, handlerData);
+ ipcacheAddPending(i, handler, handlerData);
} else if (i->status == IP_CACHED || i->status == IP_NEGATIVE_CACHED) {
/* HIT */
debug(14, 4) ("ipcache_nbgethostbyname: HIT for '%s'\n", name);
IpcacheStats.negative_hits++;
else
IpcacheStats.hits++;
- ipcacheAddPending(i, fd, handler, handlerData);
+ ipcacheAddPending(i, handler, handlerData);
ipcache_call_pending(i);
return;
} else if (i->status == IP_PENDING || i->status == IP_DISPATCHED) {
debug(14, 4) ("ipcache_nbgethostbyname: PENDING for '%s'\n", name);
IpcacheStats.pending_hits++;
- ipcacheAddPending(i, fd, handler, handlerData);
+ ipcacheAddPending(i, handler, handlerData);
if (squid_curtime - i->expires > 600) {
debug(14, 0) ("ipcache_nbgethostbyname: '%s' PENDING for %d seconds, aborting\n", name, squid_curtime + Config.negativeDnsTtl - i->expires);
ipcacheChangeKey(i);
if (p->handlerData != data)
continue;
p->handler = NULL;
- p->fd = -1;
n++;
}
}
}
}
if (flags & IP_LOOKUP_IF_MISS)
- ipcache_nbgethostbyname(name, -1, dummy_handler, NULL);
+ ipcache_nbgethostbyname(name, dummy_handler, NULL);
return NULL;
}
}
static void
-dummy_handler(int u1, const ipcache_addrs * addrs, void *u3)
+dummy_handler(const ipcache_addrs * addrs, void *u3)
{
return;
}
/*
- * $Id: main.cc,v 1.152 1997/06/04 07:00:31 wessels Exp $
+ * $Id: main.cc,v 1.153 1997/06/16 22:01:49 wessels Exp $
*
* DEBUG: section 1 Startup and Main Loop
* AUTHOR: Harvest Derived
icpHandleUdp,
NULL, 0);
for (s = Config.mcast_group_list; s; s = s->next)
- ipcache_nbgethostbyname(s->key,
- theInIcpConnection,
- comm_join_mcast_groups,
- NULL);
+ ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL);
debug(1, 1) ("Accepting ICP connections on port %d, FD %d.\n",
(int) port, theInIcpConnection);
"VizHack Port");
if (vizSock < 0)
fatal("Could not open Viz Socket");
-#if defined(IP_ADD_MEMBERSHIP) && defined(IP_MULTICAST_TTL)
- if (Config.vizHack.addr.s_addr > inet_addr("224.0.0.0")) {
- struct ip_mreq mr;
- char ttl = (char) Config.vizHack.mcast_ttl;
- memset(&mr, '\0', sizeof(struct ip_mreq));
- mr.imr_multiaddr.s_addr = Config.vizHack.addr.s_addr;
- mr.imr_interface.s_addr = INADDR_ANY;
- x = setsockopt(vizSock,
- IPPROTO_IP,
- IP_ADD_MEMBERSHIP,
- (char *) &mr,
- sizeof(struct ip_mreq));
- if (x < 0)
- debug(50, 1) ("IP_ADD_MEMBERSHIP: FD %d, addr %s: %s\n",
- vizSock, inet_ntoa(Config.vizHack.addr), xstrerror());
- x = setsockopt(vizSock,
- IPPROTO_IP,
- IP_MULTICAST_TTL,
- &ttl,
- sizeof(char));
- if (x < 0)
- debug(50, 1) ("IP_MULTICAST_TTL: FD %d, TTL %d: %s\n",
- vizSock, Config.vizHack.mcast_ttl, xstrerror());
- ttl = 0;
- x = sizeof(char);
- getsockopt(vizSock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, &x);
- debug(1, 0) ("vizSock on FD %d, ttl=%d\n", vizSock, (int) ttl);
- }
-#else
- debug(1, 0) ("vizSock: Could not join multicast group\n");
-#endif
+ mcastJoinVizSock();
memset(&Config.vizHack.S, '\0', sizeof(struct sockaddr_in));
Config.vizHack.S.sin_family = AF_INET;
Config.vizHack.S.sin_addr = Config.vizHack.addr;
/*
- * $Id: neighbors.cc,v 1.143 1997/06/04 06:16:03 wessels Exp $
+ * $Id: neighbors.cc,v 1.144 1997/06/16 22:01:50 wessels Exp $
*
* DEBUG: section 15 Neighbor Routines
* AUTHOR: Harvest Derived
debug(15, 4) ("neighborsUdpPing: pinging peer %s for '%s'\n",
p->host, url);
if (p->type == PEER_MULTICAST)
- comm_set_mcast_ttl(theOutIcpConnection, p->mcast.ttl);
+ mcastSetTtl(theOutIcpConnection, p->mcast.ttl);
reqnum = storeReqnum(entry, request->method);
debug(15, 3) ("neighborsUdpPing: key = '%s'\n", entry->key);
debug(15, 3) ("neighborsUdpPing: reqnum = %d\n", reqnum);
}
static void
-peerDNSConfigure(int fd, const ipcache_addrs * ia, void *data)
+peerDNSConfigure(const ipcache_addrs * ia, void *data)
{
peer *p = data;
struct sockaddr_in *ap;
next = p->next;
p->ip_lookup_pending = 1;
/* some random, bogus FD for ipcache */
- p->ipcache_fd = Squid_MaxFD + current_time.tv_usec;
- ipcache_nbgethostbyname(p->host, p->ipcache_fd, peerDNSConfigure, p);
+ p->test_fd = Squid_MaxFD + current_time.tv_usec;
+ ipcache_nbgethostbyname(p->host, peerDNSConfigure, p);
}
/* Reconfigure the peers every hour */
eventAdd("peerRefreshDNS", peerRefreshDNS, NULL, 3600);
if (fd < 0)
return;
p->ip_lookup_pending = 1;
- p->ipcache_fd = fd;
- ipcache_nbgethostbyname(p->host, fd, peerCheckConnect2, p);
+ p->test_fd = fd;
+ ipcache_nbgethostbyname(p->host, peerCheckConnect2, p);
}
static void
-peerCheckConnect2(int fd, const ipcache_addrs * ia, void *data)
+peerCheckConnect2(const ipcache_addrs * ia, void *data)
{
peer *p = data;
p->ip_lookup_pending = 0;
- commConnectStart(fd,
+ commConnectStart(p->test_fd,
p->host,
p->http_port,
peerCheckConnectDone,
mem->start_ping = current_time;
mem->icp_reply_callback = peerCountHandleIcpReply;
mem->ircb_data = psstate;
- comm_set_mcast_ttl(theOutIcpConnection, p->mcast.ttl);
+ mcastSetTtl(theOutIcpConnection, p->mcast.ttl);
p->mcast.reqnum = storeReqnum(fake, METHOD_GET);
query = icpCreateMessage(ICP_OP_QUERY, 0, url, p->mcast.reqnum, 0);
icpUdpSend(theOutIcpConnection,
/*
- * $Id: send-announce.cc,v 1.36 1997/06/04 06:16:08 wessels Exp $
+ * $Id: send-announce.cc,v 1.37 1997/06/16 22:01:51 wessels Exp $
*
* DEBUG: section 27 Cache Announcer
* AUTHOR: Duane Wessels
{
if (!Config.Announce.on)
return;
- ipcache_nbgethostbyname(Config.Announce.host, 0, send_announce, NULL);
+ ipcache_nbgethostbyname(Config.Announce.host, send_announce, NULL);
eventAdd("send_announce", start_announce, NULL, Config.Announce.rate);
}
static void
-send_announce(int fd, const ipcache_addrs * ia, void *data)
+send_announce(const ipcache_addrs * ia, void *data)
{
LOCAL_ARRAY(char, tbuf, 256);
LOCAL_ARRAY(char, sndbuf, BUFSIZ);
u_short port = Config.Announce.port;
int l;
int n;
+ int fd;
if (ia == NULL) {
debug(27, 1) ("send_announce: Unknown host '%s'\n", host);
return;
/*
- * $Id: squid.h,v 1.119 1997/06/02 01:06:16 wessels Exp $
+ * $Id: squid.h,v 1.120 1997/06/16 22:01:52 wessels Exp $
*
* AUTHOR: Duane Wessels
*
#include "objcache.h"
#include "refresh.h"
#include "unlinkd.h"
+#include "multicast.h"
#if !HAVE_TEMPNAM
#include "tempnam.h"