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 (c) 2000 by Sun Microsystems, Inc.
  24  * All rights reserved.
  25  */
  26 
  27 #ifndef _DHCP_NETWORK_H
  28 #define _DHCP_NETWORK_H
  29 
  30 #pragma ident   "%Z%%M% %I%     %E% SMI"
  31 
  32 /*
  33  * Implementation-specific data structures and constants for the binary
  34  * files dhcp_network container.  These structures are subject to change at
  35  * any time.
  36  */
  37 
  38 #include <sys/types.h>
  39 #include <dhcp_svc_public.h>
  40 
  41 #ifdef __cplusplus
  42 extern "C" {
  43 #endif
  44 
  45 /*
  46  * The client id hash size is based on the idea that, given a perfect hash,
  47  * the hash chain length shouldn't be more than the number of buckets.
  48  * Given a worst case network with 2^24 addresses, that means we should
  49  * have 4096 buckets; we shrink this by a bit to make the dn_header_t size
  50  * be a power of two (32768 bytes).  Note that we assert that a header is
  51  * this size in open_dn().
  52  */
  53 #define DN_CIDHASHSZ    4056
  54 #define DN_MAGIC        0x0d6c92e4      /* "dhcpnet" in hexadecimal world */
  55 #define DN_NOIMAGE      0x80            /* image field not in use */
  56 #define DN_NOREC        0x00000000      /* "no record" id value, must be zero */
  57 #define DN_TEMPREC      0xffffffff      /* "temp record" id value */
  58 #define DN_HASHHEAD     0xfffffffe      /* "hash chain head" id value */
  59 
  60 typedef uint32_t dn_recid_t;            /* record id type */
  61 
  62 /*
  63  * Macros to compute the record id for a record with address `addr' in a
  64  * container with netmask `mask', and to convert a record id `recid' to its
  65  * starting file offset within its container.  Note that we reserve the
  66  * record id value of 0 for DN_NOREC for reasons explained in open_dn().
  67  */
  68 #define RECID(addr, mask)       ((dn_recid_t)(((addr) & ~(mask)) + 1))
  69 #define RECID2OFFSET(recid)                                             \
  70         (((recid) == DN_TEMPREC) ? offsetof(dn_header_t, dnh_temp) :    \
  71         (sizeof (dn_header_t) + ((off_t)sizeof (dn_filerec_t) * ((recid) - 1))))
  72 
  73 /*
  74  * What each dn_rec_t looks like on-disk -- contains the dn_rec_t, pointers
  75  * to the previous and next dn_rec_t's on its client id hash.  See the big
  76  * theory statement in dhcp_network.c for a discussion on the redundant
  77  * dn_recid_t's.
  78  */
  79 typedef struct dn_filerec {
  80         dn_recid_t      rec_next[2];    /* id of next record in cidhash */
  81         dn_recid_t      rec_prev[2];    /* id of prev record in cidhash */
  82         dn_rec_t        rec_dn;         /* actual dn_rec_t */
  83 } dn_filerec_t;
  84 
  85 /*
  86  * Header atop each dhcp_network container -- contains some basic
  87  * information about the container and an array of buckets to chain client
  88  * id hashes from.  See the big theory statement in dhcp_network.c for a
  89  * discussion on the redundant dn_recid_t's and the concept of "images".
  90  */
  91 typedef struct dn_header {
  92         unsigned char   dnh_version;    /* container version */
  93         unsigned char   dnh_dirty;      /* container might be dirty */
  94         unsigned char   dnh_image;      /* container's active image */
  95         unsigned char   dnh_tempimage;  /* temporary record's image */
  96         uint32_t        dnh_magic;      /* container magic */
  97         ipaddr_t        dnh_network;    /* network number of table */
  98         ipaddr_t        dnh_netmask;    /* netmask of network number */
  99         dn_filerec_t    dnh_temp;       /* temporary record used in modify_dn */
 100         uint32_t        dnh_checks;     /* number of check_dn full runs */
 101         uint32_t        dnh_errors;     /* number of errors caught */
 102         uint32_t        dnh_pad[4];     /* for future use */
 103 
 104         /*
 105          * Note: read_header() assumes that dnh_cidhash is the last member.
 106          */
 107         dn_recid_t      dnh_cidhash[DN_CIDHASHSZ][2]; /* cid hash buckets */
 108 } dn_header_t;
 109 
 110 /*
 111  * Per-instance state for each handle returned from open_dn.
 112  */
 113 typedef struct dn_handle {
 114         int             dh_fd;          /* fd for open file pointer */
 115         unsigned int    dh_oflags;      /* flags passed into open_dn */
 116         ipaddr_t        dh_netmask;     /* cached netmask of container */
 117 } dn_handle_t;
 118 
 119 #ifdef __cplusplus
 120 }
 121 #endif
 122 
 123 #endif /* _DHCP_NETWORK_H */