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