17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 569bb4bb4Scarlsonj * Common Development and Distribution License (the "License"). 669bb4bb4Scarlsonj * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*65c8f1c0Smeem * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _DHCPAGENT_IPC_H 277c478bd9Sstevel@tonic-gate #define _DHCPAGENT_IPC_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/socket.h> 30*65c8f1c0Smeem #include <net/if.h> /* LIFNAMSIZ */ 317c478bd9Sstevel@tonic-gate #include <stddef.h> 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 337c478bd9Sstevel@tonic-gate #include <sys/time.h> 347c478bd9Sstevel@tonic-gate #include <netinet/dhcp.h> 357c478bd9Sstevel@tonic-gate #include <dhcp_impl.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate /* 387c478bd9Sstevel@tonic-gate * dhcpagent_ipc.[ch] comprise the interface used to perform 397c478bd9Sstevel@tonic-gate * interprocess communication with the agent. see dhcpagent_ipc.c for 407c478bd9Sstevel@tonic-gate * documentation on how to use the exported functions. 417c478bd9Sstevel@tonic-gate */ 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #ifdef __cplusplus 447c478bd9Sstevel@tonic-gate extern "C" { 457c478bd9Sstevel@tonic-gate #endif 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #define DHCP_AGENT_PATH "/sbin/dhcpagent" 487c478bd9Sstevel@tonic-gate #define DHCP_IPC_LISTEN_BACKLOG 30 497c478bd9Sstevel@tonic-gate #define IPPORT_DHCPAGENT 4999 50d04ccbb3Scarlsonj #define DHCP_IPC_MAX_WAIT 15 /* max seconds to wait to start agent */ 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * return values which should be used by programs which talk to the 547c478bd9Sstevel@tonic-gate * agent (for uniformity). 557c478bd9Sstevel@tonic-gate */ 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate #define DHCP_EXIT_SUCCESS 0 587c478bd9Sstevel@tonic-gate #define DHCP_EXIT_FAILURE 2 597c478bd9Sstevel@tonic-gate #define DHCP_EXIT_BADARGS 3 607c478bd9Sstevel@tonic-gate #define DHCP_EXIT_TIMEOUT 4 617c478bd9Sstevel@tonic-gate #define DHCP_EXIT_SYSTEM 6 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * opaque types for requests and replies. users of this api do not 657c478bd9Sstevel@tonic-gate * need to understand their contents. 667c478bd9Sstevel@tonic-gate */ 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate typedef struct dhcp_ipc_request dhcp_ipc_request_t; 697c478bd9Sstevel@tonic-gate typedef struct dhcp_ipc_reply dhcp_ipc_reply_t; 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* payloads that can be passed in a request or reply */ 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate typedef enum { 747c478bd9Sstevel@tonic-gate DHCP_TYPE_OPTION, 757c478bd9Sstevel@tonic-gate DHCP_TYPE_STATUS, 767c478bd9Sstevel@tonic-gate DHCP_TYPE_OPTNUM, 777c478bd9Sstevel@tonic-gate DHCP_TYPE_NONE 787c478bd9Sstevel@tonic-gate } dhcp_data_type_t; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * requests that can be sent to the agent 827c478bd9Sstevel@tonic-gate * 837c478bd9Sstevel@tonic-gate * code in dhcpagent relies on the numeric values of these 847c478bd9Sstevel@tonic-gate * requests -- but there's no sane reason to change them anyway. 85d04ccbb3Scarlsonj * 86cfb9c9abScarlsonj * If any commands are changed, added, or removed, see the ipc_typestr[] 87d04ccbb3Scarlsonj * array in dhcpagent_ipc.c. 887c478bd9Sstevel@tonic-gate */ 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate typedef enum { 917c478bd9Sstevel@tonic-gate DHCP_DROP, DHCP_EXTEND, DHCP_PING, DHCP_RELEASE, 927c478bd9Sstevel@tonic-gate DHCP_START, DHCP_STATUS, DHCP_INFORM, DHCP_GET_TAG, 937c478bd9Sstevel@tonic-gate DHCP_NIPC, /* number of supported requests */ 94d04ccbb3Scarlsonj DHCP_PRIMARY = 0x100, 95d04ccbb3Scarlsonj DHCP_V6 = 0x200 967c478bd9Sstevel@tonic-gate } dhcp_ipc_type_t; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate /* structure passed with the DHCP_GET_TAG request */ 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate typedef struct { 101d04ccbb3Scarlsonj uint_t category; 102d04ccbb3Scarlsonj uint_t code; 103d04ccbb3Scarlsonj uint_t size; 1047c478bd9Sstevel@tonic-gate } dhcp_optnum_t; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate #define DHCP_IPC_CMD(type) ((type) & 0x00ff) 1077c478bd9Sstevel@tonic-gate #define DHCP_IPC_FLAGS(type) ((type) & 0xff00) 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate /* special timeout values for dhcp_ipc_make_request() */ 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate #define DHCP_IPC_WAIT_FOREVER (-1) 1127c478bd9Sstevel@tonic-gate #define DHCP_IPC_WAIT_DEFAULT (-2) 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate /* 1157c478bd9Sstevel@tonic-gate * errors that can be returned from the provided functions. 1167c478bd9Sstevel@tonic-gate * note: keep in sync with dhcp_ipc_strerror() 1177c478bd9Sstevel@tonic-gate */ 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate enum { 120d04ccbb3Scarlsonj /* System call errors must be kept contiguous */ 1217c478bd9Sstevel@tonic-gate DHCP_IPC_SUCCESS, DHCP_IPC_E_SOCKET, DHCP_IPC_E_FCNTL, 1227c478bd9Sstevel@tonic-gate DHCP_IPC_E_READ, DHCP_IPC_E_ACCEPT, DHCP_IPC_E_CLOSE, 1237c478bd9Sstevel@tonic-gate DHCP_IPC_E_BIND, DHCP_IPC_E_LISTEN, DHCP_IPC_E_MEMORY, 124d04ccbb3Scarlsonj DHCP_IPC_E_CONNECT, DHCP_IPC_E_WRITEV, DHCP_IPC_E_POLL, 125d04ccbb3Scarlsonj 126d04ccbb3Scarlsonj /* All others follow */ 127d04ccbb3Scarlsonj DHCP_IPC_E_TIMEOUT, DHCP_IPC_E_SRVFAILED, DHCP_IPC_E_EOF, 1287c478bd9Sstevel@tonic-gate DHCP_IPC_E_INVIF, DHCP_IPC_E_INT, DHCP_IPC_E_PERM, 1297c478bd9Sstevel@tonic-gate DHCP_IPC_E_OUTSTATE, DHCP_IPC_E_PEND, DHCP_IPC_E_BOOTP, 1307c478bd9Sstevel@tonic-gate DHCP_IPC_E_CMD_UNKNOWN, DHCP_IPC_E_UNKIF, DHCP_IPC_E_PROTO, 1317c478bd9Sstevel@tonic-gate DHCP_IPC_E_FAILEDIF, DHCP_IPC_E_NOPRIMARY, DHCP_IPC_E_DOWNIF, 132d04ccbb3Scarlsonj DHCP_IPC_E_NOIPIF, DHCP_IPC_E_NOVALUE, DHCP_IPC_E_RUNNING 1337c478bd9Sstevel@tonic-gate }; 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate /* 1367c478bd9Sstevel@tonic-gate * low-level public dhcpagent ipc functions -- these are for use by 1377c478bd9Sstevel@tonic-gate * programs that need to communicate with the dhcpagent. these will 1387c478bd9Sstevel@tonic-gate * remain relatively stable. 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate extern const char *dhcp_ipc_strerror(int); 1427c478bd9Sstevel@tonic-gate extern dhcp_ipc_request_t *dhcp_ipc_alloc_request(dhcp_ipc_type_t, const char *, 143d04ccbb3Scarlsonj const void *, uint32_t, dhcp_data_type_t); 1447c478bd9Sstevel@tonic-gate extern void *dhcp_ipc_get_data(dhcp_ipc_reply_t *, size_t *, 1457c478bd9Sstevel@tonic-gate dhcp_data_type_t *); 1467c478bd9Sstevel@tonic-gate extern int dhcp_ipc_make_request(dhcp_ipc_request_t *, 1477c478bd9Sstevel@tonic-gate dhcp_ipc_reply_t **, int32_t); 148d04ccbb3Scarlsonj extern const char *dhcp_ipc_type_to_string(dhcp_ipc_type_t); 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate /* 1517c478bd9Sstevel@tonic-gate * high-level public dhcpagent ipc functions 1527c478bd9Sstevel@tonic-gate */ 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate extern int dhcp_ipc_getinfo(dhcp_optnum_t *, DHCP_OPT **, int32_t); 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate /* 1577c478bd9Sstevel@tonic-gate * private dhcpagent ipc "server side" functions -- these are only for 1587c478bd9Sstevel@tonic-gate * use by dhcpagent(1M) and are subject to change. 1597c478bd9Sstevel@tonic-gate */ 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate extern int dhcp_ipc_init(int *); 1627c478bd9Sstevel@tonic-gate extern int dhcp_ipc_accept(int, int *, int *); 1637c478bd9Sstevel@tonic-gate extern int dhcp_ipc_recv_request(int, dhcp_ipc_request_t **, int); 164d04ccbb3Scarlsonj extern dhcp_ipc_reply_t *dhcp_ipc_alloc_reply(dhcp_ipc_request_t *, int, 165d04ccbb3Scarlsonj const void *, uint32_t, dhcp_data_type_t); 1667c478bd9Sstevel@tonic-gate extern int dhcp_ipc_send_reply(int, dhcp_ipc_reply_t *); 1677c478bd9Sstevel@tonic-gate extern int dhcp_ipc_close(int); 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate /* 1707c478bd9Sstevel@tonic-gate * values for if_state in the dhcp_status_t 1717c478bd9Sstevel@tonic-gate * 1727c478bd9Sstevel@tonic-gate * code in this library and dhcpagent rely on the numeric values of these 1737c478bd9Sstevel@tonic-gate * requests -- but there's no sane reason to change them anyway. 1747c478bd9Sstevel@tonic-gate */ 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate typedef enum { 1777c478bd9Sstevel@tonic-gate INIT, /* nothing done yet */ 1787c478bd9Sstevel@tonic-gate SELECTING, /* sent DISCOVER, waiting for OFFERs */ 1797c478bd9Sstevel@tonic-gate REQUESTING, /* sent REQUEST, waiting for ACK/NAK */ 18069bb4bb4Scarlsonj PRE_BOUND, /* have ACK, setting up interface */ 1817c478bd9Sstevel@tonic-gate BOUND, /* have a valid lease */ 1827c478bd9Sstevel@tonic-gate RENEWING, /* have lease, but trying to renew */ 1837c478bd9Sstevel@tonic-gate REBINDING, /* have lease, but trying to rebind */ 1847c478bd9Sstevel@tonic-gate INFORMATION, /* sent INFORM, received ACK */ 185d04ccbb3Scarlsonj INIT_REBOOT, /* attempt to use cached ACK/Reply */ 1867c478bd9Sstevel@tonic-gate ADOPTING, /* attempting to adopt */ 1877c478bd9Sstevel@tonic-gate INFORM_SENT, /* sent INFORM, awaiting ACK */ 188d04ccbb3Scarlsonj DECLINING, /* sent v6 Decline, awaiting Reply */ 189d04ccbb3Scarlsonj RELEASING, /* sent v6 Release, awaiting Reply */ 1907c478bd9Sstevel@tonic-gate DHCP_NSTATES /* total number of states */ 1917c478bd9Sstevel@tonic-gate } DHCPSTATE; 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate /* values for if_dflags in the dhcp_status_t */ 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate #define DHCP_IF_PRIMARY 0x0100 /* interface is primary interface */ 1967c478bd9Sstevel@tonic-gate #define DHCP_IF_BUSY 0x0200 /* asynchronous command pending */ 1977c478bd9Sstevel@tonic-gate #define DHCP_IF_BOOTP 0x0400 /* interface is using bootp */ 1987c478bd9Sstevel@tonic-gate #define DHCP_IF_REMOVED 0x0800 /* interface is going away */ 1997c478bd9Sstevel@tonic-gate #define DHCP_IF_FAILED 0x1000 /* interface configuration problem */ 200d04ccbb3Scarlsonj #define DHCP_IF_V6 0x2000 /* DHCPv6 interface */ 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate /* 2037c478bd9Sstevel@tonic-gate * structure passed with the DHCP_STATUS replies 2047c478bd9Sstevel@tonic-gate * 2057c478bd9Sstevel@tonic-gate * when parsing a dhcp_status_t, `version' should always be checked 2067c478bd9Sstevel@tonic-gate * if there is a need to access any fields which were not defined in 2077c478bd9Sstevel@tonic-gate * version 1 of this structure. 2087c478bd9Sstevel@tonic-gate * 2097c478bd9Sstevel@tonic-gate * as new fields are added to the dhcp_status_t, they should be 2107c478bd9Sstevel@tonic-gate * appended to the structure and the version number incremented. 2117c478bd9Sstevel@tonic-gate */ 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate typedef struct dhcp_status { 2147c478bd9Sstevel@tonic-gate uint8_t version; /* version of this structure */ 2157c478bd9Sstevel@tonic-gate 216*65c8f1c0Smeem char if_name[LIFNAMSIZ]; 2177c478bd9Sstevel@tonic-gate DHCPSTATE if_state; /* state of interface; see above */ 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate time_t if_began; /* time lease began (absolute) */ 2207c478bd9Sstevel@tonic-gate time_t if_t1; /* renewing time (absolute) */ 2217c478bd9Sstevel@tonic-gate time_t if_t2; /* rebinding time (absolute) */ 2227c478bd9Sstevel@tonic-gate time_t if_lease; /* lease expiration time (absolute) */ 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate uint16_t if_dflags; /* DHCP flags on this if; see above */ 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate /* 2277c478bd9Sstevel@tonic-gate * these three fields are initially zero, and get incremented 2287c478bd9Sstevel@tonic-gate * as if_state goes from INIT -> BOUND (or INIT -> 2297c478bd9Sstevel@tonic-gate * INFORMATION). if and when the interface moves to the 2307c478bd9Sstevel@tonic-gate * RENEWING state, these fields are reset, so they always 2317c478bd9Sstevel@tonic-gate * either indicate the number of packets sent, received, and 2327c478bd9Sstevel@tonic-gate * declined while obtaining the current lease (if BOUND), or 2337c478bd9Sstevel@tonic-gate * the number of packets sent, received, and declined while 2347c478bd9Sstevel@tonic-gate * attempting to obtain a future lease (if any other state). 2357c478bd9Sstevel@tonic-gate */ 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate uint32_t if_sent; 2387c478bd9Sstevel@tonic-gate uint32_t if_recv; 2397c478bd9Sstevel@tonic-gate uint32_t if_bad_offers; 2407c478bd9Sstevel@tonic-gate } dhcp_status_t; 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate #define DHCP_STATUS_VER 1 /* current version of dhcp_status_t */ 2437c478bd9Sstevel@tonic-gate #define DHCP_STATUS_VER1_SIZE (offsetof(dhcp_status_t, if_bad_offers) + \ 2447c478bd9Sstevel@tonic-gate sizeof (uint32_t)) 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate /* 2477c478bd9Sstevel@tonic-gate * the remainder of this file contains implementation-specific 2487c478bd9Sstevel@tonic-gate * artifacts which may change. note that a `dhcp_ipc_request_t' and a 2497c478bd9Sstevel@tonic-gate * `dhcp_ipc_reply_t' are incomplete types as far as consumers of this 2507c478bd9Sstevel@tonic-gate * api are concerned. use these details at your own risk. 2517c478bd9Sstevel@tonic-gate */ 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate typedef hrtime_t dhcp_ipc_id_t; 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate /* 2567c478bd9Sstevel@tonic-gate * note: the first 4 fields of the dhcp_ipc_request_t and dhcp_ipc_reply_t 2577c478bd9Sstevel@tonic-gate * are intentionally identical; code in dhcpagent_ipc.c counts on it! 2587c478bd9Sstevel@tonic-gate */ 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate struct dhcp_ipc_request { 2617c478bd9Sstevel@tonic-gate dhcp_ipc_type_t message_type; /* type of request */ 2627c478bd9Sstevel@tonic-gate dhcp_ipc_id_t ipc_id; /* per-socket unique request id */ 2637c478bd9Sstevel@tonic-gate dhcp_data_type_t data_type; /* type of payload */ 2647c478bd9Sstevel@tonic-gate uint32_t data_length; /* size of actual data in the buffer */ 265*65c8f1c0Smeem char ifname[LIFNAMSIZ]; 2667c478bd9Sstevel@tonic-gate int32_t timeout; /* timeout in seconds */ 2677c478bd9Sstevel@tonic-gate uchar_t buffer[1]; /* dynamically extended */ 2687c478bd9Sstevel@tonic-gate }; 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate struct dhcp_ipc_reply { 2717c478bd9Sstevel@tonic-gate dhcp_ipc_type_t message_type; /* same message type as request */ 2727c478bd9Sstevel@tonic-gate dhcp_ipc_id_t ipc_id; /* same id as request */ 2737c478bd9Sstevel@tonic-gate dhcp_data_type_t data_type; /* type of payload */ 2747c478bd9Sstevel@tonic-gate uint32_t data_length; /* size of actual data in the buffer */ 2757c478bd9Sstevel@tonic-gate uint32_t return_code; /* did the request succeed? */ 2767c478bd9Sstevel@tonic-gate uchar_t buffer[1]; /* dynamically extended */ 2777c478bd9Sstevel@tonic-gate }; 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate /* 2807c478bd9Sstevel@tonic-gate * since ansi c won't let us define arrays with 0 elements, the 2817c478bd9Sstevel@tonic-gate * size of the ipc request/reply structures is off-by-1; use macros. 2827c478bd9Sstevel@tonic-gate */ 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate #define DHCP_IPC_REPLY_SIZE (sizeof (dhcp_ipc_reply_t) - 1) 2857c478bd9Sstevel@tonic-gate #define DHCP_IPC_REQUEST_SIZE (sizeof (dhcp_ipc_request_t) - 1) 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate #define DHCP_IPC_DEFAULT_WAIT 120 /* seconds */ 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate #endif 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate #endif /* _DHCPAGENT_IPC_H */ 294