Esempio n. 1
0
void
neighbors_init(void)
{
    struct sockaddr_in name;
    socklen_t len = sizeof(struct sockaddr_in);
    struct servent *sep = NULL;
    const char *me = getMyHostname();
    peer *this;
    peer *next;
    int fd = theInIcpConnection;
    if (fd >= 0) {
	memset(&name, '\0', sizeof(struct sockaddr_in));
	if (getsockname(fd, (struct sockaddr *) &name, &len) < 0)
	    debug(15, 1) ("getsockname(%d,%p,%p) failed.\n", fd, &name, &len);
	for (this = Config.peers; this; this = next) {
	    http_port_list *s;
	    next = this->next;
	    if (0 != strcmp(this->host, me))
		continue;
	    for (s = Config.Sockaddr.http; s; s = s->next) {
		if (this->http_port != ntohs(s->s.sin_port))
		    continue;
		debug(15, 1) ("WARNING: Peer looks like this host\n");
		debug(15, 1) ("         Ignoring %s %s/%d/%d\n",
		    neighborTypeStr(this), this->host, this->http_port,
		    this->icp.port);
		neighborRemove(this);
	    }
	}
    }
    peerRefreshDNS((void *) 1);
    if (0 == echo_hdr.opcode) {
	echo_hdr.opcode = ICP_SECHO;
	echo_hdr.version = ICP_VERSION_CURRENT;
	echo_hdr.length = 0;
	echo_hdr.reqnum = 0;
	echo_hdr.flags = 0;
	echo_hdr.pad = 0;
	echo_hdr.shostid = name.sin_addr.s_addr;
	sep = getservbyname("echo", "udp");
	echo_port = sep ? ntohs((u_short) sep->s_port) : 7;
    }
    first_ping = Config.peers;
    cachemgrRegister("server_list",
	"Peer Cache Statistics",
	neighborDumpPeers, 0, 1);
    if (theInIcpConnection >= 0) {
	cachemgrRegister("non_peers",
	    "List of Unknown sites sending ICP messages",
	    neighborDumpNonPeers, 0, 1);
    }
}
void
cachemgrInit(void)
{
    cachemgrRegister("menu",
	"This Cachemanager Menu",
	cachemgrMenu, 0, 1);
    cachemgrRegister("shutdown",
	"Shut Down the Squid Process",
	cachemgrShutdown, 1, 1);
    cachemgrRegister("offline_toggle",
	"Toggle offline_mode setting",
	cachemgrOfflineToggle, 1, 1);
}
Esempio n. 3
0
void
cbdataInit(void)
{
    debug(45, 3) ("cbdataInit\n");
    cachemgrRegister("cbdata",
	"Callback Data Registry Contents",
	cbdataDump, 0, 1);
#define CREATE_CBDATA(type) cbdataInitType(CBDATA_##type, #type, sizeof(type), NULL)
#define CREATE_CBDATA_FREE(type, free_func) cbdataInitType(CBDATA_##type, #type, sizeof(type), free_func)
    CREATE_CBDATA(acl_access);
    CREATE_CBDATA(aclCheck_t);
    CREATE_CBDATA(clientHttpRequest);
    CREATE_CBDATA(ConnStateData);
    CREATE_CBDATA(ErrorState);
    CREATE_CBDATA(FwdState);
    CREATE_CBDATA(generic_cbdata);
    CREATE_CBDATA(helper);
    CREATE_CBDATA(helper_server);
    CREATE_CBDATA(statefulhelper);
    CREATE_CBDATA(helper_stateful_server);
    CREATE_CBDATA(HttpStateData);
    CREATE_CBDATA_FREE(peer, peerDestroy);
    CREATE_CBDATA(ps_state);
    CREATE_CBDATA(RemovalPolicy);
    CREATE_CBDATA(RemovalPolicyWalker);
    CREATE_CBDATA(RemovalPurgeWalker);
    CREATE_CBDATA(store_client);
}
Esempio n. 4
0
void
idnsInit(void)
{
    static int init = 0;
    if (DnsSocket < 0) {
	DnsSocket = comm_open(SOCK_DGRAM,
	    0,
	    Config.Addrs.udp_outgoing,
	    0,
	    COMM_NONBLOCKING,
	    "DNS Socket");
	if (DnsSocket < 0)
	    fatal("Could not create a DNS socket");
	debug(78, 1) ("DNS Socket created on FD %d\n", DnsSocket);
    }
    assert(0 == nns);
    idnsParseNameservers();
    if (0 == nns)
	idnsParseResolvConf();
    if (0 == nns)
	fatal("Could not find any nameservers.\n"
	    "       Please check your /etc/resolv.conf file\n"
	    "       or use the 'dns_nameservers' option in squid.conf.");
    if (!init) {
	memDataInit(MEM_IDNS_QUERY, "idns_query", sizeof(idns_query), 0);
	cachemgrRegister("idns",
	    "Internal DNS Statistics",
	    idnsStats, 0, 1);
	memset(RcodeMatrix, '\0', sizeof(RcodeMatrix));
	init++;
    }
}
Esempio n. 5
0
void
dnsInit(void)
{
#if USE_DNSSERVERS
    static int init = 0;
    wordlist *w;
    if (!Config.Program.dnsserver)
	return;
    if (dnsservers == NULL)
	dnsservers = helperCreate("dnsserver");
    dnsservers->n_to_start = Config.dnsChildren;
    dnsservers->ipc_type = IPC_TCP_SOCKET;
    assert(dnsservers->cmdline == NULL);
    wordlistAdd(&dnsservers->cmdline, Config.Program.dnsserver);
    if (Config.onoff.res_defnames)
	wordlistAdd(&dnsservers->cmdline, "-D");
    for (w = Config.dns_nameservers; w != NULL; w = w->next) {
	wordlistAdd(&dnsservers->cmdline, "-s");
	wordlistAdd(&dnsservers->cmdline, w->key);
    }
    helperOpenServers(dnsservers);
    if (!init) {
	cachemgrRegister("dns",
	    "Dnsserver Statistics",
	    dnsStats, 0, 1);
	init = 1;
    }
#endif
}
Esempio n. 6
0
void
delayPoolsInit(void)
{
    delay_pools_last_update = getCurrentTime();
    FD_ZERO(&delay_no_delay);
    cachemgrRegister("delay", "Delay Pool Levels", delayPoolStats, 0, 1);
}
Esempio n. 7
0
void
eventInit(void)
{
    memDataInit(MEM_EVENT, "event", sizeof(struct ev_entry), 0);
    cachemgrRegister("events",
	"Event Queue",
	eventDump, 0, 1);
}
Esempio n. 8
0
void
idnsInit(void)
{
    static int init = 0;
    CBDATA_INIT_TYPE(idns_query);
    if (DnsSocket < 0) {
	int port;
	struct in_addr addr;
	if (Config.Addrs.udp_outgoing.s_addr != no_addr.s_addr)
	    addr = Config.Addrs.udp_outgoing;
	else
	    addr = Config.Addrs.udp_incoming;
	DnsSocket = comm_open(SOCK_DGRAM,
	    IPPROTO_UDP,
	    addr,
	    0,
	    COMM_NONBLOCKING,
	    "DNS Socket");
	if (DnsSocket < 0)
	    fatal("Could not create a DNS socket");
	/* Ouch... we can't call functions using debug from a debug
	 * statement. Doing so messes up the internal _db_level
	 */
	port = comm_local_port(DnsSocket);
	debug(78, 1) ("DNS Socket created at %s, port %d, FD %d\n",
	    inet_ntoa(addr),
	    port, DnsSocket);
    }
    assert(0 == nns);
    idnsParseNameservers();
#ifndef _SQUID_MSWIN_
    if (0 == nns)
	idnsParseResolvConf();
#endif
#ifdef _SQUID_WIN32_
    if (0 == nns)
	idnsParseWIN32Registry();
#endif
    if (0 == nns) {
	debug(78, 1) ("Warning: Could not find any nameservers. Trying to use localhost\n");
#ifdef _SQUID_WIN32_
	debug(78, 1) ("Please check your TCP-IP settings or /etc/resolv.conf file\n");
#else
	debug(78, 1) ("Please check your /etc/resolv.conf file\n");
#endif
	debug(78, 1) ("or use the 'dns_nameservers' option in squid.conf.\n");
	idnsAddNameserver("127.0.0.1");
    }
    if (!init) {
	memDataInit(MEM_IDNS_QUERY, "idns_query", sizeof(idns_query), 0);
	cachemgrRegister("idns",
	    "Internal DNS Statistics",
	    idnsStats, 0, 1);
	memset(RcodeMatrix, '\0', sizeof(RcodeMatrix));
	idns_lookup_hash = hash_create((HASHCMP *) strcmp, 103, hash_string);
	init++;
    }
}
Esempio n. 9
0
void
cbdataInit(void)
{
    debug(45, 3) ("cbdataInit\n");
    htable = hash_create(cbdata_cmp, 1 << 8, cbdata_hash);
    cachemgrRegister("cbdata",
	"Callback Data Registry Contents",
	cbdataDump, 0, 1);
}
Esempio n. 10
0
void
leakInit(void)
{
    debug(45, 3) ("ptrInit\n");
    htable = hash_create(ptr_cmp, 1 << 8, ptr_hash);
    cachemgrRegister("leaks",
	"Memory Leak Tracking",
	ptrDump, 0, 1);
}
void
aioInit(void)
{
    if (initialised)
        return;
    squidaio_ctrl_pool = memPoolCreate("aio_ctrl", sizeof(squidaio_ctrl_t));
    cachemgrRegister("squidaio_counts", "Async IO Function Counters",
                     aioStats, 0, 1);
    initialised = 1;
}
Esempio n. 12
0
void
clientdbInit(void)
{
    if (client_table)
	return;
    client_table = hash_create((HASHCMP *) strcmp, CLIENT_DB_HASH_SIZE, hash_string);
    cachemgrRegister("client_list",
	"Cache Client List",
	clientdbDump,
	0, 1);
}
Esempio n. 13
0
void
asnInit(void)
{
    static int inited = 0;
    squid_max_keylen = 40;
    CBDATA_INIT_TYPE(ASState);
    if (0 == inited++)
	squid_rn_init();
    squid_rn_inithead(&AS_tree_head_u.ptr, 8);
    asnAclInitialize(Config.aclList);
    cachemgrRegister("asndb", "AS Number Database", asnStats, 0, 1);
}
Esempio n. 14
0
void
comm_select_init(void)
{
#if !HAVE_POLL
    zero_tv.tv_sec = 0;
    zero_tv.tv_usec = 0;
#endif
    cachemgrRegister("comm_incoming",
	"comm_incoming() stats",
	commIncomingStats, 0, 1);

    BA_INIT(global_readfds,SQUID_NUMFD);
    BA_INIT(global_writefds,SQUID_NUMFD);

    BA_ZERO(global_readfds);
    BA_ZERO(global_writefds);
    nreadfds = nwritefds = 0;
}
Esempio n. 15
0
void
pconnInit(void)
{
    int i;
    assert(table == NULL);
    table = hash_create((HASHCMP *) strcmp, 229, hash_string);
    for (i = 0; i < PCONN_HIST_SZ; i++) {
	client_pconn_hist[i] = 0;
	server_pconn_hist[i] = 0;
    }
    pconn_data_pool = memPoolCreate("pconn_data", sizeof(struct _pconn));
    pconn_fds_pool = memPoolCreate("pconn_fds", PCONN_FDS_SZ * sizeof(int));

    cachemgrRegister("pconn",
	"Persistent Connection Utilization Histograms",
	pconnHistDump, 0, 1);
    debug(48, 3) ("persistent connection module initialized\n");
}
Esempio n. 16
0
void
netdbInit(void)
{
#if USE_ICMP
    int n;
    if (addr_table)
        return;
    n = hashPrime(Config.Netdb.high / 4);
    addr_table = hash_create((HASHCMP *) strcmp, n, hash_string);
    n = hashPrime(3 * Config.Netdb.high / 4);
    host_table = hash_create((HASHCMP *) strcmp, n, hash_string);
    eventAddIsh("netdbSaveState", netdbSaveState, NULL, 3600.0, 1);
    netdbReloadState();
    cachemgrRegister("netdb",
                     "Network Measurement Database",
                     netdbDump, 0, 1);
#endif
}
Esempio n. 17
0
void
authenticateInit(void)
{
    static int init = 0;
    if (!Config.Program.authenticate)
	return;
    if (authenticators == NULL)
	authenticators = helperCreate("authenticator");
    authenticators->cmdline = Config.Program.authenticate;
    authenticators->n_to_start = Config.authenticateChildren;
    authenticators->ipc_type = IPC_TCP_SOCKET;
    helperOpenServers(authenticators);
    if (!init) {
	cachemgrRegister("authenticator",
	    "User Authenticator Stats",
	    authenticateStats, 0, 1);
	init++;
    }
}
void
redirectInit(void)
{
    static int init = 0;
    if (!Config.Program.redirect)
        return;
    if (redirectors == NULL)
        redirectors = helperCreate("redirector");
    redirectors->cmdline = Config.Program.redirect;
    redirectors->n_to_start = Config.redirectChildren;
    redirectors->ipc_type = IPC_TCP_SOCKET;
    helperOpenServers(redirectors);
    if (!init) {
        cachemgrRegister("redirector",
                         "URL Redirector Stats",
                         redirectStats, 0, 1);
        init = 1;
        CBDATA_INIT_TYPE(redirectStateData);
    }
}
Esempio n. 19
0
void
locationRewriteInit(void)
{
    static int init = 0;
    if (!Config.Program.location_rewrite.command)
	return;
    if (locrewriters == NULL)
	locrewriters = helperCreate("location_rewriter");
    locrewriters->cmdline = Config.Program.location_rewrite.command;
    locrewriters->n_to_start = Config.Program.location_rewrite.children;
    locrewriters->concurrency = Config.Program.location_rewrite.concurrency;
    locrewriters->ipc_type = IPC_STREAM;
    helperOpenServers(locrewriters);
    if (!init) {
	cachemgrRegister("location_rewriter",
	    "Location Rewriter Stats",
	    locationRewriteStats, 0, 1);
	init = 1;
	CBDATA_INIT_TYPE(rewriteStateData);
    }
}
Esempio n. 20
0
void
redirectInit(void)
{
    static int init = 0;
    if (!Config.Program.url_rewrite.command)
	return;
    if (redirectors == NULL)
	redirectors = helperCreate("url_rewriter");
    redirectors->cmdline = Config.Program.url_rewrite.command;
    redirectors->n_to_start = Config.Program.url_rewrite.children;
    redirectors->concurrency = Config.Program.url_rewrite.concurrency;
    redirectors->ipc_type = IPC_STREAM;
    helperOpenServers(redirectors);
    if (!init) {
	cachemgrRegister("url_rewriter",
	    "URL Rewriter Stats",
	    redirectStats, 0, 1);
	init = 1;
	CBDATA_INIT_TYPE(redirectStateData);
    }
}
Esempio n. 21
0
void
storeDigestInit(void)
{
#if USE_CACHE_DIGESTS
    const int cap = storeDigestCalcCap();

    if (!Config.onoff.digest_generation) {
	store_digest = NULL;
	debug(71, 3) ("Local cache digest generation disabled\n");
	return;
    }
    store_digest = cacheDigestCreate(cap, Config.digest.bits_per_entry);
    debug(71, 1) ("Local cache digest enabled; rebuild/rewrite every %d/%d sec\n",
	(int) Config.digest.rebuild_period, (int) Config.digest.rewrite_period);
    memset(&sd_state, 0, sizeof(sd_state));
    cachemgrRegister("store_digest", "Store Digest",
	storeDigestReport, 0, 1);
#else
    store_digest = NULL;
    debug(71, 3) ("Local cache digest is 'off'\n");
#endif
}
Esempio n. 22
0
void
refreshCheckInit(void)
{
    static int firstTimeInit = 1;
    refresh_check_helper *p = Config.Program.refresh_check;

    if (p) {
	if (!p->helper)
	    p->helper = helperCreate("external_refresh_check");
	p->helper->cmdline = p->cmdline;
	p->helper->n_to_start = p->children;
	p->helper->concurrency = p->concurrency;
	p->helper->ipc_type = IPC_STREAM;
	helperOpenServers(p->helper);
	if (firstTimeInit) {
	    firstTimeInit = 0;
	    cachemgrRegister("refresh_check",
		"External ACL stats",
		refreshCheckStats, 0, 1);
	}
	CBDATA_INIT_TYPE_FREECB(refreshCheckState, free_refreshCheckState);
    }
}
Esempio n. 23
0
/* Initialize helpers and the like for this auth scheme. Called AFTER parsing the
 * config file */
static void
authNegotiateInit(authScheme * scheme)
{
    static int negotiateinit = 0;
    if (negotiateConfig->authenticate) {
	/*
	 * disable client side request pipelining. There is a race with
	 * Negotiate when the client sends a second request on an Negotiate
	 * connection before the authenticate challenge is sent. With
	 * this patch, the client may fail to authenticate, but squid's
	 * state will be preserved.
	 */
	if (negotiateConfig->authenticate && Config.onoff.pipeline_prefetch != 0) {
	    debug(29, 1) ("pipeline prefetching incompatile with Negotiate authentication. Disabling pipeline_prefetch\n");
	    Config.onoff.pipeline_prefetch = 0;
	}
	if (!negotiate_user_pool)
	    negotiate_user_pool = memPoolCreate("Negotiate Scheme User Data", sizeof(negotiate_user_t));
	if (!negotiate_request_pool)
	    negotiate_request_pool = memPoolCreate("Negotiate Scheme Request Data", sizeof(negotiate_request_t));
	authnegotiate_initialised = 1;
	if (negotiateauthenticators == NULL)
	    negotiateauthenticators = helperStatefulCreate("negotiateauthenticator");
	negotiateauthenticators->cmdline = negotiateConfig->authenticate;
	negotiateauthenticators->n_to_start = negotiateConfig->authenticateChildren;
	negotiateauthenticators->ipc_type = IPC_STREAM;
	helperStatefulOpenServers(negotiateauthenticators);
	if (!negotiateinit) {
	    cachemgrRegister("negotiateauthenticator",
		"Negotiate User Authenticator Stats",
		authenticateNegotiateStats, 0, 1);
	    negotiateinit++;
	}
	CBDATA_INIT_TYPE(authenticateStateData);
    }
}
Esempio n. 24
0
void
httpHeaderInitModule(void)
{
    int i;
    /* check that we have enough space for masks */
    assert(8 * sizeof(HttpHeaderMask) >= HDR_ENUM_END);
    /* all headers must be described */
    assert(countof(HeadersAttrs) == HDR_ENUM_END);
    if (!Headers)
	Headers = httpHeaderBuildFieldsInfo(HeadersAttrs, HDR_ENUM_END);
    /* create masks */
    httpHeaderMaskInit(&ListHeadersMask, 0);
    httpHeaderCalcMask(&ListHeadersMask, (const int *) ListHeadersArr, countof(ListHeadersArr));
    httpHeaderMaskInit(&ReplyHeadersMask, 0);
    httpHeaderCalcMask(&ReplyHeadersMask, (const int *) ReplyHeadersArr, countof(ReplyHeadersArr));
    httpHeaderCalcMask(&ReplyHeadersMask, (const int *) GeneralHeadersArr, countof(GeneralHeadersArr));
    httpHeaderCalcMask(&ReplyHeadersMask, (const int *) EntityHeadersArr, countof(EntityHeadersArr));
    httpHeaderMaskInit(&RequestHeadersMask, 0);
    httpHeaderCalcMask(&RequestHeadersMask, (const int *) RequestHeadersArr, countof(RequestHeadersArr));
    httpHeaderCalcMask(&RequestHeadersMask, (const int *) GeneralHeadersArr, countof(GeneralHeadersArr));
    httpHeaderCalcMask(&RequestHeadersMask, (const int *) EntityHeadersArr, countof(EntityHeadersArr));
    /* init header stats */
    assert(HttpHeaderStatCount == hoReply + 1);
    for (i = 0; i < HttpHeaderStatCount; i++)
	httpHeaderStatInit(HttpHeaderStats + i, HttpHeaderStats[i].label);
    HttpHeaderStats[hoRequest].owner_mask = &RequestHeadersMask;
    HttpHeaderStats[hoReply].owner_mask = &ReplyHeadersMask;
#if USE_HTCP
    HttpHeaderStats[hoHtcpReply].owner_mask = &ReplyHeadersMask;
#endif
    /* init dependent modules */
    httpHdrCcInitModule();
    /* register with cache manager */
    cachemgrRegister("http_headers",
	"HTTP Header Statistics", httpHeaderStoreReport, 0, 1);
}
Esempio n. 25
0
void
externalAclInit(void)
{
    static int firstTimeInit = 1;
    external_acl *p;

    for (p = Config.externalAclHelperList; p; p = p->next) {
	if (!p->cache)
	    p->cache = hash_create((HASHCMP *) strcmp, hashPrime(1024), hash4);
	if (!p->helper)
	    p->helper = helperCreate(p->name);
	p->helper->cmdline = p->cmdline;
	p->helper->n_to_start = p->children;
	p->helper->ipc_type = IPC_TCP_SOCKET;
	helperOpenServers(p->helper);
    }
    if (firstTimeInit) {
	firstTimeInit = 0;
	cachemgrRegister("external_acl",
	    "External ACL stats",
	    externalAclStats, 0, 1);
	CBDATA_INIT_TYPE_FREECB(externalAclState, free_externalAclState);
    }
}
Esempio n. 26
0
/* Initialize helpers and the like for this auth scheme. Called AFTER parsing the
 * config file */
static void
authDigestInit(authScheme * scheme)
{
    static int init = 0;
    if (digestConfig->authenticate) {
	authDigestUserSetup();
	authDigestRequestSetup();
	authenticateDigestNonceSetup();
	authdigest_initialised = 1;
	if (digestauthenticators == NULL)
	    digestauthenticators = helperCreate("digestauthenticator");
	digestauthenticators->cmdline = digestConfig->authenticate;
	digestauthenticators->n_to_start = digestConfig->authenticateChildren;
	digestauthenticators->ipc_type = IPC_TCP_SOCKET;
	helperOpenServers(digestauthenticators);
	if (!init) {
	    cachemgrRegister("digestauthenticator",
		"Digest User Authenticator Stats",
		authenticateDigestStats, 0, 1);
	    init++;
	}
	CBDATA_INIT_TYPE(authenticateStateData);
    }
}
Esempio n. 27
0
/* Initialize helpers and the like for this auth scheme. Called AFTER parsing the
 * config file */
static void
authBasicInit(authScheme * scheme)
{
    static int init = 0;
    if (basicConfig->authenticate) {
	if (!basic_data_pool)
	    basic_data_pool = memPoolCreate("Basic Scheme User Data", sizeof(basic_data));
	authbasic_initialised = 1;
	if (basicauthenticators == NULL)
	    basicauthenticators = helperCreate("basicauthenticator");
	basicauthenticators->cmdline = basicConfig->authenticate;
	basicauthenticators->n_to_start = basicConfig->authenticateChildren;
	basicauthenticators->concurrency = basicConfig->authenticateConcurrency;
	basicauthenticators->ipc_type = IPC_STREAM;
	helperOpenServers(basicauthenticators);
	if (!init) {
	    cachemgrRegister("basicauthenticator",
		"Basic User Authenticator Stats",
		authenticateBasicStats, 0, 1);
	    init++;
	}
	CBDATA_INIT_TYPE(authenticateStateData);
    }
}
void
refreshInit(void)
{
    memset(refreshCounts, 0, sizeof(refreshCounts));
    refreshCounts[rcHTTP].proto = "HTTP";
    refreshCounts[rcICP].proto = "ICP";
#if USE_HTCP
    refreshCounts[rcHTCP].proto = "HTCP";
#endif
    refreshCounts[rcStore].proto = "On Store";
#if USE_CACHE_DIGESTS
    refreshCounts[rcCDigest].proto = "Cache Digests";
#endif
    cachemgrRegister("refresh",
	"Refresh Algorithm Statistics",
	refreshStats,
	0,
	1);
    memset(&DefaultRefresh, '\0', sizeof(DefaultRefresh));
    DefaultRefresh.pattern = "<none>";
    DefaultRefresh.min = REFRESH_DEFAULT_MIN;
    DefaultRefresh.pct = REFRESH_DEFAULT_PCT;
    DefaultRefresh.max = REFRESH_DEFAULT_MAX;
}
void
memInit(void)
{
    int i;
    memInitModule();
    /* set all pointers to null */
    memset(MemPools, '\0', sizeof(MemPools));
    /*
     * it does not hurt much to have a lot of pools since sizeof(MemPool) is
     * small; someday we will figure out what to do with all the entries here
     * that are never used or used only once; perhaps we should simply use
     * malloc() for those? @?@
     */
    memDataInit(MEM_2K_BUF, "2K Buffer", 2048, 10);
    memDataInit(MEM_4K_BUF, "4K Buffer", 4096, 10);
    memDataInit(MEM_8K_BUF, "8K Buffer", 8192, 10);
    memDataInit(MEM_16K_BUF, "16K Buffer", 16384, 10);
    memDataInit(MEM_32K_BUF, "32K Buffer", 32768, 10);
    memDataInit(MEM_64K_BUF, "64K Buffer", 65536, 10);
    memDataInit(MEM_CLIENT_SOCK_BUF, "Client Socket Buffer", CLIENT_SOCK_SZ, 0);
    memDataInit(MEM_ACL, "acl", sizeof(acl), 0);
    memDataInit(MEM_ACL_DENY_INFO_LIST, "acl_deny_info_list",
                sizeof(acl_deny_info_list), 0);
    memDataInit(MEM_ACL_IP_DATA, "acl_ip_data", sizeof(acl_ip_data), 0);
    memDataInit(MEM_ACL_LIST, "acl_list", sizeof(acl_list), 0);
    memDataInit(MEM_ACL_NAME_LIST, "acl_name_list", sizeof(acl_name_list), 0);
#if USE_SSL
    memDataInit(MEM_ACL_CERT_DATA, "acl_cert_data", sizeof(acl_cert_data), 0);
#endif
    memDataInit(MEM_ACL_TIME_DATA, "acl_time_data", sizeof(acl_time_data), 0);
    memDataInit(MEM_ACL_REQUEST_TYPE, "acl_request_type", sizeof(acl_request_type), 0);
    memDataInit(MEM_AUTH_USER_T, "auth_user_t",
                sizeof(auth_user_t), 0);
    memDataInit(MEM_AUTH_USER_HASH, "auth_user_hash_pointer",
                sizeof(auth_user_hash_pointer), 0);
    memDataInit(MEM_ACL_PROXY_AUTH_MATCH, "acl_proxy_auth_match_cache",
                sizeof(acl_proxy_auth_match_cache), 0);
    memDataInit(MEM_ACL_USER_DATA, "acl_user_data",
                sizeof(acl_user_data), 0);
#if USE_CACHE_DIGESTS
    memDataInit(MEM_CACHE_DIGEST, "CacheDigest", sizeof(CacheDigest), 0);
#endif
    memDataInit(MEM_LINK_LIST, "link_list", sizeof(link_list), 10);
    memDataInit(MEM_DLINK_NODE, "dlink_node", sizeof(dlink_node), 10);
    memDataInit(MEM_DREAD_CTRL, "dread_ctrl", sizeof(dread_ctrl), 0);
    memDataInit(MEM_DWRITE_Q, "dwrite_q", sizeof(dwrite_q), 0);
    memDataInit(MEM_FWD_SERVER, "FwdServer", sizeof(FwdServer), 0);
    memDataInit(MEM_HTTP_REPLY, "HttpReply", sizeof(HttpReply), 0);
    memDataInit(MEM_HTTP_HDR_ENTRY, "HttpHeaderEntry", sizeof(HttpHeaderEntry), 0);
    memDataInit(MEM_HTTP_HDR_CC, "HttpHdrCc", sizeof(HttpHdrCc), 0);
    memDataInit(MEM_HTTP_HDR_RANGE_SPEC, "HttpHdrRangeSpec", sizeof(HttpHdrRangeSpec), 0);
    memDataInit(MEM_HTTP_HDR_RANGE, "HttpHdrRange", sizeof(HttpHdrRange), 0);
    memDataInit(MEM_HTTP_HDR_CONTENT_RANGE, "HttpHdrContRange", sizeof(HttpHdrContRange), 0);
    memDataInit(MEM_INTLIST, "intlist", sizeof(intlist), 0);
    memDataInit(MEM_MEMOBJECT, "MemObject", sizeof(MemObject),
                Squid_MaxFD >> 3);
    memDataInit(MEM_MEM_NODE, "mem_node", sizeof(mem_node), 0);
    memDataInit(MEM_NETDBENTRY, "netdbEntry", sizeof(netdbEntry), 0);
    memDataInit(MEM_NET_DB_NAME, "net_db_name", sizeof(net_db_name), 0);
    memDataInit(MEM_RELIST, "relist", sizeof(relist), 0);
    memDataInit(MEM_REQUEST_T, "request_t", sizeof(request_t),
                Squid_MaxFD >> 3);
    memDataInit(MEM_STOREENTRY, "StoreEntry", sizeof(StoreEntry), 0);
    memDataInit(MEM_WORDLIST, "wordlist", sizeof(wordlist), 0);
    memDataInit(MEM_CLIENT_INFO, "ClientInfo", sizeof(ClientInfo), 0);
    memDataInit(MEM_MD5_DIGEST, "MD5 digest", MD5_DIGEST_CHARS, 0);
    memDataInit(MEM_HELPER_REQUEST, "helper_request",
                sizeof(helper_request), 0);
    memDataInit(MEM_HELPER_STATEFUL_REQUEST, "helper_stateful_request",
                sizeof(helper_stateful_request), 0);
    memDataInit(MEM_TLV, "storeSwapTLV", sizeof(tlv), 0);
    memDataInit(MEM_SWAP_LOG_DATA, "storeSwapLogData", sizeof(storeSwapLogData), 0);

    /* init string pools */
    for (i = 0; i < mem_str_pool_count; i++) {
        StrPools[i].pool = memPoolCreate(StrPoolsAttrs[i].name, StrPoolsAttrs[i].obj_size);
    }
    cachemgrRegister("mem",
                     "Memory Utilization",
                     memStats, 0, 1);
}
Esempio n. 30
0
void
peerUserHashInit(void)
{
    int W = 0;
    int K;
    int k;
    double P_last, X_last, Xn;
    peer *p;
    peer **P;
    char *t;
    /* Clean up */
    for (k = 0; k < n_userhash_peers; k++) {
	cbdataUnlock(userhash_peers[k]);
    }
    safe_free(userhash_peers);
    n_userhash_peers = 0;
    /* find out which peers we have */
    for (p = Config.peers; p; p = p->next) {
	if (!p->options.userhash)
	    continue;
	assert(p->type == PEER_PARENT);
	if (p->weight == 0)
	    continue;
	n_userhash_peers++;
	W += p->weight;
    }
    if (n_userhash_peers == 0)
	return;
    userhash_peers = xcalloc(n_userhash_peers, sizeof(*userhash_peers));
    /* Build a list of the found peers and calculate hashes and load factors */
    for (P = userhash_peers, p = Config.peers; p; p = p->next) {
	if (!p->options.userhash)
	    continue;
	if (p->weight == 0)
	    continue;
	/* calculate this peers hash */
	p->userhash.hash = 0;
	for (t = p->name; *t != 0; t++)
	    p->userhash.hash += ROTATE_LEFT(p->userhash.hash, 19) + (unsigned int) *t;
	p->userhash.hash += p->userhash.hash * 0x62531965;
	p->userhash.hash = ROTATE_LEFT(p->userhash.hash, 21);
	/* and load factor */
	p->userhash.load_factor = ((double) p->weight) / (double) W;
	if (floor(p->userhash.load_factor * 1000.0) == 0.0)
	    p->userhash.load_factor = 0.0;
	/* add it to our list of peers */
	*P++ = p;
	cbdataLock(p);
    }
    /* Sort our list on weight */
    qsort(userhash_peers, n_userhash_peers, sizeof(*userhash_peers), peerSortWeight);
    /* Calculate the load factor multipliers X_k
     *
     * X_1 = pow ((K*p_1), (1/K))
     * X_k = ([K-k+1] * [P_k - P_{k-1}])/(X_1 * X_2 * ... * X_{k-1})
     * X_k += pow ((X_{k-1}, {K-k+1})
     * X_k = pow (X_k, {1/(K-k+1)})
     * simplified to have X_1 part of the loop
     */
    K = n_userhash_peers;
    P_last = 0.0;		/* Empty P_0 */
    Xn = 1.0;			/* Empty starting point of X_1 * X_2 * ... * X_{x-1} */
    X_last = 0.0;		/* Empty X_0, nullifies the first pow statement */
    for (k = 1; k <= K; k++) {
	double Kk1 = (double) (K - k + 1);
	p = userhash_peers[k - 1];
	p->userhash.load_multiplier = (Kk1 * (p->userhash.load_factor - P_last)) / Xn;
	p->userhash.load_multiplier += pow(X_last, Kk1);
	p->userhash.load_multiplier = pow(p->userhash.load_multiplier, 1.0 / Kk1);
	Xn *= p->userhash.load_multiplier;
	X_last = p->userhash.load_multiplier;
	P_last = p->userhash.load_factor;
    }
    cachemgrRegister("userhash", "peer userhash information", peerUserHashCachemgr, 0, 1);
}