1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 23 */ 24 25 #ifndef _LIBIPADM_IMPL_H 26 #define _LIBIPADM_IMPL_H 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 #include <sys/socket.h> 33 #include <net/if.h> 34 #include <libipadm.h> 35 #include <libdladm.h> 36 #include <ipadm_ipmgmt.h> 37 #include <inet/tunables.h> 38 #include <netinet/in.h> 39 #include <pthread.h> 40 #include <libinetutil.h> 41 #include <libsocket_priv.h> 42 43 #define IPADM_STRSIZE 256 44 #define IPADM_ONSTR "on" 45 #define IPADM_OFFSTR "off" 46 #define ARP_MOD_NAME "arp" 47 #define IPADM_LOGICAL_SEP ':' 48 #define IPV6_MIN_MTU 1280 /* rfc2460 */ 49 50 /* mask for flags accepted by libipadm functions */ 51 #define IPADM_COMMON_OPT_MASK (IPADM_OPT_ACTIVE | IPADM_OPT_PERSIST) 52 53 /* Opaque library handle */ 54 struct ipadm_handle { 55 int iph_sock; /* socket to interface */ 56 int iph_sock6; /* socket to interface */ 57 int iph_door_fd; /* door descriptor to ipmgmtd */ 58 int iph_rtsock; /* routing socket */ 59 dladm_handle_t iph_dlh; /* handle to libdladm library */ 60 uint32_t iph_flags; /* internal flags */ 61 pthread_mutex_t iph_lock; /* lock to set door_fd */ 62 zoneid_t iph_zoneid; /* zoneid where handle was opened */ 63 }; 64 65 /* 66 * Indicates that the operation being invoked is in 'init' context. This is 67 * a library private flag. 68 */ 69 #define IPH_INIT 0x10000000 70 71 struct ipadm_addrobj_s { 72 char ipadm_ifname[LIFNAMSIZ]; 73 int32_t ipadm_lifnum; 74 char ipadm_aobjname[IPADM_AOBJSIZ]; 75 ipadm_addr_type_t ipadm_atype; 76 uint32_t ipadm_flags; 77 sa_family_t ipadm_af; 78 union { 79 struct { 80 char ipadm_ahname[MAXNAMELEN]; 81 struct sockaddr_storage ipadm_addr; 82 uint32_t ipadm_prefixlen; 83 char ipadm_dhname[MAXNAMELEN]; 84 struct sockaddr_storage ipadm_dstaddr; 85 } ipadm_static_addr_s; 86 struct { 87 struct sockaddr_in6 ipadm_intfid; 88 uint32_t ipadm_intfidlen; 89 boolean_t ipadm_stateless; 90 boolean_t ipadm_stateful; 91 } ipadm_ipv6_intfid_s; 92 struct { 93 boolean_t ipadm_primary; 94 int32_t ipadm_wait; 95 } ipadm_dhcp_s; 96 } ipadm_addr_u; 97 }; 98 99 #define ipadm_static_addr ipadm_addr_u.ipadm_static_addr_s.ipadm_addr 100 #define ipadm_static_aname ipadm_addr_u.ipadm_static_addr_s.ipadm_ahname 101 #define ipadm_static_prefixlen ipadm_addr_u.ipadm_static_addr_s.ipadm_prefixlen 102 #define ipadm_static_dst_addr ipadm_addr_u.ipadm_static_addr_s.ipadm_dstaddr 103 #define ipadm_static_dname ipadm_addr_u.ipadm_static_addr_s.ipadm_dhname 104 #define ipadm_intfid ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_intfid 105 #define ipadm_intfidlen ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_intfidlen 106 #define ipadm_stateless ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_stateless 107 #define ipadm_stateful ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_stateful 108 #define ipadm_primary ipadm_addr_u.ipadm_dhcp_s.ipadm_primary 109 #define ipadm_wait ipadm_addr_u.ipadm_dhcp_s.ipadm_wait 110 111 /* 112 * Data structures and callback functions related to property management 113 */ 114 struct ipadm_prop_desc; 115 typedef struct ipadm_prop_desc ipadm_prop_desc_t; 116 117 /* property set() callback */ 118 typedef ipadm_status_t ipadm_pd_setf_t(ipadm_handle_t, const void *, 119 ipadm_prop_desc_t *, const void *, uint_t, uint_t); 120 121 /* property get() callback */ 122 typedef ipadm_status_t ipadm_pd_getf_t(ipadm_handle_t, const void *, 123 ipadm_prop_desc_t *, char *, uint_t *, uint_t, uint_t); 124 125 struct ipadm_prop_desc { 126 char *ipd_name; /* property name */ 127 uint_t ipd_class; /* prop. class - global/perif/both */ 128 uint_t ipd_proto; /* protocol to which property belongs */ 129 uint_t ipd_flags; /* see below */ 130 ipadm_pd_setf_t *ipd_set; /* set callback function */ 131 ipadm_pd_getf_t *ipd_get_range; /* get range callback function */ 132 ipadm_pd_getf_t *ipd_get; /* get value callback function */ 133 }; 134 135 /* ipd_flags values */ 136 #define IPADMPROP_MULVAL 0x00000001 /* property multi-valued */ 137 138 extern ipadm_prop_desc_t ipadm_addrprop_table[]; 139 extern ipadm_pd_getf_t i_ipadm_get_onoff; 140 141 /* libipadm.c */ 142 extern ipadm_status_t i_ipadm_get_flags(ipadm_handle_t, const char *, 143 sa_family_t, uint64_t *); 144 extern ipadm_status_t i_ipadm_set_flags(ipadm_handle_t, const char *, 145 sa_family_t, uint64_t, uint64_t); 146 extern ipadm_status_t i_ipadm_init_ifs(ipadm_handle_t, const char *, 147 nvlist_t **); 148 extern ipadm_status_t i_ipadm_init_ifobj(ipadm_handle_t, const char *, 149 nvlist_t *); 150 extern ipadm_status_t i_ipadm_init_addrobj(ipadm_handle_t, nvlist_t *); 151 extern ipadm_status_t i_ipadm_addr_persist(ipadm_handle_t, 152 const ipadm_addrobj_t, boolean_t, uint32_t); 153 extern ipadm_status_t i_ipadm_delete_addr(ipadm_handle_t, ipadm_addrobj_t); 154 extern int i_ipadm_strioctl(int, int, char *, int); 155 extern boolean_t i_ipadm_is_loopback(const char *); 156 extern boolean_t i_ipadm_is_vni(const char *); 157 extern boolean_t i_ipadm_is_ipmp(ipadm_handle_t, const char *); 158 extern boolean_t i_ipadm_is_under_ipmp(ipadm_handle_t, const char *); 159 extern boolean_t i_ipadm_is_6to4(ipadm_handle_t, char *); 160 extern boolean_t i_ipadm_validate_ifname(ipadm_handle_t, const char *); 161 extern ipadm_status_t ipadm_errno2status(int); 162 extern int ipadm_door_call(ipadm_handle_t, void *, size_t, void **, 163 size_t, boolean_t); 164 extern boolean_t ipadm_if_enabled(ipadm_handle_t, const char *, 165 sa_family_t); 166 167 /* ipadm_ndpd.c */ 168 extern ipadm_status_t i_ipadm_create_ipv6addrs(ipadm_handle_t, 169 ipadm_addrobj_t, uint32_t); 170 extern ipadm_status_t i_ipadm_delete_ipv6addrs(ipadm_handle_t, 171 ipadm_addrobj_t); 172 extern ipadm_status_t i_ipadm_disable_autoconf(const char *); 173 extern ipadm_status_t i_ipadm_enable_autoconf(const char *); 174 175 /* ipadm_persist.c */ 176 extern ipadm_status_t i_ipadm_add_ipaddr2nvl(nvlist_t *, ipadm_addrobj_t); 177 extern ipadm_status_t i_ipadm_add_ip6addr2nvl(nvlist_t *, ipadm_addrobj_t); 178 extern ipadm_status_t i_ipadm_add_intfid2nvl(nvlist_t *, ipadm_addrobj_t); 179 extern ipadm_status_t i_ipadm_add_dhcp2nvl(nvlist_t *, boolean_t, int32_t); 180 181 /* ipadm_prop.c */ 182 extern ipadm_status_t i_ipadm_persist_propval(ipadm_handle_t, 183 ipadm_prop_desc_t *, const char *, const void *, 184 uint_t); 185 extern ipadm_status_t i_ipadm_get_persist_propval(ipadm_handle_t, 186 ipadm_prop_desc_t *, char *, uint_t *, 187 const void *); 188 189 /* ipadm_addr.c */ 190 extern void i_ipadm_init_addr(ipadm_addrobj_t, const char *, 191 const char *, ipadm_addr_type_t); 192 extern ipadm_status_t i_ipadm_merge_prefixlen_from_nvl(nvlist_t *, nvlist_t *, 193 const char *); 194 extern ipadm_status_t i_ipadm_get_addrobj(ipadm_handle_t, ipadm_addrobj_t); 195 extern ipadm_status_t i_ipadm_enable_static(ipadm_handle_t, const char *, 196 nvlist_t *, sa_family_t); 197 extern ipadm_status_t i_ipadm_enable_dhcp(ipadm_handle_t, const char *, 198 nvlist_t *); 199 extern ipadm_status_t i_ipadm_enable_addrconf(ipadm_handle_t, const char *, 200 nvlist_t *); 201 extern void i_ipadm_addrobj2lifname(ipadm_addrobj_t, char *, int); 202 extern ipadm_status_t i_ipadm_nvl2in6_addr(nvlist_t *, char *, 203 in6_addr_t *); 204 extern ipadm_status_t i_ipadm_get_lif2addrobj(ipadm_handle_t, 205 ipadm_addrobj_t); 206 extern ipadm_status_t i_ipadm_lookupadd_addrobj(ipadm_handle_t, 207 ipadm_addrobj_t); 208 extern ipadm_status_t i_ipadm_setlifnum_addrobj(ipadm_handle_t, 209 ipadm_addrobj_t); 210 extern ipadm_status_t i_ipadm_do_addif(ipadm_handle_t, ipadm_addrobj_t); 211 extern ipadm_status_t i_ipadm_delete_addrobj(ipadm_handle_t, 212 const ipadm_addrobj_t, uint32_t); 213 extern boolean_t i_ipadm_name2atype(const char *, sa_family_t *, 214 ipadm_addr_type_t *); 215 extern ipadm_status_t i_ipadm_resolve_addr(const char *, sa_family_t, 216 struct sockaddr_storage *); 217 218 /* ipadm_if.c */ 219 extern ipadm_status_t i_ipadm_create_if(ipadm_handle_t, char *, sa_family_t, 220 uint32_t); 221 extern ipadm_status_t i_ipadm_delete_if(ipadm_handle_t, const char *, 222 sa_family_t, uint32_t); 223 extern ipadm_status_t i_ipadm_plumb_if(ipadm_handle_t, char *, sa_family_t, 224 uint32_t); 225 extern ipadm_status_t i_ipadm_unplumb_if(ipadm_handle_t, const char *, 226 sa_family_t); 227 extern ipadm_status_t i_ipadm_if_pexists(ipadm_handle_t, const char *, 228 sa_family_t, boolean_t *); 229 extern ipadm_status_t i_ipadm_delete_ifobj(ipadm_handle_t, const char *, 230 sa_family_t, boolean_t); 231 extern int i_ipadm_get_lnum(const char *); 232 233 #ifdef __cplusplus 234 } 235 #endif 236 237 #endif /* _LIBIPADM_IMPL_H */ 238