dhcpagent_ipc.h revision 03aa4c8d900cbdc3667ab4b43388d480324be58e
/*
* 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.
*/
/*
* Copyright (c) 2013, 2015 by Delphix. All rights reserved.
*/
#ifndef _DHCPAGENT_IPC_H
#define _DHCPAGENT_IPC_H
#include <stddef.h>
#include <dhcp_impl.h>
/*
* dhcpagent_ipc.[ch] comprise the interface used to perform
* interprocess communication with the agent. see dhcpagent_ipc.c for
* documentation on how to use the exported functions.
*/
#ifdef __cplusplus
extern "C" {
#endif
#define DHCP_AGENT_PATH "/sbin/dhcpagent"
#define DHCP_IPC_LISTEN_BACKLOG 30
#define IPPORT_DHCPAGENT 4999
/*
* return values which should be used by programs which talk to the
* agent (for uniformity).
*/
#define DHCP_EXIT_SUCCESS 0
#define DHCP_EXIT_FAILURE 2
#define DHCP_EXIT_BADARGS 3
#define DHCP_EXIT_TIMEOUT 4
#define DHCP_EXIT_SYSTEM 6
/*
* opaque types for requests and replies. users of this api do not
* need to understand their contents.
*/
typedef struct dhcp_ipc_request dhcp_ipc_request_t;
typedef struct dhcp_ipc_reply dhcp_ipc_reply_t;
/* payloads that can be passed in a request or reply */
typedef enum {
/*
* requests that can be sent to the agent
*
* code in dhcpagent relies on the numeric values of these
* requests -- but there's no sane reason to change them anyway.
*
* If any commands are changed, added, or removed, see the ipc_typestr[]
* array in dhcpagent_ipc.c.
*/
typedef enum {
DHCP_NIPC, /* number of supported requests */
DHCP_PRIMARY = 0x100,
DHCP_V6 = 0x200
/* structure passed with the DHCP_GET_TAG request */
typedef struct {
/* special timeout values for dhcp_ipc_make_request() */
#define DHCP_IPC_WAIT_FOREVER (-1)
#define DHCP_IPC_WAIT_DEFAULT (-2)
/*
* errors that can be returned from the provided functions.
* note: keep in sync with dhcp_ipc_strerror()
*/
enum {
/* System call errors must be kept contiguous */
/* All others follow */
};
/*
* low-level public dhcpagent ipc functions -- these are for use by
* programs that need to communicate with the dhcpagent. these will
* remain relatively stable.
*/
extern const char *dhcp_ipc_strerror(int);
const void *, uint32_t, dhcp_data_type_t);
dhcp_data_type_t *);
extern int dhcp_ipc_make_request(dhcp_ipc_request_t *,
dhcp_ipc_reply_t **, int32_t);
extern const char *dhcp_ipc_type_to_string(dhcp_ipc_type_t);
/*
* high-level public dhcpagent ipc functions
*/
/*
* private dhcpagent ipc "server side" functions -- these are only for
* use by dhcpagent(1M) and are subject to change.
*/
extern int dhcp_ipc_init(int *);
extern int dhcp_ipc_accept(int, int *, int *);
extern int dhcp_ipc_recv_request(int, dhcp_ipc_request_t **, int);
const void *, uint32_t, dhcp_data_type_t);
extern int dhcp_ipc_send_reply(int, dhcp_ipc_reply_t *);
extern int dhcp_ipc_close(int);
/*
* values for if_state in the dhcp_status_t
*
* code in this library and dhcpagent rely on the numeric values of these
* requests -- but there's no sane reason to change them anyway.
*/
typedef enum {
INIT, /* nothing done yet */
SELECTING, /* sent DISCOVER, waiting for OFFERs */
REQUESTING, /* sent REQUEST, waiting for ACK/NAK */
PRE_BOUND, /* have ACK, setting up interface */
BOUND, /* have a valid lease */
RENEWING, /* have lease, but trying to renew */
REBINDING, /* have lease, but trying to rebind */
INFORMATION, /* sent INFORM, received ACK */
INIT_REBOOT, /* attempt to use cached ACK/Reply */
ADOPTING, /* attempting to adopt */
INFORM_SENT, /* sent INFORM, awaiting ACK */
DECLINING, /* sent v6 Decline, awaiting Reply */
RELEASING, /* sent v6 Release, awaiting Reply */
DHCP_NSTATES /* total number of states */
} DHCPSTATE;
/* values for if_dflags in the dhcp_status_t */
/*
* structure passed with the DHCP_STATUS replies
*
* when parsing a dhcp_status_t, `version' should always be checked
* if there is a need to access any fields which were not defined in
* version 1 of this structure.
*
* as new fields are added to the dhcp_status_t, they should be
* appended to the structure and the version number incremented.
*/
typedef struct dhcp_status {
/*
* these three fields are initially zero, and get incremented
* as if_state goes from INIT -> BOUND (or INIT ->
* INFORMATION). if and when the interface 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).
*/
sizeof (uint32_t))
/*
* the remainder of this file contains implementation-specific
* artifacts which may change. note that a `dhcp_ipc_request_t' and a
* `dhcp_ipc_reply_t' are incomplete types as far as consumers of this
* api are concerned. use these details at your own risk.
*/
typedef hrtime_t dhcp_ipc_id_t;
/*
* note: the first 4 fields of the dhcp_ipc_request_t and dhcp_ipc_reply_t
* are intentionally identical; code in dhcpagent_ipc.c counts on it!
*
* we pack these structs to ensure that their lengths will be identical between
* 32-bit and 64-bit executables.
*/
#pragma pack(4)
struct dhcp_ipc_request {
};
struct dhcp_ipc_reply {
};
#pragma pack()
#ifdef __cplusplus
}
#endif
#endif /* _DHCPAGENT_IPC_H */