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