Print this page
4770 soconfig(1M) needs an option to print the in-kernel socket configuration table

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/sockfs/sockparams.c
          +++ new/usr/src/uts/common/fs/sockfs/sockparams.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) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  24   25   */
  25   26  
  26   27  #include <sys/types.h>
  27   28  #include <sys/t_lock.h>
  28   29  #include <sys/param.h>
  29   30  #include <sys/systm.h>
  30   31  #include <sys/sysmacros.h>
  31   32  #include <sys/cmn_err.h>
  32   33  #include <sys/list.h>
       34 +#include <sys/sunddi.h>
  33   35  
  34   36  #include <sys/stropts.h>
  35   37  #include <sys/socket.h>
  36   38  #include <sys/socketvar.h>
  37   39  
  38   40  #include <fs/sockfs/sockcommon.h>
  39   41  #include <fs/sockfs/sockfilter_impl.h>
  40   42  #include <fs/sockfs/socktpi.h>
  41   43  
  42   44  /*
↓ open down ↓ 773 lines elided ↑ open up ↑
 816  818  sockparams_new_filter(sof_entry_t *ent)
 817  819  {
 818  820          int error;
 819  821  
 820  822          if ((error = sockparams_new_filter_impl(ent, &sphead)) != 0)
 821  823                  return (error);
 822  824  
 823  825          if ((error = sockparams_new_filter_impl(ent, &sp_ephem_list)) != 0)
 824  826                  sockparams_filter_cleanup_impl(ent, &sphead);
 825  827          return (error);
      828 +}
      829 +
      830 +/*
      831 + * Setup and return socket configuration table.
      832 + */
      833 +int
      834 +sockparams_copyout_socktable(uintptr_t socktable)
      835 +{
      836 +        STRUCT_DECL(sockconfig_socktable, st);
      837 +        struct sockparams *sp;
      838 +        uint_t count;
      839 +        uint_t i = 0;
      840 +        int ret = 0;
      841 +        sockconfig_socktable_entry_t *se;
      842 +
      843 +        STRUCT_INIT(st, get_udatamodel());
      844 +        if (ddi_copyin((void *)socktable, STRUCT_BUF(st),
      845 +            STRUCT_SIZE(st), 0) != 0)
      846 +                return (EFAULT);
      847 +
      848 +        rw_enter(&sockconf_lock, RW_READER);
      849 +
      850 +        count = STRUCT_FGET(st, num_of_entries);
      851 +        /*
      852 +         * If the output buffer is size zero, just copy out the count.
      853 +         */
      854 +        if (count == 0) {
      855 +                for (sp = list_head(&sphead); sp != NULL;
      856 +                    sp = list_next(&sphead, sp)) {
      857 +                        count++;
      858 +                }
      859 +                STRUCT_FSET(st, num_of_entries, count);
      860 +
      861 +                rw_exit(&sockconf_lock);
      862 +                if (ddi_copyout(STRUCT_BUF(st), (void *)socktable,
      863 +                    STRUCT_SIZE(st), 0) != 0)
      864 +                        return (EFAULT);
      865 +
      866 +                return (0);
      867 +        }
      868 +
      869 +        se = kmem_alloc(count * sizeof (sockconfig_socktable_entry_t),
      870 +            KM_SLEEP);
      871 +        for (sp = list_head(&sphead); sp != NULL;
      872 +            sp = list_next(&sphead, sp)) {
      873 +                if (i >= count) {
      874 +                        /*
      875 +                         * Return if the number of entries has changed.
      876 +                         */
      877 +                        rw_exit(&sockconf_lock);
      878 +                        kmem_free(se,
      879 +                            count * sizeof (sockconfig_socktable_entry_t));
      880 +                        return (EAGAIN);
      881 +                }
      882 +                se[i].se_family = sp->sp_family;
      883 +                se[i].se_type = sp->sp_type;
      884 +                se[i].se_protocol = sp->sp_protocol;
      885 +                (void) strncpy(se[i].se_modname, sp->sp_smod_name,
      886 +                    MODMAXNAMELEN);
      887 +                if (sp->sp_sdev_info.sd_devpath != NULL)
      888 +                        (void) strncpy(se[i].se_strdev,
      889 +                            sp->sp_sdev_info.sd_devpath, MAXPATHLEN);
      890 +                se[i].se_refcnt = sp->sp_refcnt;
      891 +                se[i].se_flags = sp->sp_flags;
      892 +                i++;
      893 +        }
      894 +        rw_exit(&sockconf_lock);
      895 +        if (ddi_copyout(se, STRUCT_FGETP(st, st_entries),
      896 +            i * sizeof (sockconfig_socktable_entry_t), 0) != 0)
      897 +                ret = EFAULT;
      898 +
      899 +        STRUCT_FSET(st, num_of_entries, i);
      900 +        kmem_free(se, count * sizeof (sockconfig_socktable_entry_t));
      901 +
      902 +        if (ddi_copyout(STRUCT_BUF(st), (void *)socktable,
      903 +            STRUCT_SIZE(st), 0) != 0)
      904 +                ret = EFAULT;
      905 +
      906 +        return (ret);
 826  907  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX