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