home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / darwin / darwinx86.iso / usr / include / net / hostcache.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-30  |  4.3 KB  |  116 lines

  1. /*
  2.  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
  3.  *
  4.  * @APPLE_LICENSE_HEADER_START@
  5.  * 
  6.  * The contents of this file constitute Original Code as defined in and
  7.  * are subject to the Apple Public Source License Version 1.1 (the
  8.  * "License").  You may not use this file except in compliance with the
  9.  * License.  Please obtain a copy of the License at
  10.  * http://www.apple.com/publicsource and read it before using this file.
  11.  * 
  12.  * This Original Code and all software distributed under the License are
  13.  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  14.  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  15.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  16.  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
  17.  * License for the specific language governing rights and limitations
  18.  * under the License.
  19.  * 
  20.  * @APPLE_LICENSE_HEADER_END@
  21.  */
  22. /*
  23.  * Copyright 1997 Massachusetts Institute of Technology
  24.  *
  25.  * Permission to use, copy, modify, and distribute this software and
  26.  * its documentation for any purpose and without fee is hereby
  27.  * granted, provided that both the above copyright notice and this
  28.  * permission notice appear in all copies, that both the above
  29.  * copyright notice and this permission notice appear in all
  30.  * supporting documentation, and that the name of M.I.T. not be used
  31.  * in advertising or publicity pertaining to distribution of the
  32.  * software without specific, written prior permission.  M.I.T. makes
  33.  * no representations about the suitability of this software for any
  34.  * purpose.  It is provided "as is" without express or implied
  35.  * warranty.
  36.  * 
  37.  * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
  38.  * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
  39.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  40.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
  41.  * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  42.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  43.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  44.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  45.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  46.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  47.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  48.  * SUCH DAMAGE.
  49.  *
  50.  */
  51.  
  52. #ifndef _NET_HOSTCACHE_H
  53. #define    _NET_HOSTCACHE_H    1
  54.  
  55. /*
  56.  * This file defines the interface between network protocols and
  57.  * the cache of host-specific information maintained by the kernel.
  58.  * The generic interface takes care of inserting and deleting entries,
  59.  * maintaining mutual exclusion, and enforcing policy constraint on the
  60.  * size of the cache and the maximum age of its entries.
  61.  * It replaces an earlier scheme which overloaded the routing table
  62.  * for this purpose, and should be significantly more efficient
  63.  * at performing most operations.  (It does keep a route to each
  64.  * entry in the cache.)  Most protocols will want to define a
  65.  * structure which begins with `struct hcentry' so that they
  66.  * can keep additional, protocol-specific information in it.
  67.  */
  68.  
  69. #include <sys/queue.h>
  70.  
  71. struct hcentry {
  72.     LIST_ENTRY(hcentry) hc_link;
  73.     struct    timeval hc_idlesince;    /* time last ref dropped */
  74.     struct    sockaddr *hc_host;    /* address of this entry's host */
  75.     struct    rtentry *hc_rt;        /* route to get there */
  76.     /* struct nexthop *hc_nh; */
  77.     int    hc_refcnt;        /* reference count */
  78.     struct    hctable *hc_hct;     /* back ref to table */
  79. };
  80.  
  81. struct hccallback {
  82.     u_long    (*hccb_hash)(struct sockaddr *, u_long);
  83.     int    (*hccb_delete)(struct hcentry *);
  84.     u_long    (*hccb_bump)(u_long);
  85. };
  86.  
  87. LIST_HEAD(hchead, hcentry);
  88.  
  89. struct hctable {
  90.     u_long    hct_nentries;
  91.     u_long    hct_active;
  92.     u_long    hct_idle;
  93.     struct    hchead *hct_heads;
  94.     struct    hccallback *hct_cb;
  95.     int    hct_primes;
  96. };
  97.  
  98. #ifdef KERNEL
  99.  
  100. #ifdef MALLOC_DECLARE
  101. MALLOC_DECLARE(M_HOSTCACHE);
  102. #endif
  103. /*
  104.  * The table-modification functions must be called from user mode, as
  105.  * they may block waiting for memory and/or locks.
  106.  */
  107. int    hc_init(int af, struct hccallback *hccb, int init_nelem, int primes);
  108. struct    hcentry *hc_get(struct sockaddr *sa);
  109. void    hc_ref(struct hcentry *hc);
  110. void    hc_rele(struct hcentry *hc);
  111. int    hc_insert(struct hcentry *hc);
  112. int    hc_delete(struct hcentry *hc);
  113. #endif /* KERNEL */
  114.  
  115. #endif /* _NET_HOSTCACHE_H */
  116.