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


   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 /*
  23  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.

  24  */
  25 
  26 /*
  27  * nwamcfg is a lex/yacc based command interpreter used to manage network
  28  * configurations.  The lexer (see nwamcfg_lex.l) builds up tokens, which
  29  * the grammar (see nwamcfg_grammar.y) builds up into commands, some of
  30  * which takes resources and/or properties as arguments.
  31  */
  32 
  33 #include <arpa/inet.h>
  34 #include <assert.h>
  35 #include <ctype.h>
  36 #include <errno.h>
  37 #include <libnwam.h>
  38 #include <libtecla.h>
  39 #include <locale.h>
  40 #include <stdarg.h>
  41 #include <stdio.h>
  42 #include <string.h>
  43 #include <sys/stat.h>


 181         NWAM_LOC_PROP_DNS_NAMESERVICE_CONFIGSRC,
 182         NWAM_LOC_PROP_DNS_NAMESERVICE_DOMAIN,
 183         NWAM_LOC_PROP_DNS_NAMESERVICE_SERVERS,
 184         NWAM_LOC_PROP_DNS_NAMESERVICE_SEARCH,
 185         NWAM_LOC_PROP_NIS_NAMESERVICE_CONFIGSRC,
 186         NWAM_LOC_PROP_NIS_NAMESERVICE_SERVERS,
 187         NWAM_LOC_PROP_LDAP_NAMESERVICE_CONFIGSRC,
 188         NWAM_LOC_PROP_LDAP_NAMESERVICE_SERVERS,
 189         NWAM_LOC_PROP_DEFAULT_DOMAIN,
 190         NWAM_LOC_PROP_NFSV4_DOMAIN,
 191         NWAM_LOC_PROP_IPFILTER_CONFIG_FILE,
 192         NWAM_LOC_PROP_IPFILTER_V6_CONFIG_FILE,
 193         NWAM_LOC_PROP_IPNAT_CONFIG_FILE,
 194         NWAM_LOC_PROP_IPPOOL_CONFIG_FILE,
 195         NWAM_LOC_PROP_IKE_CONFIG_FILE,
 196         NWAM_LOC_PROP_IPSECPOLICY_CONFIG_FILE,
 197         NWAM_KNOWN_WLAN_PROP_BSSIDS,
 198         NWAM_KNOWN_WLAN_PROP_PRIORITY,
 199         NWAM_KNOWN_WLAN_PROP_KEYNAME,
 200         NWAM_KNOWN_WLAN_PROP_KEYSLOT,
 201         NWAM_KNOWN_WLAN_PROP_SECURITY_MODE


 202 };
 203 
 204 /* properties table: maps PT_* constants to property names */
 205 typedef struct prop_table_entry {
 206         int                     pte_type;
 207         const char              *pte_name;
 208 } prop_table_entry_t;
 209 
 210 /* NCU properties table */
 211 static prop_table_entry_t ncu_prop_table[] = {
 212         { PT_TYPE,                      NWAM_NCU_PROP_TYPE },
 213         { PT_CLASS,                     NWAM_NCU_PROP_CLASS },
 214         { PT_PARENT,                    NWAM_NCU_PROP_PARENT_NCP },
 215         { PT_ACTIVATION_MODE,           NWAM_NCU_PROP_ACTIVATION_MODE },
 216         { PT_ENABLED,                   NWAM_NCU_PROP_ENABLED },
 217         { PT_PRIORITY_GROUP,            NWAM_NCU_PROP_PRIORITY_GROUP },
 218         { PT_PRIORITY_MODE,             NWAM_NCU_PROP_PRIORITY_MODE },
 219         { PT_LINK_MACADDR,              NWAM_NCU_PROP_LINK_MAC_ADDR },
 220         { PT_LINK_AUTOPUSH,             NWAM_NCU_PROP_LINK_AUTOPUSH },
 221         { PT_LINK_MTU,                  NWAM_NCU_PROP_LINK_MTU },
 222         { PT_IP_VERSION,                NWAM_NCU_PROP_IP_VERSION },
 223         { PT_IPV4_ADDRSRC,              NWAM_NCU_PROP_IPV4_ADDRSRC },
 224         { PT_IPV4_ADDR,                 NWAM_NCU_PROP_IPV4_ADDR },
 225         { PT_IPV4_DEFAULT_ROUTE,        NWAM_NCU_PROP_IPV4_DEFAULT_ROUTE },
 226         { PT_IPV6_ADDRSRC,              NWAM_NCU_PROP_IPV6_ADDRSRC },
 227         { PT_IPV6_ADDR,                 NWAM_NCU_PROP_IPV6_ADDR },
 228         { PT_IPV6_DEFAULT_ROUTE,        NWAM_NCU_PROP_IPV6_DEFAULT_ROUTE },


 229         { 0, NULL }
 230 };
 231 
 232 /* ENM properties table */
 233 static prop_table_entry_t enm_prop_table[] = {
 234         { PT_ENM_FMRI,          NWAM_ENM_PROP_FMRI },
 235         { PT_ENM_START,         NWAM_ENM_PROP_START },
 236         { PT_ENM_STOP,          NWAM_ENM_PROP_STOP },
 237         { PT_ACTIVATION_MODE,   NWAM_ENM_PROP_ACTIVATION_MODE },
 238         { PT_CONDITIONS,        NWAM_ENM_PROP_CONDITIONS },
 239         { PT_ENABLED,           NWAM_ENM_PROP_ENABLED },
 240         { 0, NULL }
 241 };
 242 
 243 /* LOCation properties table */
 244 static prop_table_entry_t loc_prop_table[] = {
 245         { PT_ACTIVATION_MODE,   NWAM_LOC_PROP_ACTIVATION_MODE },
 246         { PT_CONDITIONS,        NWAM_LOC_PROP_CONDITIONS },
 247         { PT_ENABLED,           NWAM_LOC_PROP_ENABLED },
 248         { PT_LOC_NAMESERVICES,  NWAM_LOC_PROP_NAMESERVICES },


 647 
 648 /* Given an enm property and value, returns it as a string */
 649 static const char *
 650 propval_to_str(const char *propname, uint64_t value)
 651 {
 652         const char *str;
 653 
 654         if (nwam_uint64_get_value_string(propname, value, &str) == NWAM_SUCCESS)
 655                 return (str);
 656         return (NULL);
 657 }
 658 
 659 /* Given an int for a prop, returns it as string */
 660 static const char *
 661 pt_to_str(int prop_type)
 662 {
 663         assert(prop_type >= PT_MIN && prop_type <= PT_MAX);
 664         return (pt_types[prop_type]);
 665 }
 666 
 667 /* Return B_TRUE if string starts with "t" or is 1, B_FALSE otherwise */



 668 static boolean_t
 669 str_to_boolean(const char *str)
 670 {
 671         if (strncasecmp(str, "t", 1) == 0 || atoi(str) == 1)

 672                 return (B_TRUE);
 673         else
 674                 return (B_FALSE);
 675 }
 676 
 677 /*
 678  * This is a separate function rather than a set of define's because of the
 679  * gettext() wrapping.
 680  */
 681 
 682 /*
 683  * TRANSLATION_NOTE
 684  * Each string below should have \t follow \n whenever needed; the
 685  * initial \t and the terminal \n will be provided by the calling function.
 686  */
 687 
 688 static const char *
 689 long_help(int cmd_num)
 690 {
 691         assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX);


2180         { NWAM_NCU_PROP_PRIORITY_MODE, NWAM_NCU_PROP_ACTIVATION_MODE,
2181             { NWAM_ACTIVATION_MODE_PRIORITIZED, -1 } },
2182         /* show ipv4-addrsrc if ip-version == ipv4 */
2183         { NWAM_NCU_PROP_IPV4_ADDRSRC, NWAM_NCU_PROP_IP_VERSION,
2184             { IPV4_VERSION, -1 } },
2185         /* show ipv4-addr if ipv4-addrsrc == static */
2186         { NWAM_NCU_PROP_IPV4_ADDR, NWAM_NCU_PROP_IPV4_ADDRSRC,
2187             { NWAM_ADDRSRC_STATIC, -1 } },
2188         /* show ipv4-default-route if ip-version == ipv4 */
2189         { NWAM_NCU_PROP_IPV4_DEFAULT_ROUTE, NWAM_NCU_PROP_IP_VERSION,
2190             { IPV4_VERSION, -1 } },
2191         /* show ipv6-addrsrc if ip-version == ipv6 */
2192         { NWAM_NCU_PROP_IPV6_ADDRSRC, NWAM_NCU_PROP_IP_VERSION,
2193             { IPV6_VERSION, -1 } },
2194         /* show ipv6-addr if ipv6-addrsrc == static */
2195         { NWAM_NCU_PROP_IPV6_ADDR, NWAM_NCU_PROP_IPV6_ADDRSRC,
2196             { NWAM_ADDRSRC_STATIC, -1 } },
2197         /* show ipv6-default-route if ip-version == ipv6 */
2198         { NWAM_NCU_PROP_IPV6_DEFAULT_ROUTE, NWAM_NCU_PROP_IP_VERSION,
2199             { IPV6_VERSION, -1 } },












2200         { NULL, NULL, { -1 } }
2201 };
2202 
2203 /* Rules for ENMs */
2204 static prop_display_entry_t enm_prop_display_entry_table[] = {
2205         /* show conditions if activation-mode == conditional-{all,any} */
2206         { NWAM_ENM_PROP_CONDITIONS, NWAM_ENM_PROP_ACTIVATION_MODE,
2207             { NWAM_ACTIVATION_MODE_CONDITIONAL_ALL,
2208             NWAM_ACTIVATION_MODE_CONDITIONAL_ANY, -1 } },
2209         { NULL, NULL, { -1 } }
2210 };
2211 
2212 /* Rules for LOCations */
2213 static prop_display_entry_t loc_prop_display_entry_table[] = {
2214         /* show conditions if activation-mode == conditional-{all,any} */
2215         { NWAM_LOC_PROP_CONDITIONS, NWAM_LOC_PROP_ACTIVATION_MODE,
2216             { NWAM_ACTIVATION_MODE_CONDITIONAL_ALL,
2217             NWAM_ACTIVATION_MODE_CONDITIONAL_ANY, -1 } },
2218         /* show dns-nameservice-configsrc if nameservices == dns */
2219         { NWAM_LOC_PROP_DNS_NAMESERVICE_CONFIGSRC, NWAM_LOC_PROP_NAMESERVICES,




   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 /*
  23  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
  25  */
  26 
  27 /*
  28  * nwamcfg is a lex/yacc based command interpreter used to manage network
  29  * configurations.  The lexer (see nwamcfg_lex.l) builds up tokens, which
  30  * the grammar (see nwamcfg_grammar.y) builds up into commands, some of
  31  * which takes resources and/or properties as arguments.
  32  */
  33 
  34 #include <arpa/inet.h>
  35 #include <assert.h>
  36 #include <ctype.h>
  37 #include <errno.h>
  38 #include <libnwam.h>
  39 #include <libtecla.h>
  40 #include <locale.h>
  41 #include <stdarg.h>
  42 #include <stdio.h>
  43 #include <string.h>
  44 #include <sys/stat.h>


 182         NWAM_LOC_PROP_DNS_NAMESERVICE_CONFIGSRC,
 183         NWAM_LOC_PROP_DNS_NAMESERVICE_DOMAIN,
 184         NWAM_LOC_PROP_DNS_NAMESERVICE_SERVERS,
 185         NWAM_LOC_PROP_DNS_NAMESERVICE_SEARCH,
 186         NWAM_LOC_PROP_NIS_NAMESERVICE_CONFIGSRC,
 187         NWAM_LOC_PROP_NIS_NAMESERVICE_SERVERS,
 188         NWAM_LOC_PROP_LDAP_NAMESERVICE_CONFIGSRC,
 189         NWAM_LOC_PROP_LDAP_NAMESERVICE_SERVERS,
 190         NWAM_LOC_PROP_DEFAULT_DOMAIN,
 191         NWAM_LOC_PROP_NFSV4_DOMAIN,
 192         NWAM_LOC_PROP_IPFILTER_CONFIG_FILE,
 193         NWAM_LOC_PROP_IPFILTER_V6_CONFIG_FILE,
 194         NWAM_LOC_PROP_IPNAT_CONFIG_FILE,
 195         NWAM_LOC_PROP_IPPOOL_CONFIG_FILE,
 196         NWAM_LOC_PROP_IKE_CONFIG_FILE,
 197         NWAM_LOC_PROP_IPSECPOLICY_CONFIG_FILE,
 198         NWAM_KNOWN_WLAN_PROP_BSSIDS,
 199         NWAM_KNOWN_WLAN_PROP_PRIORITY,
 200         NWAM_KNOWN_WLAN_PROP_KEYNAME,
 201         NWAM_KNOWN_WLAN_PROP_KEYSLOT,
 202         NWAM_KNOWN_WLAN_PROP_SECURITY_MODE,
 203         NWAM_NCU_PROP_IP_PRIMARY,
 204         NWAM_NCU_PROP_IP_REQHOST
 205 };
 206 
 207 /* properties table: maps PT_* constants to property names */
 208 typedef struct prop_table_entry {
 209         int                     pte_type;
 210         const char              *pte_name;
 211 } prop_table_entry_t;
 212 
 213 /* NCU properties table */
 214 static prop_table_entry_t ncu_prop_table[] = {
 215         { PT_TYPE,                      NWAM_NCU_PROP_TYPE },
 216         { PT_CLASS,                     NWAM_NCU_PROP_CLASS },
 217         { PT_PARENT,                    NWAM_NCU_PROP_PARENT_NCP },
 218         { PT_ACTIVATION_MODE,           NWAM_NCU_PROP_ACTIVATION_MODE },
 219         { PT_ENABLED,                   NWAM_NCU_PROP_ENABLED },
 220         { PT_PRIORITY_GROUP,            NWAM_NCU_PROP_PRIORITY_GROUP },
 221         { PT_PRIORITY_MODE,             NWAM_NCU_PROP_PRIORITY_MODE },
 222         { PT_LINK_MACADDR,              NWAM_NCU_PROP_LINK_MAC_ADDR },
 223         { PT_LINK_AUTOPUSH,             NWAM_NCU_PROP_LINK_AUTOPUSH },
 224         { PT_LINK_MTU,                  NWAM_NCU_PROP_LINK_MTU },
 225         { PT_IP_VERSION,                NWAM_NCU_PROP_IP_VERSION },
 226         { PT_IPV4_ADDRSRC,              NWAM_NCU_PROP_IPV4_ADDRSRC },
 227         { PT_IPV4_ADDR,                 NWAM_NCU_PROP_IPV4_ADDR },
 228         { PT_IPV4_DEFAULT_ROUTE,        NWAM_NCU_PROP_IPV4_DEFAULT_ROUTE },
 229         { PT_IPV6_ADDRSRC,              NWAM_NCU_PROP_IPV6_ADDRSRC },
 230         { PT_IPV6_ADDR,                 NWAM_NCU_PROP_IPV6_ADDR },
 231         { PT_IPV6_DEFAULT_ROUTE,        NWAM_NCU_PROP_IPV6_DEFAULT_ROUTE },
 232         { PT_IP_PRIMARY,                NWAM_NCU_PROP_IP_PRIMARY },
 233         { PT_IP_REQHOST,                NWAM_NCU_PROP_IP_REQHOST },
 234         { 0, NULL }
 235 };
 236 
 237 /* ENM properties table */
 238 static prop_table_entry_t enm_prop_table[] = {
 239         { PT_ENM_FMRI,          NWAM_ENM_PROP_FMRI },
 240         { PT_ENM_START,         NWAM_ENM_PROP_START },
 241         { PT_ENM_STOP,          NWAM_ENM_PROP_STOP },
 242         { PT_ACTIVATION_MODE,   NWAM_ENM_PROP_ACTIVATION_MODE },
 243         { PT_CONDITIONS,        NWAM_ENM_PROP_CONDITIONS },
 244         { PT_ENABLED,           NWAM_ENM_PROP_ENABLED },
 245         { 0, NULL }
 246 };
 247 
 248 /* LOCation properties table */
 249 static prop_table_entry_t loc_prop_table[] = {
 250         { PT_ACTIVATION_MODE,   NWAM_LOC_PROP_ACTIVATION_MODE },
 251         { PT_CONDITIONS,        NWAM_LOC_PROP_CONDITIONS },
 252         { PT_ENABLED,           NWAM_LOC_PROP_ENABLED },
 253         { PT_LOC_NAMESERVICES,  NWAM_LOC_PROP_NAMESERVICES },


 652 
 653 /* Given an enm property and value, returns it as a string */
 654 static const char *
 655 propval_to_str(const char *propname, uint64_t value)
 656 {
 657         const char *str;
 658 
 659         if (nwam_uint64_get_value_string(propname, value, &str) == NWAM_SUCCESS)
 660                 return (str);
 661         return (NULL);
 662 }
 663 
 664 /* Given an int for a prop, returns it as string */
 665 static const char *
 666 pt_to_str(int prop_type)
 667 {
 668         assert(prop_type >= PT_MIN && prop_type <= PT_MAX);
 669         return (pt_types[prop_type]);
 670 }
 671 
 672 /*
 673  * Return B_TRUE if string starts with "t" or "on" or is 1;
 674  * B_FALSE otherwise
 675  */
 676 static boolean_t
 677 str_to_boolean(const char *str)
 678 {
 679         if (strncasecmp(str, "t", 1) == 0 || strncasecmp(str, "on", 2) == 0 ||
 680             atoi(str) == 1)
 681                 return (B_TRUE);
 682         else
 683                 return (B_FALSE);
 684 }
 685 
 686 /*
 687  * This is a separate function rather than a set of define's because of the
 688  * gettext() wrapping.
 689  */
 690 
 691 /*
 692  * TRANSLATION_NOTE
 693  * Each string below should have \t follow \n whenever needed; the
 694  * initial \t and the terminal \n will be provided by the calling function.
 695  */
 696 
 697 static const char *
 698 long_help(int cmd_num)
 699 {
 700         assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX);


2189         { NWAM_NCU_PROP_PRIORITY_MODE, NWAM_NCU_PROP_ACTIVATION_MODE,
2190             { NWAM_ACTIVATION_MODE_PRIORITIZED, -1 } },
2191         /* show ipv4-addrsrc if ip-version == ipv4 */
2192         { NWAM_NCU_PROP_IPV4_ADDRSRC, NWAM_NCU_PROP_IP_VERSION,
2193             { IPV4_VERSION, -1 } },
2194         /* show ipv4-addr if ipv4-addrsrc == static */
2195         { NWAM_NCU_PROP_IPV4_ADDR, NWAM_NCU_PROP_IPV4_ADDRSRC,
2196             { NWAM_ADDRSRC_STATIC, -1 } },
2197         /* show ipv4-default-route if ip-version == ipv4 */
2198         { NWAM_NCU_PROP_IPV4_DEFAULT_ROUTE, NWAM_NCU_PROP_IP_VERSION,
2199             { IPV4_VERSION, -1 } },
2200         /* show ipv6-addrsrc if ip-version == ipv6 */
2201         { NWAM_NCU_PROP_IPV6_ADDRSRC, NWAM_NCU_PROP_IP_VERSION,
2202             { IPV6_VERSION, -1 } },
2203         /* show ipv6-addr if ipv6-addrsrc == static */
2204         { NWAM_NCU_PROP_IPV6_ADDR, NWAM_NCU_PROP_IPV6_ADDRSRC,
2205             { NWAM_ADDRSRC_STATIC, -1 } },
2206         /* show ipv6-default-route if ip-version == ipv6 */
2207         { NWAM_NCU_PROP_IPV6_DEFAULT_ROUTE, NWAM_NCU_PROP_IP_VERSION,
2208             { IPV6_VERSION, -1 } },
2209         /* show ip-primary if ipv4-addrsrc == dhcp */
2210         { NWAM_NCU_PROP_IP_PRIMARY, NWAM_NCU_PROP_IPV4_ADDRSRC,
2211             { NWAM_ADDRSRC_DHCP, -1 } },
2212         /* show ip-primary if ipv6-addrsrc == dhcp */
2213         { NWAM_NCU_PROP_IP_PRIMARY, NWAM_NCU_PROP_IPV6_ADDRSRC,
2214             { NWAM_ADDRSRC_DHCP, -1 } },
2215         /* show ip-reqhost if ipv4-addrsrc == dhcp */
2216         { NWAM_NCU_PROP_IP_REQHOST, NWAM_NCU_PROP_IPV4_ADDRSRC,
2217             { NWAM_ADDRSRC_DHCP, -1 } },
2218         /* show ip-reqhost if ipv6-addrsrc == dhcp */
2219         { NWAM_NCU_PROP_IP_REQHOST, NWAM_NCU_PROP_IPV6_ADDRSRC,
2220             { NWAM_ADDRSRC_DHCP, -1 } },
2221         { NULL, NULL, { -1 } }
2222 };
2223 
2224 /* Rules for ENMs */
2225 static prop_display_entry_t enm_prop_display_entry_table[] = {
2226         /* show conditions if activation-mode == conditional-{all,any} */
2227         { NWAM_ENM_PROP_CONDITIONS, NWAM_ENM_PROP_ACTIVATION_MODE,
2228             { NWAM_ACTIVATION_MODE_CONDITIONAL_ALL,
2229             NWAM_ACTIVATION_MODE_CONDITIONAL_ANY, -1 } },
2230         { NULL, NULL, { -1 } }
2231 };
2232 
2233 /* Rules for LOCations */
2234 static prop_display_entry_t loc_prop_display_entry_table[] = {
2235         /* show conditions if activation-mode == conditional-{all,any} */
2236         { NWAM_LOC_PROP_CONDITIONS, NWAM_LOC_PROP_ACTIVATION_MODE,
2237             { NWAM_ACTIVATION_MODE_CONDITIONAL_ALL,
2238             NWAM_ACTIVATION_MODE_CONDITIONAL_ANY, -1 } },
2239         /* show dns-nameservice-configsrc if nameservices == dns */
2240         { NWAM_LOC_PROP_DNS_NAMESERVICE_CONFIGSRC, NWAM_LOC_PROP_NAMESERVICES,