dhcp4_lease.h

00001 /* @file dhcp4_lease.c
00002  *
00003  *  Representation of ISC dhcp lease options for libdhcp
00004  *
00005  */
00006 /*
00007  * Copyright (C) 2006  Red Hat, Inc. All rights reserved.
00008  *
00009  * This copyrighted material is made available to anyone wishing to use,
00010  * modify, copy, or redistribute it subject to the terms and conditions of
00011  * the GNU General Public License v.2.  This program is distributed in the
00012  * hope that it will be useful, but WITHOUT ANY WARRANTY expressed or
00013  * implied, including the implied warranties of MERCHANTABILITY or FITNESS
00014  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
00015  * details.  You should have received a copy of the GNU General Public
00016  * License along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00018  * USA. Any Red Hat trademarks that are incorporated in the source code or
00019  * documentation are not subject to the GNU General Public License and may
00020  * only be used or replicated with the express permission of Red Hat, Inc.
00021  *
00022  * Red Hat Author(s): Jason Vas Dias
00023  *                    David Cantrell
00024  */
00025 #ifndef _DHCP4_LEASE_H
00026 #define _DHCP4_LEASE_H
00027 
00028 #include  <sys/types.h>
00029 #include  <netinet/in.h>
00030 #include  <stdint.h>
00031 
00032 /** @addtogroup DHCPv4_lease
00033  *  @{
00034  */
00035 
00036 /**
00037  *  DHCP Option Type Codes:
00038  */
00039 typedef
00040 enum dhcp_option_type__e
00041 {   /* These are the same codes as used by dhcpd / dhclient,
00042      * and which are written by dhclient with '-x' option to 
00043      * new option information variables named x._universe_.x:
00044      */
00045     /* "atomic" types: */
00046     DHC_T_IP_ADDRESS        = 'I', /**<  I - IP address */
00047     DHC_T_HEX_STRING        = 'X', /**<  X - either an ASCII string or binary data.   On output, the string is
00048                                     *        scanned to see if it's printable ASCII and, if so, output as a
00049                                     *        quoted string.   If not, it's output as colon-seperated hex.   On
00050                                     *        input, the option can be specified either as a quoted string or as 
00051                                     *        a colon-seperated hex list. */
00052     DHC_T_DOMAIN_NAME       = 'd', /**<  d - Domain name (i.e., FOO or FOO.BAR). */
00053     DHC_T_INT32             = 'l', /**<  l - 32-bit signed integer */
00054     DHC_T_UINT32            = 'L', /**<  L - 32-bit unsigned integer */
00055     DHC_T_INT16             = 's', /**<  s - 16-bit signed integer */
00056     DHC_T_UINT16            = 'S', /**<  S - 16-bit unsigned integer */
00057     DHC_T_CHAR              = 'b', /**<  b - 8-bit signed integer */
00058     DHC_T_UCHAR             = 'B', /**<  B - 8-bit unsigned integer */
00059     DHC_T_TEXT              = 't', /**<  t - ASCII text */
00060     DHC_T_BOOL              = 'f', /**<  f - flag (true or false) */
00061     DHC_T_IMPLICIT_BOOL     = 'F', /**<  F - implicit flag - the presence of the option indicates that the */
00062 
00063     /* compound types: */
00064     DHC_T_ARRAY             = 'A', /**<  A - array of whatever precedes (e.g., IA means array of IP addresses) */
00065     DHC_T_LIST              = 'a', /**<  a - array of the preceding character (e.g., IIa means two or more IP
00066                                      *       addresses) */
00067     DHC_T_ENUMERATION       = 'N', /**<  N - enumeration.   N is followed by a text string containing 
00068                                     *        the name of the set of enumeration values to parse or emit,
00069                                     *        followed by a '.'.   The width of the data is specified in the
00070                                     *        named enumeration.   Named enumerations are tracked in parse.c. */
00071     /* these are types internal to DHCP and can  safely be ignored .
00072      * ( they are not emitted by dhclient in environment -
00073      *   except "vendor-option-space", which we deal with by use of
00074      *   '._universe_.' information.
00075      * )
00076      */
00077     DHC_T_OPTION_SPACE      = 'U', /**<  U - name of an option space (universe) */
00078     DHC_T_OPTIONAL          = 'o', /**<  o - the preceding value is optional. */
00079     DHC_T_ENCAPSULATION     = 'E', /**<  E - encapsulation, string or colon-seperated hex list (the latter 
00080                                     *        two for parsing).   E is followed by a text string containing
00081                                     *        the name of the option space to encapsulate, followed by a '.'.
00082                                     *        If the E is immediately followed by '.', the applicable vendor
00083                                     *        option space is used if one is defined. */
00084     DHC_T_ENCAPSULATION_NO_DIRECTIVE= 'e',/**<  e - If an encapsulation directive is not the first thing in the string,
00085                                     *        the option scanner requires an efficient way to find the encapsulation.
00086                                     *        This is done by placing a 'e' at the beginning of the option.   The
00087                                     *        'e' has no other purpose, and is not required if 'E' is the first
00088                                     *        thing in the option. */
00089     DHC_T_NONE               = '\0'
00090 }   DHCPv4_Option_Type;
00091 
00092 /**
00093  * DHCPv4_Option_Structure_Type - used internally by the DHCPv4_lease parser.
00094  */
00095 typedef
00096 enum dhcpv4_option_structure_type_e
00097 {
00098     DHCO_SCALAR,                   /**< SCALAR option */
00099     DHCO_ARRAY,                    /**< ARRAY option */
00100     DHCO_STRUCT                    /**< STRUCT option */
00101 }   DHCPv4_Option_Structure_Type;
00102 
00103 /**
00104  *  The maximum length in bytes of a DHCP option:
00105  */
00106 #define DHCPV4_MAX_OPTION_LENGTH  1236
00107 
00108 /**
00109  * The DHCP Option structure.
00110  *
00111  * Structured options (options with more than one member)
00112  * are laid out as C structures in 'opt->value', with a
00113  * list of pointers to each member following the C structure.
00114  * opt->length will be :
00115  * sizeof(structure) + (n_members * sizeof(void*)).
00116  * ie. sizeof(structure) 
00117  *     == opt->length -(n_members * sizeof(void*)).
00118  *
00119  * Array options have exactly opt->n_members elements of opt->size,
00120  * and are packed as a c array.
00121  *
00122  * For scalars, n_members == 1.
00123  */
00124 
00125 typedef struct dhcp4_option_s
00126 {   /* Generic option structure */
00127     struct dhcp4_lease_s *lease;      /**< the lease this option is associated with */
00128     char *                name;       /**< dhcp option name, defined in dhcp/common/tables.c */
00129     char *                format;     /**< dhcp format string of DHCPv4_Option_Type(s) */
00130     char *                universe;   /**< universe name */
00131     uint8_t               unicode;    /**< universe code */
00132     uint8_t               code;       /**< 0 - 255 */
00133     uint8_t               form;       /**< DHCPv4_Option_Structure_Type */
00134     uint8_t               size;       /**< If struct / array, size of element */
00135     uint8_t               udefined;   /**< 1 if user defined option */
00136     uint8_t               redefined;  /**< 1 if user redefined option*/
00137     uint16_t              n_members;  /**< > 1 if structure */ 
00138     uint16_t              n_elements; /**< > 1 if array */   
00139     uint16_t              length;     /**< size of value in bytes */
00140     uint8_t               **members;  /**< points to array of pointers to members at end of value */
00141     uint8_t               value[1];   /**< option value(s) c-structure ; must be aligned for integer */
00142 } DHCPv4_option;
00143 
00144 
00145 /**
00146  * The DHCP Option Callback function type
00147  */
00148 typedef  void (*DHCPv4_option_handler)(DHCPv4_option *, void* );
00149 
00150 /**
00151  * The DHCP lease structure
00152  */
00153 typedef struct dhcp4_lease_s
00154 {
00155     struct in_addr address;           /**< client IP address being leased    */ 
00156     struct in_addr requested_address; /**< address we requested, (if any)    */
00157     struct in_addr server_address;    /**< boot server IP address (if any)   */
00158     char *filename;                   /**< boot filename                     */
00159     char *server_name;                /**< boot server name                  */
00160     uint8_t is_static;                /**< 1: was from config, not pool      */
00161     uint8_t is_bootp;                 /**< 1: is a bootp lease               */
00162     uint16_t if_index;                /**< lease on interface with this index*/
00163     char *if_name;                    /**< lease on interface with this name */
00164     time_t  requested,                /**< time that lease was requested     */
00165             expiry, renewal, rebind;  /**< times in seconds since epoch      */
00166     void *options;                    /**< glibc tsearch(3) btree of options */
00167     void *options_by_name;            /**< glibc tsearch(3) btree of options */
00168     DHCPv4_option_handler handler;    /**< handler for this lease            */
00169     void *handler_arg;                /**< argument to pass to handler       */
00170 } DHCPv4_lease;
00171 
00172 struct client_state;                  /**< include "dhcpd.h" to get this     */
00173 
00174 extern DHCPv4_lease *dhcpv4_lease( struct client_state * ); /**<
00175      * creates a DHCPv4_lease from an ISC DHCP 'struct client_state'.
00176      */
00177 
00178 extern void dhcpv4_lease_free( DHCPv4_lease * ); /**<
00179      * frees all resources associated with lease 
00180      */
00181 
00182 extern void dhcpv4_process_options ( DHCPv4_lease *, DHCPv4_option_handler, void *); /**<
00183      * calls handler with each option in lease and the void* arg 
00184      */
00185 
00186 extern DHCPv4_option *dhcpv4_get_option_by_code( DHCPv4_lease *, uint8_t universe, uint8_t code); /**<
00187      * returns a DHCP lease option by universe and option code, or NULL
00188      */ 
00189 
00190 extern DHCPv4_option *dhcpv4_get_option_by_name( DHCPv4_lease *, char *);  /**<
00191      * returns a DHCP lease option by name, or NULL
00192      */ 
00193 
00194 extern int dhcpv4_pack_lease ( DHCPv4_lease*, uint8_t *buf, uint32_t len); /**<
00195      * packs a DHCPv4_lease in a buffer of length length, suitable for 
00196      * IPC / mmap'd file storage.
00197      */
00198 
00199 extern DHCPv4_lease *dhcpv4_unpack_lease (uint8_t *buf); /**<
00200      * unpacks a DHCPv4_lease from a buffer packed by dhcpv4_pack_lease.
00201      */
00202 
00203 /** DHCP Code Spaces:
00204  *
00205  * Option Codes have unique values in one of these "DHCP_Universe" 
00206  * code spaces:
00207  */
00208 
00209 /**  DHCP can define no more than 256 options, 0-255, in a "universe" */
00210 #define DHCP_OPTION_MAX   256
00211 
00212 /**  DHCP currently supports no more than 10 universes (a hardcoded constant in tables.c).
00213  *  It defines 4 of its own and supports up to 5 user defined option spaces.
00214  */
00215 #define DHCP_UNIVERSE_MAX 10
00216 
00217 /**  "Universe" codes defined by ISC DHCP: */
00218 typedef 
00219 enum dhcp_u_e
00220 {
00221     DHC_DHCP_Universe=0,           /**< Proper DHCP Options as defined in RFC 1533 */
00222     DHC_RAI_Universe=1,            /**< Relay Agent Information sub-option encapsulation */
00223     DHC_NWIP_Universe=2,           /**< NetWare/IP sub-option encapsulation */
00224     DHC_FQDN_Universe=3,           /**< Fully Qualified Domain Name sub-option encapsulation */
00225     DHC_DEFINED_UNIVERSE_N=4
00226 } DHCP_Universe;
00227 
00228 /**  DHCP Universe  Option Codes - 
00229  *   Codes of options in the DHCP universe.
00230  *   enum value names map to option names converted to lowercase, 
00231  *   with '_' replaced by '-'.
00232  */
00233 typedef
00234 enum dhcp_oc_e
00235 {
00236     DHCO_PAD                            =       0, /**< Unused */
00237     DHCO_SUBNET_MASK                    =       1, /**< subnet-mask */
00238     DHCO_TIME_OFFSET                    =       2, /**< time-offset */
00239     DHCO_ROUTERS                        =       3, /**< routers */
00240     DHCO_TIME_SERVERS                   =       4, /**< time-servers */
00241     DHCO_NAME_SERVERS                   =       5, /**< name-servers */
00242     DHCO_DOMAIN_NAME_SERVERS            =       6, /**< domain-name-servers */
00243     DHCO_LOG_SERVERS                    =       7, /**< log-servers */
00244     DHCO_COOKIE_SERVERS                 =       8, /**< cookie-servers */
00245     DHCO_LPR_SERVERS                    =       9, /**< lpr-servers */
00246     DHCO_IMPRESS_SERVERS                =       10, /**< impress-servers */
00247     DHCO_RESOURCE_LOCATION_SERVERS      =       11, /**< resource-location-servers */
00248     DHCO_HOST_NAME                      =       12, /**< host-name */
00249     DHCO_BOOT_SIZE                      =       13, /**< boot-size */
00250     DHCO_MERIT_DUMP                     =       14, /**< merit-dump */
00251     DHCO_DOMAIN_NAME                    =       15, /**< domain-name */
00252     DHCO_SWAP_SERVER                    =       16, /**< swap-server */
00253     DHCO_ROOT_PATH                      =       17, /**< root-path */
00254     DHCO_EXTENSIONS_PATH                =       18, /**< extensions-path */
00255     DHCO_IP_FORWARDING                  =       19, /**< ip-forwarding */
00256     DHCO_NON_LOCAL_SOURCE_ROUTING       =       20, /**< non-local-source-routing */
00257     DHCO_POLICY_FILTER                  =       21, /**< policy-filter */
00258     DHCO_MAX_DGRAM_REASSEMBLY           =       22, /**< max-dgram-reassembly */
00259     DHCO_DEFAULT_IP_TTL                 =       23, /**< default-ip-ttl */
00260     DHCO_PATH_MTU_AGING_TIMEOUT         =       24, /**< path-mtu-aging-timeout */
00261     DHCO_PATH_MTU_PLATEAU_TABLE         =       25, /**< path-mtu-plateau-table */
00262     DHCO_INTERFACE_MTU                  =       26, /**< interface-mtu */
00263     DHCO_ALL_SUBNETS_LOCAL              =       27, /**< all-subnets-local */
00264     DHCO_BROADCAST_ADDRESS              =       28, /**< broadcast-address */
00265     DHCO_PERFORM_MASK_DISCOVERY         =       29, /**< perform-mask-discovery */
00266     DHCO_MASK_SUPPLIER                  =       30, /**< mask-supplier */
00267     DHCO_ROUTER_DISCOVERY               =       31, /**< router-discovery */
00268     DHCO_ROUTER_SOLICITATION_ADDRESS    =       32, /**< router-solicitation-address */
00269     DHCO_STATIC_ROUTES                  =       33, /**< static-routes */
00270     DHCO_TRAILER_ENCAPSULATION          =       34, /**< trailer-encapsulation */
00271     DHCO_ARP_CACHE_TIMEOUT              =       35, /**< arp-cache-timeout */
00272     DHCO_IEEE802_3_ENCAPSULATION        =       36, /**< ieee802-3-encapsulation */
00273     DHCO_DEFAULT_TCP_TTL                =       37, /**< default-tcp-ttl */
00274     DHCO_TCP_KEEPALIVE_INTERVAL         =       38, /**< tcp-keepalive-interval */
00275     DHCO_TCP_KEEPALIVE_GARBAGE          =       39, /**< tcp-keepalive-garbage */
00276     DHCO_NIS_DOMAIN                     =       40, /**< nis-domain */
00277     DHCO_NIS_SERVERS                    =       41, /**< nis-servers */
00278     DHCO_NTP_SERVERS                    =       42, /**< ntp-servers */
00279     DHCO_VENDOR_ENCAPSULATED_OPTIONS    =       43, /**< vendor-encapsulated-options */
00280     DHCO_NETBIOS_NAME_SERVERS           =       44, /**< netbios-name-servers */
00281     DHCO_NETBIOS_DD_SERVER              =       45, /**< netbios-dd-server */
00282     DHCO_NETBIOS_NODE_TYPE              =       46, /**< netbios-node-type */
00283     DHCO_NETBIOS_SCOPE                  =       47, /**< netbios-scope */
00284     DHCO_FONT_SERVERS                   =       48, /**< font-servers */
00285     DHCO_X_DISPLAY_MANAGER              =       49, /**< x-display-manager */
00286     DHCO_DHCP_REQUESTED_ADDRESS         =       50, /**< dhcp-requested-address */
00287     DHCO_DHCP_LEASE_TIME                =       51, /**< dhcp-lease-time */
00288     DHCO_DHCP_OPTION_OVERLOAD           =       52, /**< dhcp-option-overload */
00289     DHCO_DHCP_MESSAGE_TYPE              =       53, /**< dhcp-message-type */
00290     DHCO_DHCP_SERVER_IDENTIFIER         =       54, /**< dhcp-server-identifier */
00291     DHCO_DHCP_PARAMETER_REQUEST_LIST    =       55, /**< dhcp-parameter-request-list */
00292     DHCO_DHCP_MESSAGE                   =       56, /**< dhcp-message */
00293     DHCO_DHCP_MAX_MESSAGE_SIZE          =       57, /**< dhcp-max-message-size */
00294     DHCO_DHCP_RENEWAL_TIME              =       58, /**< dhcp-renewal-time */
00295     DHCO_DHCP_REBINDING_TIME            =       59, /**< dhcp-rebinding-time */
00296     DHCO_VENDOR_CLASS_IDENTIFIER        =       60, /**< vendor-class-identifier */
00297     DHCO_DHCP_CLIENT_IDENTIFIER         =       61, /**< dhcp-client-identifier */
00298     DHCO_NWIP_DOMAIN_NAME               =       62, /**< nwip-domain-name */
00299     DHCO_NWIP_SUBOPTIONS                =       63, /**< nwip-suboptions */
00300     DHCO_NISPLUS_DOMAIN                 =       64, /**< nisplus-domain */
00301     DHCO_NISPLUS_SERVERS                =       65, /**< nisplus-servers */
00302     DHCO_TFTP_SERVER_NAME               =       66, /**< tftp-server-name */
00303     DHCO_BOOTFILE_NAME                  =       67, /**< bootfile-name */
00304     DHCO_MOBILE_IP_HOME_AGENT           =       68, /**< mobile-ip-home-agent */
00305     DHCO_SMTP_SERVER                    =       69, /**< smtp-server */
00306     DHCO_POP_SERVER                     =       70, /**< pop-server */
00307     DHCO_NNTP_SERVER                    =       71, /**< nntp-server */
00308     DHCO_WWW_SERVER                     =       72, /**< www-server */
00309     DHCO_FINGER_SERVER                  =       73, /**< finger-server */
00310     DHCO_IRC_SERVER                     =       74, /**< irc-server */
00311     DHCO_STREETTALK_SERVER              =       75, /**< streettalk-server */
00312     DHCO_STREETTALK_DIRECTORY_ASSISTANCE_SERVER=76, /**< streettalk-directory-assistance-server */
00313     DHCO_USER_CLASS                     =       77, /**< user-class */
00314     DHCO_SLP_DIRECTORY_AGENT            =       78, /**< slp-directory-server */
00315     DHCO_SLP_SERVICE_SCOPE              =       79, /**< slp-service-scope */
00316     DHCO_FQDN                           =       81, /**< fqdn */
00317     DHCO_DHCP_AGENT_OPTIONS             =       82, /**< dhcp-agent-options */
00318     DHCO_NDS_SERVERS                    =       85, /**< nds-servers */
00319     DHCO_NDS_TREE_NAME                  =       86, /**< nds-tree-name */
00320     DHCO_NDS_CONTEXT                    =       87, /**< nds-context */
00321     DHCO_UAP_SERVERS                    =       98, /**< uap-servers */
00322     DHCO_SUBNET_SELECTION               =       118, /**< subnet-selection */
00323     DHCO_AUTHENTICATE                   =       210, /**< authenticate */
00324     DHCO_END                            =       210, /**< */
00325     DHCO_N                              =       211 /**< */
00326 }   DHCP_Option_Code;
00327 
00328 /** DHCP Relay Agent Information Sub-Options:
00329  */
00330 typedef
00331 enum dho_rai_c_e
00332 {
00333     DHCO_RAI_PAD                         =       0, /**< */
00334     DHCO_RAI_CIRCUIT_ID                  =       1, /**< rai.circuit-id */
00335     DHCO_RAI_REMOTE_ID                   =       2, /**< rai.remote-id */
00336     DHCO_RAI_AGENT_ID                    =       3, /**< rai.agent-id */
00337     DHCO_RAI_END                         =       3, /**< */
00338     DHCO_RAI_N                           =       4  /**< */
00339 } DHCP_RAI_Options;
00340 
00341 /** DHCP NetWare/IP (nwip) Sub-Options:
00342  */
00343 typedef
00344 enum dho_nwip_c_e
00345 {
00346     DHCO_NWIP_PAD                        =       0, /**< */
00347     DHCO_NWIP_ILL1                       =       1, /**< */
00348     DHCO_NWIP_ILL2                       =       2, /**< */
00349     DHCO_NWIP_ILL3                       =       3, /**< */
00350     DHCO_NWIP_ILL4                       =       4, /**< */
00351     DHCO_NWIP_NSQ_BROADCAST              =       5, /**< nwip.nsq-broadcast */
00352     DHCO_NWIP_PREFERRED_DSS              =       6, /**< nwip.preferred-dss */
00353     DHCO_NWIP_NEAREST_NWIP_SERVER        =       7, /**< nwip.nearest-nwip-server */
00354     DHCO_NWIP_AUTORETRIES                =       8, /**< nwip.autoretries */
00355     DHCO_NWIP_AUTORETRY_SECS             =       9, /**< nwip.autoretry-secs */
00356     DHCO_NWIP_1_1                        =      10, /**< nwip.1-1 */
00357     DHCO_NWIP_PRIMARY_DSS                =      11, /**< nwip.primary-dss */
00358     DHCO_NWIP_END                        =      11, /**< */
00359     DHCO_NWIP_N                          =      12  /**< */
00360 } DHCP_NWIP_Options;
00361 
00362 /** DHCP Fully Qualified Domain Name (fqdn) Sub-Options:
00363  */
00364 typedef
00365 enum dho_fqdn_c_e
00366 {
00367     DHCO_FQDN_PAD                        =       0, /**< */
00368     DHCO_FQDN_NO_CLIENT_UPDATE           =       1, /**< fqdn.no-client-update */
00369     DHCO_FQDN_SERVER_UPDATE              =       2, /**< fqdn.server-update */
00370     DHCO_FQDN_ENCODED                    =       3, /**< fqdn.encoded */
00371     DHCO_FQDN_RCODE1                     =       4, /**< fqdn.rcode1 */
00372     DHCO_FQDN_RCODE2                     =       5, /**< fqdn.rcode2 */
00373     DHCO_FQDN_HOSTNAME                   =       6, /**< fqdn.hostname */
00374     DHCO_FQDN_DOMAINNAME                 =       7, /**< fqdn.domain-name */
00375     DHCO_FQDN_FQDN                       =       8, /**< fqdn.fqdn */
00376     DHCO_FQDN_END                        =       8, /**< */
00377     DHCO_FQDN_N                          =       9  /**< */
00378 } DHCP_FQDN_Options;
00379 
00380 /** NOTE: programs using DHCP must be able to handle (or ignore)
00381  * user defined options in new universes with user defined formats,
00382  * and handle existing defined options that have been redefined by
00383  * the user (ISC dhcp allows this!).
00384  */
00385 /**@}*/
00386 #endif

Generated on Mon Aug 14 17:25:56 2006 for libdhcp by  doxygen 1.4.7