Print this page
10052 "dladm show-ether" should pick one kstat snapshot and stick with it
Reviewed by: Rob Johnston <rob.johnston@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Gergo Doma <domag02@gmail.com>
Reviewed by: Andy Fiddaman <andy@omniosce.org>


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




  25 #include <unistd.h>
  26 #include <errno.h>
  27 #include <ctype.h>
  28 #include <fcntl.h>
  29 #include <strings.h>
  30 #include <dirent.h>
  31 #include <stdlib.h>
  32 #include <netinet/in.h>
  33 #include <arpa/inet.h>
  34 #include <sys/param.h>
  35 #include <sys/stat.h>
  36 #include <sys/dld.h>
  37 #include <sys/dld_ioc.h>
  38 #include <libdladm_impl.h>
  39 #include <libintl.h>
  40 #include <libdlpi.h>
  41 #include <libdllink.h>
  42 
  43 static char     dladm_rootdir[MAXPATHLEN] = "/";
  44 


 104                 return (DLADM_STATUS_BADARG);
 105 
 106         if ((dld_fd = open(DLD_CONTROL_DEV, O_RDWR)) < 0)
 107                 return (dladm_errno2status(errno));
 108 
 109         /*
 110          * Don't open DLMGMT_DOOR now.  dlmgmtd(1M) is not able to
 111          * open the door when the dladm handle is opened because the
 112          * door hasn't been created yet at that time.  Thus, we must
 113          * open it on-demand in dladm_door_fd().  Move the open()
 114          * to dladm_door_fd() for all cases.
 115          */
 116 
 117         if ((*handle = malloc(sizeof (struct dladm_handle))) == NULL) {
 118                 (void) close(dld_fd);
 119                 return (DLADM_STATUS_NOMEM);
 120         }
 121 
 122         (*handle)->dld_fd = dld_fd;
 123         (*handle)->door_fd = -1;

 124 
 125         return (DLADM_STATUS_OK);
 126 }
 127 
 128 void
 129 dladm_close(dladm_handle_t handle)
 130 {
 131         if (handle != NULL) {
 132                 (void) close(handle->dld_fd);
 133                 if (handle->door_fd != -1)
 134                         (void) close(handle->door_fd);


 135                 free(handle);
 136         }
 137 }
 138 
 139 int
 140 dladm_dld_fd(dladm_handle_t handle)
 141 {
 142         return (handle->dld_fd);
 143 }
 144 








 145 /*
 146  * If DLMGMT_DOOR hasn't been opened in the handle yet, open it.
 147  */
 148 dladm_status_t
 149 dladm_door_fd(dladm_handle_t handle, int *door_fd)
 150 {
 151         int fd;
 152 
 153         if (handle->door_fd == -1) {
 154                 if ((fd = open(DLMGMT_DOOR, O_RDONLY)) < 0)
 155                         return (dladm_errno2status(errno));
 156                 handle->door_fd = fd;
 157         }
 158         *door_fd = handle->door_fd;
 159 
 160         return (DLADM_STATUS_OK);
 161 }
 162 
 163 const char *
 164 dladm_status2str(dladm_status_t status, char *buf)




   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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23  */
  24 
  25 /*
  26  * Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
  27  */
  28 
  29 #include <unistd.h>
  30 #include <errno.h>
  31 #include <ctype.h>
  32 #include <fcntl.h>
  33 #include <strings.h>
  34 #include <dirent.h>
  35 #include <stdlib.h>
  36 #include <netinet/in.h>
  37 #include <arpa/inet.h>
  38 #include <sys/param.h>
  39 #include <sys/stat.h>
  40 #include <sys/dld.h>
  41 #include <sys/dld_ioc.h>
  42 #include <libdladm_impl.h>
  43 #include <libintl.h>
  44 #include <libdlpi.h>
  45 #include <libdllink.h>
  46 
  47 static char     dladm_rootdir[MAXPATHLEN] = "/";
  48 


 108                 return (DLADM_STATUS_BADARG);
 109 
 110         if ((dld_fd = open(DLD_CONTROL_DEV, O_RDWR)) < 0)
 111                 return (dladm_errno2status(errno));
 112 
 113         /*
 114          * Don't open DLMGMT_DOOR now.  dlmgmtd(1M) is not able to
 115          * open the door when the dladm handle is opened because the
 116          * door hasn't been created yet at that time.  Thus, we must
 117          * open it on-demand in dladm_door_fd().  Move the open()
 118          * to dladm_door_fd() for all cases.
 119          */
 120 
 121         if ((*handle = malloc(sizeof (struct dladm_handle))) == NULL) {
 122                 (void) close(dld_fd);
 123                 return (DLADM_STATUS_NOMEM);
 124         }
 125 
 126         (*handle)->dld_fd = dld_fd;
 127         (*handle)->door_fd = -1;
 128         (*handle)->dld_kcp = NULL;
 129 
 130         return (DLADM_STATUS_OK);
 131 }
 132 
 133 void
 134 dladm_close(dladm_handle_t handle)
 135 {
 136         if (handle != NULL) {
 137                 (void) close(handle->dld_fd);
 138                 if (handle->door_fd != -1)
 139                         (void) close(handle->door_fd);
 140                 if (handle->dld_kcp != NULL)
 141                         (void) kstat_close(handle->dld_kcp);
 142                 free(handle);
 143         }
 144 }
 145 
 146 int
 147 dladm_dld_fd(dladm_handle_t handle)
 148 {
 149         return (handle->dld_fd);
 150 }
 151 
 152 kstat_ctl_t *
 153 dladm_dld_kcp(dladm_handle_t handle)
 154 {
 155         if (handle->dld_kcp == NULL)
 156                 handle->dld_kcp = kstat_open();
 157         return (handle->dld_kcp);
 158 }
 159 
 160 /*
 161  * If DLMGMT_DOOR hasn't been opened in the handle yet, open it.
 162  */
 163 dladm_status_t
 164 dladm_door_fd(dladm_handle_t handle, int *door_fd)
 165 {
 166         int fd;
 167 
 168         if (handle->door_fd == -1) {
 169                 if ((fd = open(DLMGMT_DOOR, O_RDONLY)) < 0)
 170                         return (dladm_errno2status(errno));
 171                 handle->door_fd = fd;
 172         }
 173         *door_fd = handle->door_fd;
 174 
 175         return (DLADM_STATUS_OK);
 176 }
 177 
 178 const char *
 179 dladm_status2str(dladm_status_t status, char *buf)