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  */
00007 /*
00008  * Copyright (C) 2006  Red Hat, Inc. All rights reserved.
00009  *
00010  * This copyrighted material is made available to anyone wishing to use,
00011  * modify, copy, or redistribute it subject to the terms and conditions of
00012  * the GNU General Public License v.2.  This program is distributed in the
00013  * hope that it will be useful, but WITHOUT ANY WARRANTY expressed or
00014  * implied, including the implied warranties of MERCHANTABILITY or FITNESS
00015  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
00016  * details.  You should have received a copy of the GNU General Public
00017  * License along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00019  * USA. Any Red Hat trademarks that are incorporated in the source code or
00020  * documentation are not subject to the GNU General Public License and may
00021  * only be used or replicated with the express permission of Red Hat, Inc.
00022  *
00023  * Red Hat Author(s): Jason Vas Dias
00024  *                    David Cantrell
00025  */
00026 
00027 #include <libdhcp.h>
00028 #include <nic.h>
00029 #include <dhcp4_nic.h>
00030 #include <dhcp4_lease.h>
00031 #include <dhcp6_nic.h>
00032 #include <dhcp6_lease.h>
00033 #include <malloc.h>
00034 
00035 /**
00036  * @addtogroup DHCP
00037  * @{
00038  */
00039 
00040 /**
00041  * The DHCP_Preference enumeration.
00042  *
00043  * Controls which clients are to be run, and which configuration actions 
00044  * are to be enabled on receipt of a lease.
00045  */
00046 typedef
00047 enum 
00048 {
00049     DHCPv4_DISABLE  = 1,  /**< disables the DHCPv4 client */
00050     DHCPv6_DISABLE  = 2,  /**< disabled the DHCPv6 client */
00051     IPv6_PREFERENCE = 4,  /**< If neither DHCPv4_DISABLE nor DHCPv6_DISABLE are enabled,
00052                            * setting this will run the DHCPv6 client first, and configure 
00053                            * IPv6 addresses / routes / DNS first */ 
00054     DHCPv4_DISABLE_ADDRESSES = 8,  /**< Don't configure DHCPv4 addresses */
00055     DHCPv4_DISABLE_ROUTES    = 16, /**< Don't configure DHCPv4 routes */
00056     DHCPv4_DISABLE_RESOLVER  = 32, /**< Don't configure DHCPv4 resolv.conf entries */
00057     DHCPv6_DISABLE_ADDRESSES = 64, /**< Don't configure DHCPv6 address (ie. use radvd) */
00058     DHCPv6_DISABLE_RESOLVER  = 128,/**< Don't configure DHCPv6 resolv.conf entries */
00059     DHCPv4_DISABLE_HOSTNAME_SET=256,/**< Don't set hostname if DHCPv4 host-name option sent */ 
00060     DHCP_ACCEPT_FIRST_LEASE  = 512 /**< If timeout == 0, and both clients are enabled,
00061                                     * v4 and v6 clients are run in separate  processes; 
00062                                     * if this preference is set, then the first client
00063                                     * to get a lease will cause that lease to be accepted
00064                                     * and the other client process to be terminated. */
00065 }   DHCP_Preference;
00066 
00067 /**
00068  *  DHCP_config: The DHCP network interface configuration structure.
00069  *
00070  *  This structure encapsulates the network configuration information returned
00071  *  in a DHCP lease, and the lease itself.
00072  */
00073 typedef
00074 struct dhcpc_nic_s
00075 {
00076     NLH_t          nh;               /**< nic library handle */
00077     NIC_t          nic;              /**< network interface  */
00078     IPaddr_list_t  address_list;     /**< list of addresses assigned to the nic by the lease */
00079     IProute_list_t route_list;       /**< list of routes assigned to the nic by the lease */
00080     IPaddr_list_t  dns_list;         /**< list of DNS servers assigned by the lease */
00081     char          *search_list;      /**< DNS search list assigned by the lease */ 
00082     char          *host_name;        /**< host name assigned by the lease */
00083     union 
00084     { 
00085         DHCPv4_lease  *dhcp4_lease;  /**< DHCPv4 lease - see @ref DHCPv4  */
00086         DHCPv6_lease  *dhcp6_lease;  /**< DHCPv6 lease - see @ref DHCPv6  */
00087     } lease;
00088 } DHCP_config;
00089 
00090 /**
00091  * DHCP_nic: The DHCP network interface control structure.
00092  *
00093  * This structure encapsulates the control and configuration
00094  * of both DHCP clients.
00095  */
00096 typedef
00097 struct dhcp_nic
00098 {
00099     DHCPv4_control  *dhc4ctl;        /**< DHCPv4 control - see @ref DHCPv4 */
00100     LIBDHCP_Control *dhc6ctl;        /**< DHCPv6 control - see @ref DHCPv6 */
00101     NLH_t            nh;             /**< nic library handle - see @ref NIC */
00102     DHCP_config     *dhcpv4;         /**< DHCPv4 configuration - see @ref DHCPv4 */
00103     DHCP_config     *dhcpv6;         /**< DHCPv6 configuration - see @ref DHCPv6 */
00104     DHCP_Preference preference;      /**< DHCP_Preference - @see ::DHCP_Preference */
00105 } DHCP_nic;
00106 
00107 /**
00108  * dhcp_nic() : function which invokes the DHCP clients and returns a network interface configuration.
00109  *
00110  */
00111 extern 
00112 DHCP_nic *dhcp_nic
00113 ( 
00114     NLH_t nh,                               /**< nic library handle - see  @ref NIC */
00115     DHCP_Preference preference,             /**< DHCP_Preference - @see ::DHCP_Preference */
00116     char                  *eth_if_name,     /**< network interface name - eg. 'eth0' */
00117     LIBDHCP_Capability     dhc_cap,         /**< DHCP_Capability - @see ::DHCP_Capability */
00118     time_t                 timeout,         /**< timeout - @see ::LIBDHCP_Control::timeout */
00119     LIBDHCP_Error_Handler  error_handler,   /**< error handler - @see LIBDHCP_Control::error_handler */
00120     uint8_t                log_level,       /**< log level - @see LIBDHCP_Control::log_level */
00121     ... /**< extra DHCPv4 dhclient arguments;
00122          * last arg MUST be 0 .
00123          */
00124 );
00125 
00126 /**
00127  * dhcp_nic_configure () : function to apply the DHCP configuration to the network interface .
00128  */
00129 extern 
00130 NIC_Res_t
00131 dhcp_nic_configure
00132 (
00133     DHCP_nic *dhcp_nic  /**< @see ::DHCP_nic */
00134 );
00135 
00136 /**
00137  *  function dhcp_nic_free() : frees all resources associated with the DHCP_nic structure  
00138  */
00139 extern
00140 void dhcp_nic_free(DHCP_nic *);
00141 
00142 /**
00143  * do_dhcp(): function to run the clients and apply the DHCP configuration to the network interface
00144  */
00145 extern 
00146 NIC_Res_t do_dhcp
00147 ( 
00148     DHCP_Preference preference,           /**< DHCP_Preference - @see ::DHCP_Preference */
00149     char                  *eth_if_name,   /**< interface name */
00150     LIBDHCP_Capability     dhc_cap,       /**< DHCP_Capability - @see ::DHCP_Capability */
00151     time_t                 timeout,       /**< timeout - @see ::LIBDHCP_Control::timeout */
00152     LIBDHCP_Error_Handler  error_handler, /**< error_handler @see ::LIBDHCP_Control::error_handler */
00153     uint8_t                log_level,     /**< log_level - @see ::LIBDHCP_Control::log_level */
00154     ... /**< extra DHCPv4 dhclient arguments;
00155          * last arg MUST be 0 .
00156          */
00157 );
00158 
00159 /**@}*/
00160 

Generated on Mon Aug 14 17:26:18 2006 for libdhcp by  doxygen 1.4.7