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

*** 18,27 **** --- 18,28 ---- * * CDDL HEADER END */ /* * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2015 Nexenta Systems, Inc. All rights reserved. */ #include <ctype.h> #include <dirent.h> #include <errno.h>
*** 52,61 **** --- 53,65 ---- * registers * * soconfig <fam> <type> <protocol> * deregisters * + * soconfig -l + * print the in-kernel socket configuration table + * * Filter Operations (Consolidation Private): * * soconfig -F <name> <modname> {auto [top | bottom | before:filter | * after:filter] | prog} <fam>:<type>:<proto>,... * configure filter
*** 77,86 **** --- 81,92 ---- static void usage(void); static int parse_filter_params(int argc, char **argv); + static int print_socktable(); + int main(argc, argv) int argc; char *argv[]; {
*** 92,101 **** --- 98,112 ---- #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); + if (argc == 1 && strcmp(argv[0], "-l") == 0) { + ret = print_socktable(); + exit(ret); + } + if (argc >= 2 && strcmp(argv[0], "-F") == 0) { argc--; argv++; ret = parse_filter_params(argc, argv); exit(ret); }
*** 126,136 **** { fprintf(stderr, gettext( "Usage: soconfig -d <dir>\n" "\tsoconfig -f <file>\n" "\tsoconfig <fam> <type> <protocol> <path|module>\n" ! "\tsoconfig <fam> <type> <protocol>\n")); } /* * Parse all files in the given directory. */ --- 137,148 ---- { fprintf(stderr, gettext( "Usage: soconfig -d <dir>\n" "\tsoconfig -f <file>\n" "\tsoconfig <fam> <type> <protocol> <path|module>\n" ! "\tsoconfig <fam> <type> <protocol>\n" ! "\tsoconfig -l\n")); } /* * Parse all files in the given directory. */
*** 573,577 **** --- 585,645 ---- return (1); } free(socktuples); return (0); } + + /* + * Print the in-kernel socket configuration table + */ + + static int + print_socktable() + { + sockconfig_socktable_t sc_table; + int i; + + (void) memset(&sc_table, 0, sizeof (sockconfig_socktable_t)); + + /* get number of entries */ + if (_sockconfig(SOCKCONFIG_GET_SOCKTABLE, &sc_table) == -1) { + fprintf(stderr, + gettext("cannot get in-kernel socket table: %s\n"), + strerror(errno)); + return (-1); + } + if (sc_table.num_of_entries == 0) + return (0); + + sc_table.st_entries = calloc(sc_table.num_of_entries, + sizeof (sockconfig_socktable_entry_t)); + if (sc_table.st_entries == NULL) { + fprintf(stderr, gettext("out of memory\n")); + return (-1); + } + + /* get socket table entries */ + if (_sockconfig(SOCKCONFIG_GET_SOCKTABLE, &sc_table) == -1) { + fprintf(stderr, + gettext("cannot get in-kernel socket table: %s\n"), + strerror(errno)); + return (-1); + } + + printf("%6s %4s %5s %15s %15s %6s %6s\n", + "FAMILY", "TYPE", "PROTO", "STRDEV", "SOCKMOD", + "REFS", "FLAGS"); + for (i = 0; i < sc_table.num_of_entries; i++) { + printf("%6u %4u %5u %15s %15s %6u %#6x\n", + sc_table.st_entries[i].se_family, + sc_table.st_entries[i].se_type, + sc_table.st_entries[i].se_protocol, + (strcmp(sc_table.st_entries[i].se_modname, + "socktpi") == 0) ? + sc_table.st_entries[i].se_strdev : "-", + sc_table.st_entries[i].se_modname, + sc_table.st_entries[i].se_refcnt, + sc_table.st_entries[i].se_flags); + } + free(sc_table.st_entries); + return (0); + }