Print this page
10096 kstat update routines shouldn't check for NULL kstat


   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) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2013 by Delphix. All rights reserved.
  24  * Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved.

  25  */
  26 /* Copyright (c) 1990 Mentat Inc. */
  27 
  28 #include <sys/types.h>
  29 #include <sys/stream.h>
  30 #include <sys/stropts.h>
  31 #include <sys/strlog.h>
  32 #include <sys/strsun.h>
  33 #define _SUN_TPI_VERSION 2
  34 #include <sys/tihdr.h>
  35 #include <sys/timod.h>
  36 #include <sys/ddi.h>
  37 #include <sys/sunddi.h>
  38 #include <sys/strsubr.h>
  39 #include <sys/suntpi.h>
  40 #include <sys/xti_inet.h>
  41 #include <sys/cmn_err.h>
  42 #include <sys/kmem.h>
  43 #include <sys/cred.h>
  44 #include <sys/policy.h>


5055         return (ksp);
5056 }
5057 
5058 static void
5059 rawip_kstat_fini(netstackid_t stackid, kstat_t *ksp)
5060 {
5061         if (ksp != NULL) {
5062                 ASSERT(stackid == (netstackid_t)(uintptr_t)ksp->ks_private);
5063                 kstat_delete_netstack(ksp, stackid);
5064         }
5065 }
5066 
5067 static int
5068 rawip_kstat_update(kstat_t *ksp, int rw)
5069 {
5070         rawip_named_kstat_t *rawipkp;
5071         netstackid_t    stackid = (netstackid_t)(uintptr_t)ksp->ks_private;
5072         netstack_t      *ns;
5073         icmp_stack_t    *is;
5074 
5075         if ((ksp == NULL) || (ksp->ks_data == NULL))
5076                 return (EIO);
5077 
5078         if (rw == KSTAT_WRITE)
5079                 return (EACCES);
5080 
5081         rawipkp = (rawip_named_kstat_t *)ksp->ks_data;
5082 
5083         ns = netstack_find_by_stackid(stackid);
5084         if (ns == NULL)
5085                 return (-1);
5086         is = ns->netstack_icmp;
5087         if (is == NULL) {
5088                 netstack_rele(ns);
5089                 return (-1);
5090         }
5091         rawipkp->inDatagrams.value.ui32 =  is->is_rawip_mib.rawipInDatagrams;
5092         rawipkp->inCksumErrs.value.ui32 =  is->is_rawip_mib.rawipInCksumErrs;
5093         rawipkp->inErrors.value.ui32 =          is->is_rawip_mib.rawipInErrors;
5094         rawipkp->outDatagrams.value.ui32 = is->is_rawip_mib.rawipOutDatagrams;
5095         rawipkp->outErrors.value.ui32 =         is->is_rawip_mib.rawipOutErrors;




   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) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2013 by Delphix. All rights reserved.
  24  * Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved.
  25  * Copyright (c) 2018, Joyent, Inc.
  26  */
  27 /* Copyright (c) 1990 Mentat Inc. */
  28 
  29 #include <sys/types.h>
  30 #include <sys/stream.h>
  31 #include <sys/stropts.h>
  32 #include <sys/strlog.h>
  33 #include <sys/strsun.h>
  34 #define _SUN_TPI_VERSION 2
  35 #include <sys/tihdr.h>
  36 #include <sys/timod.h>
  37 #include <sys/ddi.h>
  38 #include <sys/sunddi.h>
  39 #include <sys/strsubr.h>
  40 #include <sys/suntpi.h>
  41 #include <sys/xti_inet.h>
  42 #include <sys/cmn_err.h>
  43 #include <sys/kmem.h>
  44 #include <sys/cred.h>
  45 #include <sys/policy.h>


5056         return (ksp);
5057 }
5058 
5059 static void
5060 rawip_kstat_fini(netstackid_t stackid, kstat_t *ksp)
5061 {
5062         if (ksp != NULL) {
5063                 ASSERT(stackid == (netstackid_t)(uintptr_t)ksp->ks_private);
5064                 kstat_delete_netstack(ksp, stackid);
5065         }
5066 }
5067 
5068 static int
5069 rawip_kstat_update(kstat_t *ksp, int rw)
5070 {
5071         rawip_named_kstat_t *rawipkp;
5072         netstackid_t    stackid = (netstackid_t)(uintptr_t)ksp->ks_private;
5073         netstack_t      *ns;
5074         icmp_stack_t    *is;
5075 
5076         if (ksp->ks_data == NULL)
5077                 return (EIO);
5078 
5079         if (rw == KSTAT_WRITE)
5080                 return (EACCES);
5081 
5082         rawipkp = (rawip_named_kstat_t *)ksp->ks_data;
5083 
5084         ns = netstack_find_by_stackid(stackid);
5085         if (ns == NULL)
5086                 return (-1);
5087         is = ns->netstack_icmp;
5088         if (is == NULL) {
5089                 netstack_rele(ns);
5090                 return (-1);
5091         }
5092         rawipkp->inDatagrams.value.ui32 =  is->is_rawip_mib.rawipInDatagrams;
5093         rawipkp->inCksumErrs.value.ui32 =  is->is_rawip_mib.rawipInCksumErrs;
5094         rawipkp->inErrors.value.ui32 =          is->is_rawip_mib.rawipInErrors;
5095         rawipkp->outDatagrams.value.ui32 = is->is_rawip_mib.rawipOutDatagrams;
5096         rawipkp->outErrors.value.ui32 =         is->is_rawip_mib.rawipOutErrors;