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) 2001 by Sun Microsystems, Inc.
  24  * All rights reserved.
  25  */
  26 
  27 #ifndef _DHCP_SVC_PUBLIC_H
  28 #define _DHCP_SVC_PUBLIC_H
  29 
  30 #pragma ident   "%Z%%M% %I%     %E% SMI"
  31 
  32 /*
  33  * Contains published interfaces to the DHCP data service.
  34  */
  35 
  36 #ifdef  __cplusplus
  37 extern "C" {
  38 #endif
  39 
  40 #include <sys/types.h>
  41 #include <netinet/in.h>                   /* struct in_addr */
  42 #include <netinet/dhcp.h>
  43 
  44 #define DSVC_PUBLIC_VERSION     1       /* version of public layer interface */
  45 
  46 /*
  47  * Errors which can be returned from the defined API
  48  * Note: must be kept in sync with errmsgs[] in private/errmsgs.c.
  49  */
  50 #define DSVC_SUCCESS            0       /* success */
  51 #define DSVC_EXISTS             1       /* object already exists */
  52 #define DSVC_ACCESS             2       /* access denied */
  53 #define DSVC_NO_CRED            3       /* no underlying credential */
  54 #define DSVC_NOENT              4       /* object doesn't exist */
  55 #define DSVC_BUSY               5       /* object temporarily busy (again) */
  56 #define DSVC_INVAL              6       /* invalid argument(s) */
  57 #define DSVC_INTERNAL           7       /* internal data store error */
  58 #define DSVC_UNAVAILABLE        8       /* underlying service required by */
  59                                         /* public module unavailable */
  60 #define DSVC_COLLISION          9       /* update collision */
  61 #define DSVC_UNSUPPORTED        10      /* operation not supported */
  62 #define DSVC_NO_MEMORY          11      /* operation ran out of memory */
  63 #define DSVC_NO_RESOURCES       12      /* non-memory resources unavailable */
  64 #define DSVC_BAD_RESOURCE       13      /* malformed/missing RESOURCE setting */
  65 #define DSVC_BAD_PATH           14      /* malformed/missing PATH setting */
  66 #define DSVC_MODULE_VERSION     15      /* public layer version mismatch */
  67 #define DSVC_MODULE_ERR         16      /* internal public module error */
  68 #define DSVC_MODULE_LOAD_ERR    17      /* error loading public module */
  69 #define DSVC_MODULE_UNLOAD_ERR  18      /* error unloading public module */
  70 #define DSVC_MODULE_CFG_ERR     19      /* Module configuration failure */
  71 #define DSVC_SYNCH_ERR          20      /* error in synchronization protocol */
  72 #define DSVC_NO_LOCKMGR         21      /* cannot contact lock manager */
  73 #define DSVC_NO_LOCATION        22      /* location nonexistent */
  74 #define DSVC_BAD_CONVER         23      /* malformed/missing CONVER setting */
  75 #define DSVC_NO_TABLE           24      /* container does not exist */
  76 #define DSVC_TABLE_EXISTS       25      /* container already exists */
  77 
  78 #define DSVC_NERR               (DSVC_TABLE_EXISTS + 1)
  79 
  80 /*
  81  * Flags that can be passed to open_*
  82  */
  83 #define DSVC_CREATE             0x01    /* create container; must not exist */
  84 #define DSVC_READ               0x02    /* open container for reading */
  85 #define DSVC_WRITE              0x04    /* open container for writing */
  86 #define DSVC_NONBLOCK           0x08    /* open container in nonblocking mode */
  87 
  88 /*
  89  * Query macros - used for initializing query flags to lookup_*
  90  */
  91 #define DSVC_QINIT(q)           ((q) = 0)
  92 #define DSVC_QEQ(q, v)          ((q) = ((q) | (v) | ((v) << 16)))
  93 #define DSVC_QNEQ(q, v)         ((q) = ((~((v) << 16)) & (q)) | (v))
  94 #define DSVC_QISEQ(q, v)        (((q) & (v)) && ((q) & ((v) << 16)))
  95 #define DSVC_QISNEQ(q, v)       (((q) & (v)) && (!((q) & ((v) << 16))))
  96 
  97 #define DSVC_MAX_MACSYM_LEN     128     /* max length of a macro or symbol */
  98 
  99 /*
 100  * DHCP Configuration Container (dhcptab(4))
 101  */
 102 #define DT_DHCPTAB              "dhcptab"       /* Default name of container */
 103 #define DT_SYMBOL               's'
 104 #define DT_MACRO                'm'
 105 
 106 /* Query flags for lookup_dt */
 107 #define DT_QKEY                 0x01
 108 #define DT_QTYPE                0x02
 109 #define DT_QALL                 (DT_QKEY|DT_QTYPE)
 110 
 111 /*
 112  * Consumer's dhcptab record form. Dynamically allocated by underlying data
 113  * store.  dt_sig is set by underlying data store -- it's opaque to the
 114  * DHCP service, and is used by the data store to detect update collisions.
 115  * All fields must be fixed-width types and in host byte order.  Note that
 116  * SUNWbinfiles writes these records directly to disk, thus changing its
 117  * definition may introduce binary compatibility problems.  Note also that
 118  * fields have been carefully ordered to avoid internal padding and the
 119  * structure's size is 64-bit aligned to avoid capricious trailing padding.
 120  */
 121 typedef struct {
 122         uint64_t        dt_sig;                 /* Opaque atomic cookie */
 123         char            *dt_value;              /* Value of type dt_type */
 124         char            dt_key[DSVC_MAX_MACSYM_LEN + 1]; /* Macro/symbol name */
 125         char            dt_type;                /* Type of data */
 126         char            dt_pad[2];              /* Pad to 64-bit boundary */
 127 } dt_rec_t;
 128 
 129 typedef struct dt_rec_list {
 130         dt_rec_t                *dtl_rec;
 131         struct dt_rec_list      *dtl_next;      /* Next record in the list */
 132 } dt_rec_list_t;
 133 
 134 /*
 135  * DHCP Network Container (dhcp_network(4))
 136  */
 137 #define DN_MAX_CID_LEN          (DSVC_MAX_MACSYM_LEN / 2)
 138 #define DN_MAX_COMMENT_LEN      48
 139 
 140 /* Query flags for lookup_dn */
 141 #define DN_QCID                 0x0001
 142 #define DN_QCIP                 0x0002
 143 #define DN_QSIP                 0x0004
 144 #define DN_QLEASE               0x0008
 145 #define DN_QMACRO               0x0010
 146 #define DN_QFDYNAMIC            0x0020
 147 #define DN_QFAUTOMATIC          0x0040
 148 #define DN_QFMANUAL             0x0080
 149 #define DN_QFUNUSABLE           0x0100
 150 #define DN_QFBOOTP_ONLY         0x0200
 151 #define DN_QALL                 (DN_QCID | DN_QCIP | DN_QSIP | DN_QLEASE |\
 152                                     DN_QMACRO | DN_QFDYNAMIC | DN_QFAUTOMATIC |\
 153                                     DN_QFMANUAL | DN_QFUNUSABLE |\
 154                                     DN_QFBOOTP_ONLY)
 155 
 156 /* dn_flags values */
 157 #define DN_FDYNAMIC             0x00    /* Non-permanent */
 158 #define DN_FAUTOMATIC           0x01    /* Lease is permanent */
 159 #define DN_FMANUAL              0x02    /* Manually allocated (sacred) */
 160 #define DN_FUNUSABLE            0x04    /* Address is unusable */
 161 #define DN_FBOOTP_ONLY          0x08    /* Address is reserved for BOOTP */
 162 #define DN_FALL                 (DN_FDYNAMIC | DN_FAUTOMATIC | DN_FMANUAL |\
 163                                     DN_FUNUSABLE | DN_FBOOTP_ONLY)
 164 
 165 /*
 166  * Consumer's DHCP network container record form. Dynamically allocated by
 167  * underlying data store.  dn_sig is set by underlying data store -- it's
 168  * opaque to the DHCP service, and is used by the data store to detect
 169  * update collisions.  All fields must be fixed-width types and in host
 170  * byte order. Note that SUNWbinfiles writes these records directly to
 171  * disk, thus changing its definition may introduce binary compatibility
 172  * problems.  Note also that fields have been carefully ordered to avoid
 173  * internal padding and the structure's size is 64-bit aligned to avoid
 174  * capricious trailing padding.
 175  */
 176 typedef struct {
 177         uint64_t        dn_sig;                 /* Opaque atomic cookie */
 178         struct in_addr  dn_cip;                 /* Client IP address */
 179         struct in_addr  dn_sip;                 /* Server IP address */
 180         lease_t         dn_lease;               /* Abs lease expiration */
 181         char            dn_macro[DSVC_MAX_MACSYM_LEN + 1];
 182         char            dn_comment[DN_MAX_COMMENT_LEN + 1];
 183         uchar_t         dn_cid[DN_MAX_CID_LEN]; /* Opaque client id */
 184         uchar_t         dn_cid_len;             /* Length of client id */
 185         uchar_t         dn_flags;               /* Flags */
 186 } dn_rec_t;
 187 
 188 typedef struct dn_rec_list {
 189         dn_rec_t                *dnl_rec;       /* The record itself */
 190         struct dn_rec_list      *dnl_next;      /* Next entry in the list */
 191 } dn_rec_list_t;
 192 
 193 /*
 194  * Synchronization Service Type and values.
 195  */
 196 typedef uint32_t dsvc_synchtype_t;
 197 
 198 #define DSVC_SYNCH_NONE         0               /* no synch type */
 199 #define DSVC_SYNCH_DSVCD        1               /* dsvclockd(1M) synch type */
 200 
 201 /*
 202  * Generic API provided by SMI
 203  */
 204 extern dt_rec_t *alloc_dtrec(const char *, char, const char *);
 205 extern dn_rec_t *alloc_dnrec(const uchar_t *, uchar_t, uchar_t, struct in_addr,
 206                     struct in_addr, lease_t, const char *, const char *);
 207 extern dt_rec_list_t *add_dtrec_to_list(dt_rec_t *, dt_rec_list_t *);
 208 extern dn_rec_list_t *add_dnrec_to_list(dn_rec_t *, dn_rec_list_t *);
 209 extern void     free_dtrec(dt_rec_t *);
 210 extern void     free_dnrec(dn_rec_t *);
 211 extern void     free_dtrec_list(dt_rec_list_t *);
 212 extern void     free_dnrec_list(dn_rec_list_t *);
 213 extern const char *dhcpsvc_errmsg(uint_t);
 214 
 215 /*
 216  * The remaining functions are not directly callable by the libdhcpsvc
 217  * implementation; don't expose them to it.
 218  */
 219 #ifndef _DHCPSVC_IMPL
 220 
 221 /*
 222  * Generic Service Provider Layer API provided by data store implementor
 223  */
 224 extern int      status(const char *);
 225 extern int      version(int *);
 226 extern int      configure(const char *);
 227 extern int      mklocation(const char *);
 228 
 229 /*
 230  * dhcptab Service Provider Layer API
 231  */
 232 extern int      list_dt(const char *, char ***, uint_t *);
 233 extern int      open_dt(void **, const char *, uint_t);
 234 extern int      close_dt(void **);
 235 extern int      add_dt(void *, dt_rec_t *);
 236 extern int      remove_dt(const char *);
 237 extern int      modify_dt(void *, const dt_rec_t *, dt_rec_t *);
 238 extern int      delete_dt(void *, const dt_rec_t *);
 239 extern int      lookup_dt(void *, boolean_t, uint_t, int,
 240                     const dt_rec_t *, dt_rec_list_t **, uint_t *);
 241 /*
 242  * DHCP Network Service Provider Layer API
 243  * IP address arguments are host order.
 244  */
 245 extern int      list_dn(const char *, char ***, uint_t *);
 246 extern int      open_dn(void **, const char *, uint_t, const struct in_addr *,
 247                     const struct in_addr *);
 248 extern int      close_dn(void **);
 249 extern int      add_dn(void *, dn_rec_t *);
 250 extern int      remove_dn(const char *, const struct in_addr *);
 251 extern int      modify_dn(void *, const dn_rec_t *, dn_rec_t *);
 252 extern int      delete_dn(void *, const dn_rec_t *);
 253 extern int      lookup_dn(void *, boolean_t, uint_t, int,
 254                     const dn_rec_t *, dn_rec_list_t **, uint_t *);
 255 #endif
 256 
 257 #ifdef  __cplusplus
 258 }
 259 #endif
 260 
 261 #endif  /* !_DHCP_SVC_PUBLIC_H */