cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * CDDL HEADER START
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * The contents of this file are subject to the terms of the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Common Development and Distribution License (the "License").
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * You may not use this file except in compliance with the License.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * or http://www.opensolaris.org/os/licensing.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * See the License for the specific language governing permissions
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * and limitations under the License.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * When distributing Covered Code, include this CDDL HEADER in each
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * If applicable, add the following below this CDDL HEADER, with the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * fields enclosed by brackets "[]" replaced with your own identifying
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * information: Portions Copyright [yyyy] [name of copyright owner]
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * CDDL HEADER END
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
07925104db56e5c3eacc4865b918bd16af5cec59gww * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#ifndef _NSCD_H
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSCD_H
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * This is a private header file. Applications should not directly include
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * this file.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#ifdef __cplusplus
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern "C" {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#endif
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <sys/avl.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <thread.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <synch.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include <nss_dbdefs.h>
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include "getxby_door.h"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include "nscd_common.h"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#include "nscd_config.h"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * OR'D in by server to call self for updates
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define UPDATEBIT (1<<30)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define MASKUPDATEBIT(a) ((~UPDATEBIT)&(a))
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * debug levels
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define DBG_OFF 0
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define DBG_CANT_FIND 2
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define DBG_NETLOOKUPS 4
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define DBG_ALL 6
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Max size name we allow to be passed to avoid
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * buffer overflow problems
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define NSCDMAXNAMELEN 255
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * cached entry status
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define ST_UPDATE_PENDING 0x1
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define ST_LOOKUP_PENDING 0x2
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define ST_PENDING (ST_LOOKUP_PENDING | ST_UPDATE_PENDING)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define ST_NEW_ENTRY 0x4
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define ST_DISCARD 0x8
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Cache eviction start and stop levels
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_EVICTION_START_LEVEL 90
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_EVICTION_SAFE_LEVEL 80
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * other internal constants
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
c9a5bc8f8ef20fd68ff0b46331bbaf26e1415abbMilan Jurik#define _NSC_MAX_DB 3
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_PUBLIC_ACCESS -1
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_FILE_CHECK_TIME 0 /* check always for backwards compat */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Macros used for logging purposes
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define yes_no(flag) (flag == nscd_true)?"yes":"no"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define check_null(str) (str)?str:"<null>"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Macros used by compare routines
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_INT_KEY_CMP(n1, n2) \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (n1 > n2)?1:((n1 == n2)?0:-1)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_GET_HITRATE(sp) \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl sp->hitrate = sp->pos_misses + sp->neg_misses + \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl sp->pos_hits + sp->neg_hits; \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if (sp->hitrate > 0.0) \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl sp->hitrate = (100.0 * \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ((double)sp->pos_hits + \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (double)sp->neg_hits)) / sp->hitrate;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * nsc_lookup action
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjltypedef enum {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSC_NSLOOKUP = 0,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSC_WAIT,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSC_USECACHED
cb5caa98562cf06753163f558cbcfe30b8f4673adjl} nsc_action_t;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * What each entry in the nameserver cache looks like.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjltypedef struct nsc_entry_stat {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl uint_t hits; /* number of hits */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl uint8_t status; /* activity status */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl time_t timestamp; /* expiry time */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int refcount; /* reference count */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl} nsc_entry_stat_t;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjltypedef struct nsc_entry {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl avl_node_t avl_link; /* libavl requirement */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl struct nsc_entry *qnext; /* next on pqueue */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl struct nsc_entry *qprev; /* prev on pqueue */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_entry_stat_t stats; /* entry's statistics */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nss_XbyY_key_t key; /* entry's key */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl void *buffer; /* data buffer */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl size_t bufsize; /* data buffer length */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl} nsc_entry_t;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjltypedef struct nsc_keephot {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl void *ptr;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl uint_t num;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl} nsc_keephot_t;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
3ea037cc19cdc1fa08072c41271d316bfbf9c54amichen/*
3ea037cc19cdc1fa08072c41271d316bfbf9c54amichen * Structure to handle waiting for pending name service requests
3ea037cc19cdc1fa08072c41271d316bfbf9c54amichen */
3ea037cc19cdc1fa08072c41271d316bfbf9c54amichentypedef struct waiter {
3ea037cc19cdc1fa08072c41271d316bfbf9c54amichen cond_t w_waitcv;
3ea037cc19cdc1fa08072c41271d316bfbf9c54amichen uint8_t w_signaled;
3ea037cc19cdc1fa08072c41271d316bfbf9c54amichen nsc_entry_t *w_key;
3ea037cc19cdc1fa08072c41271d316bfbf9c54amichen struct waiter *w_next, *w_prev;
3ea037cc19cdc1fa08072c41271d316bfbf9c54amichen} waiter_t;
3ea037cc19cdc1fa08072c41271d316bfbf9c54amichen
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Macros used by hash table
cb5caa98562cf06753163f558cbcfe30b8f4673adjl *
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * _NSC_HTSIZE_PRIMES are prime numbers that are used as hash table
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * sizes when hash table type is nsc_ht_prime. For hash tables of
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * type nsc_ht_power2, the size is automatically calculated.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Number of primes listed below is _NSC_HTSIZE_NUM_SLOTS + 1.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Each number (except the first) is a prime closest to a
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * power of 2 in increasing order. Ex: 509 is the closest prime to
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * 512 (2**9), 1021 is closest to 1024 (2**10), and so on.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * The first prime is chosen as 211 for historical reasons.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_INIT_HTSIZE_PRIME 211
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_INIT_HTSIZE_POWER2 256
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_INIT_HTSIZE_SLOT_VALUE 2896
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_HTSIZE_NUM_SLOTS 10
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_HTSIZE_PRIMES 211, 509, 1021, 2053, 4099, 8191, \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl 16381, 32771, 65537, 131071, 262147
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_DB_CES_KEY(ptr) \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ((ptr)->db_type == nsc_key_ces)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_DB_CIS_KEY(ptr) \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ((ptr)->db_type == nsc_key_cis)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_DB_STR_KEY(ptr) \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSC_DB_CES_KEY(ptr) || _NSC_DB_CIS_KEY(ptr)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define _NSC_DB_INT_KEY(ptr) \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ((ptr)->db_type == nsc_key_int)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * cache backend param group (global)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define NSCD_CFG_GROUP_INFO_GLOBAL_CACHE {1, 0x0001}
cb5caa98562cf06753163f558cbcfe30b8f4673adjltypedef struct nscd_cfg_global_cache {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_cfg_group_info_t gi; /* config requirement */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_bool_t enable;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl} nscd_cfg_global_cache_t;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define NSCD_CFG_GLOBAL_CACHE_DEFAULTS \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl { NSCD_CFG_GROUP_INFO_GLOBAL_CACHE, nscd_true }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * cache backend param group (per database)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define NSCD_CFG_GROUP_INFO_CACHE {12, 0x0fff}
cb5caa98562cf06753163f558cbcfe30b8f4673adjltypedef struct nscd_cfg_cache {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_cfg_group_info_t gi; /* config requirement */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_bool_t enable; /* if false return NOSERVER */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_bool_t per_user; /* if true per user access */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_bool_t avoid_ns; /* if true avoid name service */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_bool_t check_files; /* if true check file */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int check_interval; /* check interval */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int pos_ttl; /* time to live for +ve entries */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int neg_ttl; /* time to live for -ve entries */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int keephot; /* keep hot count */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int hint_size; /* size to return for a GETHINTS */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ulong_t maxentries; /* maximum entries allowed */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int suggestedsize; /* obsolete */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_bool_t old_data_ok; /* obsolete */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl} nscd_cfg_cache_t;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define NSCD_CFG_CACHE_DEFAULTS \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl { \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl NSCD_CFG_GROUP_INFO_CACHE, \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_true, nscd_false, nscd_false, nscd_true, \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl _NSC_FILE_CHECK_TIME, 600, 10, 0, 1 << 11, 0, \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl 0, nscd_false \
cb5caa98562cf06753163f558cbcfe30b8f4673adjl }
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * cache backend stat group (per database)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#define NSCD_CFG_STAT_GROUP_INFO_CACHE {9, 0x01ff}
cb5caa98562cf06753163f558cbcfe30b8f4673adjltypedef struct nscd_cfg_stat_cache {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_cfg_group_info_t gi; /* config requirement */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ulong_t pos_hits; /* hits on +ve entries */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ulong_t neg_hits; /* hits on -ve entries */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ulong_t pos_misses; /* misses on +ve entries */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ulong_t neg_misses; /* misses on -ve entries */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ulong_t entries; /* count of cache entries */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ulong_t drop_count; /* cache queries dropped */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ulong_t wait_count; /* cache queries queued */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ulong_t invalidate_count; /* count for cache invalidation */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl double hitrate; /* computed from other fields */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl} nscd_cfg_stat_cache_t;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjltypedef struct nsc_db {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Data
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl avl_tree_t tree;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_entry_t **htable;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_entry_t *qhead;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_entry_t *qtail;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_entry_t *reap_node;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int callnumber;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int dbop;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl char *name;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl mutex_t db_mutex;
3ea037cc19cdc1fa08072c41271d316bfbf9c54amichen waiter_t db_wait; /* lookup wait CV */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int htsize;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl enum hash_type {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_ht_default = 0,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_ht_prime = 1,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_ht_power2 = 2
cb5caa98562cf06753163f558cbcfe30b8f4673adjl } hash_type;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl enum db_type {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_key_ces = 0,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_key_cis = 1,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_key_int = 2,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_key_other = 3
cb5caa98562cf06753163f558cbcfe30b8f4673adjl } db_type;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Methods
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl uint_t (*gethash)(nss_XbyY_key_t *, int);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int (*compar)(const void *, const void *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl void (*getlogstr)(char *, char *, size_t, nss_XbyY_args_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /*
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Config
cb5caa98562cf06753163f558cbcfe30b8f4673adjl */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_cfg_cache_t cfg;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl time_t cfg_mtime;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl} nsc_db_t;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjltypedef struct nsc_ctx {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl char *dbname; /* cache name */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_cfg_stat_cache_t stats; /* statistics */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_cfg_cache_t cfg; /* configs */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl time_t cfg_mtime; /* config last modified time */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl rwlock_t cfg_rwlp; /* config rwlock */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl mutex_t stats_mutex; /* stats mutex */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl mutex_t file_mutex; /* file mutex */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl time_t file_mtime; /* file last modified time */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl time_t file_chktime; /* file last checked time */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl off_t file_size; /* file size at last check */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl ino_t file_ino; /* file inode at last check */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl const char *file_name; /* filename for check_files */
c9a5bc8f8ef20fd68ff0b46331bbaf26e1415abbMilan Jurik int db_count; /* number of caches, max _NSC_MAX_DB */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_db_t *nsc_db[_NSC_MAX_DB]; /* caches */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl sema_t throttle_sema; /* throttle lookups */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl sema_t revalidate_sema; /* revalidation threads */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_bool_t revalidate_on; /* reval. thread started */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_bool_t reaper_on; /* reaper thread started */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl} nsc_ctx_t;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjltypedef struct nsc_lookup_args {
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_ctx_t *ctx;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nsc_db_t *nscdb;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl void *buffer;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl size_t bufsize;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl} nsc_lookup_args_t;
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
07925104db56e5c3eacc4865b918bd16af5cec59gww#define CACHE_CTX_COUNT 19
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/* Context initialization */
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void passwd_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void group_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void host_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void ipnode_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void exec_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void prof_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void user_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void ether_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void rpc_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void proto_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void net_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void bootp_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void auth_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void serv_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void netmask_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void printer_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void project_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void tnrhtp_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void tnrhdb_init_ctx(nsc_ctx_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/* Functions used to throttle threads */
3ea037cc19cdc1fa08072c41271d316bfbf9c54amichenextern int nscd_wait(nsc_ctx_t *, nsc_db_t *, nsc_entry_t *);
3ea037cc19cdc1fa08072c41271d316bfbf9c54amichenextern int nscd_signal(nsc_ctx_t *, nsc_db_t *, nsc_entry_t *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/* Cache creation and initialization */
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern nscd_rc_t init_cache();
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern nsc_db_t *make_cache(enum db_type, int, char *,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl int (*compar) (const void *, const void *),
cb5caa98562cf06753163f558cbcfe30b8f4673adjl void (*getlogstr)(char *, char *, size_t, nss_XbyY_args_t *),
cb5caa98562cf06753163f558cbcfe30b8f4673adjl uint_t (*gethash)(nss_XbyY_key_t *, int),
cb5caa98562cf06753163f558cbcfe30b8f4673adjl enum hash_type, int);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/* Cache backend lookup */
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void nsc_lookup(nsc_lookup_args_t *, int);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/* Cache backend info */
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void nsc_info(nsc_ctx_t *, char *, nscd_cfg_cache_t cfg[],
cb5caa98562cf06753163f558cbcfe30b8f4673adjl nscd_cfg_stat_cache_t stats[]);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#ifdef NSCD_DEBUG
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern int nsc_dump(char *, int);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#endif /* NSCD_DEBUG */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/* Cache invalidate */
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void nsc_invalidate(nsc_ctx_t *, char *, nsc_ctx_t **);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/* Keep hot functions */
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern nsc_keephot_t *maken(int);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void *insertn(nsc_keephot_t *, uint_t, void *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/* hash related routines */
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern uint_t cis_gethash(const char *, int);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern uint_t ces_gethash(const char *, int);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern uint_t db_gethash(const void *, int, int);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern void leave(int n);
cb5caa98562cf06753163f558cbcfe30b8f4673adjlextern int get_cache_idx(char *);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#ifdef __cplusplus
cb5caa98562cf06753163f558cbcfe30b8f4673adjl}
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#endif
cb5caa98562cf06753163f558cbcfe30b8f4673adjl
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#endif /* _NSCD_H */