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 2010 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _LIBIPADM_IMPL_H 27 #define _LIBIPADM_IMPL_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 #include <sys/socket.h> 34 #include <net/if.h> 35 #include <libipadm.h> 36 #include <libdladm.h> 37 #include <ipadm_ipmgmt.h> 38 #include <inet/tunables.h> 39 #include <netinet/in.h> 40 #include <pthread.h> 41 #include <libinetutil.h> 42 #include <libsocket_priv.h> 43 44 #define IPADM_STRSIZE 256 45 #define IPADM_ONSTR "on" 46 #define IPADM_OFFSTR "off" 47 #define ARP_MOD_NAME "arp" 48 #define IPADM_LOGICAL_SEP ':' 49 #define IPV6_MIN_MTU 1280 /* rfc2460 */ 50 51 /* mask for flags accepted by libipadm functions */ 52 #define IPADM_COMMON_OPT_MASK (IPADM_OPT_ACTIVE | IPADM_OPT_PERSIST) 53 54 /* Opaque library handle */ 55 struct ipadm_handle { 56 int iph_sock; /* socket to interface */ 57 int iph_sock6; /* socket to interface */ 58 int iph_door_fd; /* door descriptor to ipmgmtd */ 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 }; 63 64 /* 65 * Indicates that the operation being invoked is in 'init' context. This is 66 * a library private flag. 67 */ 68 #define IPH_INIT 0x10000000 69 70 struct ipadm_addrobj_s { 71 char ipadm_ifname[LIFNAMSIZ]; 72 int32_t ipadm_lifnum; 73 char ipadm_aobjname[IPADM_AOBJSIZ]; 74 ipadm_addr_type_t ipadm_atype; 75 uint32_t ipadm_flags; 76 sa_family_t ipadm_af; 77 union { 78 struct { 79 char ipadm_ahname[MAXNAMELEN]; 80 struct sockaddr_storage ipadm_addr; 81 uint32_t ipadm_prefixlen; 82 char ipadm_dhname[MAXNAMELEN]; 83 struct sockaddr_storage ipadm_dstaddr; 84 } ipadm_static_addr_s; 85 struct { 86 struct sockaddr_in6 ipadm_intfid; 87 uint32_t ipadm_intfidlen; 88 boolean_t ipadm_stateless; 89 boolean_t ipadm_stateful; 90 } ipadm_ipv6_intfid_s; 91 struct { 92 boolean_t ipadm_primary; 93 int32_t ipadm_wait; 94 } ipadm_dhcp_s; 95 } ipadm_addr_u; 96 }; 97 98 #define ipadm_static_addr ipadm_addr_u.ipadm_static_addr_s.ipadm_addr 99 #define ipadm_static_aname ipadm_addr_u.ipadm_static_addr_s.ipadm_ahname 100 #define ipadm_static_prefixlen ipadm_addr_u.ipadm_static_addr_s.ipadm_prefixlen 101 #define ipadm_static_dst_addr ipadm_addr_u.ipadm_static_addr_s.ipadm_dstaddr 102 #define ipadm_static_dname ipadm_addr_u.ipadm_static_addr_s.ipadm_dhname 103 #define ipadm_intfid ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_intfid 104 #define ipadm_intfidlen ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_intfidlen 105 #define ipadm_stateless ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_stateless 106 #define ipadm_stateful ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_stateful 107 #define ipadm_primary ipadm_addr_u.ipadm_dhcp_s.ipadm_primary 108 #define ipadm_wait ipadm_addr_u.ipadm_dhcp_s.ipadm_wait 109 110 /* 111 * Data structures and callback functions related to property management 112 */ 113 struct ipadm_prop_desc; 114 typedef struct ipadm_prop_desc ipadm_prop_desc_t; 115 116 /* property set() callback */ 117 typedef ipadm_status_t ipadm_pd_setf_t(ipadm_handle_t, const void *, 118 ipadm_prop_desc_t *, const void *, uint_t, uint_t); 119 120 /* property get() callback */ 121 typedef ipadm_status_t ipadm_pd_getf_t(ipadm_handle_t, const void *, 122 ipadm_prop_desc_t *, char *, uint_t *, uint_t, uint_t); 123 124 struct ipadm_prop_desc { 125 char *ipd_name; /* property name */ 126 uint_t ipd_class; /* prop. class - global/perif/both */ 127 uint_t ipd_proto; /* protocol to which property belongs */ 128 ipadm_pd_setf_t *ipd_set; /* set callback function */ 129 ipadm_pd_getf_t *ipd_get_range; /* get range callback function */ 130 ipadm_pd_getf_t *ipd_get; /* get value callback function */ 131 }; 132 133 extern ipadm_prop_desc_t ipadm_addrprop_table[]; 134 extern ipadm_pd_getf_t i_ipadm_get_onoff; 135 136 /* libipadm.c */ 137 extern ipadm_status_t i_ipadm_get_flags(ipadm_handle_t, const char *, 138 sa_family_t, uint64_t *); 139 extern ipadm_status_t i_ipadm_set_flags(ipadm_handle_t, const char *, 140 sa_family_t, uint64_t, uint64_t); 141 extern ipadm_status_t i_ipadm_init_ifs(ipadm_handle_t, const char *, 142 nvlist_t **); 143 extern ipadm_status_t i_ipadm_init_ifobj(ipadm_handle_t, const char *, 144 nvlist_t *); 145 extern ipadm_status_t i_ipadm_init_addrobj(ipadm_handle_t, nvlist_t *); 146 extern ipadm_status_t i_ipadm_addr_persist(ipadm_handle_t, 147 const ipadm_addrobj_t, boolean_t, uint32_t); 148 extern ipadm_status_t i_ipadm_delete_addr(ipadm_handle_t, ipadm_addrobj_t); 149 extern int i_ipadm_strioctl(int, int, char *, int); 150 extern boolean_t i_ipadm_is_loopback(const char *); 151 extern boolean_t i_ipadm_is_vni(const char *); 152 extern boolean_t i_ipadm_is_ipmp(ipadm_handle_t, const char *); 153 extern boolean_t i_ipadm_is_under_ipmp(ipadm_handle_t, const char *); 154 extern boolean_t i_ipadm_is_6to4(ipadm_handle_t, char *); 155 extern boolean_t i_ipadm_validate_ifname(ipadm_handle_t, const char *); 156 extern ipadm_status_t ipadm_errno2status(int); 157 extern int ipadm_door_call(ipadm_handle_t, void *, size_t, void **, 158 size_t, boolean_t); 159 extern boolean_t ipadm_if_enabled(ipadm_handle_t, const char *, 160 sa_family_t); 161 162 /* ipadm_ndpd.c */ 163 extern ipadm_status_t i_ipadm_create_ipv6addrs(ipadm_handle_t, 164 ipadm_addrobj_t, uint32_t); 165 extern ipadm_status_t i_ipadm_delete_ipv6addrs(ipadm_handle_t, 166 ipadm_addrobj_t); 167 extern ipadm_status_t i_ipadm_disable_autoconf(const char *); 168 extern ipadm_status_t i_ipadm_enable_autoconf(const char *); 169 170 /* ipadm_persist.c */ 171 extern ipadm_status_t i_ipadm_add_ipaddr2nvl(nvlist_t *, ipadm_addrobj_t); 172 extern ipadm_status_t i_ipadm_add_ip6addr2nvl(nvlist_t *, ipadm_addrobj_t); 173 extern ipadm_status_t i_ipadm_add_intfid2nvl(nvlist_t *, ipadm_addrobj_t); 174 extern ipadm_status_t i_ipadm_add_dhcp2nvl(nvlist_t *, boolean_t, int32_t); 175 176 /* ipadm_prop.c */ 177 extern ipadm_status_t i_ipadm_persist_propval(ipadm_handle_t, 178 ipadm_prop_desc_t *, const char *, const void *, 179 uint_t); 180 extern ipadm_status_t i_ipadm_get_persist_propval(ipadm_handle_t, 181 ipadm_prop_desc_t *, char *, uint_t *, 182 const void *); 183 184 /* ipadm_addr.c */ 185 extern void i_ipadm_init_addr(ipadm_addrobj_t, const char *, 186 const char *, ipadm_addr_type_t); 187 extern ipadm_status_t i_ipadm_merge_prefixlen_from_nvl(nvlist_t *, nvlist_t *, 188 const char *); 189 extern ipadm_status_t i_ipadm_get_addrobj(ipadm_handle_t, ipadm_addrobj_t); 190 extern ipadm_status_t i_ipadm_enable_static(ipadm_handle_t, const char *, 191 nvlist_t *, sa_family_t); 192 extern ipadm_status_t i_ipadm_enable_dhcp(ipadm_handle_t, const char *, 193 nvlist_t *); 194 extern ipadm_status_t i_ipadm_enable_addrconf(ipadm_handle_t, const char *, 195 nvlist_t *); 196 extern void i_ipadm_addrobj2lifname(ipadm_addrobj_t, char *, int); 197 extern ipadm_status_t i_ipadm_nvl2in6_addr(nvlist_t *, char *, 198 in6_addr_t *); 199 extern ipadm_status_t i_ipadm_get_lif2addrobj(ipadm_handle_t, 200 ipadm_addrobj_t); 201 extern ipadm_status_t i_ipadm_lookupadd_addrobj(ipadm_handle_t, 202 ipadm_addrobj_t); 203 extern ipadm_status_t i_ipadm_delete_addrobj(ipadm_handle_t, 204 const ipadm_addrobj_t, uint32_t); 205 extern boolean_t i_ipadm_name2atype(const char *, sa_family_t *, 206 ipadm_addr_type_t *); 207 208 /* ipadm_if.c */ 209 extern ipadm_status_t i_ipadm_create_if(ipadm_handle_t, char *, sa_family_t, 210 uint32_t); 211 extern ipadm_status_t i_ipadm_delete_if(ipadm_handle_t, const char *, 212 sa_family_t, uint32_t); 213 extern ipadm_status_t i_ipadm_plumb_if(ipadm_handle_t, char *, sa_family_t, 214 uint32_t); 215 extern ipadm_status_t i_ipadm_unplumb_if(ipadm_handle_t, const char *, 216 sa_family_t); 217 extern ipadm_status_t i_ipadm_if_pexists(ipadm_handle_t, const char *, 218 sa_family_t, boolean_t *); 219 extern ipadm_status_t i_ipadm_delete_ifobj(ipadm_handle_t, const char *, 220 sa_family_t, boolean_t); 221 extern int i_ipadm_get_lnum(const char *); 222 223 #ifdef __cplusplus 224 } 225 #endif 226 227 #endif /* _LIBIPADM_IMPL_H */ 228