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/cmd/cmd-inet/usr.sbin/soconfig.c
          +++ new/usr/src/cmd/cmd-inet/usr.sbin/soconfig.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  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   * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
       23 + * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  23   24   */
  24   25  
  25   26  #include <ctype.h>
  26   27  #include <dirent.h>
  27   28  #include <errno.h>
  28   29  #include <locale.h>
  29   30  #include <stdio.h>
  30   31  #include <stdlib.h>
  31   32  #include <string.h>
  32   33  #include <sys/socket.h>
↓ open down ↓ 14 lines elided ↑ open up ↑
  47   48   *                       <fam> <type> <protocol>
  48   49   *              with the first line registering and the second line
  49   50   *              deregistering.
  50   51   *
  51   52   *      soconfig <fam> <type> <protocol> <path|module>
  52   53   *              registers
  53   54   *
  54   55   *      soconfig <fam> <type> <protocol>
  55   56   *              deregisters
  56   57   *
       58 + *      soconfig -l
       59 + *              print the in-kernel socket configuration table
       60 + *
  57   61   * Filter Operations (Consolidation Private):
  58   62   *
  59   63   *      soconfig -F <name> <modname> {auto [top | bottom | before:filter |
  60   64   *              after:filter] | prog} <fam>:<type>:<proto>,...
  61   65   *              configure filter
  62   66   *
  63   67   *      soconfig -F <name>
  64   68   *              unconfigures filter
  65   69   */
  66   70  
↓ open down ↓ 5 lines elided ↑ open up ↑
  72   76  
  73   77  static int      parse_params(char *famstr, char *typestr, char *protostr,
  74   78                                  char *path, const char *file, int line);
  75   79  
  76   80  static int      parse_int(char *str);
  77   81  
  78   82  static void     usage(void);
  79   83  
  80   84  static int      parse_filter_params(int argc, char **argv);
  81   85  
       86 +static int      print_socktable();
       87 +
  82   88  int
  83   89  main(argc, argv)
  84   90          int argc;
  85   91          char *argv[];
  86   92  {
  87   93          int ret;
  88   94  
  89   95          argc--; argv++;
  90   96  
  91   97          (void) setlocale(LC_ALL, "");
  92   98  #if !defined(TEXT_DOMAIN)
  93   99  #define TEXT_DOMAIN "SYS_TEST"
  94  100  #endif
  95  101          (void) textdomain(TEXT_DOMAIN);
  96  102  
      103 +        if (argc == 1 && strcmp(argv[0], "-l") == 0) {
      104 +                ret = print_socktable();
      105 +                exit(ret);
      106 +        }
      107 +
  97  108          if (argc >= 2 && strcmp(argv[0], "-F") == 0) {
  98  109                  argc--; argv++;
  99  110                  ret = parse_filter_params(argc, argv);
 100  111                  exit(ret);
 101  112          }
 102  113          if (argc == 2 && strcmp(argv[0], "-d") == 0) {
 103  114                  ret = parse_files_in_dir(argv[1]);
 104  115                  exit(ret);
 105  116          }
 106  117          if (argc == 2 && strcmp(argv[0], "-f") == 0) {
↓ open down ↓ 14 lines elided ↑ open up ↑
 121  132          /* NOTREACHED */
 122  133  }
 123  134  
 124  135  static void
 125  136  usage(void)
 126  137  {
 127  138          fprintf(stderr, gettext(
 128  139              "Usage:     soconfig -d <dir>\n"
 129  140              "\tsoconfig -f <file>\n"
 130  141              "\tsoconfig <fam> <type> <protocol> <path|module>\n"
 131      -            "\tsoconfig <fam> <type> <protocol>\n"));
      142 +            "\tsoconfig <fam> <type> <protocol>\n"
      143 +            "\tsoconfig -l\n"));
 132  144  }
 133  145  
 134  146  /*
 135  147   * Parse all files in the given directory.
 136  148   */
 137  149  static int
 138  150  parse_files_in_dir(const char *dirname)
 139  151  {
 140  152          DIR             *dp;
 141  153          struct dirent   *dirp;
↓ open down ↓ 426 lines elided ↑ open up ↑
 568  580                  default:
 569  581                          perror("sockconfig");
 570  582                          break;
 571  583                  }
 572  584                  free(socktuples);
 573  585                  return (1);
 574  586          }
 575  587          free(socktuples);
 576  588          return (0);
 577  589  }
      590 +
      591 +/*
      592 + *  Print the in-kernel socket configuration table
      593 + */
      594 +
      595 +static int
      596 +print_socktable()
      597 +{
      598 +        sockconfig_socktable_t sc_table;
      599 +        int i;
      600 +
      601 +        (void) memset(&sc_table, 0, sizeof (sockconfig_socktable_t));
      602 +
      603 +        /* get number of entries */
      604 +        if (_sockconfig(SOCKCONFIG_GET_SOCKTABLE, &sc_table) == -1) {
      605 +                fprintf(stderr,
      606 +                    gettext("cannot get in-kernel socket table: %s\n"),
      607 +                    strerror(errno));
      608 +                return (-1);
      609 +        }
      610 +        if (sc_table.num_of_entries == 0)
      611 +                return (0);
      612 +
      613 +        sc_table.st_entries = calloc(sc_table.num_of_entries,
      614 +            sizeof (sockconfig_socktable_entry_t));
      615 +        if (sc_table.st_entries == NULL) {
      616 +                fprintf(stderr, gettext("out of memory\n"));
      617 +                return (-1);
      618 +        }
      619 +
      620 +        /* get socket table entries */
      621 +        if (_sockconfig(SOCKCONFIG_GET_SOCKTABLE, &sc_table) == -1) {
      622 +                fprintf(stderr,
      623 +                    gettext("cannot get in-kernel socket table: %s\n"),
      624 +                    strerror(errno));
      625 +                return (-1);
      626 +        }
      627 +
      628 +        printf("%6s %4s %5s %15s %15s %6s %6s\n",
      629 +            "FAMILY", "TYPE", "PROTO", "STRDEV", "SOCKMOD",
      630 +            "REFS", "FLAGS");
      631 +        for (i = 0; i < sc_table.num_of_entries; i++) {
      632 +                printf("%6u %4u %5u %15s %15s %6u %#6x\n",
      633 +                    sc_table.st_entries[i].se_family,
      634 +                    sc_table.st_entries[i].se_type,
      635 +                    sc_table.st_entries[i].se_protocol,
      636 +                    (strcmp(sc_table.st_entries[i].se_modname,
      637 +                    "socktpi") == 0) ?
      638 +                    sc_table.st_entries[i].se_strdev : "-",
      639 +                    sc_table.st_entries[i].se_modname,
      640 +                    sc_table.st_entries[i].se_refcnt,
      641 +                    sc_table.st_entries[i].se_flags);
      642 +        }
      643 +        free(sc_table.st_entries);
      644 +        return (0);
      645 +}
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX