From: kostas <> Date: Sun, 28 Dec 1997 01:14:59 +0000 (+0000) Subject: Squid now caches whois replies for efficiency in retrieving as<->network X-Git-Tag: SQUID_3_0_PRE1~4349 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=53ad48e6f692d51d2b006993a16697080927447f;p=thirdparty%2Fsquid.git Squid now caches whois replies for efficiency in retrieving as<->network number info. Error pages are reloaded on SIGHUP. Minor snmp cleanup. --- diff --git a/src/acl.cc b/src/acl.cc index 2595061f9c..17036a0325 100644 --- a/src/acl.cc +++ b/src/acl.cc @@ -1,6 +1,6 @@ /* - * $Id: acl.cc,v 1.122 1997/12/05 21:02:06 wessels Exp $ + * $Id: acl.cc,v 1.123 1997/12/27 18:15:08 kostas Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -55,6 +55,7 @@ static int decode_addr(const char *, struct in_addr *, struct in_addr *); static void aclCheck(aclCheck_t * checklist); static void aclCheckCallback(aclCheck_t * checklist, allow_t answer); static IPH aclLookupDstIPDone; +static IPH aclLookupDstIPforASNDone; static FQDNH aclLookupSrcFQDNDone; static FQDNH aclLookupDstFQDNDone; static int aclReadProxyAuth(struct _acl_proxy_auth *p); @@ -1272,9 +1273,22 @@ aclMatchAcl(struct _acl *acl, aclCheck_t * checklist) } /* NOTREACHED */ case ACL_SRC_ASN: - return asnMatchIp(&acl->data, checklist->src_addr); + return asnMatchIp(acl->data, checklist->src_addr); case ACL_DST_ASN: - assert(0); + ia = ipcache_gethostbyname(r->host, IP_LOOKUP_IF_MISS); + if (ia) { + for (k = 0; k < (int) ia->count; k++) { + if (asnMatchIp(acl->data, ia->in_addrs[k])) + return 1; + } + return 0; + } else if (checklist->state[ACL_DST_ASN] == ACL_LOOKUP_NONE) { + debug(28, 3) ("asnMatchAcl: Can't yet compare '%s' ACL for '%s'\n", + acl->name, r->host); + checklist->state[ACL_DST_ASN] = ACL_LOOKUP_NEEDED; + } else { + return asnMatchIp(&acl->data, no_addr); + } return 0; #if USE_ARP_ACL case ACL_SRC_ARP: @@ -1330,12 +1344,19 @@ aclCheck(aclCheck_t * checklist) debug(28, 3) ("aclCheck: checking '%s'\n", A->cfgline); allow = A->allow; match = aclMatchAclList(A->acl_list, checklist); + if (checklist->state[ACL_DST_IP] == ACL_LOOKUP_NEEDED) { checklist->state[ACL_DST_IP] = ACL_LOOKUP_PENDING; ipcache_nbgethostbyname(checklist->request->host, aclLookupDstIPDone, checklist); return; + } else if (checklist->state[ACL_DST_ASN] == ACL_LOOKUP_NEEDED) { + checklist->state[ACL_DST_ASN] = ACL_LOOKUP_PENDING; + ipcache_nbgethostbyname(checklist->request->host, + aclLookupDstIPforASNDone, + checklist); + return; } else if (checklist->state[ACL_SRC_DOMAIN] == ACL_LOOKUP_NEEDED) { checklist->state[ACL_SRC_DOMAIN] = ACL_LOOKUP_PENDING; fqdncache_nbgethostbyaddr(checklist->src_addr, @@ -1403,6 +1424,13 @@ aclLookupDstIPDone(const ipcache_addrs * ia, void *data) checklist->state[ACL_DST_IP] = ACL_LOOKUP_DONE; aclCheck(checklist); } +static void +aclLookupDstIPforASNDone(const ipcache_addrs * ia, void *data) +{ + aclCheck_t *checklist = data; + checklist->state[ACL_DST_ASN] = ACL_LOOKUP_DONE; + aclCheck(checklist); +} static void aclLookupSrcFQDNDone(const char *fqdn, void *data) @@ -1427,15 +1455,19 @@ aclChecklistCreate(const struct _acl_access *A, char *user_agent, char *ident) { + int i; aclCheck_t *checklist = xcalloc(1, sizeof(aclCheck_t));; cbdataAdd(checklist); checklist->access_list = A; checklist->request = requestLink(request); checklist->src_addr = src_addr; + for (i = 0; i < ACL_ENUM_MAX; i++) + checklist->state[i] = ACL_LOOKUP_NONE; if (user_agent) xstrncpy(checklist->browser, user_agent, BROWSERNAMELEN); if (ident) xstrncpy(checklist->ident, ident, ICP_IDENT_SZ); + debug(28, 6) ("aclChecklistCreate: %x\n", checklist); return checklist; } @@ -1445,6 +1477,7 @@ aclNBCheck(aclCheck_t * checklist, PF callback, void *callback_data) checklist->callback = callback; checklist->callback_data = callback_data; cbdataLock(callback_data); + debug(28, 5) ("aclNBCheck: calling aclCheck with %x\n", checklist); aclCheck(checklist); } @@ -1976,7 +2009,7 @@ decode_eth(const char *asc, char *eth) { int a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0; if (sscanf(asc, "%x:%x:%x:%x:%x:%x", &a1, &a2, &a3, &a4, &a5, &a6) != 6) { - debug(28, 0)("decode_eth: Invalid ethernet address '%s'\n", asc); + debug(28, 0) ("decode_eth: Invalid ethernet address '%s'\n", asc); return 0; /* This is not valid address */ } eth[0] = (u_char) a1; @@ -1993,16 +2026,16 @@ aclParseArpData(const char *t) { LOCAL_ARRAY(char, eth, 256); /* addr1 ---> eth */ struct _acl_arp_data *q = xcalloc(1, sizeof(struct _acl_arp_data)); - debug(28, 5)( "aclParseArpData: %s\n", t); + debug(28, 5) ("aclParseArpData: %s\n", t); if (sscanf(t, "%[0-9a-f:]", eth) != 1) { - debug(28, 0)( "aclParseArpData: Bad ethernet address: '%s'\n", t); + debug(28, 0) ("aclParseArpData: Bad ethernet address: '%s'\n", t); safe_free(q); return NULL; } if (!decode_eth(eth, q->eth)) { - debug(28, 0)( "%s line %d: %s\n", + debug(28, 0) ("%s line %d: %s\n", cfg_filename, config_lineno, config_input_line); - debug(28, 0)( "aclParseArpData: Ignoring invalid ARP acl entry: can't parse '%s'\n", q); + debug(28, 0) ("aclParseArpData: Ignoring invalid ARP acl entry: can't parse '%s'\n", q); safe_free(q); return NULL; } @@ -2069,7 +2102,7 @@ aclMatchArp(void *dataptr, struct in_addr c) { splayNode **Top = dataptr; *Top = splay_splay(ð, *Top, aclArpNetworkCompare); - debug(28, 3)( "aclMatchArp: '%s' %s\n", + debug(28, 3) ("aclMatchArp: '%s' %s\n", inet_ntoa(c), splayLastResult ? "NOT found" : "found"); return !splayLastResult; } @@ -2079,10 +2112,10 @@ aclMatchArp(void *dataptr, struct in_addr c) { tree **data = dataptr; if (tree_srch(data, bintreeArpNetworkCompare, &c)) { - debug(28, 3)( "aclMatchArp: '%s' found\n", inet_ntoa(c)); + debug(28, 3) ("aclMatchArp: '%s' found\n", inet_ntoa(c)); return 1; } - debug(28, 3)( "aclMatchArp: '%s' NOT found\n", inet_ntoa(c)); + debug(28, 3) ("aclMatchArp: '%s' NOT found\n", inet_ntoa(c)); return 0; } #else @@ -2095,12 +2128,12 @@ aclMatchArp(void *dataptr, struct in_addr c) first = data; /* remember first element, will never be moved */ prev = NULL; /* previous element in the list */ while (data) { - debug(28, 3)( "aclMatchArp: ip = %s\n", inet_ntoa(c)); - debug(28, 3)( "aclMatchArp: arp = %x:%x:%x:%x:%x:%x\n", + debug(28, 3) ("aclMatchArp: ip = %s\n", inet_ntoa(c)); + debug(28, 3) ("aclMatchArp: arp = %x:%x:%x:%x:%x:%x\n", data->eth[0], data->eth[1], data->eth[2], data->eth[3], data->eth[4], data->eth[5]); if (checkARP(c.s_addr, data->eth)) { - debug(28, 3)( "aclMatchArp: returning 1\n"); + debug(28, 3) ("aclMatchArp: returning 1\n"); if (prev != NULL) { /* shift the element just found to the second position * in the list */ @@ -2113,7 +2146,7 @@ aclMatchArp(void *dataptr, struct in_addr c) prev = data; data = data->next; } - debug(28, 3)( "aclMatchArp: returning 0\n"); + debug(28, 3) ("aclMatchArp: returning 0\n"); return 0; } #endif /* USE_SPLAY_TREE */ @@ -2141,15 +2174,15 @@ checkARP(u_long ip, char *eth) struct sockaddr_inarp *sin; struct sockaddr_dl *sdl; if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) { - debug(28, 0)( "Can't estimate ARP table size!"); + debug(28, 0) ("Can't estimate ARP table size!"); return 0; } if ((buf = malloc(needed)) == NULL) { - debug(28, 0)( "Can't allocate temporary ARP table!"); + debug(28, 0) ("Can't allocate temporary ARP table!"); return 0; } if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { - debug(28, 0)( "Can't retrieve ARP table!"); + debug(28, 0) ("Can't retrieve ARP table!"); return 0; } lim = buf + needed; diff --git a/src/asn.cc b/src/asn.cc index ce787cd25e..21afc543dd 100644 --- a/src/asn.cc +++ b/src/asn.cc @@ -41,15 +41,10 @@ typedef u_char m_int[1 + sizeof(unsigned int)]; /* int in memory with length */ /* END of definitions for radix tree entries */ -static int asndbAddNet(char *, int); -static void asnLoadStart(int as); -static PF asnLoadClose; -static CNCB asnLoadConnected; -static PF asnLoadRead; -extern struct radix_node *rn_lookup(void *, void *, void *); /* Head for ip to asn radix tree */ struct radix_node_head *AS_tree_head; +#ifdef ASN_DIRECT /* passed to asnLoadStart when reading configuration options */ struct _asnLoadData { int as; @@ -58,6 +53,15 @@ struct _asnLoadData { off_t offset; }; +#endif + +struct _whoisState { + char *buf; + StoreEntry *entry; + request_t *request; + size_t bufsz; + off_t offset; +}; /* structure for as number information. it could be simply * an intlist but it's coded as a structure for future @@ -66,7 +70,18 @@ struct _as_info { intlist *as_number; int expires; }; + +struct _ASState { + StoreEntry *entry; + StoreEntry *asres_e; + request_t *request; + int flags; + int as_number; +}; + +typedef struct _ASState ASState; typedef struct _as_info as_info; +typedef struct _whoisState whoisState; /* entry into the radix tree */ struct _rtentry { @@ -78,6 +93,23 @@ struct _rtentry { typedef struct _rtentry rtentry; +static int asndbAddNet(char *, int); +#ifdef ASN_DIRECT +static CNCB asnLoadConnected; +static PF asnLoadRead; +static void asnLoadStart(int as); +static PF asnLoadClose; +#endif +static void asnCacheStart(int as); +static PF whoisClose; +static CNCB whoisConnectDone; +static PF whoisReadReply; +static STCB asHandleReply; + +static void destroyRadixNodeInfo(as_info *); + +/*static int destroyRadixNode(struct radix_node *,caddr_t); */ +extern struct radix_node *rn_lookup(void *, void *, void *); /* PUBLIC */ @@ -123,7 +155,11 @@ asnAclInitialize(acl * acls) if (a->type != ACL_DST_ASN && a->type != ACL_SRC_ASN) continue; for (i = a->data; i; i = i->next) { +#ifdef ASN_DIRECT asnLoadStart(i->i); +#else + asnCacheStart(i->i); +#endif } } } @@ -131,6 +167,103 @@ asnAclInitialize(acl * acls) /* PRIVATE */ +static void +asnCacheStart(int as) +{ + LOCAL_ARRAY(char, asres, 4096); + const cache_key *k; + StoreEntry *asres_e; + ASState *asState; + request_t *asres_r; + snprintf(asres, 4096, "whois://%s/!gAS%d", Config.as_whois_server, as); + k = storeKeyPublic(asres, METHOD_GET); + asState = xcalloc(1, sizeof(asState)); + cbdataAdd(asState); + asres_r = urlParse(METHOD_GET, asres); + asState->as_number = as; + asState->request = asres_r; + + if ((asres_e = storeGet(k)) == NULL) { + asres_e = storeCreateEntry(asres, asres, 0, METHOD_GET); + asState->asres_e = asres_e; + storeClientListAdd(asres_e, asState); + protoDispatch(0, asres_e, asres_r); + } else { + storeLockObject(asres_e); + asState->asres_e = asres_e; + storeClientListAdd(asres_e, asState); + } + storeClientCopy(asres_e, + 0, + 0, + 4096, + get_free_4k_page(), + asHandleReply, + asState); +} + +static void +asHandleReply(void *data, char *buf, ssize_t size) +{ + + ASState *asState = data; + StoreEntry *asres_e = asState->asres_e; + char *s, *t; + + debug(50, 3) ("asHandleReply: Called with size=%d.\n", size); + if (asres_e->store_status == STORE_ABORTED) { + put_free_4k_page(buf); + return; + } + if (size == 0) { + put_free_4k_page(buf); + return; + } else if (size < 0) { + put_free_4k_page(buf); + return; + } + if (asres_e->store_status == STORE_PENDING) { + storeClientCopy(asres_e, + size, + 0, + SM_PAGE_SIZE, + buf, + asHandleReply, + asState); + return; + } +/* XXX do the processing here */ + s = buf; + while (*s) { + for (t = s; *t; t++) { + if (isspace(*t)) + break; + } + if (*t == '\0') { + /* oof, word should continue on next block */ + break; + } + *t = '\0'; + debug(53, 4) ("asHandleReply: AS# %s (%d) '\n", s, asState->as_number); + asndbAddNet(s, asState->as_number); + s = t + 1; + while (*s && isspace(*s)) + s++; + } + + assert(asres_e->mem_obj->reply); + storeUnregister(asres_e, asState); + storeUnlockObject(asres_e); + requestUnlink(asState->request); +/* XXX this dumps core, don't know why */ +#if 0 + cbdataFree(asState); +#endif +} + + +#ifdef ASN_DIRECT + /* connects to whois server to find out networks belonging to * a certain AS */ @@ -140,15 +273,15 @@ asnLoadStart(int as) int fd; struct _asnLoadData *p = xcalloc(1, sizeof(struct _asnLoadData)); cbdataAdd(p); - debug(53, 1) ("asnLoad: AS# %d\n", as); + debug(53, 1) ("asnLoadStart: AS# %d\n", as); p->as = as; fd = comm_open(SOCK_STREAM, 0, any_addr, 0, COMM_NONBLOCKING, "asnLoad"); if (fd == COMM_ERROR) { - debug(53, 0) ("asnLoad: failed to open a socket\n"); + debug(53, 0) ("asnLoadStart: failed to open a socket\n"); return; } comm_add_close_handler(fd, asnLoadClose, p); - commConnectStart(fd, "whois.ra.net", WHOIS_PORT, asnLoadConnected, p); + commConnectStart(fd, Config.as_whois_server, WHOIS_PORT, asnLoadConnected, p); } @@ -159,7 +292,7 @@ static void asnLoadClose(int fdnotused, void *data) { struct _asnLoadData *p = data; - debug(53, 6) ("asnLoadClose called\n"); + debug(53, 6) ("asnLoadClose: called\n"); cbdataFree(p); } @@ -239,6 +372,7 @@ asnLoadRead(int fd, void *data) commSetSelect(fd, COMM_SELECT_READ, asnLoadRead, p, Config.Timeout.read); } +#endif /* initialize the radix tree structure */ @@ -271,7 +405,7 @@ asndbAddNet(char *as_string, int as_number) t = index(as_string, '/'); if (t == NULL) { - debug(53, 3) ("asndbAddNet: failed, no network.\n"); + debug(53, 3) ("asndbAddNet: failed, invalid response from whois server.\n"); return 0; } *t = '\0'; @@ -291,7 +425,7 @@ asndbAddNet(char *as_string, int as_number) store_m_int(mask, e->e_mask); rn = rn_lookup(e->e_addr, e->e_mask, AS_tree_head); if (rn != 0) { - debug(53, 3) ("Oops. Found a network with multiple AS numbers!\n"); + debug(53, 3) ("asndbAddNet: warning: Found a network with multiple AS numbers!\n"); info = ((rtentry *) rn)->e_info; for (Tail = &(info->as_number); *Tail; Tail = &((*Tail)->next)); q = xcalloc(1, sizeof(intlist)); @@ -313,10 +447,133 @@ asndbAddNet(char *as_string, int as_number) } if (rn == 0) { xfree(e); - debug(53, 3) ("Could not add entry.\n"); + debug(53, 3) ("asndbAddNet: Could not add entry.\n"); return 0; } e->e_info = info; - debug(53, 3) ("added successfully.\n"); + debug(53, 3) ("asndbAddNet: added successfully.\n"); + return 1; +} + +static int +destroyRadixNode(struct radix_node *rn, void *w) +{ + struct radix_node_head *rnh = (struct radix_node_head *) w; + + if (rn && !(rn->rn_flags & RNF_ROOT)) { + rtentry *e = (rtentry *) rn; + rn = rn_delete(rn->rn_key, rn->rn_mask, rnh); + if (rn == 0) + debug(53, 3) ("destroyRadixNode: internal screwup\n"); + destroyRadixNodeInfo(e->e_info); + xfree(rn); + } return 1; } + +void +asnCleanup() +{ + rn_walktree(AS_tree_head, destroyRadixNode, AS_tree_head); + destroyRadixNode((struct radix_node *) 0, (void *) AS_tree_head); +} + +static void +destroyRadixNodeInfo(as_info * e_info) +{ + intlist *first, *prev; + intlist *data = e_info->as_number; + first = data; + prev = NULL; + while (data) { + prev = data; + data = data->next; + xfree(prev); + } + xfree(data); +} + + +void +whoisStart(request_t * request, StoreEntry * entry) +{ + int fd; + whoisState *p = xcalloc(1, sizeof(whoisState)); + p->request = request; + p->entry = entry; + cbdataAdd(p); + + fd = comm_open(SOCK_STREAM, 0, any_addr, 0, COMM_NONBLOCKING, "whois"); + if (fd == COMM_ERROR) { + debug(53, 0) ("whoisStart: failed to open a socket\n"); + return; + } + comm_add_close_handler(fd, whoisClose, p); + commConnectStart(fd, request->host, request->port, whoisConnectDone, p); +} + +static void +whoisConnectDone(int fd, int status, void *data) +{ + whoisState *p = data; + char buf[128]; + if (status != COMM_OK) { + debug(53, 0) ("whoisConnectDone: connection failed\n"); + comm_close(fd); + return; + } + snprintf(buf, 128, "%s\r\n", p->request->urlpath + 1); + p->offset = 0; + p->bufsz = 4096; + p->buf = get_free_4k_page(); + debug(53, 1) ("whoisConnectDone: FD %d, '%s'\n", fd, p->request->urlpath + 1); + comm_write(fd, xstrdup(buf), strlen(buf), NULL, p, xfree); + commSetSelect(fd, COMM_SELECT_READ, whoisReadReply, p, Config.Timeout.read); +} + +static void +whoisReadReply(int fd, void *data) +{ + whoisState *p = data; + StoreEntry *entry = p->entry; + char *s; + size_t readsz; + int len; + + readsz = p->bufsz - p->offset; + readsz--; + debug(53, 6) ("whoisReadReply: offset = %d\n", p->offset); + s = p->buf + p->offset; + len = read(fd, s, readsz); + debug(53, 6) ("whoisReadReply: read %d bytes\n", len); + if (len <= 0) { + debug(53, 5) ("whoisReadReply: got EOF (%s)\n", p->buf); + comm_close(fd); + return; + } + storeAppend(entry, s, len); + fd_bytes(fd, len, FD_READ); + p->offset += len; + *(s + len) = '\0'; + if (*s) { + /* expect more */ + debug(53, 6) ("whoisReadReply: expecting more\n"); + xstrncpy(p->buf, s, p->bufsz); + p->offset = strlen(p->buf); + debug(53, 6) ("whoisReadReply: p->buf = '%s'\n", p->buf); + } else { + p->offset = 0; + } + commSetSelect(fd, COMM_SELECT_READ, whoisReadReply, p, Config.Timeout.read); +} + +static void +whoisClose(int fdnotused, void *data) +{ + whoisState *p = data; + StoreEntry *entry = p->entry; + debug(53, 6) ("whoisClose called\n"); + storeComplete(entry); + /* XXX free up whoisState */ + cbdataFree(p); +} diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 5437a04f77..e698d19737 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.238 1997/12/03 01:29:56 wessels Exp $ + * $Id: cache_cf.cc,v 1.239 1997/12/27 18:15:07 kostas Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -485,6 +485,12 @@ check_null_cachedir(struct _cacheSwap swap) return swap.swapDirs == NULL; } +static int +check_null_string(char *s) +{ + return s == NULL; +} + static void parse_cachedir(struct _cacheSwap *swap) { @@ -719,6 +725,7 @@ parse_peeracl(void) { char *host = NULL; char *aclname = NULL; + if (!(host = strtok(NULL, w_space))) self_destruct(); while ((aclname = strtok(NULL, list_sep))) { diff --git a/src/cf.data.pre b/src/cf.data.pre index cf1112dc13..7f7d2120bc 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -2091,4 +2091,13 @@ DOC_START snmp_agent_conf community readwrite all all DOC_END +NAME: as_whois_server +TYPE: string +LOC: Config.as_whois_server +DEFAULT: whois.ra.net +DEFAULT_IF_NONE: whois.ra.net +DOC_START + WHOIS server to query for AS numbers. +DOC_END + EOF diff --git a/src/enums.h b/src/enums.h index 70c65502d2..458a982da6 100644 --- a/src/enums.h +++ b/src/enums.h @@ -254,6 +254,7 @@ typedef enum { PROTO_CACHEOBJ, PROTO_ICP, PROTO_URN, + PROTO_WHOIS, PROTO_MAX } protocol_t; diff --git a/src/errorpage.cc b/src/errorpage.cc index ea09b2af1c..413e259d17 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -1,6 +1,6 @@ /* - * $Id: errorpage.cc,v 1.112 1997/12/08 15:14:37 wessels Exp $ + * $Id: errorpage.cc,v 1.113 1997/12/27 18:15:05 kostas Exp $ * * DEBUG: section 4 Error Generation * AUTHOR: Duane Wessels @@ -79,6 +79,14 @@ errorInitialize(void) } } +void +errorFree(void) +{ + int i; + for (i = ERR_NONE + 1; i < ERR_MAX; i++) + safe_free(error_text[i]); +} + /* * Function: errorCon * @@ -237,7 +245,7 @@ errorConvert(char token, ErrorState * err) break; case 'E': if (err->xerrno) - snprintf(buf, CVT_BUF_SZ, "(%d) %s", err->xerrno, strerror(err->xerrno)); + snprintf(buf, CVT_BUF_SZ, "(%d) %s", err->xerrno, strerror(err->xerrno)); else snprintf(buf, CVT_BUF_SZ, "[No Error]"); break; diff --git a/src/main.cc b/src/main.cc index c0a2983beb..b36dd4d9bb 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.197 1997/11/24 18:27:17 wessels Exp $ + * $Id: main.cc,v 1.198 1997/12/27 18:15:04 kostas Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -324,6 +324,7 @@ serverConnectionsOpen(void) clientdbInit(); icmpOpen(); netdbInit(); + asndbInit(); peerSelectInit(); } @@ -374,12 +375,16 @@ mainReconfigure(void) theOutIcpConnection = -1; } dnsShutdownServers(); + asnCleanup(); redirectShutdownServers(); storeDirCloseSwapLogs(); + errorFree(); parseConfigFile(ConfigFile); _db_init(Config.Log.log, Config.debugOptions); + asnAclInitialize(Config.aclList); /* reload network->AS database */ ipcache_restart(); /* clear stuck entries */ fqdncache_restart(); /* sigh, fqdncache too */ + errorInitialize(); /* reload error pages */ dnsOpenServers(); redirectOpenServers(); serverConnectionsOpen(); @@ -439,7 +444,6 @@ mainInitialize(void) useragentOpenLog(); errorInitialize(); accessLogInit(); - asnAclInitialize(Config.aclList); #if MALLOC_DBG malloc_debug(0, malloc_debug_level); @@ -453,7 +457,7 @@ mainInitialize(void) stat_init(&ICPCacheInfo, NULL); objcacheInit(); storeInit(); - + asnAclInitialize(Config.aclList); if (Config.effectiveUser) { /* we were probably started as root, so cd to a swap * directory in case we dump core */ diff --git a/src/mib.txt b/src/mib.txt index a81183fdcc..7e9bdc72d7 100644 --- a/src/mib.txt +++ b/src/mib.txt @@ -16,14 +16,16 @@ SQUID-MIB DEFINITIONS ::= BEGIN -- definitions included for standalone agent/managers -- -mgmt OBJECT IDENTIFIER ::= { iso org(3) dod(6) internet(1) 2 } -mib OBJECT IDENTIFIER ::= { mgmt 1 } -directory OBJECT IDENTIFIER ::= { internet 1 } -experimental OBJECT IDENTIFIER ::= { internet 3 } -private OBJECT IDENTIFIER ::= { internet 4 } -enterprises OBJECT IDENTIFIER ::= { private 1 } -nsfnet OBJECT IDENTIFIER ::= { experimental 25 } -squid OBJECT IDENTIFIER ::= { nsfnet 17 } +--mgmt OBJECT IDENTIFIER ::= { iso org(3) dod(6) internet(1) 2 } +--mib OBJECT IDENTIFIER ::= { mgmt 1 } +--directory OBJECT IDENTIFIER ::= { internet 1 } +--experimental OBJECT IDENTIFIER ::= { internet 3 } +--private OBJECT IDENTIFIER ::= { internet 4 } +--enterprises OBJECT IDENTIFIER ::= { private 1 } +--nsfnet OBJECT IDENTIFIER ::= { experimental 25 } +squid OBJECT IDENTIFIER ::= { iso org(3) dod(6) internet(1) experimental(3) nsfnet(25) 17 } +-- squid OBJECT IDENTIFIER ::= { nsfnet 17 } + -- -- Major MIB groups diff --git a/src/snmp_agent.cc b/src/snmp_agent.cc index 16385b01ed..ac6d73b101 100644 --- a/src/snmp_agent.cc +++ b/src/snmp_agent.cc @@ -1,4 +1,4 @@ -#if SQUID_SNMP +#ifdef SQUID_SNMP /* * Simple Network Management Protocol (RFC 1067). * @@ -373,7 +373,7 @@ snmp_agent_parse(sn_data, length, out_sn_data, out_length, sourceip, ireqid) create_toobig(out_auth, *out_length, reqid, pi); break; } /* else FALLTHRU */ -#endif +#lendif case SNMP_ERR_NOACCESS: case SNMP_ERR_WRONGTYPE: case SNMP_ERR_WRONGLENGTH: @@ -656,31 +656,6 @@ create_identical(snmp_in, snmp_out, snmp_length, errstat, errindex) return 1; } -#ifdef KINETICS -struct pbuf * -definitelyGetBuf() -{ - struct pbuf *p; - - K_PGET(PT_DATA, p); - while (p == 0) { -#ifdef notdef - if (pq->pq_head != NULL) { - K_PDEQ(SPLIMP, pq, p); - if (p) - K_PFREE(p); - } else if (sendq->pq_head != NULL) { - K_PDEQ(SPLIMP, sendq, p); - if (p) - K_PFREE(p); - } -#endif - K_PGET(PT_DATA, p); - } - return p; -} -#endif - static int check_auth(session, sn_data, length, pp, plen, ueret) struct snmp_session *session; @@ -1015,5 +990,4 @@ bulk_var_op_list(sn_data, length, out_sn_data, out_length, non_repeaters, max_re *index = 0; return SNMP_ERR_NOERROR; } - #endif diff --git a/src/structs.h b/src/structs.h index 9334e428b4..493d598518 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,4 +1,5 @@ + struct _acl_ip_data { struct in_addr addr1; /* if addr2 non-zero then its a range */ struct in_addr addr2; @@ -36,11 +37,12 @@ struct _acl_deny_info_list { #if USE_ARP_ACL struct _acl_arp_data { - unsigned char eth[6]; + unsigned char eth[6]; #ifndef USE_SPLAY_TREE - struct _acl_arp_data *next; + struct _acl_arp_data *next; #endif }; + #endif #if SQUID_SNMP @@ -193,6 +195,7 @@ struct _SquidConfig { communityEntry *communities; } Snmp; #endif + char *as_whois_server; struct { char *log; char *access; @@ -289,6 +292,7 @@ struct _SquidConfig { struct _acl_access *miss; struct _acl_access *NeverDirect; struct _acl_access *AlwaysDirect; + struct _acl_access *ASlists; } accessList; struct _acl_deny_info_list *denyInfoList; struct { diff --git a/src/tools.cc b/src/tools.cc index c1a38f2509..40b8a48709 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -1,6 +1,6 @@ /* - * $Id: tools.cc,v 1.134 1997/12/06 05:17:03 wessels Exp $ + * $Id: tools.cc,v 1.135 1997/12/27 18:15:00 kostas Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -396,6 +396,7 @@ normal_shutdown(void) netdbFreeMemory(); ipcacheFreeMemory(); fqdncacheFreeMemory(); + asndbFreeMemory(); #endif file_close(0); file_close(1); diff --git a/src/url.cc b/src/url.cc index 060feb5657..51814289eb 100644 --- a/src/url.cc +++ b/src/url.cc @@ -1,6 +1,6 @@ /* - * $Id: url.cc,v 1.71 1997/12/06 19:25:42 wessels Exp $ + * $Id: url.cc,v 1.72 1997/12/27 18:14:59 kostas Exp $ * * DEBUG: section 23 URL Parsing * AUTHOR: Duane Wessels @@ -53,12 +53,13 @@ const char *ProtocolStr[] = "cache_object", "icp", "urn", + "whois", "TOTAL" }; static int url_acceptable[256]; static const char *const hex = "0123456789abcdef"; -static request_t * urnParse(method_t method, char *urn); +static request_t *urnParse(method_t method, char *urn); /* convert %xx in url string to a character * Allocate a new string and return a pointer to converted string */ @@ -105,7 +106,7 @@ urlInitialize(void) url_acceptable[i] = 0; for (; *good; good++) url_acceptable[(unsigned int) *good] = 1; - assert(sizeof(ProtocolStr) == (PROTO_MAX + 1) * sizeof(char *)); + assert(sizeof(ProtocolStr) == (PROTO_MAX + 1) * sizeof(char *)); } @@ -173,6 +174,8 @@ urlParseProtocol(const char *s) return PROTO_CACHEOBJ; if (strncasecmp(s, "urn", 3) == 0) return PROTO_URN; + if (strncasecmp(s, "whois", 5) == 0) + return PROTO_WHOIS; return PROTO_NONE; } @@ -191,6 +194,8 @@ urlDefaultPort(protocol_t p) return 210; case PROTO_CACHEOBJ: return CACHE_HTTP_PORT; + case PROTO_WHOIS: + return 43; default: return 0; } @@ -283,7 +288,7 @@ static request_t * urnParse(method_t method, char *urn) { request_t *request = NULL; - debug(50,5)("urnParse: %s\n", urn); + debug(50, 5) ("urnParse: %s\n", urn); request = get_free_request_t(); request->method = method; request->protocol = PROTO_URN; @@ -302,23 +307,24 @@ urlCanonical(const request_t * request, char *buf) buf = urlbuf; if (request->protocol == PROTO_URN) { snprintf(buf, MAX_URL, "urn:%s", request->urlpath); - } else switch (request->method) { - case METHOD_CONNECT: - snprintf(buf, MAX_URL, "%s:%d", request->host, request->port); - break; - default: - portbuf[0] = '\0'; - if (request->port != urlDefaultPort(request->protocol)) - snprintf(portbuf, 32, ":%d", request->port); - snprintf(buf, MAX_URL, "%s://%s%s%s%s%s", - ProtocolStr[request->protocol], - request->login, - *request->login ? "@" : null_string, - request->host, - portbuf, - request->urlpath); - break; - } + } else + switch (request->method) { + case METHOD_CONNECT: + snprintf(buf, MAX_URL, "%s:%d", request->host, request->port); + break; + default: + portbuf[0] = '\0'; + if (request->port != urlDefaultPort(request->protocol)) + snprintf(portbuf, 32, ":%d", request->port); + snprintf(buf, MAX_URL, "%s://%s%s%s%s%s", + ProtocolStr[request->protocol], + request->login, + *request->login ? "@" : null_string, + request->host, + portbuf, + request->urlpath); + break; + } return buf; } @@ -331,31 +337,32 @@ urlCanonicalClean(const request_t * request) char *t; if (request->protocol == PROTO_URN) { snprintf(buf, MAX_URL, "urn:%s", request->urlpath); - } else switch (request->method) { - case METHOD_CONNECT: - snprintf(buf, MAX_URL, "%s:%d", request->host, request->port); - break; - default: - portbuf[0] = '\0'; - if (request->port != urlDefaultPort(request->protocol)) - snprintf(portbuf, 32, ":%d", request->port); - loginbuf[0] = '\0'; - if (strlen(request->login) > 0) { - strcpy(loginbuf, request->login); - if ((t = strchr(loginbuf, ':'))) + } else + switch (request->method) { + case METHOD_CONNECT: + snprintf(buf, MAX_URL, "%s:%d", request->host, request->port); + break; + default: + portbuf[0] = '\0'; + if (request->port != urlDefaultPort(request->protocol)) + snprintf(portbuf, 32, ":%d", request->port); + loginbuf[0] = '\0'; + if (strlen(request->login) > 0) { + strcpy(loginbuf, request->login); + if ((t = strchr(loginbuf, ':'))) + *t = '\0'; + strcat(loginbuf, "@"); + } + snprintf(buf, MAX_URL, "%s://%s%s%s%s", + ProtocolStr[request->protocol], + loginbuf, + request->host, + portbuf, + request->urlpath); + if ((t = strchr(buf, '?'))) *t = '\0'; - strcat(loginbuf, "@"); + break; } - snprintf(buf, MAX_URL, "%s://%s%s%s%s", - ProtocolStr[request->protocol], - loginbuf, - request->host, - portbuf, - request->urlpath); - if ((t = strchr(buf, '?'))) - *t = '\0'; - break; - } return buf; }