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 _IPADM_IPMGMT_H 27 #define _IPADM_IPMGMT_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 #include <sys/types.h> 33 #include <sys/stat.h> 34 #include <fcntl.h> 35 #include <sys/mman.h> 36 #include <door.h> 37 #include <libipadm.h> 38 #include <inet/tunables.h> 39 40 /* 41 * Function declarations and data structures shared by libipadm.so and 42 * the IP management daemon. 43 */ 44 45 /* Authorization required to configure network interfaces */ 46 #define NETWORK_INTERFACE_CONFIG_AUTH "solaris.network.interface.config" 47 48 /* 49 * Data store read/write utilities related declarations. 50 */ 51 /* Permanent data store for ipadm */ 52 #define IPADM_DB_FILE "/etc/ipadm/ipadm.conf" 53 #define IPADM_FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) 54 #define IPADM_TMPFS_DIR "/etc/svc/volatile/ipadm" 55 56 /* 57 * For more information on these definitions please refer to the top of 58 * ipadm_persist.c. These are the name of the nvpairs which hold the 59 * respective values. All nvpairs private to ipadm have names that begin 60 * with "_". Note below that 'prefixlen' is an address property and therefore 61 * not a private nvpair name. 62 */ 63 #define IPADM_NVP_PROTONAME "_protocol" /* protocol name */ 64 #define IPADM_NVP_IFNAME "_ifname" /* interface name */ 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_IPV6ADDR "_ipv6addr" /* name of IPv6 addr nvlist */ 73 #define IPADM_NVP_DHCP "_dhcp" /* name of DHCP nvlist */ 74 #define IPADM_NVP_WAIT "_wait" /* DHCP timeout value */ 75 #define IPADM_NVP_PRIMARY "_primary" /* DHCP primary interface */ 76 #define IPADM_NVP_LIFNUM "_lifnum" /* logical interface number */ 77 #define IPADM_NVP_INTFID "_intfid" /* name of IPv6 intfid nvlist */ 78 #define IPADM_NVP_STATELESS "_stateless" /* IPv6 autoconf stateless */ 79 #define IPADM_NVP_STATEFUL "_stateful" /* IPv6 autoconf dhcpv6 */ 80 81 #define IPADM_PRIV_NVP(s) ((s)[0] == '_') 82 83 /* data-store operations */ 84 typedef enum { 85 IPADM_DB_WRITE = 0, /* Writes to DB */ 86 IPADM_DB_DELETE, /* Deletes an entry from DB */ 87 IPADM_DB_READ /* Read from DB */ 88 } ipadm_db_op_t; 89 90 /* 91 * callback arg used by db_wfunc_t that writes to DB. The contents to be 92 * written to DB are captured in `dbw_nvl'. 93 */ 94 typedef struct ipadm_dbwrite_cbarg_s { 95 nvlist_t *dbw_nvl; 96 uint_t dbw_flags; 97 } ipadm_dbwrite_cbarg_t; 98 99 /* 100 * door related function declarations and data structures. 101 */ 102 103 /* The door file for the ipmgmt (ip-interface management) daemon */ 104 #define IPMGMT_DOOR "/etc/svc/volatile/ipadm/ipmgmt_door" 105 #define MAXPROTONAMELEN 32 106 107 /* door call command type */ 108 typedef enum { 109 IPMGMT_CMD_SETPROP = 1, /* persist property */ 110 IPMGMT_CMD_SETIF, /* persist interface */ 111 IPMGMT_CMD_SETADDR, /* persist address */ 112 IPMGMT_CMD_GETPROP, /* retrieve persisted property value */ 113 IPMGMT_CMD_GETIF, /* retrieve persisted interface conf. */ 114 IPMGMT_CMD_GETADDR, /* retrieve persisted addresses */ 115 IPMGMT_CMD_RESETIF, /* purge interface configuration */ 116 IPMGMT_CMD_RESETADDR, /* purge address configuration */ 117 IPMGMT_CMD_RESETPROP, /* purge property configuration */ 118 IPMGMT_CMD_INITIF, /* retrieve interfaces to initialize */ 119 IPMGMT_CMD_ADDROBJ_LOOKUPADD, /* addr. object lookup & add */ 120 IPMGMT_CMD_ADDROBJ_ADD, /* add addr. object to addrobj map */ 121 IPMGMT_CMD_LIF2ADDROBJ, /* lifname to addrobj mapping */ 122 IPMGMT_CMD_AOBJNAME2ADDROBJ /* aobjname to addrobj mapping */ 123 } ipmgmt_door_cmd_type_t; 124 125 /* 126 * Note: We need to keep the size of the structure the same on amd64 and i386 127 * for all door_call arguments and door_return structures. 128 */ 129 /* door_call argument */ 130 typedef struct ipmgmt_arg { 131 ipmgmt_door_cmd_type_t ia_cmd; 132 } ipmgmt_arg_t; 133 134 /* IPMGMT_CMD_{SETPROP|GETPROP|RESETPROP} door_call argument */ 135 typedef struct ipmgmt_prop_arg_s { 136 ipmgmt_door_cmd_type_t ia_cmd; 137 uint32_t ia_flags; 138 char ia_ifname[LIFNAMSIZ]; 139 char ia_aobjname[IPADM_AOBJSIZ]; 140 char ia_module[MAXPROTONAMELEN]; 141 char ia_pname[MAXPROPNAMELEN]; 142 char ia_pval[MAXPROPVALLEN]; 143 } ipmgmt_prop_arg_t; 144 /* 145 * ia_flags used in ipmgmt_prop_arg_t. 146 * - APPEND updates the multi-valued property entry with a new value 147 * - REDUCE updates the multi-valued property entry by removing a value 148 */ 149 #define IPMGMT_APPEND 0x00000001 150 #define IPMGMT_REMOVE 0x00000002 151 152 /* IPMGMT_CMD_GETIF door_call argument structure */ 153 typedef struct ipmgmt_getif_arg_s { 154 ipmgmt_door_cmd_type_t ia_cmd; 155 uint32_t ia_flags; 156 char ia_ifname[LIFNAMSIZ]; 157 } ipmgmt_getif_arg_t; 158 159 /* IPMGMT_CMD_RESETIF, IPMGMT_CMD_SETIF door_call argument structure */ 160 typedef struct ipmgmt_if_arg_s { 161 ipmgmt_door_cmd_type_t ia_cmd; 162 uint32_t ia_flags; 163 char ia_ifname[LIFNAMSIZ]; 164 sa_family_t ia_family; 165 } ipmgmt_if_arg_t; 166 167 /* IPMGMT_CMD_INITIF door_call argument structure */ 168 typedef struct ipmgmt_initif_arg_s { 169 ipmgmt_door_cmd_type_t ia_cmd; 170 uint32_t ia_flags; 171 sa_family_t ia_family; 172 size_t ia_nvlsize; 173 /* packed nvl follows */ 174 } ipmgmt_initif_arg_t; 175 176 /* IPMGMT_CMD_SETADDR door_call argument */ 177 typedef struct ipmgmt_setaddr_arg_s { 178 ipmgmt_door_cmd_type_t ia_cmd; 179 uint32_t ia_flags; 180 size_t ia_nvlsize; 181 /* packed nvl follows */ 182 } ipmgmt_setaddr_arg_t; 183 184 /* IPMGMT_CMD_GETADDR door_call argument */ 185 typedef struct ipmgmt_getaddr_arg_s { 186 ipmgmt_door_cmd_type_t ia_cmd; 187 uint32_t ia_flags; 188 char ia_ifname[LIFNAMSIZ]; 189 sa_family_t ia_family; 190 char ia_aobjname[IPADM_AOBJSIZ]; 191 } ipmgmt_getaddr_arg_t; 192 193 /* IPMGMT_CMD_RESETADDR door_call argument */ 194 typedef struct ipmgmt_addr_arg_s { 195 ipmgmt_door_cmd_type_t ia_cmd; 196 uint32_t ia_flags; 197 char ia_aobjname[IPADM_AOBJSIZ]; 198 int32_t ia_lnum; 199 } ipmgmt_addr_arg_t; 200 201 /* 202 * IPMGMT_CMD_{ADDROBJ_ADD|ADDROBJ_LOOKUPADD|LIFNUM2ADDROBJ| 203 * ADDROBJ2LIFNUM} door_call argument. 204 */ 205 typedef struct ipmgmt_aobjop_arg_s { 206 ipmgmt_door_cmd_type_t ia_cmd; 207 uint32_t ia_flags; 208 char ia_aobjname[IPADM_AOBJSIZ]; 209 char ia_ifname[LIFNAMSIZ]; 210 int32_t ia_lnum; 211 sa_family_t ia_family; 212 ipadm_addr_type_t ia_atype; 213 } ipmgmt_aobjop_arg_t; 214 215 /* 216 * ia_flags used inside the arguments for interface/address commands 217 * - ACTIVE updates the running configuration 218 * - PERSIST updates the permanent data store 219 * - INIT indicates that operation being performed is under init 220 * context 221 */ 222 #define IPMGMT_ACTIVE 0x00000001 223 #define IPMGMT_PERSIST 0x00000002 224 #define IPMGMT_INIT 0x00000004 225 226 /* door call return value */ 227 typedef struct ipmgmt_retval_s { 228 int32_t ir_err; 229 } ipmgmt_retval_t; 230 231 /* IPMGMT_CMD_GETADDR door_return value */ 232 typedef struct ipmgmt_get_rval_s { 233 int32_t ir_err; 234 size_t ir_nvlsize; 235 /* packed nvl follows */ 236 } ipmgmt_get_rval_t; 237 238 /* IPMGMT_CMD_GETPROP door_return value */ 239 typedef struct ipmgmt_getprop_rval_s { 240 int32_t ir_err; 241 char ir_pval[MAXPROPVALLEN]; 242 } ipmgmt_getprop_rval_t; 243 244 /* IPMGMT_CMD_GETIF door_return value */ 245 typedef struct ipmgmt_getif_rval_s { 246 int32_t ir_err; 247 uint32_t ir_ifcnt; 248 ipadm_if_info_t ir_ifinfo[1]; 249 } ipmgmt_getif_rval_t; 250 251 /* IPMGMT_CMD_{LOOKUPADD|LIFNUM2ADDROBJ|ADDROBJ2LIFNUM} door_return value */ 252 typedef struct ipmgmt_aobjop_rval_s { 253 int32_t ir_err; 254 char ir_aobjname[IPADM_AOBJSIZ]; 255 char ir_ifname[LIFNAMSIZ]; 256 int32_t ir_lnum; 257 sa_family_t ir_family; 258 uint32_t ir_flags; 259 ipadm_addr_type_t ir_atype; 260 struct sockaddr_storage ir_ifid; 261 } ipmgmt_aobjop_rval_t; 262 263 /* DB walk callback functions */ 264 typedef boolean_t db_wfunc_t(void *, nvlist_t *, char *, size_t, int *); 265 extern int ipadm_rw_db(db_wfunc_t *, void *, const char *, mode_t, 266 ipadm_db_op_t); 267 268 #ifdef __cplusplus 269 } 270 #endif 271 272 #endif /* _IPADM_IPMGMT_H */ 273