dhcp_nic.h

00001 /* @file dhcp_nic.h
00002  *
00003  * Network Interface Configurator for BOTH the ISC DHCP IPv4 client library
00004  * and the DHCPv6 IPv6 client, API.
00005  *
00006  * @author Jason Vas Dias<jvdias@redhat.com>
00007  */
00008 /*
00009  *  Copyright(C) Jason Vas Dias <jvdias@redhat.com> Red Hat Inc. May 2006
00010  *
00011  *  This program is free software; you can redistribute it and/or modify
00012  *  it under the terms of the GNU General Public License as published by
00013  *  the Free Software Foundation at 
00014  *           http://www.fsf.org/licensing/licenses/gpl.txt
00015  *  and included in this software distribution as the "LICENSE" file.
00016  *
00017  *  This program is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *  GNU General Public License for more details.
00021  */
00022 
00023 #include <libdhcp.h>
00024 #include <nic.h>
00025 #include <dhcp4_nic.h>
00026 #include <dhcp4_lease.h>
00027 #include <dhcp6_nic.h>
00028 #include <dhcp6_lease.h>
00029 #include <malloc.h>
00030 
00031 /**
00032  * @addtogroup DHCP
00033  * @{
00034  */
00035 
00036 /**
00037  * The DHCP_Preference enumeration.
00038  *
00039  * Controls which clients are to be run, and which configuration actions 
00040  * are to be enabled on receipt of a lease.
00041  */
00042 typedef
00043 enum 
00044 {
00045     DHCPv4_DISABLE  = 1,  /**< disables the DHCPv4 client */
00046     DHCPv6_DISABLE  = 2,  /**< disabled the DHCPv6 client */
00047     IPv6_PREFERENCE = 4,  /**< If neither DHCPv4_DISABLE nor DHCPv6_DISABLE are enabled,
00048                            * setting this will run the DHCPv6 client first, and configure 
00049                            * IPv6 addresses / routes / DNS first */ 
00050     DHCPv4_DISABLE_ADDRESSES = 8,  /**< Don't configure DHCPv4 addresses */
00051     DHCPv4_DISABLE_ROUTES    = 16, /**< Don't configure DHCPv4 routes */
00052     DHCPv4_DISABLE_RESOLVER  = 32, /**< Don't configure DHCPv4 resolv.conf entries */
00053     DHCPv6_DISABLE_ADDRESSES = 64, /**< Don't configure DHCPv6 address (ie. use radvd) */
00054     DHCPv6_DISABLE_RESOLVER  = 128,/**< Don't configure DHCPv6 resolv.conf entries */
00055     DHCPv4_DISABLE_HOSTNAME_SET=256,/**< Don't set hostname if DHCPv4 host-name option sent */ 
00056     DHCP_ACCEPT_FIRST_LEASE  = 512 /**< If timeout == 0, and both clients are enabled,
00057                                     * v4 and v6 clients are run in separate  processes; 
00058                                     * if this preference is set, then the first client
00059                                     * to get a lease will cause that lease to be accepted
00060                                     * and the other client process to be terminated. */
00061 }   DHCP_Preference;
00062 
00063 /**
00064  *  DHCP_config: The DHCP network interface configuration structure.
00065  *
00066  *  This structure encapsulates the network configuration information returned
00067  *  in a DHCP lease, and the lease itself.
00068  */
00069 typedef
00070 struct dhcpc_nic_s
00071 {
00072     NLH_t          nh;               /**< nic library handle */
00073     NIC_t          nic;              /**< network interface  */
00074     IPaddr_list_t  address_list;     /**< list of addresses assigned to the nic by the lease */
00075     IProute_list_t route_list;       /**< list of routes assigned to the nic by the lease */
00076     IPaddr_list_t  dns_list;         /**< list of DNS servers assigned by the lease */
00077     char          *search_list;      /**< DNS search list assigned by the lease */ 
00078     char          *host_name;        /**< host name assigned by the lease */
00079     union 
00080     { 
00081         DHCPv4_lease  *dhcp4_lease;  /**< DHCPv4 lease - see @ref DHCPv4  */
00082         DHCPv6_lease  *dhcp6_lease;  /**< DHCPv6 lease - see @ref DHCPv6  */
00083     } lease;
00084 } DHCP_config;
00085 
00086 /**
00087  * DHCP_nic: The DHCP network interface control structure.
00088  *
00089  * This structure encapsulates the control and configuration
00090  * of both DHCP clients.
00091  */
00092 typedef
00093 struct dhcp_nic
00094 {
00095     DHCPv4_control  *dhc4ctl;        /**< DHCPv4 control - see @ref DHCPv4 */
00096     LIBDHCP_Control *dhc6ctl;        /**< DHCPv6 control - see @ref DHCPv6 */
00097     NLH_t            nh;             /**< nic library handle - see @ref NIC */
00098     DHCP_config     *dhcpv4;         /**< DHCPv4 configuration - see @ref DHCPv4 */
00099     DHCP_config     *dhcpv6;         /**< DHCPv6 configuration - see @ref DHCPv6 */
00100     DHCP_Preference preference;      /**< DHCP_Preference - @see ::DHCP_Preference */
00101 } DHCP_nic;
00102 
00103 /**
00104  * dhcp_nic() : function which invokes the DHCP clients and returns a network interface configuration.
00105  *
00106  */
00107 extern 
00108 DHCP_nic *dhcp_nic
00109 ( 
00110     NLH_t nh,                               /**< nic library handle - see  @ref NIC */
00111     DHCP_Preference preference,             /**< DHCP_Preference - @see ::DHCP_Preference */
00112     char                  *eth_if_name,     /**< network interface name - eg. 'eth0' */
00113     LIBDHCP_Capability     dhc_cap,         /**< DHCP_Capability - @see ::DHCP_Capability */
00114     time_t                 timeout,         /**< timeout - @see ::LIBDHCP_Control::timeout */
00115     LIBDHCP_Error_Handler  error_handler,   /**< error handler - @see LIBDHCP_Control::error_handler */
00116     uint8_t                log_level,       /**< log level - @see LIBDHCP_Control::log_level */
00117     ... /**< extra DHCPv4 dhclient arguments;
00118          * last arg MUST be 0 .
00119          */
00120 );
00121 
00122 /**
00123  * dhcp_nic_configure () : function to apply the DHCP configuration to the network interface .
00124  */
00125 extern 
00126 NIC_Res_t
00127 dhcp_nic_configure
00128 (
00129     DHCP_nic *dhcp_nic  /**< @see ::DHCP_nic */
00130 );
00131 
00132 /**
00133  *  function dhcp_nic_free() : frees all resources associated with the DHCP_nic structure  
00134  */
00135 extern
00136 void dhcp_nic_free(DHCP_nic *);
00137 
00138 /**
00139  * do_dhcp(): function to run the clients and apply the DHCP configuration to the network interface
00140  */
00141 extern 
00142 NIC_Res_t do_dhcp
00143 ( 
00144     DHCP_Preference preference,           /**< DHCP_Preference - @see ::DHCP_Preference */
00145     char                  *eth_if_name,   /**< interface name */
00146     LIBDHCP_Capability     dhc_cap,       /**< DHCP_Capability - @see ::DHCP_Capability */
00147     time_t                 timeout,       /**< timeout - @see ::LIBDHCP_Control::timeout */
00148     LIBDHCP_Error_Handler  error_handler, /**< error_handler @see ::LIBDHCP_Control::error_handler */
00149     uint8_t                log_level,     /**< log_level - @see ::LIBDHCP_Control::log_level */
00150     ... /**< extra DHCPv4 dhclient arguments;
00151          * last arg MUST be 0 .
00152          */
00153 );
00154 
00155 /**@}*/
00156 

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