states.h revision a1196271e1d6e6ce9cc40c8b94f5b659935e82bc
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef STATES_H
#define STATES_H
#include <libinetutil.h>
#include "common.h"
#include "ipc_action.h"
#include "async.h"
#include "packet.h"
#include "util.h"
/*
* interfaces for state transition/action functions. these functions
* renew.c, etc.
*/
#ifdef __cplusplus
extern "C" {
#endif
/*
* DHCP state machine representation: includes all of the information used for
* a state machine instance. For IPv4, this represents a single logical
* interface and (usually) a leased address. For IPv6, it represents a
* DUID+IAID combination. Note that if multiple DUID+IAID instances are one
* day allowed per interface, this will need to become a list.
*/
struct dhcp_smach_s {
/*
* The name of the state machine. This is currently just a pointer to
* the controlling LIF's name, but could be otherwise.
*/
const char *dsm_name;
/*
* each state machine can have at most one pending asynchronous
* action, which is represented in a `struct async_action'.
* if that asynchronous action was a result of a user request,
* then the `struct ipc_action' is used to hold information
* about the user request. these structures are opaque to
* users of the ifslist, and the functional interfaces
* provided in async.[ch] and ipc_action.[ch] should be used
* to maintain them.
*/
/*
* current state of the machine
*/
/*
* We retain the very first ack obtained on the state machine to
* provide access to options which were originally assigned by
* the server but may not have been included in subsequent
* acks, as there are servers which do this and customers have
* had unsatisfactory results when using our agent with them.
* ipc_event() in agent.c provides a fallback to the original
* ack when the current ack doesn't have the information
* requested.
*
* Note that neither of these is actually a list of packets. There's
* exactly one packet here, so use free_pkt_entry.
*/
/*
* other miscellaneous variables set or needed in the process
* of acquiring a lease.
*/
int dsm_offer_wait; /* seconds between sending offers */
/*
* time we sent the DISCOVER relative to dsm_neg_hrtime, so that the
* REQUEST can have the same pkt->secs.
*/
/*
* this is a chain of packets which have been received on this
* state machine over some interval of time. the packets may have
* to meet some criteria in order to be put on this list. in
* general, packets are put on this list through recv_pkt()
*/
/*
* these three fields are initially zero, and get incremented
* as the ifslist goes from INIT -> BOUND. if and when the
* ifslist moves to the RENEWING state, these fields are
* reset, so they always either indicate the number of packets
* sent, received, and declined while obtaining the current
* lease (if BOUND), or the number of packets sent, received,
* and declined while attempting to obtain a future lease
* (if any other state).
*/
/*
* dsm_send_pkt.pkt is dynamically allocated to be as big a
* packet as we can send out on this state machine. the remainder
* of this information is needed to make it easy to handle
* retransmissions. note that other than dsm_bad_offers, all
* of these fields are maintained internally in send_pkt(),
* and consequently should never need to be modified by any
* other functions.
*/
union {
struct sockaddr_in v4;
struct sockaddr_in6 v6;
/*
* For v4, dsm_send_tcenter is used to track the central timer value in
* milliseconds (4000, 8000, 16000, 32000, 64000), and dsm_send_timeout
* is that value plus the +/- 1000 millisecond fuzz.
*
* For v6, dsm_send_tcenter is the MRT (maximum retransmit timer)
* value, and dsm_send_timeout must be set to the IRT (initial
* retransmit timer) value by the sender.
*/
/*
* The host name we've been asked to request is remembered
* here between the DISCOVER and the REQUEST. (v4 only)
*/
char *dsm_reqhost;
/*
* V4 and V6 use slightly different timers. For v4, we must count
* seconds from the point where we first try to configure the
* interface. For v6, only seconds while performing a transaction
* matter.
*
* In v4, `dsm_neg_hrtime' represents the time since DHCP started
* configuring the interface, and is used for computing the pkt->secs
* field in v4. In v6, it represents the time since the current
* transaction (if any) was started, and is used for the ELAPSED_TIME
* option.
*
* `dsm_newstart_monosec' represents the time the ACKed REQUEST was
* sent, which represents the start time of a new batch of leases.
* When the lease time actually begins (and thus becomes current),
* `dsm_curstart_monosec' is set to `dsm_newstart_monosec'.
*/
int dsm_script_fd;
const char *dsm_script_event;
void *dsm_callback_arg;
};
struct dhcp_lease_s {
/*
* the following fields are set when a lease is acquired, and
* may be updated over the lifetime of the lease. they are
* all reset by reset_smach().
*/
};
/* The IU event callback functions */
/* Common state-machine related routines throughout dhcpagent */
boolean_t dhcp_adopt(void);
void dhcp_adopt_complete(dhcp_smach_t *);
void dhcp_bound_complete(dhcp_smach_t *);
int dhcp_drop(dhcp_smach_t *, void *);
void dhcp_deprecate(iu_tq_t *, void *);
void dhcp_expire(iu_tq_t *, void *);
void dhcp_inform(dhcp_smach_t *);
void dhcp_init_reboot(dhcp_smach_t *);
void dhcp_rebind(iu_tq_t *, void *);
int dhcp_release(dhcp_smach_t *, void *);
void dhcp_renew(iu_tq_t *, void *);
void dhcp_requesting(iu_tq_t *, void *);
void dhcp_restart(dhcp_smach_t *);
void dhcp_selecting(dhcp_smach_t *);
void send_declines(dhcp_smach_t *);
void send_v6_request(dhcp_smach_t *);
/* State machine support functions in states.c */
void hold_smach(dhcp_smach_t *);
void release_smach(dhcp_smach_t *);
void remove_smach(dhcp_smach_t *);
void make_primary(dhcp_smach_t *);
void finished_smach(dhcp_smach_t *, int);
int get_smach_cid(dhcp_smach_t *);
uint_t smach_count(void);
void reset_smach(dhcp_smach_t *);
void refresh_smachs(iu_eh_t *, int, void *);
void refresh_smach(dhcp_smach_t *);
void nuke_smach_list(void);
iu_tq_callback_t *);
void cancel_offer_timer(dhcp_smach_t *);
void cancel_smach_timers(dhcp_smach_t *);
void discard_default_routes(dhcp_smach_t *);
void remove_default_routes(dhcp_smach_t *);
/* Lease-related support functions in states.c */
void hold_lease(dhcp_lease_t *);
void release_lease(dhcp_lease_t *);
void remove_lease(dhcp_lease_t *);
void deprecate_leases(dhcp_smach_t *);
void cancel_lease_timers(dhcp_lease_t *);
iu_tq_callback_t *);
#ifdef __cplusplus
}
#endif
#endif /* STATES_H */