/* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.h,v 1.21 2003/07/06 05:34:36 actmodern Exp $ * * Copyright 2002 Thamer Alharbash * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #ifndef DHCP_CLIENT_H #define DHCP_CLIENT_H #include "dhcp-client-defaults.h" /* include defaults. */ /* data structures. */ typedef struct { /* use these for unicasting. */ ip_addr_t sip_addr; /* server or relay agent ip address */ eth_addr_t shw_addr; /* server or relay agent hardware address. */ timer_keeper_t *timer; /* timer for rebind/renew. */ } dhcp_client_control_context_t; /* client control object. */ typedef struct { rawnet_t *rawnet; /* raw network handle */ client_cache_t *cache; /* cache */ client_conf_t *conf; /* configuration. */ uint32_t xid; /* unique xid */ time_t started; /* the amount of milliseconds since we started. */ time_t secs; /* secs -- used to save secs value. */ char *interface; /* interface name. */ unsigned char *class_id, *client_id; /* client_id, class_id */ int state; /* our current state. */ uint8_t lease_time_is_infinite; /* whether or not the lease time is infinite. */ /* use this for validation purposes. */ uint16_t server_port; /* port to expect UDP packets from. */ /* context information: this information is stateful so keep it seperate * so it may be saved in case we need to recreate our control object. */ dhcp_client_control_context_t *context; } dhcp_client_control_t; typedef void (*client_command) (char *interface); typedef char *(*interface_lister) (void); typedef int (*client_state) (dhcp_client_control_t *); /* client commands. */ enum client_commands { DO_VERSION = 0, DO_KILL, DO_WAKE, DO_CLEAR, DO_CLIENT, DO_STATUS }; /* DHCP client states. */ enum client_states { STATE_INIT = 0, STATE_INIT_REBOOT, STATE_REQUEST, STATE_RENEW, STATE_REBIND, STATE_SETUP, STATE_BOUND, STATE_INFORM, STATE_SHUTDOWN, STATE_RELEASE, STATE_DECLINE, STATE_FATAL_ERROR, STATE_NO_LEASES, STATE_USER_INTERRUPT }; /* timer IDs. */ enum client_timer_types { TIMER_IP_LEASE = 1, TIMER_REBIND, TIMER_RENEW }; /* prototypes. */ /* client states. */ extern int client_init(dhcp_client_control_t *dc); extern int client_init_reboot(dhcp_client_control_t *dc); extern int client_inform(dhcp_client_control_t *dc); extern int client_requesting(dhcp_client_control_t *dc); extern int client_rebinding(dhcp_client_control_t *dc); extern int client_renewing(dhcp_client_control_t *dc); extern int client_bound(dhcp_client_control_t *dc); extern int client_release(dhcp_client_control_t *dc); extern int client_setup(dhcp_client_control_t *dc); extern int client_shutdown(dhcp_client_control_t *dc); extern int client_reinitialize(dhcp_client_control_t *dc); extern int client_decline(dhcp_client_control_t *dc); /* client control. */ extern dhcp_client_control_t *dhcp_client_control_create(char *interface, int promiscuous, int clear_interface); extern dhcp_client_control_t *dhcp_client_control_create_dummy(char *interface); extern void dhcp_client_control_destroy(dhcp_client_control_t *dc); extern void dhcp_client_update_secs(dhcp_client_control_t *dc); extern void dhcp_client_reset_secs(dhcp_client_control_t *dc); extern void dhcp_client_update_xid(dhcp_client_control_t *dc); extern void dhcp_client_control_use_fake_hw_addr(dhcp_client_control_t *dc, char *fake_hw_addr); extern void dhcp_client_set_server_ip_address(dhcp_client_control_t *dc, ip_addr_t ip_addr); extern void dhcp_client_set_server_hw_address(dhcp_client_control_t *dc, eth_addr_t eth_addr); extern ip_addr_t dhcp_client_get_server_ip_address(dhcp_client_control_t *dc); extern eth_addr_t dhcp_client_get_server_hw_address(dhcp_client_control_t *dc); extern void dhcp_client_lease_time_is_infinite(dhcp_client_control_t *dc); extern void dhcp_client_lease_time_is_finite(dhcp_client_control_t *dc); /* context information. */ extern dhcp_client_control_context_t *dhcp_client_control_context_create(void); extern void dhcp_client_control_destroy_context(dhcp_client_control_context_t *context); extern dhcp_client_control_context_t *dhcp_client_control_copy_context(dhcp_client_control_t *dc); extern void dhcp_client_control_set_context(dhcp_client_control_t *dc, dhcp_client_control_context_t *context); #endif /* DHCP_CLIENT_H */