Home | History | Annotate | only in /onnv/onnv-gate/usr/src/cmd/cmd-inet/usr.lib/in.dhcpd
Up to higher level directory
NameDateSize
bootp.c08-Dec-200811.4K
dhcp-server.xml15-May-20093.5K
dhcp.c25-Feb-200982.1K
dhcpd.h08-Dec-20088.3K
dhcptab.c08-Dec-200830K
encode.c08-Dec-20085.2K
generic.c04-Jun-200917.6K
hash.c08-Dec-200814.7K
hash.h08-Dec-20085.4K
icmp.c08-Dec-20086.4K
in.dhcpd.xcl08-Dec-20083K
inc.flg08-Dec-20081K
interfaces.c25-Feb-200938.1K
interfaces.h25-Feb-20093.3K
logging.c08-Dec-20082.9K
main.c08-Dec-200836.1K
Makefile08-Dec-20082.6K
misc.c08-Dec-200819.4K
per_dnet.c08-Dec-200815.9K
per_dnet.h08-Dec-20087.5K
README.caching08-Dec-20086.5K
relay.c08-Dec-20087.6K
tests/08-Dec-2008
THIRDPARTYLICENSE08-Dec-20081K
THIRDPARTYLICENSE.descrip08-Dec-200821

README.caching

      1 #
      2 # CDDL HEADER START
      3 #
      4 # The contents of this file are subject to the terms of the
      5 # Common Development and Distribution License, Version 1.0 only
      6 # (the "License").  You may not use this file except in compliance
      7 # with the License.
      8 #
      9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10 # or http://www.opensolaris.org/os/licensing.
     11 # See the License for the specific language governing permissions
     12 # and limitations under the License.
     13 #
     14 # When distributing Covered Code, include this CDDL HEADER in each
     15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16 # If applicable, add the following below this CDDL HEADER, with the
     17 # fields enclosed by brackets "[]" replaced with your own identifying
     18 # information: Portions Copyright [yyyy] [name of copyright owner]
     19 #
     20 # CDDL HEADER END
     21 #
     22 #
     23 # Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
     24 # Use is subject to license terms.
     25 # 
     26 
     27 The DHCP server cache implementation
     28 Zhenghui.Xie@sun.com
     29 
     30 
     31 #ident	"%Z%%M%	%I%	%E% SMI"
     32 
     33 INTRODUCTION
     34 ============
     35 
     36 The Solaris DHCP server implements a caching mechanism to:
     37 
     38  	* Ensure the ACK is consistent with the original OFFER, so that
     39 	  subsequent requests get the same answer.
     40 	* Ensure the same IP address isn't offered to a different client.
     41 	* Improve performance by reducing the frequency of datastore lookups.
     42 
     43 IMPLEMENTATION OVERVIEW
     44 =======================
     45 
     46 The cache implementation consists of a number of hash tables and lists,
     47 enumerated below, along with a timeout and refresh mechanism:
     48 
     49 	* A global DHCP table hash (ntable):
     50 
     51 	  Each active network table (dvsc_dnet_t) is hashed by subnet number
     52 	  into a global hash called 'ntable'.  The dsvc_dnet_t itself
     53 	  contains a variety of information about each subnet, an access
     54 	  handle to the underlying datastore, and a variety of caches which
     55 	  we describe next.
     56 
     57 	  An ntable hash entry will be removed after DHCP_NET_THRESHOLD
     58 	  seconds of inactivity.
     59 
     60 	* A per-network client hash (ctable):
     61 
     62 	  Each client structure (dsvc_clnt_t) is hashed by client identifier
     63 	  into the per-network ctable.  This table is used by the interface
     64 	  worker thread to get client information.
     65 
     66 	  A ctable hash entry will be removed if the client does not communicate
     67 	  with the server for DHCP_CLIENT_THRESHOLD seconds.
     68 
     69 	* A per-network offer hash (itable):
     70 
     71 	  The IP address associated with each pending OFFER is hashed into
     72 	  the per-network itable.  This table is used to reserve the offered
     73 	  and in-use IP addresses on the given network.
     74 
     75 	  An itable hash entry will be removed if more than DSVC_CV_OFFER_TTL
     76 	  seconds elapse without update_offer() being called on it.
     77 
     78 	* A per-network free record list (freerec):
     79 
     80 	  This is a cache of free records, populated with any unused records
     81 	  retrieved from previous datastore lookups or from IP addresses that
     82 	  have been explicitly released by DHCP clients.  This is the first
     83 	  list select_offer() consults.
     84 
     85 	  An entry in the freerec list expires after DSVC_CV_CACHE_TTL seconds.
     86 
     87 	* A per-network least recently used record list (lrurec)
     88 
     89 	  This is a cache of least recently used records, populated with any
     90 	  unused records retrieved from a previous datastore lookup for
     91 	  LRU records.  This is the second list select_offer() consults, after
     92 	  checking freerec.
     93 
     94 	  An entry in the lrurec list expires after DSVC_CV_CACHE_TTL seconds.
     95 
     96 The concurrency between the datastore and cached records is handled by the
     97 underlying datastore implementation using perimeters and is transparent to
     98 in.dhcpd.  $SRC/lib/libdhcpsvc/private/{private.c,public.c} implement the
     99 functions used by in.dhcpd and DHCP server admin tools to lookup and modify
    100 the underlying datastore records.
    101 
    102 TRANSACTIONS
    103 ============
    104 
    105 When in.dhcpd receives a packet from a client, the interface thread first
    106 calls open_dnet() to retrieve the dsvc_dnet_t which describes the network.
    107 The dsvc_dnet_t is either in the ntable hash, in which case it is returned,
    108 or a new dsvc_dnet_t is allocated and inserted to ntable.  Then, using the
    109 dsvc_dnet_t, the interface thread calls open_clnt(), which searches the
    110 dsvc_dnet_t's ctable hash and returns the client structure (dsvc_clnt_t) if
    111 found.  Otherwise, a new dsvc_clnt_t is allocated and inserted into the
    112 ctable.  Finally, the packet is put to the client's packet list so that the
    113 client thread can process it.
    114 
    115 The client thread then processes the packet according to whether it's a
    116 DISCOVER, REQUEST, RELEASE, or DECLINE.
    117 
    118 For a DISCOVER:
    119 
    120 	1. If there is a pre-assigned IP for this client and the cached offer
    121 	   is not timed out, then use the IP and the record in the
    122 	   dsvc_clnt_t and make an OFFER.
    123 
    124 	2. If there is a pre-assigned IP but the cached offer is expired,
    125 	   remove the cached OFFER from the itable, and try to find a new
    126 	   record for the client (see below).
    127 
    128 	3. If there is no pre-assigned IP for this client, just try to find
    129 	   a new record for the client (see following text).
    130 
    131 	To find a new record, the client thread first searches the datastore
    132 	for a record matching the client identifier provided in the packet.
    133 	If none is found, then the free record list (freerec) and least
    134 	recently used record list (lrurec) are searched, in that order.  If
    135 	either freerec or lrurec is empty, or the head record on either list
    136 	is expired, in.dhcpd removes any existing records and attempts to
    137 	repopulate them by performing datastore lookups.  Finally, any
    138 	unused records are cached for later use.
    139 
    140 	If a usable record is found, the server generates and sends an OFFER
    141 	to the client.  Once sent, the client's dsvc_clnt_t is inserted to
    142 	the dsvc_dnet_t's itable if it is a new IP, or the itable is refreshed
    143 	if it is a pre-assigned IP.
    144 
    145 For a REQUEST:
    146 
    147 	1. If the REQUEST is a reply to a previous OFFER, it checks if the
    148 	   OFFER has expired.  If not, the itable timer is reset, the client
    149 	   record is updated, and the ACK is sent.  If it is expired and the
    150 	   address cannot be confirmed to still be free, the REQUEST is 
    151 	   silently ignored (and the client should eventually drop back
    152 	   to DISCOVER).
    153 
    154 	2. If the REQUEST is associated with a client INIT-REBOOT or a client
    155 	   extending a lease, then the client thread does a datastore lookup
    156 	   by client identifier.  If a match is found, the record is updated
    157 	   and an ACK is sent.
    158 
    159 If the packet is a RELEASE, the client thread modifies the record in the
    160 datastore so that it is marked free, and, if successful, puts the record onto
    161 the free record list (freerec).
    162 
    163 Finally, if the packet is a DECLINE, the client thread modifies the record in
    164 the datastore so that it is marked unusable.
    165