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