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

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/cmd-inet/lib/nwamd/ncu.c
          +++ new/usr/src/cmd/cmd-inet/lib/nwamd/ncu.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  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  /*
  23   23   * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
  24   25   */
  25   26  
  26   27  #include <arpa/inet.h>
  27   28  #include <assert.h>
  28   29  #include <libdlaggr.h>
  29   30  #include <libdllink.h>
  30   31  #include <libdlstat.h>
  31   32  #include <libnwam.h>
  32   33  #include <libscf.h>
  33   34  #include <netinet/in.h>
  34   35  #include <stdlib.h>
  35   36  #include <strings.h>
       37 +#include <sys/param.h>
  36   38  #include <sys/socket.h>
  37   39  #include <sys/time.h>
  38   40  #include <sys/types.h>
  39   41  #include <values.h>
  40   42  #include <zone.h>
  41   43  
  42   44  #include "conditions.h"
  43   45  #include "events.h"
  44   46  #include "objects.h"
  45   47  #include "ncp.h"
↓ open down ↓ 75 lines elided ↑ open up ↑
 121  123  nwamd_get_ncu_uint(nwam_ncu_handle_t ncuh, nwam_value_t *val,
 122  124      uint64_t **uintval, uint_t *cnt, const char *prop)
 123  125  {
 124  126          nwam_error_t err;
 125  127  
 126  128          if ((err = nwam_ncu_get_prop_value(ncuh, prop, val)) != NWAM_SUCCESS)
 127  129                  return (err);
 128  130          return (nwam_value_get_uint64_array(*val, uintval, cnt));
 129  131  }
 130  132  
      133 +nwam_error_t
      134 +nwamd_get_ncu_boolean(nwam_ncu_handle_t ncuh, nwam_value_t *val,
      135 +    boolean_t **boolval, uint_t *cnt, const char *prop)
      136 +{
      137 +        nwam_error_t err;
      138 +
      139 +        if ((err = nwam_ncu_get_prop_value(ncuh, prop, val)) != NWAM_SUCCESS)
      140 +                return (err);
      141 +        return (nwam_value_get_boolean_array(*val, boolval, cnt));
      142 +}
      143 +
 131  144  /*
 132  145   * Run link/interface state machine in response to a state change
 133  146   * or enable/disable action event.
 134  147   */
 135  148  static void
 136  149  nwamd_ncu_state_machine(const char *object_name)
 137  150  {
 138  151          nwamd_object_t object;
 139  152          nwamd_ncu_t *ncu;
 140  153          link_state_t link_state;
↓ open down ↓ 585 lines elided ↑ open up ↑
 726  739                      NWAM_NCU_PROP_LINK_AUTOPUSH, nwam_strerror(err));
 727  740                  ncu_data->ncu_link.nwamd_link_num_autopush = 0;
 728  741          }
 729  742  }
 730  743  
 731  744  static void
 732  745  populate_ip_ncu_properties(nwam_ncu_handle_t ncuh, nwamd_ncu_t *ncu_data)
 733  746  {
 734  747          nwamd_if_t *nif = &ncu_data->ncu_if;
 735  748          struct nwamd_if_address **nifa, *nifai, *nifait;
 736      -        boolean_t static_addr = B_FALSE;
      749 +        boolean_t static_addr = B_FALSE, *boolvalue, dhcp_primary = B_FALSE;
 737  750          uint64_t *addrsrcvalue;
 738  751          nwam_value_t ncu_prop;
 739  752          nwam_error_t err;
 740  753          ipadm_addrobj_t ipaddr;
 741  754          ipadm_status_t ipstatus;
 742      -        char **addrvalue;
      755 +        char **addrvalue, ipreqhost[MAXNAMELEN];
 743  756          uint_t numvalues;
 744  757          uint64_t *ipversion;
 745  758          int i;
 746  759  
 747  760          nif->nwamd_if_ipv4 = B_FALSE;
 748  761          nif->nwamd_if_ipv6 = B_FALSE;
 749  762          nif->nwamd_if_dhcp_requested = B_FALSE;
 750  763          nif->nwamd_if_stateful_requested = B_FALSE;
 751  764          nif->nwamd_if_stateless_requested = B_FALSE;
 752  765          nif->nwamd_if_ipv4_default_route_set = B_FALSE;
↓ open down ↓ 16 lines elided ↑ open up ↑
 769  782                                  break;
 770  783                          default:
 771  784                                  nlog(LOG_ERR, "bogus ip version %lld",
 772  785                                      ipversion[i]);
 773  786                                  break;
 774  787                          }
 775  788                  }
 776  789                  nwam_value_free(ncu_prop);
 777  790          }
 778  791  
      792 +        /* ip-primary */
      793 +        if ((err = nwamd_get_ncu_boolean(ncuh, &ncu_prop, &boolvalue,
      794 +            &numvalues, NWAM_NCU_PROP_IP_PRIMARY)) != NWAM_SUCCESS) {
      795 +                /* ip-primary is optional, so do not LOG_ERR */
      796 +                nlog(LOG_DEBUG, "populate_ip_ncu_properties: "
      797 +                    "could not get %s value: %s",
      798 +                    NWAM_NCU_PROP_IP_PRIMARY, nwam_strerror(err));
      799 +        } else {
      800 +                if (numvalues > 0)
      801 +                        dhcp_primary = boolvalue[0];
      802 +                nwam_value_free(ncu_prop);
      803 +        }
      804 +
      805 +        /* ip-reqhost */
      806 +        *ipreqhost = '\0';
      807 +
      808 +        if ((err = nwamd_get_ncu_string(ncuh, &ncu_prop, &addrvalue,
      809 +            &numvalues, NWAM_NCU_PROP_IP_REQHOST)) != NWAM_SUCCESS) {
      810 +                /* ip-reqhost is optional, so do not LOG_ERR */
      811 +                nlog(LOG_DEBUG, "populate_ip_ncu_properties: "
      812 +                    "could not get %s value: %s",
      813 +                    NWAM_NCU_PROP_IP_REQHOST, nwam_strerror(err));
      814 +        } else {
      815 +                if (numvalues > 0 && strlcpy(ipreqhost, addrvalue[0],
      816 +                    sizeof (ipreqhost)) >= sizeof (ipreqhost)) {
      817 +                        nlog(LOG_WARNING, "populate_ip_ncu_properties: "
      818 +                            "too long %s value: %s",
      819 +                            NWAM_NCU_PROP_IP_REQHOST, addrvalue[0]);
      820 +                        *ipreqhost = '\0';
      821 +                }
      822 +                nwam_value_free(ncu_prop);
      823 +        }
      824 +
 779  825          /* Free the old list. */
 780  826          for (nifai = nif->nwamd_if_list; nifai != NULL; nifai = nifait) {
 781  827                  nifait = nifai->next;
 782  828                  nifai->next = NULL;
 783  829                  ipadm_destroy_addrobj(nifai->ipaddr);
 784  830                  free(nifai);
 785  831          }
 786  832          nif->nwamd_if_list = NULL;
 787  833          nifa = &(nif->nwamd_if_list);
 788  834  
↓ open down ↓ 32 lines elided ↑ open up ↑
 821  867                  }
 822  868  
 823  869                  ipstatus = ipadm_set_wait_time(ipaddr, ncu_wait_time);
 824  870                  if (ipstatus != IPADM_SUCCESS) {
 825  871                          nlog(LOG_ERR, "populate_ip_ncu_properties: "
 826  872                              "ipadm_set_wait_time failed for v4 dhcp: %s",
 827  873                              ipadm_status2str(ipstatus));
 828  874                          ipadm_destroy_addrobj(ipaddr);
 829  875                          goto skip_ipv4_dhcp;
 830  876                  }
      877 +                ipstatus = ipadm_set_primary(ipaddr, dhcp_primary);
      878 +                if (ipstatus != IPADM_SUCCESS) {
      879 +                        nlog(LOG_ERR, "populate_ip_ncu_properties: "
      880 +                            "ipadm_set_primary failed for v4 dhcp: %s",
      881 +                            ipadm_status2str(ipstatus));
      882 +                        ipadm_destroy_addrobj(ipaddr);
      883 +                        goto skip_ipv4_dhcp;
      884 +                }
      885 +                ipstatus = ipadm_set_reqhost(ipaddr, ipreqhost);
      886 +                if (ipstatus != IPADM_SUCCESS) {
      887 +                        nlog(LOG_ERR, "populate_ip_ncu_properties: "
      888 +                            "ipadm_set_reqhost failed for v4 dhcp: %s",
      889 +                            ipadm_status2str(ipstatus));
      890 +                        ipadm_destroy_addrobj(ipaddr);
      891 +                        goto skip_ipv4_dhcp;
      892 +                }
 831  893                  if ((*nifa = calloc(sizeof (**nifa), 1)) != NULL) {
 832  894                          (*nifa)->family = AF_INET;
 833  895                          (*nifa)->ipaddr_atype = IPADM_ADDR_DHCP;
 834  896                          (*nifa)->ipaddr = ipaddr;
 835  897                          nifa = &((*nifa)->next);
 836  898                          *nifa = NULL;
 837  899                  } else {
 838  900                          nlog(LOG_ERR, "populate_ip_ncu_properties: "
 839  901                              "couldn't allocate nwamd address for v4 dhcp: %s",
 840  902                              strerror(errno));
 841  903                          ipadm_destroy_addrobj(ipaddr);
 842  904                  }
 843  905          }
 844  906  
 845  907  skip_ipv4_dhcp:
 846  908          /* ipv4-addr */
 847  909          if (static_addr) {
 848  910                  if ((err = nwamd_get_ncu_string(ncuh, &ncu_prop, &addrvalue,
 849  911                      &numvalues, NWAM_NCU_PROP_IPV4_ADDR)) != NWAM_SUCCESS) {
 850  912                          nlog(LOG_ERR, "populate_ip_ncu_properties: "
 851      -                            "could not get %s value; %s",
      913 +                            "could not get %s value: %s",
 852  914                              NWAM_NCU_PROP_IPV4_ADDR, nwam_strerror(err));
 853  915                  } else {
 854  916                          for (i = 0; i < numvalues; i++) {
 855  917                                  ipstatus = ipadm_create_addrobj(
 856  918                                      IPADM_ADDR_STATIC, ncu_data->ncu_name,
 857  919                                      &ipaddr);
 858  920                                  if (ipstatus != IPADM_SUCCESS) {
 859  921                                          nlog(LOG_ERR,
 860  922                                              "populate_ip_ncu_properties: "
 861  923                                              "ipadm_create_addrobj failed "
↓ open down ↓ 126 lines elided ↑ open up ↑
 988 1050                          ipadm_destroy_addrobj(ipaddr);
 989 1051                  }
 990 1052          }
 991 1053  
 992 1054  skip_ipv6_addrconf:
 993 1055          /* ipv6-addr */
 994 1056          if (static_addr) {
 995 1057                  if ((err = nwamd_get_ncu_string(ncuh, &ncu_prop, &addrvalue,
 996 1058                      &numvalues, NWAM_NCU_PROP_IPV6_ADDR)) != NWAM_SUCCESS) {
 997 1059                          nlog(LOG_ERR, "populate_ip_ncu_properties: "
 998      -                            "could not get %s value; %s",
     1060 +                            "could not get %s value: %s",
 999 1061                              NWAM_NCU_PROP_IPV6_ADDR, nwam_strerror(err));
1000 1062                  } else {
1001 1063                          for (i = 0; i < numvalues; i++) {
1002 1064                                  ipstatus = ipadm_create_addrobj(
1003 1065                                      IPADM_ADDR_STATIC, ncu_data->ncu_name,
1004 1066                                      &ipaddr);
1005 1067                                  if (ipstatus != IPADM_SUCCESS) {
1006 1068                                          nlog(LOG_ERR,
1007 1069                                              "populate_ip_ncu_properties: "
1008 1070                                              "ipadm_create_addrobj failed "
↓ open down ↓ 1092 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX