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