827332
/* libdhcp_control.h
827332
 *
827332
 * DHCP client control API for libdhcp, a minimal interface to the
827332
 * ISC dhcp IPv4 client libdhcp4client library,
827332
 * and to the dhcpv6 DHCPv6 client libdhcp6client library.
827332
 *
827332
 * Each DHCP client library must include this file to be controlled
827332
 * by libdhcp.
827332
 *
827332
 * Copyright (C) 2006  Red Hat, Inc. All rights reserved.
827332
 *
827332
 * This copyrighted material is made available to anyone wishing to use,
827332
 * modify, copy, or redistribute it subject to the terms and conditions of
827332
 * the GNU General Public License v.2, or (at your option) any later version.
827332
 * This program is distributed in the hope that it will be useful, but WITHOUT
827332
 * ANY WARRANTY expressed or implied, including the implied warranties of
827332
 * MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE.  See the GNU General
827332
 * Public License for more details.  You should have received a copy of the
827332
 * GNU General Public License along with this program; if not, write to the
827332
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
827332
 * 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
827332
 * source code or documentation are not subject to the GNU General Public
827332
 * License and may only be used or replicated with the express permission of
827332
 * Red Hat, Inc.
827332
 *
827332
 * Red Hat Author(s): Jason Vas Dias
827332
 *                    David Cantrell <dcantrell@redhat.com>
827332
 */
827332
827332
#ifndef LIBDHCP_CONTROL_H
827332
#define LIBDHCP_CONTROL_H
827332
827332
#include <stdarg.h>
827332
#include <stdint.h>
827332
827332
#define  LOG_FATAL 8
827332
827332
typedef enum dhcp_state_e {
827332
    /* DHCPv4 client states
827332
     * third callback arg will be a 'struct client_state *'
827332
     */
827332
    DHC4_NBI,     /* failed: no broadcast interfaces found              */
827332
    DHC4_PREINIT, /* configuration started - bring the interface "UP"   */
827332
    DHC4_BOUND,   /* lease obtained                                     */
827332
    DHC4_RENEW,   /* lease renewed                                      */
827332
    DHC4_REBOOT,  /* have valid lease, but now obtained a different one */
827332
    DHC4_REBIND,  /* new, different lease                               */
827332
    DHC4_STOP,    /* remove old lease                                   */
827332
    DHC4_MEDIUM,  /* media selection begun                              */
827332
    DHC4_TIMEOUT, /* timed out contacting DHCP server                   */
827332
    DHC4_FAIL,    /* all attempts to contact server timed out, sleeping */
827332
    DHC4_EXPIRE,  /* lease has expired, renewing                        */
827332
    DHC4_RELEASE, /* releasing lease                                    */
827332
827332
    /* This state raised by both clients: */
827332
    DHC_TIMEDOUT, /* libdhcp_control timeout has been exceeded          */
827332
827332
    /* DHCPv6 client states:    */
827332
    DHC6_BOUND,   /* new lease obtained             - arg is optinfo *  */
827332
    DHC6_REBIND,  /* existing expired lease rebound - arg is optinfo *  */
827332
    DHC6_RELEASE  /* existing lease expired         - arg is dhcp6_iaidaddr*/
827332
} DHCP_State;
827332
827332
struct libdhcp_control_s;
827332
827332
/* ala syslog(3): LOG_EMERG=0 - LOG_DEBUG=7 (+ LOG_FATAL=8 : finished -> 1) */
827332
typedef int (*LIBDHCP_Error_Handler) (struct libdhcp_control_s *ctl,
827332
                                      int priority, const char *fmt,
827332
                                      va_list ap);
827332
827332
/* The DHCP clients will call the users' callback on important state change
827332
 * events, with the second arg set to the client DHCP_State, and the third
827332
 * arg set to a client specific pointer as described below. */
827332
typedef int (*LIBDHCP_Callback) (struct libdhcp_control_s *control,
827332
                                 enum dhcp_state_e, void*);
827332
827332
typedef struct libdhcp_control_s {
827332
    /* the DHCP clients' main loop calls this on state changes */
827332
    LIBDHCP_Callback callback;
827332
827332
    /* LIBDHCP_Capability bits to enable */
827332
    uint16_t capability;
827332
827332
    /* set to one to make clients exit their main loop */
827332
    uint8_t finished;
827332
827332
    /* set to one to decline the lease (DHCPv4 only) */
827332
    uint8_t decline;
827332
827332
    /* (timeout+now) == time after which clients MUST return */
827332
    time_t timeout;
827332
827332
    /* clients set this to time(0) on entering main loop */
827332
    time_t now;
827332
827332
    /* user data pointer */
827332
    void *arg;
827332
    LIBDHCP_Error_Handler eh;
827332
} LIBDHCP_Control;
827332
827332
/* DHCP client "capabilities" */
827332
typedef enum libdhcp_capability_e {
827332
    /* use / do not use persistent lease database files */
827332
    DHCP_USE_LEASE_DATABASE = 1,
827332
827332
    /* use / do not use pid file */
827332
    DHCP_USE_PID_FILE = 2,
827332
827332
    /*
827332
     * DHCPv6 supports these capabilities in process, 
827332
     * while the DHCPv4 client will fork and exec the dhclient-script to
827332
     * implement them if these bits are set - otherwise, if no bits are set,
827332
     * the callback is called and the script is not run.
827332
     */
827332
    /* configure interfaces UP/DOWN as required */
827332
    DHCP_CONFIGURE_INTERFACES = 4,
827332
827332
    /* configure interface addresses as required */
827332
    DHCP_CONFIGURE_ADDRESSES = 8,
827332
827332
    /* configure routes as required */
827332
    DHCP_CONFIGURE_ROUTES = 16,
827332
827332
    /* configure resolv.conf as required */
827332
    DHCP_CONFIGURE_RESOLVER = 32,
827332
827332
    /* DHCPv6 only: */
827332
    /* configure radvd.conf & restart radvd as required */
827332
    DHCP_CONFIGURE_RADVD = 64,
827332
} LIBDHCP_Capability;
827332
827332
#endif