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 * Copyright (c) 2016, Chris Fraire <cfraire@me.com>. 24 * Copyright 2021, Tintri by DDN. All rights reserved. 25 */ 26 27 #ifndef _IPADM_IPMGMT_H 28 #define _IPADM_IPMGMT_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 #include <sys/types.h> 34 #include <sys/stat.h> 35 #include <fcntl.h> 36 #include <sys/mman.h> 37 #include <door.h> 38 #include <libipadm.h> 39 #include <inet/tunables.h> 40 41 /* 42 * Function declarations and data structures shared by libipadm.so and 43 * the IP management daemon. 44 */ 45 46 /* Authorization required to configure network interfaces */ 47 #define NETWORK_INTERFACE_CONFIG_AUTH "solaris.network.interface.config" 48 49 /* 50 * Data store read/write utilities related declarations. 51 */ 52 /* 53 * For more information on these definitions please refer to the top of 54 * ipadm_persist.c. These are the name of the nvpairs which hold the 55 * respective values. All nvpairs private to ipadm have names that begin 56 * with "_". Note below that 'prefixlen' and 'reqhost' are address 57 * properties and therefore not a private nvpair name. 58 */ 59 #define IPADM_NVP_PROTONAME "_protocol" /* protocol name */ 60 #define IPADM_NVP_IFNAME "_ifname" /* interface name */ 61 #define IPADM_NVP_IFCLASS "_ifclass" /* interface class */ 62 #define IPADM_NVP_FAMILIES "_families" /* interface families */ 63 #define IPADM_NVP_GIFNAME "_gifname" /* IPMP group interface name */ 64 #define IPADM_NVP_MIFNAMES "_mifnames" /* IPMP group members */ 65 #define IPADM_NVP_AOBJNAME "_aobjname" /* addrobj name */ 66 #define IPADM_NVP_FAMILY "_family" /* address family */ 67 #define IPADM_NVP_IPV4ADDR "_ipv4addr" /* name of IPv4 addr nvlist */ 68 #define IPADM_NVP_IPNUMADDR "_addr" /* local address */ 69 #define IPADM_NVP_IPADDRHNAME "_aname" /* local hostname */ 70 #define IPADM_NVP_IPDADDRHNAME "_dname" /* remote hostname */ 71 #define IPADM_NVP_PREFIXLEN "prefixlen" /* prefixlen */ 72 #define IPADM_NVP_REQHOST "reqhost" /* requested hostname */ 73 #define IPADM_NVP_IPV6ADDR "_ipv6addr" /* name of IPv6 addr nvlist */ 74 #define IPADM_NVP_DHCP "_dhcp" /* name of DHCP nvlist */ 75 #define IPADM_NVP_WAIT "_wait" /* DHCP timeout value */ 76 #define IPADM_NVP_PRIMARY "_primary" /* DHCP primary interface */ 77 #define IPADM_NVP_LIFNUM "_lifnum" /* logical interface number */ 78 #define IPADM_NVP_INTFID "_intfid" /* name of IPv6 intfid nvlist */ 79 #define IPADM_NVP_STATELESS "_stateless" /* IPv6 autoconf stateless */ 80 #define IPADM_NVP_STATEFUL "_stateful" /* IPv6 autoconf dhcpv6 */ 81 82 #define IPADM_PRIV_NVP(s) ((s)[0] == '_' && (s)[1] != '_') 83 84 /* 85 * All protocol properties that are private to ipadm are stored in the 86 * ipadm datastore with "__" as prefix. This is to ensure there 87 * is no collision of namespace between ipadm private nvpair names and 88 * the private protocol property names. 89 */ 90 #define IPADM_PERSIST_PRIVPROP_PREFIX "__" 91 92 /* data-store operations */ 93 typedef enum { 94 IPADM_DB_WRITE = 0, /* Writes to DB */ 95 IPADM_DB_DELETE, /* Deletes an entry from DB */ 96 IPADM_DB_READ /* Read from DB */ 97 } ipadm_db_op_t; 98 99 /* 100 * callback arg used by db_wfunc_t that writes to DB. The contents to be 101 * written to DB are captured in `dbw_nvl'. 102 */ 103 typedef struct ipadm_dbwrite_cbarg_s { 104 nvlist_t *dbw_nvl; 105 uint_t dbw_flags; 106 } ipadm_dbwrite_cbarg_t; 107 108 /* 109 * door related function declarations and data structures. 110 */ 111 112 /* The door file for the ipmgmt (ip-interface management) daemon */ 113 #define IPMGMT_DOOR "/etc/svc/volatile/ipadm/ipmgmt_door" 114 #define MAXPROTONAMELEN 32 115 116 /* 117 * ia_flags used inside the arguments for interface/address commands 118 * 119 * - APPEND updates the multi-valued ipadm DB entry with a new value 120 * - REMOVE updates the multi-valued ipadm DB entry by removing a value 121 * - ACTIVE updates the running configuration 122 * - PERSIST updates the permanent data store 123 * - INIT indicates that operation being performed is under init context 124 * - PROPS_ONLY indicates the update changes the running configuration of 125 * "props" data on the interface/address object. The props are cached 126 * there on the parent, so a PROPS_ONLY change does not affect the 127 * ACTIVE/PERSIST state of the parent. 128 * 129 * These two flags are used by ipmgmt_db_update_if function, 130 * because it can be used to update more that one DB line 131 * and we need to be sure that we finished all operations, 132 * after the operation has finished the related flag is cleared 133 * 134 * - UPDATE_IF - used when we need to update IPADM_NVP_FAMILIES and 135 * IPADM_NVP_MIFNAMES fields 136 * - UPDATE_IPMP - used when we need to update IPADM_NVP_GIFNAME 137 */ 138 #define IPMGMT_APPEND 0x00000001 139 #define IPMGMT_REMOVE 0x00000002 140 #define IPMGMT_ACTIVE 0x00000004 141 #define IPMGMT_PERSIST 0x00000008 142 #define IPMGMT_INIT 0x00000010 143 #define IPMGMT_PROPS_ONLY 0x00000020 144 #define IPMGMT_UPDATE_IF 0x00000040 145 #define IPMGMT_UPDATE_IPMP 0x00000080 146 147 148 /* door call command type */ 149 typedef enum { 150 IPMGMT_CMD_SETPROP = 1, /* persist property */ 151 IPMGMT_CMD_SETIF, /* persist interface */ 152 IPMGMT_CMD_SETADDR, /* persist address */ 153 IPMGMT_CMD_GETPROP, /* retrieve persisted property value */ 154 IPMGMT_CMD_GETIF, /* retrieve persisted interface conf. */ 155 IPMGMT_CMD_GETADDR, /* retrieve persisted addresses */ 156 IPMGMT_CMD_RESETIF, /* purge interface configuration */ 157 IPMGMT_CMD_RESETADDR, /* purge address configuration */ 158 IPMGMT_CMD_RESETPROP, /* purge property configuration */ 159 IPMGMT_CMD_INITIF, /* retrieve interfaces to initialize */ 160 IPMGMT_CMD_ADDROBJ_LOOKUPADD, /* addr. object lookup & add */ 161 IPMGMT_CMD_ADDROBJ_SETLIFNUM, /* set lifnum on the addrobj */ 162 IPMGMT_CMD_ADDROBJ_ADD, /* add addr. object to addrobj map */ 163 IPMGMT_CMD_LIF2ADDROBJ, /* lifname to addrobj mapping */ 164 IPMGMT_CMD_AOBJNAME2ADDROBJ, /* aobjname to addrobj mapping */ 165 IPMGMT_CMD_IPMP_UPDATE /* update IPMP group members */ 166 } ipmgmt_door_cmd_type_t; 167 168 /* 169 * Note: We need to keep the size of the structure the same on amd64 and i386 170 * for all door_call arguments and door_return structures. 171 */ 172 /* door_call argument */ 173 typedef struct ipmgmt_arg { 174 ipmgmt_door_cmd_type_t ia_cmd; 175 } ipmgmt_arg_t; 176 177 /* IPMGMT_CMD_{SETPROP|GETPROP|RESETPROP} door_call argument */ 178 typedef struct ipmgmt_prop_arg_s { 179 ipmgmt_door_cmd_type_t ia_cmd; 180 uint32_t ia_flags; 181 char ia_ifname[LIFNAMSIZ]; 182 char ia_aobjname[IPADM_AOBJSIZ]; 183 char ia_module[MAXPROTONAMELEN]; 184 char ia_pname[MAXPROPNAMELEN]; 185 char ia_pval[MAXPROPVALLEN]; 186 } ipmgmt_prop_arg_t; 187 188 /* 189 * ipadm_addr_type_t-specific values that are cached in ipmgmtd and can 190 * make a round-trip back to client programs 191 */ 192 typedef union { 193 struct { 194 boolean_t ipmgmt_linklocal; 195 struct sockaddr_in6 ipmgmt_ifid; 196 } ipmgmt_ipv6_cache_s; 197 struct { 198 char ipmgmt_reqhost[MAXNAMELEN]; 199 } ipmgmt_dhcp_cache_s; 200 } ipmgmt_addr_type_cache_u; 201 202 /* IPMGMT_CMD_GETIF door_call argument structure */ 203 typedef struct ipmgmt_getif_arg_s { 204 ipmgmt_door_cmd_type_t ia_cmd; 205 uint32_t ia_flags; 206 char ia_ifname[LIFNAMSIZ]; 207 } ipmgmt_getif_arg_t; 208 209 /* IPMGMT_CMD_RESETIF, IPMGMT_CMD_SETIF door_call argument structure */ 210 typedef struct ipmgmt_if_arg_s { 211 ipmgmt_door_cmd_type_t ia_cmd; 212 uint32_t ia_flags; 213 char ia_ifname[LIFNAMSIZ]; 214 sa_family_t ia_family; 215 ipadm_if_class_t ia_ifclass; 216 } ipmgmt_if_arg_t; 217 218 /* IPMGMT_CMD_INITIF door_call argument structure */ 219 typedef struct ipmgmt_initif_arg_s { 220 ipmgmt_door_cmd_type_t ia_cmd; 221 uint32_t ia_flags; 222 sa_family_t ia_family; 223 size_t ia_nvlsize; 224 /* packed nvl follows */ 225 } ipmgmt_initif_arg_t; 226 227 /* IPMGMT_CMD_IPMP_UPDATE door_call argument structure */ 228 typedef struct ipmgmt_ipmp_update_arg_s { 229 ipmgmt_door_cmd_type_t ia_cmd; 230 uint32_t ia_flags; 231 char ia_gifname[LIFNAMSIZ]; /* group interface name */ 232 char ia_mifname[LIFNAMSIZ]; /* group's member interface name */ 233 } ipmgmt_ipmp_update_arg_t; 234 235 /* IPMGMT_CMD_SETADDR door_call argument */ 236 typedef struct ipmgmt_setaddr_arg_s { 237 ipmgmt_door_cmd_type_t ia_cmd; 238 uint32_t ia_flags; 239 size_t ia_nvlsize; 240 /* packed nvl follows */ 241 } ipmgmt_setaddr_arg_t; 242 243 /* IPMGMT_CMD_GETADDR door_call argument */ 244 typedef struct ipmgmt_getaddr_arg_s { 245 ipmgmt_door_cmd_type_t ia_cmd; 246 uint32_t ia_flags; 247 char ia_ifname[LIFNAMSIZ]; 248 sa_family_t ia_family; 249 char ia_aobjname[IPADM_AOBJSIZ]; 250 } ipmgmt_getaddr_arg_t; 251 252 /* IPMGMT_CMD_RESETADDR door_call argument */ 253 typedef struct ipmgmt_addr_arg_s { 254 ipmgmt_door_cmd_type_t ia_cmd; 255 uint32_t ia_flags; 256 char ia_aobjname[IPADM_AOBJSIZ]; 257 int32_t ia_lnum; 258 } ipmgmt_addr_arg_t; 259 260 /* 261 * IPMGMT_CMD_{ADDROBJ_ADD|ADDROBJ_LOOKUPADD|LIFNUM2ADDROBJ| 262 * ADDROBJ2LIFNUM} door_call argument. 263 */ 264 typedef struct ipmgmt_aobjop_arg_s { 265 ipmgmt_door_cmd_type_t ia_cmd; 266 uint32_t ia_flags; 267 char ia_aobjname[IPADM_AOBJSIZ]; 268 char ia_ifname[LIFNAMSIZ]; 269 int32_t ia_lnum; 270 sa_family_t ia_family; 271 ipadm_addr_type_t ia_atype; 272 } ipmgmt_aobjop_arg_t; 273 274 /* door call return value */ 275 typedef struct ipmgmt_retval_s { 276 int32_t ir_err; 277 } ipmgmt_retval_t; 278 279 /* IPMGMT_CMD_GETADDR door_return value */ 280 typedef struct ipmgmt_get_rval_s { 281 int32_t ir_err; 282 uint32_t ir_nvlsize; 283 /* packed nvl follows */ 284 } ipmgmt_get_rval_t; 285 286 /* IPMGMT_CMD_GETPROP door_return value */ 287 typedef struct ipmgmt_getprop_rval_s { 288 int32_t ir_err; 289 char ir_pval[MAXPROPVALLEN]; 290 } ipmgmt_getprop_rval_t; 291 292 /* IPMGMT_CMD_GETIF door_return value */ 293 typedef struct ipmgmt_getif_rval_s { 294 int32_t ir_err; 295 uint32_t ir_ifcnt; 296 ipadm_if_info_t ir_ifinfo[1]; 297 } ipmgmt_getif_rval_t; 298 299 /* IPMGMT_CMD_{LOOKUPADD|LIFNUM2ADDROBJ|ADDROBJ2LIFNUM} door_return value */ 300 typedef struct ipmgmt_aobjop_rval_s { 301 int32_t ir_err; 302 char ir_aobjname[IPADM_AOBJSIZ]; 303 char ir_ifname[LIFNAMSIZ]; 304 int32_t ir_lnum; 305 sa_family_t ir_family; 306 uint32_t ir_flags; 307 ipadm_addr_type_t ir_atype; 308 ipmgmt_addr_type_cache_u ir_atype_cache; 309 } ipmgmt_aobjop_rval_t; 310 311 #define ipmgmt_ir_intfid ir_atype_cache. \ 312 ipmgmt_ipv6_cache_s.ipmgmt_ifid 313 #define ipmgmt_ir_reqhost ir_atype_cache. \ 314 ipmgmt_dhcp_cache_s.ipmgmt_reqhost 315 316 /* DB walk callback functions */ 317 typedef boolean_t db_wfunc_t(void *, nvlist_t *, char *, size_t, int *); 318 extern int ipadm_rw_db(db_wfunc_t *, void *, const char *, mode_t, 319 ipadm_db_op_t); 320 321 /* zone related functions */ 322 /* 323 * callback function to persist an interface in ipmgmtd data store 324 */ 325 typedef void (*persist_cb_t)(char *, boolean_t, boolean_t); 326 /* 327 * ipmgmtd/libipadm network initialization interface. 328 */ 329 extern ipadm_status_t ipadm_init_net_from_gz(ipadm_handle_t, char *, 330 persist_cb_t); 331 332 #ifdef __cplusplus 333 } 334 #endif 335 336 #endif /* _IPADM_IPMGMT_H */ 337