Print this page
7388 Support DHCP Client FQDN. Allow IAID/DUID for all v4.


   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 /*
  23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.

  25  */
  26 
  27 #include <assert.h>
  28 #include <ctype.h>
  29 #include <libgen.h>
  30 #include <netdb.h>
  31 #include <sys/param.h>
  32 #include <sys/types.h>
  33 #include <sys/stat.h>
  34 #include <sys/socket.h>
  35 #include <netinet/in.h>
  36 #include <arpa/inet.h>
  37 #include <stdio.h>
  38 #include <stdlib.h>
  39 #include <strings.h>
  40 #include <unistd.h>
  41 #include <libdladm.h>

  42 
  43 #include "libnwam_impl.h"
  44 #include <libnwam_priv.h>
  45 #include <libnwam.h>
  46 
  47 /*
  48  * Functions to support creating, modifying, destroying, querying the
  49  * state of and changing the state of NCP (Network Configuration Profiles)
  50  * and the NCUs (Network Configuration Units) that are contained in those
  51  * NCP objects.  An NCP is simply a container for a set of NCUs which represent
  52  * the datalink and interface configuration preferences for the system.
  53  * An NCP can consist a set of prioritized link NCUs, e.g. wired links preferred
  54  * over wireless, a set of manually enabled/diasbled NCUs, or a combination
  55  * of both. Interface NCUs inherit activation from their underlying links,
  56  * so if wired is preferred over wireless and a cable is plugged in,
  57  * the wired link NCU will be active, as will the IP interface NCU above it.
  58  */
  59 
  60 /*
  61  * The NCU property table is used to mapping property types to property name
  62  * strings, their associated value types etc. The table is used for validation
  63  * purposes, and for commit()ing and read()ing NCUs.
  64  */
  65 
  66 static nwam_error_t valid_type(nwam_value_t);
  67 static nwam_error_t valid_class(nwam_value_t);
  68 static nwam_error_t valid_ncp(nwam_value_t);
  69 static nwam_error_t valid_priority_mode(nwam_value_t);
  70 static nwam_error_t valid_ncu_activation_mode(nwam_value_t);
  71 static nwam_error_t valid_link_autopush(nwam_value_t);
  72 static nwam_error_t valid_link_mtu(nwam_value_t);
  73 static nwam_error_t valid_ip_version(nwam_value_t);
  74 static nwam_error_t valid_addrsrc_v4(nwam_value_t);
  75 static nwam_error_t valid_addrsrc_v6(nwam_value_t);

  76 
  77 struct nwam_prop_table_entry ncu_prop_table_entries[] = {
  78         {NWAM_NCU_PROP_TYPE, NWAM_VALUE_TYPE_UINT64, B_FALSE, 1, 1, valid_type,
  79             "specifies the NCU type - valid values are \'datalink\' and \'ip\'",
  80             NWAM_FLAG_NCU_TYPE_ALL, NWAM_FLAG_NCU_CLASS_ALL},
  81         {NWAM_NCU_PROP_CLASS, NWAM_VALUE_TYPE_UINT64, B_FALSE, 1, 1,
  82             valid_class,
  83             "specifies the NCU class - valid values are "
  84             "\'phys\' and \'ip\'",
  85             NWAM_FLAG_NCU_TYPE_ALL, NWAM_FLAG_NCU_CLASS_ALL},
  86         {NWAM_NCU_PROP_PARENT_NCP, NWAM_VALUE_TYPE_STRING, B_FALSE, 1, 1,
  87             valid_ncp,
  88             "specifies the parent NCP name",
  89             NWAM_FLAG_NCU_TYPE_ALL, NWAM_FLAG_NCU_CLASS_ALL},
  90         {NWAM_NCU_PROP_ACTIVATION_MODE, NWAM_VALUE_TYPE_UINT64, B_FALSE, 1, 1,
  91             valid_ncu_activation_mode,
  92             "specifies the NCU activation mode - valid values are:\n"
  93             "\'prioritized\' and \'manual\'",
  94             NWAM_FLAG_NCU_TYPE_LINK, NWAM_FLAG_NCU_CLASS_ALL_LINK},
  95         {NWAM_NCU_PROP_ENABLED, NWAM_VALUE_TYPE_BOOLEAN, B_TRUE, 0, 1,


 132             NWAM_MAX_NUM_VALUES, nwam_valid_host_v4,
 133             "specifies static IPv4 host address(es)",
 134             NWAM_FLAG_NCU_TYPE_INTERFACE, NWAM_FLAG_NCU_CLASS_ALL_INTERFACE},
 135         {NWAM_NCU_PROP_IPV4_DEFAULT_ROUTE, NWAM_VALUE_TYPE_STRING, B_FALSE, 0,
 136             1, nwam_valid_route_v4,
 137             "specifies per-interface default IPv4 route",
 138             NWAM_FLAG_NCU_TYPE_INTERFACE, NWAM_FLAG_NCU_CLASS_ALL_INTERFACE},
 139         {NWAM_NCU_PROP_IPV6_ADDRSRC, NWAM_VALUE_TYPE_UINT64, B_FALSE, 0,
 140             NWAM_MAX_NUM_VALUES, valid_addrsrc_v6,
 141             "specifies IPv6 address source(s) - valid values are:\n"
 142             "\'dhcp\', \'autoconf\' and \'static\'.\n"
 143             "\'dhcp\' and \'autoconf\' are mandatory values.",
 144             NWAM_FLAG_NCU_TYPE_INTERFACE, NWAM_FLAG_NCU_CLASS_ALL_INTERFACE},
 145         {NWAM_NCU_PROP_IPV6_ADDR, NWAM_VALUE_TYPE_STRING, B_FALSE, 0,
 146             NWAM_MAX_NUM_VALUES, nwam_valid_host_v6,
 147             "specifies static IPv6 host address(es)",
 148             NWAM_FLAG_NCU_TYPE_INTERFACE, NWAM_FLAG_NCU_CLASS_ALL_INTERFACE},
 149         {NWAM_NCU_PROP_IPV6_DEFAULT_ROUTE, NWAM_VALUE_TYPE_STRING, B_FALSE, 0,
 150             1, nwam_valid_route_v6,
 151             "specifies per-interface default IPv6 route",
 152             NWAM_FLAG_NCU_TYPE_INTERFACE, NWAM_FLAG_NCU_CLASS_ALL_INTERFACE}









 153 };
 154 
 155 #define NWAM_NUM_NCU_PROPS      (sizeof (ncu_prop_table_entries) / \
 156                                 sizeof (*ncu_prop_table_entries))
 157 
 158 struct nwam_prop_table ncu_prop_table =
 159         { NWAM_NUM_NCU_PROPS, ncu_prop_table_entries };
 160 
 161 nwam_error_t
 162 nwam_ncp_get_name(nwam_ncp_handle_t ncph, char **namep)
 163 {
 164         return (nwam_get_name(ncph, namep));
 165 }
 166 
 167 static nwam_error_t
 168 nwam_ncp_name_to_file(const char *name, char **filename)
 169 {
 170         assert(name != NULL && filename != NULL);
 171 
 172         if ((*filename = malloc(MAXPATHLEN)) == NULL)


1631         for (i = 0; i < numvalues; i++) {
1632                 if (addrsrc[i] != NWAM_ADDRSRC_DHCP &&
1633                     addrsrc[i] != NWAM_ADDRSRC_STATIC &&
1634                     addrsrc[i] != NWAM_ADDRSRC_AUTOCONF)
1635                         return (NWAM_ENTITY_INVALID_VALUE);
1636                 if (addrsrc[i] == NWAM_ADDRSRC_DHCP)
1637                         dhcp_found = B_TRUE;
1638                 if (addrsrc[i] == NWAM_ADDRSRC_AUTOCONF)
1639                         autoconf_found = B_TRUE;
1640         }
1641         /*
1642          * DHCP and AUTOCONF need to be specified as v6 address sources
1643          * since there is no way to switch them off in NWAM at present.
1644          */
1645         if (dhcp_found && autoconf_found)
1646                 return (NWAM_SUCCESS);
1647         else
1648                 return (NWAM_ENTITY_INVALID_VALUE);
1649 }
1650 











1651 /* ARGSUSED0 */
1652 static nwam_error_t
1653 valid_link_mtu(nwam_value_t value)
1654 {
1655         return (NWAM_SUCCESS);
1656 }
1657 
1658 nwam_error_t
1659 nwam_ncu_validate(nwam_ncu_handle_t ncuh, const char **errpropp)
1660 {
1661         return (nwam_validate(ncu_prop_table, ncuh, errpropp));
1662 }
1663 
1664 /*
1665  * Given the ncu type and ncu class, return the list of properties that needs
1666  * to be set. Note this list is a complete property list that includes both
1667  * the required ones and the optional ones. Caller needs to free prop_list.
1668  */
1669 nwam_error_t
1670 nwam_ncu_get_default_proplist(nwam_ncu_type_t type, nwam_ncu_class_t class,




   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 /*
  23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
  26  */
  27 
  28 #include <assert.h>
  29 #include <ctype.h>
  30 #include <libgen.h>
  31 #include <netdb.h>
  32 #include <sys/param.h>
  33 #include <sys/types.h>
  34 #include <sys/stat.h>
  35 #include <sys/socket.h>
  36 #include <netinet/in.h>
  37 #include <arpa/inet.h>
  38 #include <stdio.h>
  39 #include <stdlib.h>
  40 #include <strings.h>
  41 #include <unistd.h>
  42 #include <libdladm.h>
  43 #include <libipadm.h>
  44 
  45 #include "libnwam_impl.h"
  46 #include <libnwam_priv.h>
  47 #include <libnwam.h>
  48 
  49 /*
  50  * Functions to support creating, modifying, destroying, querying the
  51  * state of and changing the state of NCP (Network Configuration Profiles)
  52  * and the NCUs (Network Configuration Units) that are contained in those
  53  * NCP objects.  An NCP is simply a container for a set of NCUs which represent
  54  * the datalink and interface configuration preferences for the system.
  55  * An NCP can consist a set of prioritized link NCUs, e.g. wired links preferred
  56  * over wireless, a set of manually enabled/diasbled NCUs, or a combination
  57  * of both. Interface NCUs inherit activation from their underlying links,
  58  * so if wired is preferred over wireless and a cable is plugged in,
  59  * the wired link NCU will be active, as will the IP interface NCU above it.
  60  */
  61 
  62 /*
  63  * The NCU property table is used to mapping property types to property name
  64  * strings, their associated value types etc. The table is used for validation
  65  * purposes, and for commit()ing and read()ing NCUs.
  66  */
  67 
  68 static nwam_error_t valid_type(nwam_value_t);
  69 static nwam_error_t valid_class(nwam_value_t);
  70 static nwam_error_t valid_ncp(nwam_value_t);
  71 static nwam_error_t valid_priority_mode(nwam_value_t);
  72 static nwam_error_t valid_ncu_activation_mode(nwam_value_t);
  73 static nwam_error_t valid_link_autopush(nwam_value_t);
  74 static nwam_error_t valid_link_mtu(nwam_value_t);
  75 static nwam_error_t valid_ip_version(nwam_value_t);
  76 static nwam_error_t valid_addrsrc_v4(nwam_value_t);
  77 static nwam_error_t valid_addrsrc_v6(nwam_value_t);
  78 static nwam_error_t valid_reqhost(nwam_value_t);
  79 
  80 struct nwam_prop_table_entry ncu_prop_table_entries[] = {
  81         {NWAM_NCU_PROP_TYPE, NWAM_VALUE_TYPE_UINT64, B_FALSE, 1, 1, valid_type,
  82             "specifies the NCU type - valid values are \'datalink\' and \'ip\'",
  83             NWAM_FLAG_NCU_TYPE_ALL, NWAM_FLAG_NCU_CLASS_ALL},
  84         {NWAM_NCU_PROP_CLASS, NWAM_VALUE_TYPE_UINT64, B_FALSE, 1, 1,
  85             valid_class,
  86             "specifies the NCU class - valid values are "
  87             "\'phys\' and \'ip\'",
  88             NWAM_FLAG_NCU_TYPE_ALL, NWAM_FLAG_NCU_CLASS_ALL},
  89         {NWAM_NCU_PROP_PARENT_NCP, NWAM_VALUE_TYPE_STRING, B_FALSE, 1, 1,
  90             valid_ncp,
  91             "specifies the parent NCP name",
  92             NWAM_FLAG_NCU_TYPE_ALL, NWAM_FLAG_NCU_CLASS_ALL},
  93         {NWAM_NCU_PROP_ACTIVATION_MODE, NWAM_VALUE_TYPE_UINT64, B_FALSE, 1, 1,
  94             valid_ncu_activation_mode,
  95             "specifies the NCU activation mode - valid values are:\n"
  96             "\'prioritized\' and \'manual\'",
  97             NWAM_FLAG_NCU_TYPE_LINK, NWAM_FLAG_NCU_CLASS_ALL_LINK},
  98         {NWAM_NCU_PROP_ENABLED, NWAM_VALUE_TYPE_BOOLEAN, B_TRUE, 0, 1,


 135             NWAM_MAX_NUM_VALUES, nwam_valid_host_v4,
 136             "specifies static IPv4 host address(es)",
 137             NWAM_FLAG_NCU_TYPE_INTERFACE, NWAM_FLAG_NCU_CLASS_ALL_INTERFACE},
 138         {NWAM_NCU_PROP_IPV4_DEFAULT_ROUTE, NWAM_VALUE_TYPE_STRING, B_FALSE, 0,
 139             1, nwam_valid_route_v4,
 140             "specifies per-interface default IPv4 route",
 141             NWAM_FLAG_NCU_TYPE_INTERFACE, NWAM_FLAG_NCU_CLASS_ALL_INTERFACE},
 142         {NWAM_NCU_PROP_IPV6_ADDRSRC, NWAM_VALUE_TYPE_UINT64, B_FALSE, 0,
 143             NWAM_MAX_NUM_VALUES, valid_addrsrc_v6,
 144             "specifies IPv6 address source(s) - valid values are:\n"
 145             "\'dhcp\', \'autoconf\' and \'static\'.\n"
 146             "\'dhcp\' and \'autoconf\' are mandatory values.",
 147             NWAM_FLAG_NCU_TYPE_INTERFACE, NWAM_FLAG_NCU_CLASS_ALL_INTERFACE},
 148         {NWAM_NCU_PROP_IPV6_ADDR, NWAM_VALUE_TYPE_STRING, B_FALSE, 0,
 149             NWAM_MAX_NUM_VALUES, nwam_valid_host_v6,
 150             "specifies static IPv6 host address(es)",
 151             NWAM_FLAG_NCU_TYPE_INTERFACE, NWAM_FLAG_NCU_CLASS_ALL_INTERFACE},
 152         {NWAM_NCU_PROP_IPV6_DEFAULT_ROUTE, NWAM_VALUE_TYPE_STRING, B_FALSE, 0,
 153             1, nwam_valid_route_v6,
 154             "specifies per-interface default IPv6 route",
 155             NWAM_FLAG_NCU_TYPE_INTERFACE, NWAM_FLAG_NCU_CLASS_ALL_INTERFACE},
 156         {NWAM_NCU_PROP_IP_PRIMARY, NWAM_VALUE_TYPE_BOOLEAN, B_FALSE, 0,
 157             1, nwam_valid_boolean,
 158             "specifies the status of an interface as primary for the delivery"
 159             " of client-wide configuration data",
 160             NWAM_FLAG_NCU_TYPE_INTERFACE, NWAM_FLAG_NCU_CLASS_ALL_INTERFACE},
 161         {NWAM_NCU_PROP_IP_REQHOST, NWAM_VALUE_TYPE_STRING, B_FALSE, 0,
 162             1, valid_reqhost,
 163             "specifies a requested hostname for the interface",
 164             NWAM_FLAG_NCU_TYPE_INTERFACE, NWAM_FLAG_NCU_CLASS_ALL_INTERFACE},
 165 };
 166 
 167 #define NWAM_NUM_NCU_PROPS      (sizeof (ncu_prop_table_entries) / \
 168                                 sizeof (*ncu_prop_table_entries))
 169 
 170 struct nwam_prop_table ncu_prop_table =
 171         { NWAM_NUM_NCU_PROPS, ncu_prop_table_entries };
 172 
 173 nwam_error_t
 174 nwam_ncp_get_name(nwam_ncp_handle_t ncph, char **namep)
 175 {
 176         return (nwam_get_name(ncph, namep));
 177 }
 178 
 179 static nwam_error_t
 180 nwam_ncp_name_to_file(const char *name, char **filename)
 181 {
 182         assert(name != NULL && filename != NULL);
 183 
 184         if ((*filename = malloc(MAXPATHLEN)) == NULL)


1643         for (i = 0; i < numvalues; i++) {
1644                 if (addrsrc[i] != NWAM_ADDRSRC_DHCP &&
1645                     addrsrc[i] != NWAM_ADDRSRC_STATIC &&
1646                     addrsrc[i] != NWAM_ADDRSRC_AUTOCONF)
1647                         return (NWAM_ENTITY_INVALID_VALUE);
1648                 if (addrsrc[i] == NWAM_ADDRSRC_DHCP)
1649                         dhcp_found = B_TRUE;
1650                 if (addrsrc[i] == NWAM_ADDRSRC_AUTOCONF)
1651                         autoconf_found = B_TRUE;
1652         }
1653         /*
1654          * DHCP and AUTOCONF need to be specified as v6 address sources
1655          * since there is no way to switch them off in NWAM at present.
1656          */
1657         if (dhcp_found && autoconf_found)
1658                 return (NWAM_SUCCESS);
1659         else
1660                 return (NWAM_ENTITY_INVALID_VALUE);
1661 }
1662 
1663 static nwam_error_t
1664 valid_reqhost(nwam_value_t value)
1665 {
1666         char *hostname;
1667 
1668         if (nwam_value_get_string(value, &hostname) != NWAM_SUCCESS)
1669                 return (NWAM_ENTITY_INVALID_VALUE);
1670         return (ipadm_is_valid_hostname(hostname) ? NWAM_SUCCESS
1671             : NWAM_ENTITY_INVALID_VALUE);
1672 }
1673 
1674 /* ARGSUSED0 */
1675 static nwam_error_t
1676 valid_link_mtu(nwam_value_t value)
1677 {
1678         return (NWAM_SUCCESS);
1679 }
1680 
1681 nwam_error_t
1682 nwam_ncu_validate(nwam_ncu_handle_t ncuh, const char **errpropp)
1683 {
1684         return (nwam_validate(ncu_prop_table, ncuh, errpropp));
1685 }
1686 
1687 /*
1688  * Given the ncu type and ncu class, return the list of properties that needs
1689  * to be set. Note this list is a complete property list that includes both
1690  * the required ones and the optional ones. Caller needs to free prop_list.
1691  */
1692 nwam_error_t
1693 nwam_ncu_get_default_proplist(nwam_ncu_type_t type, nwam_ncu_class_t class,