xref: /titanic_52/usr/src/lib/libipadm/common/libipadm_impl.h (revision 299625c6492013aa7bd163862f0d181854f69b3c)
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 /*
228b88711aSGirish Moodalbail  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23*299625c6SSebastien Roy  * Copyright (c) 2013 by Delphix. All rights reserved.
246e91bba0SGirish Moodalbail  */
256e91bba0SGirish Moodalbail 
266e91bba0SGirish Moodalbail #ifndef _LIBIPADM_IMPL_H
276e91bba0SGirish Moodalbail #define	_LIBIPADM_IMPL_H
286e91bba0SGirish Moodalbail 
296e91bba0SGirish Moodalbail #ifdef	__cplusplus
306e91bba0SGirish Moodalbail extern "C" {
316e91bba0SGirish Moodalbail #endif
326e91bba0SGirish Moodalbail 
336e91bba0SGirish Moodalbail #include <sys/socket.h>
346e91bba0SGirish Moodalbail #include <net/if.h>
356e91bba0SGirish Moodalbail #include <libipadm.h>
366e91bba0SGirish Moodalbail #include <libdladm.h>
376e91bba0SGirish Moodalbail #include <ipadm_ipmgmt.h>
386e91bba0SGirish Moodalbail #include <inet/tunables.h>
396e91bba0SGirish Moodalbail #include <netinet/in.h>
406e91bba0SGirish Moodalbail #include <pthread.h>
416e91bba0SGirish Moodalbail #include <libinetutil.h>
426e91bba0SGirish Moodalbail #include <libsocket_priv.h>
436e91bba0SGirish Moodalbail 
446e91bba0SGirish Moodalbail #define	IPADM_STRSIZE		256
456e91bba0SGirish Moodalbail #define	IPADM_ONSTR		"on"
466e91bba0SGirish Moodalbail #define	IPADM_OFFSTR		"off"
476e91bba0SGirish Moodalbail #define	ARP_MOD_NAME		"arp"
486e91bba0SGirish Moodalbail #define	IPADM_LOGICAL_SEP	':'
496e91bba0SGirish Moodalbail #define	IPV6_MIN_MTU		1280	/* rfc2460 */
506e91bba0SGirish Moodalbail 
516e91bba0SGirish Moodalbail /* mask for flags accepted by libipadm functions */
526e91bba0SGirish Moodalbail #define	IPADM_COMMON_OPT_MASK	(IPADM_OPT_ACTIVE | IPADM_OPT_PERSIST)
536e91bba0SGirish Moodalbail 
546e91bba0SGirish Moodalbail /* Opaque library handle */
556e91bba0SGirish Moodalbail struct ipadm_handle {
566e91bba0SGirish Moodalbail 	int		iph_sock;	/* socket to interface */
576e91bba0SGirish Moodalbail 	int		iph_sock6;	/* socket to interface */
586e91bba0SGirish Moodalbail 	int		iph_door_fd;	/* door descriptor to ipmgmtd */
59550b6e40SSowmini Varadhan 	int		iph_rtsock;	/* routing socket */
606e91bba0SGirish Moodalbail 	dladm_handle_t	iph_dlh;	/* handle to libdladm library */
616e91bba0SGirish Moodalbail 	uint32_t	iph_flags;	/* internal flags */
626e91bba0SGirish Moodalbail 	pthread_mutex_t	iph_lock;	/* lock to set door_fd */
63550b6e40SSowmini Varadhan 	zoneid_t	iph_zoneid;	/* zoneid where handle was opened */
646e91bba0SGirish Moodalbail };
656e91bba0SGirish Moodalbail 
666e91bba0SGirish Moodalbail struct ipadm_addrobj_s {
676e91bba0SGirish Moodalbail 	char 			ipadm_ifname[LIFNAMSIZ];
686e91bba0SGirish Moodalbail 	int32_t			ipadm_lifnum;
696e91bba0SGirish Moodalbail 	char			ipadm_aobjname[IPADM_AOBJSIZ];
706e91bba0SGirish Moodalbail 	ipadm_addr_type_t	ipadm_atype;
716e91bba0SGirish Moodalbail 	uint32_t		ipadm_flags;
726e91bba0SGirish Moodalbail 	sa_family_t		ipadm_af;
736e91bba0SGirish Moodalbail 	union {
746e91bba0SGirish Moodalbail 		struct {
756e91bba0SGirish Moodalbail 			char			ipadm_ahname[MAXNAMELEN];
766e91bba0SGirish Moodalbail 			struct sockaddr_storage	ipadm_addr;
776e91bba0SGirish Moodalbail 			uint32_t		ipadm_prefixlen;
786e91bba0SGirish Moodalbail 			char			ipadm_dhname[MAXNAMELEN];
796e91bba0SGirish Moodalbail 			struct sockaddr_storage ipadm_dstaddr;
806e91bba0SGirish Moodalbail 		} ipadm_static_addr_s;
816e91bba0SGirish Moodalbail 		struct {
826e91bba0SGirish Moodalbail 			struct sockaddr_in6	ipadm_intfid;
836e91bba0SGirish Moodalbail 			uint32_t		ipadm_intfidlen;
846e91bba0SGirish Moodalbail 			boolean_t		ipadm_stateless;
856e91bba0SGirish Moodalbail 			boolean_t		ipadm_stateful;
866e91bba0SGirish Moodalbail 		} ipadm_ipv6_intfid_s;
876e91bba0SGirish Moodalbail 		struct {
886e91bba0SGirish Moodalbail 			boolean_t		ipadm_primary;
896e91bba0SGirish Moodalbail 			int32_t			ipadm_wait;
906e91bba0SGirish Moodalbail 		} ipadm_dhcp_s;
916e91bba0SGirish Moodalbail 	} ipadm_addr_u;
926e91bba0SGirish Moodalbail };
936e91bba0SGirish Moodalbail 
946e91bba0SGirish Moodalbail #define	ipadm_static_addr	ipadm_addr_u.ipadm_static_addr_s.ipadm_addr
956e91bba0SGirish Moodalbail #define	ipadm_static_aname	ipadm_addr_u.ipadm_static_addr_s.ipadm_ahname
966e91bba0SGirish Moodalbail #define	ipadm_static_prefixlen	ipadm_addr_u.ipadm_static_addr_s.ipadm_prefixlen
976e91bba0SGirish Moodalbail #define	ipadm_static_dst_addr	ipadm_addr_u.ipadm_static_addr_s.ipadm_dstaddr
986e91bba0SGirish Moodalbail #define	ipadm_static_dname	ipadm_addr_u.ipadm_static_addr_s.ipadm_dhname
996e91bba0SGirish Moodalbail #define	ipadm_intfid		ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_intfid
1006e91bba0SGirish Moodalbail #define	ipadm_intfidlen		ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_intfidlen
1016e91bba0SGirish Moodalbail #define	ipadm_stateless		ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_stateless
1026e91bba0SGirish Moodalbail #define	ipadm_stateful		ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_stateful
1036e91bba0SGirish Moodalbail #define	ipadm_primary		ipadm_addr_u.ipadm_dhcp_s.ipadm_primary
1046e91bba0SGirish Moodalbail #define	ipadm_wait		ipadm_addr_u.ipadm_dhcp_s.ipadm_wait
1056e91bba0SGirish Moodalbail 
1066e91bba0SGirish Moodalbail /*
1076e91bba0SGirish Moodalbail  * Data structures and callback functions related to property management
1086e91bba0SGirish Moodalbail  */
1096e91bba0SGirish Moodalbail struct ipadm_prop_desc;
1106e91bba0SGirish Moodalbail typedef struct ipadm_prop_desc ipadm_prop_desc_t;
1116e91bba0SGirish Moodalbail 
1126e91bba0SGirish Moodalbail /* property set() callback */
1136e91bba0SGirish Moodalbail typedef ipadm_status_t	ipadm_pd_setf_t(ipadm_handle_t, const void *,
1146e91bba0SGirish Moodalbail     ipadm_prop_desc_t *, const void *, uint_t, uint_t);
1156e91bba0SGirish Moodalbail 
1166e91bba0SGirish Moodalbail /* property get() callback */
1176e91bba0SGirish Moodalbail typedef ipadm_status_t	ipadm_pd_getf_t(ipadm_handle_t, const void *,
1186e91bba0SGirish Moodalbail     ipadm_prop_desc_t *, char *, uint_t *, uint_t, uint_t);
1196e91bba0SGirish Moodalbail 
1206e91bba0SGirish Moodalbail struct ipadm_prop_desc {
1216e91bba0SGirish Moodalbail 	char		*ipd_name;	/* property name */
122*299625c6SSebastien Roy 	char		*ipd_old_name;	/* for backward compatibility */
1236e91bba0SGirish Moodalbail 	uint_t		ipd_class;	/* prop. class - global/perif/both */
1246e91bba0SGirish Moodalbail 	uint_t		ipd_proto;	/* protocol to which property belongs */
1258b88711aSGirish Moodalbail 	uint_t		ipd_flags;	/* see below */
1266e91bba0SGirish Moodalbail 	ipadm_pd_setf_t	*ipd_set;	/* set callback function */
1276e91bba0SGirish Moodalbail 	ipadm_pd_getf_t	*ipd_get_range;	/* get range callback function */
1286e91bba0SGirish Moodalbail 	ipadm_pd_getf_t	*ipd_get;	/* get value callback function */
1296e91bba0SGirish Moodalbail };
1306e91bba0SGirish Moodalbail 
1318b88711aSGirish Moodalbail /* ipd_flags values */
1328b88711aSGirish Moodalbail #define	IPADMPROP_MULVAL	0x00000001	/* property multi-valued */
1338b88711aSGirish Moodalbail 
1346e91bba0SGirish Moodalbail extern ipadm_prop_desc_t	ipadm_addrprop_table[];
1356e91bba0SGirish Moodalbail extern ipadm_pd_getf_t		i_ipadm_get_onoff;
1366e91bba0SGirish Moodalbail 
1376e91bba0SGirish Moodalbail /* libipadm.c */
1386e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_get_flags(ipadm_handle_t, const char *,
1396e91bba0SGirish Moodalbail 			    sa_family_t, uint64_t *);
1406e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_set_flags(ipadm_handle_t, const char *,
1416e91bba0SGirish Moodalbail 			    sa_family_t, uint64_t, uint64_t);
1426e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_init_ifs(ipadm_handle_t, const char *,
1436e91bba0SGirish Moodalbail 			    nvlist_t **);
1446e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_init_ifobj(ipadm_handle_t, const char *,
1456e91bba0SGirish Moodalbail 			    nvlist_t *);
1466e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_init_addrobj(ipadm_handle_t, nvlist_t *);
1476e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_addr_persist(ipadm_handle_t,
1486e91bba0SGirish Moodalbail 			    const ipadm_addrobj_t, boolean_t, uint32_t);
1496e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_delete_addr(ipadm_handle_t, ipadm_addrobj_t);
1506e91bba0SGirish Moodalbail extern int		i_ipadm_strioctl(int, int, char *, int);
1516e91bba0SGirish Moodalbail extern boolean_t	i_ipadm_is_loopback(const char *);
1526e91bba0SGirish Moodalbail extern boolean_t	i_ipadm_is_vni(const char *);
1536e91bba0SGirish Moodalbail extern boolean_t	i_ipadm_is_ipmp(ipadm_handle_t, const char *);
1546e91bba0SGirish Moodalbail extern boolean_t	i_ipadm_is_under_ipmp(ipadm_handle_t, const char *);
1556e91bba0SGirish Moodalbail extern boolean_t	i_ipadm_is_6to4(ipadm_handle_t, char *);
1566e91bba0SGirish Moodalbail extern boolean_t	i_ipadm_validate_ifname(ipadm_handle_t, const char *);
1576e91bba0SGirish Moodalbail extern ipadm_status_t	ipadm_errno2status(int);
1586e91bba0SGirish Moodalbail extern int		ipadm_door_call(ipadm_handle_t, void *, size_t, void **,
1596e91bba0SGirish Moodalbail 			    size_t, boolean_t);
1606e91bba0SGirish Moodalbail extern boolean_t 	ipadm_if_enabled(ipadm_handle_t, const char *,
1616e91bba0SGirish Moodalbail 			    sa_family_t);
1626e91bba0SGirish Moodalbail 
1636e91bba0SGirish Moodalbail /* ipadm_ndpd.c */
1646e91bba0SGirish Moodalbail extern	ipadm_status_t	i_ipadm_create_ipv6addrs(ipadm_handle_t,
1656e91bba0SGirish Moodalbail 			    ipadm_addrobj_t, uint32_t);
1666e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_delete_ipv6addrs(ipadm_handle_t,
1676e91bba0SGirish Moodalbail 			    ipadm_addrobj_t);
1686e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_disable_autoconf(const char *);
1696e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_enable_autoconf(const char *);
1706e91bba0SGirish Moodalbail 
1716e91bba0SGirish Moodalbail /* ipadm_persist.c */
1726e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_add_ipaddr2nvl(nvlist_t *, ipadm_addrobj_t);
1736e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_add_ip6addr2nvl(nvlist_t *, ipadm_addrobj_t);
1746e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_add_intfid2nvl(nvlist_t *, ipadm_addrobj_t);
1756e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_add_dhcp2nvl(nvlist_t *, boolean_t, int32_t);
1766e91bba0SGirish Moodalbail 
1776e91bba0SGirish Moodalbail /* ipadm_prop.c */
1786e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_persist_propval(ipadm_handle_t,
1796e91bba0SGirish Moodalbail 			    ipadm_prop_desc_t *, const char *, const void *,
1806e91bba0SGirish Moodalbail 			    uint_t);
1816e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_get_persist_propval(ipadm_handle_t,
1826e91bba0SGirish Moodalbail 			    ipadm_prop_desc_t *, char *, uint_t *,
1836e91bba0SGirish Moodalbail 			    const void *);
1846e91bba0SGirish Moodalbail 
1856e91bba0SGirish Moodalbail /* ipadm_addr.c */
1866e91bba0SGirish Moodalbail extern void		i_ipadm_init_addr(ipadm_addrobj_t, const char *,
1876e91bba0SGirish Moodalbail 			    const char *, ipadm_addr_type_t);
1886e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_merge_prefixlen_from_nvl(nvlist_t *, nvlist_t *,
1896e91bba0SGirish Moodalbail 			    const char *);
1906e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_get_addrobj(ipadm_handle_t, ipadm_addrobj_t);
1916e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_enable_static(ipadm_handle_t, const char *,
1926e91bba0SGirish Moodalbail 			    nvlist_t *, sa_family_t);
1936e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_enable_dhcp(ipadm_handle_t, const char *,
1946e91bba0SGirish Moodalbail 			    nvlist_t *);
1956e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_enable_addrconf(ipadm_handle_t, const char *,
1966e91bba0SGirish Moodalbail 			    nvlist_t *);
1976e91bba0SGirish Moodalbail extern void		i_ipadm_addrobj2lifname(ipadm_addrobj_t, char *, int);
1986e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_nvl2in6_addr(nvlist_t *, char *,
1996e91bba0SGirish Moodalbail 			    in6_addr_t *);
2006e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_get_lif2addrobj(ipadm_handle_t,
2016e91bba0SGirish Moodalbail 			    ipadm_addrobj_t);
2026e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_lookupadd_addrobj(ipadm_handle_t,
2036e91bba0SGirish Moodalbail 			    ipadm_addrobj_t);
204ec3706caSVasumathi Sundaram extern ipadm_status_t	i_ipadm_setlifnum_addrobj(ipadm_handle_t,
205ec3706caSVasumathi Sundaram 			    ipadm_addrobj_t);
206ec3706caSVasumathi Sundaram extern ipadm_status_t	i_ipadm_do_addif(ipadm_handle_t, ipadm_addrobj_t);
2076e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_delete_addrobj(ipadm_handle_t,
2086e91bba0SGirish Moodalbail 			    const ipadm_addrobj_t, uint32_t);
2096e91bba0SGirish Moodalbail extern boolean_t	i_ipadm_name2atype(const char *, sa_family_t *,
2106e91bba0SGirish Moodalbail 			    ipadm_addr_type_t *);
211550b6e40SSowmini Varadhan extern ipadm_status_t	i_ipadm_resolve_addr(const char *, sa_family_t,
212550b6e40SSowmini Varadhan 			    struct sockaddr_storage *);
2136e91bba0SGirish Moodalbail 
2146e91bba0SGirish Moodalbail /* ipadm_if.c */
2156e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_create_if(ipadm_handle_t, char *,  sa_family_t,
2166e91bba0SGirish Moodalbail 			    uint32_t);
2176e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_delete_if(ipadm_handle_t, const char *,
2186e91bba0SGirish Moodalbail 			    sa_family_t, uint32_t);
2196e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_plumb_if(ipadm_handle_t, char *, sa_family_t,
2206e91bba0SGirish Moodalbail 			    uint32_t);
2216e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_unplumb_if(ipadm_handle_t, const char *,
2226e91bba0SGirish Moodalbail 			    sa_family_t);
2236e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_if_pexists(ipadm_handle_t, const char *,
2246e91bba0SGirish Moodalbail 			    sa_family_t, boolean_t *);
2256e91bba0SGirish Moodalbail extern ipadm_status_t	i_ipadm_delete_ifobj(ipadm_handle_t, const char *,
2266e91bba0SGirish Moodalbail 			    sa_family_t, boolean_t);
2276e91bba0SGirish Moodalbail extern int		i_ipadm_get_lnum(const char *);
2286e91bba0SGirish Moodalbail 
2296e91bba0SGirish Moodalbail #ifdef	__cplusplus
2306e91bba0SGirish Moodalbail }
2316e91bba0SGirish Moodalbail #endif
2326e91bba0SGirish Moodalbail 
2336e91bba0SGirish Moodalbail #endif	/* _LIBIPADM_IMPL_H */
234