cache.h revision 3ea037cc19cdc1fa08072c41271d316bfbf9c54a
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _NSCD_H
#define _NSCD_H
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This is a private header file. Applications should not directly include
* this file.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <thread.h>
#include <synch.h>
#include <nss_dbdefs.h>
#include "getxby_door.h"
#include "nscd_common.h"
#include "nscd_config.h"
/*
* OR'D in by server to call self for updates
*/
#define MASKUPDATEBIT(a) ((~UPDATEBIT)&(a))
/*
* debug levels
*/
#define DBG_OFF 0
#define DBG_CANT_FIND 2
#define DBG_NETLOOKUPS 4
#define DBG_ALL 6
/*
* Max size name we allow to be passed to avoid
* buffer overflow problems
*/
#define NSCDMAXNAMELEN 255
/*
* cached entry status
*/
#define ST_UPDATE_PENDING 0x1
#define ST_LOOKUP_PENDING 0x2
#define ST_NEW_ENTRY 0x4
#define ST_DISCARD 0x8
/*
* Cache eviction start and stop levels
*/
#define _NSC_EVICTION_START_LEVEL 90
#define _NSC_EVICTION_SAFE_LEVEL 80
/*
* other internal constants
*/
#define _NSC_MAX_DB 2
#define _NSC_PUBLIC_ACCESS -1
#define _NSC_FILE_CHECK_TIME 0 /* check always for backwards compat */
/*
* Macros used for logging purposes
*/
/*
* Macros used by compare routines
*/
#define _NSC_GET_HITRATE(sp) \
/*
* nsc_lookup action
*/
typedef enum {
_NSC_NSLOOKUP = 0,
} nsc_action_t;
/*
* What each entry in the nameserver cache looks like.
*/
typedef struct nsc_entry_stat {
int refcount; /* reference count */
typedef struct nsc_entry {
void *buffer; /* data buffer */
} nsc_entry_t;
typedef struct nsc_keephot {
void *ptr;
/*
* Structure to handle waiting for pending name service requests
*/
typedef struct waiter {
} waiter_t;
/*
* Macros used by hash table
*
* _NSC_HTSIZE_PRIMES are prime numbers that are used as hash table
* sizes when hash table type is nsc_ht_prime. For hash tables of
* type nsc_ht_power2, the size is automatically calculated.
* Number of primes listed below is _NSC_HTSIZE_NUM_SLOTS + 1.
* Each number (except the first) is a prime closest to a
* power of 2 in increasing order. Ex: 509 is the closest prime to
* 512 (2**9), 1021 is closest to 1024 (2**10), and so on.
* The first prime is chosen as 211 for historical reasons.
*/
#define _NSC_INIT_HTSIZE_PRIME 211
#define _NSC_INIT_HTSIZE_POWER2 256
#define _NSC_INIT_HTSIZE_SLOT_VALUE 2896
#define _NSC_HTSIZE_NUM_SLOTS 10
16381, 32771, 65537, 131071, 262147
#define _NSC_DB_CES_KEY(ptr) \
#define _NSC_DB_CIS_KEY(ptr) \
#define _NSC_DB_STR_KEY(ptr) \
#define _NSC_DB_INT_KEY(ptr) \
/*
* cache backend param group (global)
*/
typedef struct nscd_cfg_global_cache {
#define NSCD_CFG_GLOBAL_CACHE_DEFAULTS \
/*
* cache backend param group (per database)
*/
typedef struct nscd_cfg_cache {
int check_interval; /* check interval */
int pos_ttl; /* time to live for +ve entries */
int neg_ttl; /* time to live for -ve entries */
int keephot; /* keep hot count */
int hint_size; /* size to return for a GETHINTS */
int suggestedsize; /* obsolete */
#define NSCD_CFG_CACHE_DEFAULTS \
{ \
0, nscd_false \
}
/*
* cache backend stat group (per database)
*/
typedef struct nscd_cfg_stat_cache {
double hitrate; /* computed from other fields */
typedef struct nsc_db {
/*
* Data
*/
int callnumber;
int dbop;
char *name;
int htsize;
enum hash_type {
nsc_ht_default = 0,
nsc_ht_prime = 1,
nsc_ht_power2 = 2
} hash_type;
enum db_type {
nsc_key_ces = 0,
nsc_key_cis = 1,
nsc_key_int = 2,
nsc_key_other = 3
} db_type;
/*
* Methods
*/
int (*compar)(const void *, const void *);
/*
* Config
*/
} nsc_db_t;
typedef struct nsc_ctx {
char *dbname; /* cache name */
const char *file_name; /* filename for check_files */
int db_count; /* number of caches */
} nsc_ctx_t;
typedef struct nsc_lookup_args {
void *buffer;
#define CACHE_CTX_COUNT 20
/* Context initialization */
extern void passwd_init_ctx(nsc_ctx_t *);
extern void group_init_ctx(nsc_ctx_t *);
extern void host_init_ctx(nsc_ctx_t *);
extern void ipnode_init_ctx(nsc_ctx_t *);
extern void exec_init_ctx(nsc_ctx_t *);
extern void prof_init_ctx(nsc_ctx_t *);
extern void user_init_ctx(nsc_ctx_t *);
extern void ether_init_ctx(nsc_ctx_t *);
extern void rpc_init_ctx(nsc_ctx_t *);
extern void proto_init_ctx(nsc_ctx_t *);
extern void net_init_ctx(nsc_ctx_t *);
extern void bootp_init_ctx(nsc_ctx_t *);
extern void auuser_init_ctx(nsc_ctx_t *);
extern void auth_init_ctx(nsc_ctx_t *);
extern void serv_init_ctx(nsc_ctx_t *);
extern void netmask_init_ctx(nsc_ctx_t *);
extern void printer_init_ctx(nsc_ctx_t *);
extern void project_init_ctx(nsc_ctx_t *);
extern void tnrhtp_init_ctx(nsc_ctx_t *);
extern void tnrhdb_init_ctx(nsc_ctx_t *);
/* Functions used to throttle threads */
/* Cache creation and initialization */
extern nscd_rc_t init_cache();
int (*compar) (const void *, const void *),
enum hash_type, int);
/* Cache backend lookup */
extern void nsc_lookup(nsc_lookup_args_t *, int);
/* Cache backend info */
#ifdef NSCD_DEBUG
extern int nsc_dump(char *, int);
#endif /* NSCD_DEBUG */
/* Cache invalidate */
/* Keep hot functions */
extern nsc_keephot_t *maken(int);
/* hash related routines */
extern uint_t cis_gethash(const char *, int);
extern uint_t ces_gethash(const char *, int);
extern uint_t db_gethash(const void *, int, int);
extern void leave(int n);
extern int get_cache_idx(char *);
#ifdef __cplusplus
}
#endif
#endif /* _NSCD_H */