interface.h revision e704a8f24a369484ba8f4a1cf49d4db00dd91166
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef INTERFACE_H
#define INTERFACE_H
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Interface.[ch] encapsulate all of the agent's knowledge of network
* interfaces from the DHCP agent's perspective. See interface.c for
* documentation on how to use the exported functions. Note that there are not
* functional interfaces for manipulating all of the fields in a PIF or LIF --
* please read the comments in the structure definitions below for the rules on
* accessing various fields.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <dhcpagent_ipc.h>
#include <libinetutil.h>
#include "common.h"
#include "util.h"
struct dhcp_pif_s {
};
struct dhcp_lif_s {
int lif_sock_ip_fd; /* Bound to addr.BOOTPC for src addr */
const char *lif_declined; /* reason to refuse this address */
/*
* While in any states except ADOPTING, INIT, INFORMATION and
* INFORM_SENT, the following three fields are equal to what we believe
* the current address, netmask, and broadcast address on the interface
* to be. This is so we can detect if the user changes them and
* abandon the interface.
*/
};
/* used by expired_lif_state to express state of DHCP interfaces */
typedef enum dhcp_expire_e {
/*
* A word on memory management and LIFs and PIFs:
*
* Since LIFs are often passed as context to callback functions, they cannot be
* freed when the interface they represent is dropped or released (or when
* those callbacks finally go off, they will be hosed). To handle this
* situation, the structures are reference counted. Here are the rules for
* managing these counts:
*
* A PIF is created through insert_pif(). Along with initializing the PIF,
* this puts a hold on the PIF. A LIF is created through insert_lif(). This
* also initializes the LIF and places a hold on it. The caller's hold on the
* underlying PIF is transferred to the LIF.
*
* Whenever a lease is released or dropped (implicitly or explicitly),
* remove_lif() is called, which sets the lif_removed flag and removes the
* interface from the internal list of managed interfaces. Lastly,
* remove_lif() calls release_lif() to remove the hold acquired in
* insert_lif(). If this decrements the hold count on the interface to zero,
* then free() is called and the hold on the PIF is dropped. If there are
* holds other than the hold acquired in insert_lif(), the hold count will
* still be > 0, and the interface will remain allocated (though dormant).
*
* Whenever a callback is scheduled against a LIF, another hold must be put on
* the ifslist through hold_lif().
*
* Whenever a callback is called back against a LIF, release_lif() must be
* called to decrement the hold count, which may end up freeing the LIF if the
* hold count becomes zero.
*
* Since some callbacks may take a long time to get called back (such as
* timeout callbacks for lease expiration, etc), it is sometimes more
* appropriate to cancel the callbacks and call release_lif() if the
* cancellation succeeds. This is done in remove_lif() for the lease preferred
* and expire callbacks.
*
* In general, a callback may also call verify_lif() when it gets called back
* in addition to release_lif(), to make sure that the interface is still in
* fact under the dhcpagent's control. To make coding simpler, there is a
* third function, verify_smach(), which performs both the release_lif() and
* the verify_lif() on all LIFs controlled by a state machine.
*/
extern dhcp_pif_t *v4root;
extern dhcp_pif_t *v6root;
void hold_pif(dhcp_pif_t *);
void release_pif(dhcp_pif_t *);
void hold_lif(dhcp_lif_t *);
void release_lif(dhcp_lif_t *);
void remove_lif(dhcp_lif_t *);
void unplumb_lif(dhcp_lif_t *);
void set_lif_deprecated(dhcp_lif_t *);
void close_ip_lif(dhcp_lif_t *);
void lif_mark_decline(dhcp_lif_t *, const char *);
iu_tq_callback_t *);
void cancel_lif_timers(dhcp_lif_t *);
void remove_v6_strays(void);
#ifdef __cplusplus
}
#endif
#endif /* INTERFACE_H */