xref: /titanic_50/usr/src/lib/libipadm/common/ipadm_ipmgmt.h (revision 6a634c9dca3093f3922e4b7ab826d7bdf17bf78e)
16e91bba0SGirish Moodalbail /*
26e91bba0SGirish Moodalbail  * CDDL HEADER START
36e91bba0SGirish Moodalbail  *
46e91bba0SGirish Moodalbail  * The contents of this file are subject to the terms of the
56e91bba0SGirish Moodalbail  * Common Development and Distribution License (the "License").
66e91bba0SGirish Moodalbail  * You may not use this file except in compliance with the License.
76e91bba0SGirish Moodalbail  *
86e91bba0SGirish Moodalbail  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
96e91bba0SGirish Moodalbail  * or http://www.opensolaris.org/os/licensing.
106e91bba0SGirish Moodalbail  * See the License for the specific language governing permissions
116e91bba0SGirish Moodalbail  * and limitations under the License.
126e91bba0SGirish Moodalbail  *
136e91bba0SGirish Moodalbail  * When distributing Covered Code, include this CDDL HEADER in each
146e91bba0SGirish Moodalbail  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
156e91bba0SGirish Moodalbail  * If applicable, add the following below this CDDL HEADER, with the
166e91bba0SGirish Moodalbail  * fields enclosed by brackets "[]" replaced with your own identifying
176e91bba0SGirish Moodalbail  * information: Portions Copyright [yyyy] [name of copyright owner]
186e91bba0SGirish Moodalbail  *
196e91bba0SGirish Moodalbail  * CDDL HEADER END
206e91bba0SGirish Moodalbail  */
216e91bba0SGirish Moodalbail /*
22ec3706caSVasumathi Sundaram  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
236e91bba0SGirish Moodalbail  */
246e91bba0SGirish Moodalbail 
256e91bba0SGirish Moodalbail #ifndef _IPADM_IPMGMT_H
266e91bba0SGirish Moodalbail #define	_IPADM_IPMGMT_H
276e91bba0SGirish Moodalbail 
286e91bba0SGirish Moodalbail #ifdef	__cplusplus
296e91bba0SGirish Moodalbail extern "C" {
306e91bba0SGirish Moodalbail #endif
316e91bba0SGirish Moodalbail #include <sys/types.h>
326e91bba0SGirish Moodalbail #include <sys/stat.h>
336e91bba0SGirish Moodalbail #include <fcntl.h>
346e91bba0SGirish Moodalbail #include <sys/mman.h>
356e91bba0SGirish Moodalbail #include <door.h>
366e91bba0SGirish Moodalbail #include <libipadm.h>
376e91bba0SGirish Moodalbail #include <inet/tunables.h>
386e91bba0SGirish Moodalbail 
396e91bba0SGirish Moodalbail /*
406e91bba0SGirish Moodalbail  * Function declarations and data structures shared by libipadm.so and
416e91bba0SGirish Moodalbail  * the IP management daemon.
426e91bba0SGirish Moodalbail  */
436e91bba0SGirish Moodalbail 
446e91bba0SGirish Moodalbail /* Authorization required to configure network interfaces */
456e91bba0SGirish Moodalbail #define	NETWORK_INTERFACE_CONFIG_AUTH	"solaris.network.interface.config"
466e91bba0SGirish Moodalbail 
476e91bba0SGirish Moodalbail /*
486e91bba0SGirish Moodalbail  * Data store read/write utilities related declarations.
496e91bba0SGirish Moodalbail  */
506e91bba0SGirish Moodalbail /*
516e91bba0SGirish Moodalbail  * For more information on these definitions please refer to the top of
526e91bba0SGirish Moodalbail  * ipadm_persist.c. These are the name of the nvpairs which hold the
536e91bba0SGirish Moodalbail  * respective values. All nvpairs private to ipadm have names that begin
546e91bba0SGirish Moodalbail  * with "_". Note below that 'prefixlen' is an address property and therefore
556e91bba0SGirish Moodalbail  * not a private nvpair name.
566e91bba0SGirish Moodalbail  */
576e91bba0SGirish Moodalbail #define	IPADM_NVP_PROTONAME	"_protocol"	/* protocol name */
586e91bba0SGirish Moodalbail #define	IPADM_NVP_IFNAME	"_ifname"	/* interface name */
596e91bba0SGirish Moodalbail #define	IPADM_NVP_AOBJNAME	"_aobjname"	/* addrobj name */
606e91bba0SGirish Moodalbail #define	IPADM_NVP_FAMILY	"_family"	/* address family */
616e91bba0SGirish Moodalbail #define	IPADM_NVP_IPV4ADDR	"_ipv4addr"	/* name of IPv4 addr nvlist */
626e91bba0SGirish Moodalbail #define	IPADM_NVP_IPNUMADDR	"_addr"		/* local address */
636e91bba0SGirish Moodalbail #define	IPADM_NVP_IPADDRHNAME	"_aname"	/* local hostname */
646e91bba0SGirish Moodalbail #define	IPADM_NVP_IPDADDRHNAME	"_dname"	/* remote hostname */
656e91bba0SGirish Moodalbail #define	IPADM_NVP_PREFIXLEN	"prefixlen"	/* prefixlen */
666e91bba0SGirish Moodalbail #define	IPADM_NVP_IPV6ADDR	"_ipv6addr"	/* name of IPv6 addr nvlist */
676e91bba0SGirish Moodalbail #define	IPADM_NVP_DHCP		"_dhcp"		/* name of DHCP nvlist */
686e91bba0SGirish Moodalbail #define	IPADM_NVP_WAIT		"_wait"		/* DHCP timeout value */
696e91bba0SGirish Moodalbail #define	IPADM_NVP_PRIMARY	"_primary"	/* DHCP primary interface */
706e91bba0SGirish Moodalbail #define	IPADM_NVP_LIFNUM	"_lifnum"	/* logical interface number */
716e91bba0SGirish Moodalbail #define	IPADM_NVP_INTFID	"_intfid"	/* name of IPv6 intfid nvlist */
726e91bba0SGirish Moodalbail #define	IPADM_NVP_STATELESS	"_stateless"	/* IPv6 autoconf stateless */
736e91bba0SGirish Moodalbail #define	IPADM_NVP_STATEFUL	"_stateful"	/* IPv6 autoconf dhcpv6 */
746e91bba0SGirish Moodalbail 
75*8887b57dSGirish Moodalbail #define	IPADM_PRIV_NVP(s) ((s)[0] == '_' && (s)[1] != '_')
76*8887b57dSGirish Moodalbail 
77*8887b57dSGirish Moodalbail /*
78*8887b57dSGirish Moodalbail  * All protocol properties that are private to ipadm are stored in the
79*8887b57dSGirish Moodalbail  * ipadm datastore with "__" as prefix. This is to ensure there
80*8887b57dSGirish Moodalbail  * is no collision of namespace between ipadm private nvpair names and
81*8887b57dSGirish Moodalbail  * the private protocol property names.
82*8887b57dSGirish Moodalbail  */
83*8887b57dSGirish Moodalbail #define	IPADM_PERSIST_PRIVPROP_PREFIX	"__"
846e91bba0SGirish Moodalbail 
856e91bba0SGirish Moodalbail /* data-store operations */
866e91bba0SGirish Moodalbail typedef enum {
876e91bba0SGirish Moodalbail 	IPADM_DB_WRITE = 0,	/* Writes to DB */
886e91bba0SGirish Moodalbail 	IPADM_DB_DELETE,	/* Deletes an entry from DB */
896e91bba0SGirish Moodalbail 	IPADM_DB_READ		/* Read from DB */
906e91bba0SGirish Moodalbail } ipadm_db_op_t;
916e91bba0SGirish Moodalbail 
926e91bba0SGirish Moodalbail /*
936e91bba0SGirish Moodalbail  * callback arg used by db_wfunc_t that writes to DB. The contents to be
946e91bba0SGirish Moodalbail  * written to DB are captured in `dbw_nvl'.
956e91bba0SGirish Moodalbail  */
966e91bba0SGirish Moodalbail typedef	struct	ipadm_dbwrite_cbarg_s {
976e91bba0SGirish Moodalbail 	nvlist_t	*dbw_nvl;
986e91bba0SGirish Moodalbail 	uint_t		dbw_flags;
996e91bba0SGirish Moodalbail } ipadm_dbwrite_cbarg_t;
1006e91bba0SGirish Moodalbail 
1016e91bba0SGirish Moodalbail /*
1026e91bba0SGirish Moodalbail  * door related function declarations and data structures.
1036e91bba0SGirish Moodalbail  */
1046e91bba0SGirish Moodalbail 
1056e91bba0SGirish Moodalbail /* The door file for the ipmgmt (ip-interface management) daemon */
1066e91bba0SGirish Moodalbail #define	IPMGMT_DOOR		"/etc/svc/volatile/ipadm/ipmgmt_door"
1076e91bba0SGirish Moodalbail #define	MAXPROTONAMELEN		32
1086e91bba0SGirish Moodalbail 
1096e91bba0SGirish Moodalbail /* door call command type */
1106e91bba0SGirish Moodalbail typedef enum {
1116e91bba0SGirish Moodalbail 	IPMGMT_CMD_SETPROP = 1,		/* persist property */
1126e91bba0SGirish Moodalbail 	IPMGMT_CMD_SETIF,		/* persist interface */
1136e91bba0SGirish Moodalbail 	IPMGMT_CMD_SETADDR,		/* persist address */
1146e91bba0SGirish Moodalbail 	IPMGMT_CMD_GETPROP,		/* retrieve persisted property value */
1156e91bba0SGirish Moodalbail 	IPMGMT_CMD_GETIF,		/* retrieve persisted interface conf. */
1166e91bba0SGirish Moodalbail 	IPMGMT_CMD_GETADDR,		/* retrieve persisted addresses */
1176e91bba0SGirish Moodalbail 	IPMGMT_CMD_RESETIF,		/* purge interface configuration */
1186e91bba0SGirish Moodalbail 	IPMGMT_CMD_RESETADDR,		/* purge address configuration */
1196e91bba0SGirish Moodalbail 	IPMGMT_CMD_RESETPROP,		/* purge property configuration */
1206e91bba0SGirish Moodalbail 	IPMGMT_CMD_INITIF,		/* retrieve interfaces to initialize */
1216e91bba0SGirish Moodalbail 	IPMGMT_CMD_ADDROBJ_LOOKUPADD,	/* addr. object lookup & add */
122ec3706caSVasumathi Sundaram 	IPMGMT_CMD_ADDROBJ_SETLIFNUM,	/* set lifnum on the addrobj */
1236e91bba0SGirish Moodalbail 	IPMGMT_CMD_ADDROBJ_ADD,		/* add addr. object to addrobj map */
1246e91bba0SGirish Moodalbail 	IPMGMT_CMD_LIF2ADDROBJ,		/* lifname to addrobj mapping */
1256e91bba0SGirish Moodalbail 	IPMGMT_CMD_AOBJNAME2ADDROBJ	/* aobjname to addrobj mapping */
1266e91bba0SGirish Moodalbail } ipmgmt_door_cmd_type_t;
1276e91bba0SGirish Moodalbail 
1286e91bba0SGirish Moodalbail /*
1296e91bba0SGirish Moodalbail  * Note: We need to keep the size of the structure the same on amd64 and i386
1306e91bba0SGirish Moodalbail  * for all door_call arguments and door_return structures.
1316e91bba0SGirish Moodalbail  */
1326e91bba0SGirish Moodalbail /* door_call argument */
1336e91bba0SGirish Moodalbail typedef struct ipmgmt_arg {
1346e91bba0SGirish Moodalbail 	ipmgmt_door_cmd_type_t	ia_cmd;
1356e91bba0SGirish Moodalbail } ipmgmt_arg_t;
1366e91bba0SGirish Moodalbail 
1376e91bba0SGirish Moodalbail /* IPMGMT_CMD_{SETPROP|GETPROP|RESETPROP} door_call argument */
1386e91bba0SGirish Moodalbail typedef struct ipmgmt_prop_arg_s {
1396e91bba0SGirish Moodalbail 	ipmgmt_door_cmd_type_t	ia_cmd;
1406e91bba0SGirish Moodalbail 	uint32_t		ia_flags;
1416e91bba0SGirish Moodalbail 	char			ia_ifname[LIFNAMSIZ];
1426e91bba0SGirish Moodalbail 	char			ia_aobjname[IPADM_AOBJSIZ];
1436e91bba0SGirish Moodalbail 	char			ia_module[MAXPROTONAMELEN];
1446e91bba0SGirish Moodalbail 	char			ia_pname[MAXPROPNAMELEN];
1456e91bba0SGirish Moodalbail 	char			ia_pval[MAXPROPVALLEN];
1466e91bba0SGirish Moodalbail } ipmgmt_prop_arg_t;
1476e91bba0SGirish Moodalbail /*
1486e91bba0SGirish Moodalbail  * ia_flags used in ipmgmt_prop_arg_t.
1496e91bba0SGirish Moodalbail  *	- APPEND updates the multi-valued property entry with a new value
1506e91bba0SGirish Moodalbail  *	- REDUCE updates the multi-valued property entry by removing a value
1516e91bba0SGirish Moodalbail  */
1526e91bba0SGirish Moodalbail #define	IPMGMT_APPEND	0x00000001
1536e91bba0SGirish Moodalbail #define	IPMGMT_REMOVE	0x00000002
1546e91bba0SGirish Moodalbail 
1556e91bba0SGirish Moodalbail /* IPMGMT_CMD_GETIF door_call argument structure */
1566e91bba0SGirish Moodalbail typedef struct ipmgmt_getif_arg_s {
1576e91bba0SGirish Moodalbail 	ipmgmt_door_cmd_type_t	ia_cmd;
1586e91bba0SGirish Moodalbail 	uint32_t	ia_flags;
1596e91bba0SGirish Moodalbail 	char		ia_ifname[LIFNAMSIZ];
1606e91bba0SGirish Moodalbail } ipmgmt_getif_arg_t;
1616e91bba0SGirish Moodalbail 
1626e91bba0SGirish Moodalbail /* IPMGMT_CMD_RESETIF, IPMGMT_CMD_SETIF door_call argument structure */
1636e91bba0SGirish Moodalbail typedef struct ipmgmt_if_arg_s {
1646e91bba0SGirish Moodalbail 	ipmgmt_door_cmd_type_t	ia_cmd;
1656e91bba0SGirish Moodalbail 	uint32_t		ia_flags;
1666e91bba0SGirish Moodalbail 	char			ia_ifname[LIFNAMSIZ];
1676e91bba0SGirish Moodalbail 	sa_family_t		ia_family;
1686e91bba0SGirish Moodalbail } ipmgmt_if_arg_t;
1696e91bba0SGirish Moodalbail 
1706e91bba0SGirish Moodalbail /* IPMGMT_CMD_INITIF door_call argument structure */
1716e91bba0SGirish Moodalbail typedef struct ipmgmt_initif_arg_s {
1726e91bba0SGirish Moodalbail 	ipmgmt_door_cmd_type_t	ia_cmd;
1736e91bba0SGirish Moodalbail 	uint32_t	ia_flags;
1746e91bba0SGirish Moodalbail 	sa_family_t	ia_family;
1756e91bba0SGirish Moodalbail 	size_t		ia_nvlsize;
1766e91bba0SGirish Moodalbail 	/* packed nvl follows */
1776e91bba0SGirish Moodalbail } ipmgmt_initif_arg_t;
1786e91bba0SGirish Moodalbail 
1796e91bba0SGirish Moodalbail /* IPMGMT_CMD_SETADDR door_call argument */
1806e91bba0SGirish Moodalbail typedef struct ipmgmt_setaddr_arg_s {
1816e91bba0SGirish Moodalbail 	ipmgmt_door_cmd_type_t	ia_cmd;
1826e91bba0SGirish Moodalbail 	uint32_t		ia_flags;
1836e91bba0SGirish Moodalbail 	size_t			ia_nvlsize;
1846e91bba0SGirish Moodalbail 	/* packed nvl follows */
1856e91bba0SGirish Moodalbail } ipmgmt_setaddr_arg_t;
1866e91bba0SGirish Moodalbail 
1876e91bba0SGirish Moodalbail /* IPMGMT_CMD_GETADDR door_call argument */
1886e91bba0SGirish Moodalbail typedef struct ipmgmt_getaddr_arg_s {
1896e91bba0SGirish Moodalbail 	ipmgmt_door_cmd_type_t	ia_cmd;
1906e91bba0SGirish Moodalbail 	uint32_t	ia_flags;
1916e91bba0SGirish Moodalbail 	char		ia_ifname[LIFNAMSIZ];
1926e91bba0SGirish Moodalbail 	sa_family_t	ia_family;
1936e91bba0SGirish Moodalbail 	char		ia_aobjname[IPADM_AOBJSIZ];
1946e91bba0SGirish Moodalbail } ipmgmt_getaddr_arg_t;
1956e91bba0SGirish Moodalbail 
1966e91bba0SGirish Moodalbail /* IPMGMT_CMD_RESETADDR door_call argument */
1976e91bba0SGirish Moodalbail typedef struct ipmgmt_addr_arg_s {
1986e91bba0SGirish Moodalbail 	ipmgmt_door_cmd_type_t	ia_cmd;
1996e91bba0SGirish Moodalbail 	uint32_t	ia_flags;
2006e91bba0SGirish Moodalbail 	char		ia_aobjname[IPADM_AOBJSIZ];
2016e91bba0SGirish Moodalbail 	int32_t		ia_lnum;
2026e91bba0SGirish Moodalbail } ipmgmt_addr_arg_t;
2036e91bba0SGirish Moodalbail 
2046e91bba0SGirish Moodalbail /*
2056e91bba0SGirish Moodalbail  * IPMGMT_CMD_{ADDROBJ_ADD|ADDROBJ_LOOKUPADD|LIFNUM2ADDROBJ|
2066e91bba0SGirish Moodalbail  * ADDROBJ2LIFNUM} door_call argument.
2076e91bba0SGirish Moodalbail  */
2086e91bba0SGirish Moodalbail typedef struct ipmgmt_aobjop_arg_s {
2096e91bba0SGirish Moodalbail 	ipmgmt_door_cmd_type_t	ia_cmd;
2106e91bba0SGirish Moodalbail 	uint32_t		ia_flags;
2116e91bba0SGirish Moodalbail 	char			ia_aobjname[IPADM_AOBJSIZ];
2126e91bba0SGirish Moodalbail 	char			ia_ifname[LIFNAMSIZ];
2136e91bba0SGirish Moodalbail 	int32_t			ia_lnum;
2146e91bba0SGirish Moodalbail 	sa_family_t		ia_family;
2156e91bba0SGirish Moodalbail 	ipadm_addr_type_t	ia_atype;
2166e91bba0SGirish Moodalbail } ipmgmt_aobjop_arg_t;
2176e91bba0SGirish Moodalbail 
2186e91bba0SGirish Moodalbail /*
2196e91bba0SGirish Moodalbail  * ia_flags used inside the arguments for interface/address commands
2206e91bba0SGirish Moodalbail  *	- ACTIVE updates the running configuration
2216e91bba0SGirish Moodalbail  *	- PERSIST updates the permanent data store
2226e91bba0SGirish Moodalbail  *	- INIT	indicates that operation being performed is under init
2236e91bba0SGirish Moodalbail  *		    context
2246e91bba0SGirish Moodalbail  */
2256e91bba0SGirish Moodalbail #define	IPMGMT_ACTIVE		0x00000001
2266e91bba0SGirish Moodalbail #define	IPMGMT_PERSIST		0x00000002
2276e91bba0SGirish Moodalbail #define	IPMGMT_INIT		0x00000004
2286e91bba0SGirish Moodalbail 
2296e91bba0SGirish Moodalbail /* door call return value */
2306e91bba0SGirish Moodalbail typedef struct ipmgmt_retval_s {
2316e91bba0SGirish Moodalbail 	int32_t	ir_err;
2326e91bba0SGirish Moodalbail } ipmgmt_retval_t;
2336e91bba0SGirish Moodalbail 
2346e91bba0SGirish Moodalbail /* IPMGMT_CMD_GETADDR door_return value */
2356e91bba0SGirish Moodalbail typedef struct ipmgmt_get_rval_s {
2366e91bba0SGirish Moodalbail 	int32_t		ir_err;
2376e91bba0SGirish Moodalbail 	size_t		ir_nvlsize;
2386e91bba0SGirish Moodalbail 	/* packed nvl follows */
2396e91bba0SGirish Moodalbail } ipmgmt_get_rval_t;
2406e91bba0SGirish Moodalbail 
2416e91bba0SGirish Moodalbail /* IPMGMT_CMD_GETPROP door_return value */
2426e91bba0SGirish Moodalbail typedef struct ipmgmt_getprop_rval_s {
2436e91bba0SGirish Moodalbail 	int32_t		ir_err;
2446e91bba0SGirish Moodalbail 	char		ir_pval[MAXPROPVALLEN];
2456e91bba0SGirish Moodalbail } ipmgmt_getprop_rval_t;
2466e91bba0SGirish Moodalbail 
2476e91bba0SGirish Moodalbail /* IPMGMT_CMD_GETIF door_return value */
2486e91bba0SGirish Moodalbail typedef struct ipmgmt_getif_rval_s {
2496e91bba0SGirish Moodalbail 	int32_t		ir_err;
2506e91bba0SGirish Moodalbail 	uint32_t	ir_ifcnt;
2516e91bba0SGirish Moodalbail 	ipadm_if_info_t	ir_ifinfo[1];
2526e91bba0SGirish Moodalbail } ipmgmt_getif_rval_t;
2536e91bba0SGirish Moodalbail 
2546e91bba0SGirish Moodalbail /* IPMGMT_CMD_{LOOKUPADD|LIFNUM2ADDROBJ|ADDROBJ2LIFNUM} door_return value */
2556e91bba0SGirish Moodalbail typedef struct ipmgmt_aobjop_rval_s {
2566e91bba0SGirish Moodalbail 	int32_t			ir_err;
2576e91bba0SGirish Moodalbail 	char			ir_aobjname[IPADM_AOBJSIZ];
2586e91bba0SGirish Moodalbail 	char			ir_ifname[LIFNAMSIZ];
2596e91bba0SGirish Moodalbail 	int32_t			ir_lnum;
2606e91bba0SGirish Moodalbail 	sa_family_t		ir_family;
2616e91bba0SGirish Moodalbail 	uint32_t		ir_flags;
2626e91bba0SGirish Moodalbail 	ipadm_addr_type_t	ir_atype;
2636e91bba0SGirish Moodalbail 	struct sockaddr_storage	ir_ifid;
2646e91bba0SGirish Moodalbail } ipmgmt_aobjop_rval_t;
2656e91bba0SGirish Moodalbail 
2666e91bba0SGirish Moodalbail /* DB walk callback functions */
2676e91bba0SGirish Moodalbail typedef boolean_t	db_wfunc_t(void *, nvlist_t *, char *, size_t, int *);
2686e91bba0SGirish Moodalbail extern int		ipadm_rw_db(db_wfunc_t *, void *, const char *, mode_t,
2696e91bba0SGirish Moodalbail 			    ipadm_db_op_t);
2706e91bba0SGirish Moodalbail 
271550b6e40SSowmini Varadhan /* zone related functions */
272550b6e40SSowmini Varadhan /*
273550b6e40SSowmini Varadhan  *  callback function to persist an interface in ipmgmtd data store
274550b6e40SSowmini Varadhan  */
275550b6e40SSowmini Varadhan typedef void (*persist_cb_t)(char *, boolean_t, boolean_t);
276550b6e40SSowmini Varadhan /*
277550b6e40SSowmini Varadhan  * ipmgmtd/libipadm network initialization interface.
278550b6e40SSowmini Varadhan  */
279550b6e40SSowmini Varadhan extern ipadm_status_t	ipadm_init_net_from_gz(ipadm_handle_t, char *,
280550b6e40SSowmini Varadhan 			    persist_cb_t);
281550b6e40SSowmini Varadhan 
2826e91bba0SGirish Moodalbail #ifdef	__cplusplus
2836e91bba0SGirish Moodalbail }
2846e91bba0SGirish Moodalbail #endif
2856e91bba0SGirish Moodalbail 
2866e91bba0SGirish Moodalbail #endif	/* _IPADM_IPMGMT_H */
287