Print this page
    
OS-161: Integrate IPMP changes
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/lib/libipadm/common/libipadm.h
          +++ new/usr/src/lib/libipadm/common/libipadm.h
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  11   11   * and limitations under the License.
  12   12   *
  
    | 
      ↓ open down ↓ | 
    12 lines elided | 
    
      ↑ open up ↑ | 
  
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
       23 + * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
  23   24   * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
  24   25   */
  25   26  #ifndef _LIBIPADM_H
  26   27  #define _LIBIPADM_H
  27   28  
  28   29  #ifdef  __cplusplus
  29   30  extern "C" {
  30   31  #endif
  31   32  
  32   33  #include <sys/types.h>
  33   34  #include <sys/param.h>
  34   35  #include <sys/socket.h>
  35   36  #include <net/if.h>
  36   37  #include <netdb.h>
  37   38  #include <ifaddrs.h>
  38   39  #include <libnvpair.h>
  39   40  #include <netinet/tcp.h>
  40   41  #include <sys/stropts.h>
       42 +#include <sys/list.h>
       43 +#include <stddef.h>
  41   44  
  42   45  #define IPADM_AOBJ_USTRSIZ      32
  43   46  #define IPADM_AOBJSIZ           (LIFNAMSIZ + IPADM_AOBJ_USTRSIZ)
  44   47  #define MAXPROPVALLEN           512
  45   48  #define LOOPBACK_IF             "lo0"
  46   49  
  47   50  /* special timeout values for dhcp operations */
  48   51  #define IPADM_DHCP_WAIT_DEFAULT (-1)
  49   52  #define IPADM_DHCP_WAIT_FOREVER (-2)
  50   53  
  51   54  /*
  52   55   * Specifies that the string passed to ipadm_str2nvlist() is a string of comma
  53   56   * separated names and that each name does not have values associated with it.
  54   57   */
  55   58  #define IPADM_NORVAL            0x00000001
  56   59  
  57   60  /* error codes */
  58   61  typedef enum {
  59   62          IPADM_SUCCESS,          /* No error occurred */
  60   63          IPADM_FAILURE,          /* Generic failure */
  61   64          IPADM_EAUTH,            /* Insufficient user authorizations */
  62   65          IPADM_EPERM,            /* Permission denied */
  63   66          IPADM_NO_BUFS,          /* No Buffer space available */
  64   67          IPADM_NO_MEMORY,        /* Insufficient memory */
  65   68          IPADM_BAD_ADDR,         /* Invalid address */
  66   69          IPADM_BAD_PROTOCOL,     /* Wrong protocol family for operation */
  67   70          IPADM_DAD_FOUND,        /* Duplicate address detected */
  68   71          IPADM_EXISTS,           /* Already exists */
  69   72          IPADM_IF_EXISTS,        /* Interface already exists */
  70   73          IPADM_ADDROBJ_EXISTS,   /* Address object already exists */
  71   74          IPADM_ADDRCONF_EXISTS,  /* Addrconf already in progress */
  72   75          IPADM_ENXIO,            /* Interface does not exist */
  73   76          IPADM_GRP_NOTEMPTY,     /* IPMP Group non-empty on unplumb */
  74   77          IPADM_INVALID_ARG,      /* Invalid argument */
  75   78          IPADM_INVALID_NAME,     /* Invalid name */
  76   79          IPADM_DLPI_FAILURE,     /* Could not open DLPI link */
  77   80          IPADM_DLADM_FAILURE,    /* DLADM error encountered */
  78   81          IPADM_PROP_UNKNOWN,     /* Unknown property */
  79   82          IPADM_ERANGE,           /* Value is outside the allowed range */
  80   83          IPADM_ESRCH,            /* Value does not exist */
  81   84          IPADM_EOVERFLOW,        /* Number of values exceed the allowed limit */
  82   85          IPADM_NOTFOUND,         /* Object not found */
  83   86          IPADM_IF_INUSE,         /* Interface already in use */
  84   87          IPADM_ADDR_INUSE,       /* Address alrelady in use */
  85   88          IPADM_BAD_HOSTNAME,     /* hostname maps to multiple IP addresses */
  86   89          IPADM_ADDR_NOTAVAIL,    /* Can't assign requested address */
  87   90          IPADM_ALL_ADDRS_NOT_ENABLED, /* All addresses could not be enabled */
  88   91          IPADM_NDPD_NOT_RUNNING, /* in.ndpd not running */
  89   92          IPADM_DHCP_START_ERROR, /* Cannot start dhcpagent */
  90   93          IPADM_DHCP_IPC_ERROR,   /* Cannot communicate with dhcpagent */
  91   94          IPADM_DHCP_IPC_TIMEOUT, /* Communication with dhcpagent timed out */
  92   95          IPADM_TEMPORARY_OBJ,    /* Permanent operation on temporary object */
  93   96          IPADM_IPC_ERROR,        /* Cannot communicate with ipmgmtd */
  94   97          IPADM_OP_DISABLE_OBJ,   /* Operation on disable object */
  95   98          IPADM_NOTSUP,           /* Operation not supported */
  96   99          IPADM_EBADE,            /* Invalid data exchange with ipmgmtd */
  97  100          IPADM_GZ_PERM           /* Operation not permitted on from-gz intf */
  98  101  } ipadm_status_t;
  99  102  
 100  103  /*
 101  104   * option flags taken by the libipadm functions
 102  105   *
 103  106   *  - IPADM_OPT_PERSIST:
 104  107   *      For all the create/delete/up/down/set/get functions,
 105  108   *      requests to persist the configuration so that it can be
 106  109   *      re-enabled or re-applied on boot.
 107  110   *
 108  111   *  - IPADM_OPT_ACTIVE:
 109  112   *      Requests to apply configuration without persisting it and
 110  113   *      used by show-* subcommands to retrieve current values.
 111  114   *
 112  115   *  - IPADM_OPT_DEFAULT:
 113  116   *      retrieves the default value for a given property
 114  117   *
 115  118   *  - IPADM_OPT_PERM
 116  119   *      retrieves the permission for a given property
 117  120   *
 118  121   *  - IPADM_OPT_POSSIBLE
 119  122   *      retrieves the range of values for a given property
 120  123   *
 121  124   *  - IPADM_OPT_APPEND
 122  125   *      for multi-valued properties, appends a new value.
 123  126   *
 124  127   *  - IPADM_OPT_REMOVE
 125  128   *      for multi-valued properties, removes the specified value
 126  129   *
 127  130   *  - IPADM_OPT_IPMP
 128  131   *      Used in ipadm_create_if() to plumb ipmp interfaces.
 129  132   *
 130  133   *  - IPADM_OPT_GENPPA
 131  134   *      Used in ipadm_create_if() to generate a ppa for the given interface.
 132  135   *
 133  136   *  - IPADM_OPT_ZEROADDR
 134  137   *      return :: or INADDR_ANY
 135  138   *
 136  139   *  - IPADM_OPT_RELEASE
 137  140   *      Used to release the lease on a dhcp address object
 138  141   *
 139  142   *  - IPADM_OPT_INFORM
 140  143   *      Used to perform DHCP_INFORM on a specified static address object
 141  144   *
 142  145   *  - IPADM_OPT_UP
 143  146   *      Used to bring up a static address on creation
 144  147   *
 145  148   *  - IPADM_OPT_V46
 146  149   *      Used to plumb both IPv4 and IPv6 interfaces by ipadm_create_addr()
 147  150   *
 148  151   *  - IPADM_OPT_SET_PROPS
 149  152   *      Used to indicate the update changes the running configuration of
 150  153   *      "props" data on the object. The props are cached there on the parent,
 151  154   *      but the PROPS_ONLY change does not affect the ACTIVE/PERSIST state of
 152  155   *      the parent.
 153  156   *
 154  157   *  - IPADM_OPT_PERSIST_PROPS
 155  158   *      Used when IPADM_OPT_SET_PROPS is active to indicate the update changes
 156  159   *  the persistent configuration of the "props" data on the object.
 157  160   */
 158  161  #define IPADM_OPT_PERSIST       0x00000001
 159  162  #define IPADM_OPT_ACTIVE        0x00000002
 160  163  #define IPADM_OPT_DEFAULT       0x00000004
 161  164  #define IPADM_OPT_PERM          0x00000008
 162  165  #define IPADM_OPT_POSSIBLE      0x00000010
 163  166  #define IPADM_OPT_APPEND        0x00000020
 164  167  #define IPADM_OPT_REMOVE        0x00000040
 165  168  #define IPADM_OPT_IPMP          0x00000080
 166  169  #define IPADM_OPT_GENPPA        0x00000100
 167  170  #define IPADM_OPT_ZEROADDR      0x00000200
 168  171  #define IPADM_OPT_RELEASE       0x00000400
 169  172  #define IPADM_OPT_INFORM        0x00000800
 170  173  #define IPADM_OPT_UP            0x00001000
 171  174  #define IPADM_OPT_V46           0x00002000
 172  175  #define IPADM_OPT_SET_PROPS     0x00004000
 173  176  #define IPADM_OPT_PERSIST_PROPS         0x00008000
 174  177  
 175  178  /* IPADM property class */
 176  179  #define IPADMPROP_CLASS_MODULE  0x00000001      /* on 'protocol' only */
 177  180  #define IPADMPROP_CLASS_IF      0x00000002      /* on 'IP interface' only */
 178  181  #define IPADMPROP_CLASS_ADDR    0x00000004      /* on 'IP address' only */
 179  182  /* protocol property that can be applied on interface too */
 180  183  #define IPADMPROP_CLASS_MODIF   (IPADMPROP_CLASS_MODULE | IPADMPROP_CLASS_IF)
 181  184  
 182  185  /* opaque ipadm handle to libipadm functions */
 183  186  struct ipadm_handle;
 184  187  typedef struct ipadm_handle     *ipadm_handle_t;
 185  188  
 186  189  /* ipadm_handle flags */
 187  190  #define IPH_VRRP                0x00000001      /* Caller is VRRP */
 188  191  #define IPH_LEGACY              0x00000002      /* Caller is legacy app */
 189  192  #define IPH_IPMGMTD             0x00000004      /* Caller is ipmgmtd itself */
 190  193  /*
 191  194   * Indicates that the operation being invoked is in 'init' context. This is
 192  195   * a library private flag.
 193  196   */
 194  197  #define IPH_INIT                0x10000000
 195  198  
 196  199  /* opaque address object structure */
 197  200  typedef struct ipadm_addrobj_s  *ipadm_addrobj_t;
  
    | 
      ↓ open down ↓ | 
    147 lines elided | 
    
      ↑ open up ↑ | 
  
 198  201  
 199  202  /* ipadm_if_info_t states */
 200  203  typedef enum {
 201  204          IFIS_OK,                /* Interface is usable */
 202  205          IFIS_DOWN,              /* Interface has no UP addresses */
 203  206          IFIS_FAILED,            /* Interface has failed. */
 204  207          IFIS_OFFLINE,           /* Interface has been offlined */
 205  208          IFIS_DISABLED           /* Interface has been disabled. */
 206  209  } ipadm_if_state_t;
 207  210  
      211 +typedef list_t ipadm_ipmp_members_t;
      212 +
      213 +typedef struct {
      214 +    list_node_t node;
      215 +    char if_name[LIFNAMSIZ];
      216 +} ipadm_ipmp_member_t;
      217 +
      218 +typedef enum {
      219 +    IPADM_IF_CLASS_REGULAR,
      220 +    IPADM_IF_CLASS_IPMP,
      221 +    IPADM_IF_CLASS_VIRTUAL,
      222 +    IPADM_IF_CLASS_UNKNOWN
      223 +} ipadm_if_class_t;
      224 +
 208  225  typedef struct ipadm_if_info_s {
 209  226          struct ipadm_if_info_s  *ifi_next;
 210  227          char                    ifi_name[LIFNAMSIZ];    /* interface name */
      228 +        ipadm_if_class_t        ifi_class;              /* interface class */
 211  229          ipadm_if_state_t        ifi_state;              /* see above */
 212  230          uint_t                  ifi_cflags;             /* current flags */
 213  231          uint_t                  ifi_pflags;             /* persistent flags */
      232 +        ipadm_ipmp_members_t    ifi_ipmp_cmembers; /* current IPMP members */
      233 +        ipadm_ipmp_members_t    ifi_ipmp_pmembers; /* persistent IPMP members */
 214  234  } ipadm_if_info_t;
 215  235  
 216  236  /* ipadm_if_info_t flags */
 217  237  #define IFIF_BROADCAST          0x00000001
 218  238  #define IFIF_MULTICAST          0x00000002
 219  239  #define IFIF_POINTOPOINT        0x00000004
 220  240  #define IFIF_VIRTUAL            0x00000008
 221  241  #define IFIF_IPMP               0x00000010
 222  242  #define IFIF_STANDBY            0x00000020
 223  243  #define IFIF_INACTIVE           0x00000040
 224  244  #define IFIF_VRRP               0x00000080
 225  245  #define IFIF_NOACCEPT           0x00000100
 226  246  #define IFIF_IPV4               0x00000200
 227  247  #define IFIF_IPV6               0x00000400
 228  248  #define IFIF_L3PROTECT          0x00000800
 229  249  
 230  250  /* ipadm_addr_info_t state */
 231  251  typedef enum {
 232  252          IFA_DISABLED,           /* Address not in active configuration. */
 233  253          IFA_DUPLICATE,          /* DAD failed. */
 234  254          IFA_DOWN,               /* Address is not IFF_UP */
 235  255          IFA_TENTATIVE,          /* DAD verification initiated */
 236  256          IFA_OK,                 /* Address is usable */
 237  257          IFA_INACCESSIBLE        /* Interface has failed */
 238  258  } ipadm_addr_state_t;
 239  259  
 240  260  /* possible address types */
 241  261  typedef enum  {
 242  262          IPADM_ADDR_NONE,
 243  263          IPADM_ADDR_STATIC,
 244  264          IPADM_ADDR_IPV6_ADDRCONF,
 245  265          IPADM_ADDR_DHCP
 246  266  } ipadm_addr_type_t;
 247  267  
 248  268  typedef struct ipadm_addr_info_s {
 249  269          struct ifaddrs          ia_ifa;         /* list of addresses */
 250  270          char                    ia_sname[NI_MAXHOST];   /* local hostname */
 251  271          char                    ia_dname[NI_MAXHOST];   /* remote hostname */
 252  272          char                    ia_aobjname[IPADM_AOBJSIZ];
 253  273          uint_t                  ia_cflags;      /* active flags */
 254  274          uint_t                  ia_pflags;      /* persistent flags */
 255  275          ipadm_addr_type_t       ia_atype;       /* see above */
 256  276          ipadm_addr_state_t      ia_state;       /* see above */
 257  277  } ipadm_addr_info_t;
 258  278  #define IA_NEXT(ia)             ((ipadm_addr_info_t *)(ia->ia_ifa.ifa_next))
 259  279  
 260  280  /* ipadm_addr_info_t flags */
 261  281  #define IA_UP                   0x00000001
 262  282  #define IA_UNNUMBERED           0x00000002
 263  283  #define IA_PRIVATE              0x00000004
 264  284  #define IA_TEMPORARY            0x00000008
 265  285  #define IA_DEPRECATED           0x00000010
 266  286  
 267  287  /* open/close libipadm handle */
 268  288  extern ipadm_status_t   ipadm_open(ipadm_handle_t *, uint32_t);
 269  289  extern void             ipadm_close(ipadm_handle_t);
 270  290  
 271  291  /* Check authorization for network configuration */
 272  292  extern boolean_t        ipadm_check_auth(void);
 273  293  /*
 274  294   * Interface management functions
 275  295   */
 276  296  extern ipadm_status_t   ipadm_create_if(ipadm_handle_t, char *, sa_family_t,
  
    | 
      ↓ open down ↓ | 
    53 lines elided | 
    
      ↑ open up ↑ | 
  
 277  297                              uint32_t);
 278  298  extern ipadm_status_t   ipadm_disable_if(ipadm_handle_t, const char *,
 279  299                              uint32_t);
 280  300  extern ipadm_status_t   ipadm_enable_if(ipadm_handle_t, const char *, uint32_t);
 281  301  extern ipadm_status_t   ipadm_if_info(ipadm_handle_t, const char *,
 282  302                              ipadm_if_info_t **, uint32_t, int64_t);
 283  303  extern void             ipadm_free_if_info(ipadm_if_info_t *);
 284  304  extern ipadm_status_t   ipadm_delete_if(ipadm_handle_t, const char *,
 285  305                              sa_family_t, uint32_t);
 286  306  extern void             ipadm_if_move(ipadm_handle_t, const char *);
      307 +extern ipadm_status_t ipadm_add_ipmp_member(ipadm_handle_t, const char *,
      308 +            const char *, uint32_t);
      309 +extern ipadm_status_t ipadm_remove_ipmp_member(ipadm_handle_t, const char *,
      310 +            const char *, uint32_t);
 287  311  
 288  312  /*
 289  313   * Address management functions
 290  314   */
 291  315  extern ipadm_status_t   ipadm_create_addr(ipadm_handle_t, ipadm_addrobj_t,
 292  316                              uint32_t);
 293  317  extern ipadm_status_t   ipadm_disable_addr(ipadm_handle_t, const char *,
 294  318                              uint32_t);
 295  319  extern ipadm_status_t   ipadm_enable_addr(ipadm_handle_t, const char *,
 296  320                              uint32_t);
 297  321  extern ipadm_status_t   ipadm_addr_info(ipadm_handle_t, const char *,
 298  322                              ipadm_addr_info_t **, uint32_t, int64_t);
 299  323  extern void             ipadm_free_addr_info(ipadm_addr_info_t *);
 300  324  extern ipadm_status_t   ipadm_up_addr(ipadm_handle_t, const char *,
 301  325                              uint32_t);
 302  326  extern ipadm_status_t   ipadm_down_addr(ipadm_handle_t, const char *,
 303  327                              uint32_t);
 304  328  extern ipadm_status_t   ipadm_refresh_addr(ipadm_handle_t, const char *,
 305  329                              uint32_t);
 306  330  extern ipadm_status_t   ipadm_delete_addr(ipadm_handle_t, const char *,
 307  331                              uint32_t);
 308  332  
 309  333  /* Functions related to creating/deleting/modifying opaque address object */
 310  334  extern ipadm_status_t   ipadm_create_addrobj(ipadm_addr_type_t, const char *,
 311  335                              ipadm_addrobj_t *);
 312  336  extern void             ipadm_destroy_addrobj(ipadm_addrobj_t);
 313  337  extern ipadm_status_t   ipadm_get_aobjname(const ipadm_addrobj_t, char *,
 314  338                              size_t);
 315  339  
 316  340  /* Functions to set fields in addrobj for static addresses */
 317  341  extern ipadm_status_t   ipadm_set_addr(ipadm_addrobj_t, const char *,
 318  342                              sa_family_t);
 319  343  extern ipadm_status_t   ipadm_set_dst_addr(ipadm_addrobj_t, const char *,
 320  344                              sa_family_t);
 321  345  extern ipadm_status_t   ipadm_get_addr(const ipadm_addrobj_t,
 322  346                              struct sockaddr_storage *);
 323  347  
 324  348  /* Functions to set fields in addrobj for IPv6 addrconf */
 325  349  extern ipadm_status_t   ipadm_set_interface_id(ipadm_addrobj_t, const char *);
 326  350  extern ipadm_status_t   ipadm_set_stateless(ipadm_addrobj_t, boolean_t);
 327  351  extern ipadm_status_t   ipadm_set_stateful(ipadm_addrobj_t, boolean_t);
 328  352  
 329  353  /* Functions to set fields in addrobj for DHCP */
 330  354  extern ipadm_status_t   ipadm_set_primary(ipadm_addrobj_t, boolean_t);
 331  355  extern ipadm_status_t   ipadm_set_wait_time(ipadm_addrobj_t, int32_t);
 332  356  extern ipadm_status_t   ipadm_set_reqhost(ipadm_addrobj_t, const char *);
 333  357  
 334  358  /*
 335  359   * Property management functions
 336  360   */
 337  361  /* call back function for the property walker */
 338  362  typedef boolean_t       ipadm_prop_wfunc_t(void *, const char *, uint_t);
 339  363  extern ipadm_status_t   ipadm_walk_proptbl(uint_t, uint_t, ipadm_prop_wfunc_t *,
 340  364                              void *);
 341  365  extern ipadm_status_t   ipadm_walk_prop(const char *, uint_t, uint_t,
 342  366                              ipadm_prop_wfunc_t *, void *);
 343  367  
 344  368  /* Interface property management - set, reset and get */
 345  369  extern ipadm_status_t   ipadm_set_ifprop(ipadm_handle_t, const char *,
 346  370                              const char *, const char *, uint_t, uint_t);
 347  371  extern ipadm_status_t   ipadm_get_ifprop(ipadm_handle_t, const char *,
 348  372                              const char *, char *, uint_t *, uint_t, uint_t);
 349  373  
 350  374  /* Address property management - set, reset and get */
 351  375  extern ipadm_status_t   ipadm_set_addrprop(ipadm_handle_t, const char *,
 352  376                              const char *, const char *, uint_t);
 353  377  extern ipadm_status_t   ipadm_get_addrprop(ipadm_handle_t, const char *, char *,
 354  378                              uint_t *, const char *, uint_t);
 355  379  
 356  380  /* Protoocl property management - set, reset and get */
 357  381  extern ipadm_status_t   ipadm_set_prop(ipadm_handle_t, const char *,
 358  382                              const char *, uint_t, uint_t);
 359  383  extern ipadm_status_t   ipadm_get_prop(ipadm_handle_t, const char *, char *,
 360  384                              uint_t *, uint_t, uint_t);
 361  385  
 362  386  /*
 363  387   * miscellaneous helper functions.
 364  388   */
 365  389  extern const char       *ipadm_status2str(ipadm_status_t);
 366  390  extern int              ipadm_str2nvlist(const char *, nvlist_t **, uint_t);
 367  391  extern size_t           ipadm_nvlist2str(nvlist_t *, char *, size_t);
 368  392  extern char             *ipadm_proto2str(uint_t);
 369  393  extern uint_t           ipadm_str2proto(const char *);
 370  394  extern ipadm_status_t   ipadm_open_arp_on_udp(const char *, int *);
 371  395  extern int              ipadm_legacy2new_propname(const char *, char *,
 372  396                              uint_t, uint_t *);
 373  397  extern int              ipadm_new2legacy_propname(const char *, char *,
 374  398                              uint_t, uint_t);
 375  399  extern boolean_t        ipadm_is_valid_hostname(const char *hostname);
 376  400  extern boolean_t        ipadm_is_nil_hostname(const char *hostname);
 377  401  
 378  402  #ifdef  __cplusplus
 379  403  }
 380  404  #endif
 381  405  
 382  406  #endif  /* _LIBIPADM_H */
  
    | 
      ↓ open down ↓ | 
    86 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX