dhcp4_lease.h

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

Generated on Thu Aug 10 21:26:25 2006 for libdhcp by  doxygen 1.4.7