Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/sysctl Moved from usr.sbin/sysctl/sysctl.c,v



details:   https://anonhg.NetBSD.org/src/rev/22b7413304d4
branches:  trunk
changeset: 480639:22b7413304d4
user:      itojun <itojun%NetBSD.org@localhost>
date:      Mon Jan 17 02:32:06 2000 +0000

description:
Moved from usr.sbin/sysctl/sysctl.c,v

diffstat:

 sbin/sysctl/sysctl.c |  1096 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 1096 insertions(+), 0 deletions(-)

diffs (truncated from 1100 to 300 lines):

diff -r e5af9d2113d0 -r 22b7413304d4 sbin/sysctl/sysctl.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/sysctl/sysctl.c      Mon Jan 17 02:32:06 2000 +0000
@@ -0,0 +1,1096 @@
+/*     $NetBSD: sysctl.c,v 1.23 2000/01/17 02:32:06 itojun Exp $       */
+
+/*
+ * Copyright (c) 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__COPYRIGHT(
+"@(#) Copyright (c) 1993\n\
+       The Regents of the University of California.  All rights reserved.\n");
+#endif /* not lint */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)sysctl.c   8.1 (Berkeley) 6/6/93";
+#else
+__RCSID("$NetBSD: sysctl.c,v 1.23 2000/01/17 02:32:06 itojun Exp $");
+#endif
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/gmon.h>
+#include <sys/stat.h>
+#include <sys/sysctl.h>
+#include <sys/socket.h>
+#include <sys/mount.h>
+#include <sys/mbuf.h>
+#include <sys/resource.h>
+#include <vm/vm_param.h>
+#include <machine/cpu.h>
+
+#include <ufs/ufs/dinode.h>
+#include <ufs/ufs/dir.h>
+#include <ufs/ffs/fs.h>
+#include <ufs/ffs/ffs_extern.h>
+
+#include <nfs/rpcv2.h>
+#include <nfs/nfsproto.h>
+#include <nfs/nfs.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_icmp.h>
+#include <netinet/icmp_var.h>
+#include <netinet/ip_var.h>
+#include <netinet/udp.h>
+#include <netinet/udp_var.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
+
+#ifdef INET6
+#include <netinet6/ip6.h>
+#include <netinet6/icmp6.h>
+#include <netinet6/ip6_var.h>
+#include <netinet6/udp6.h>
+#include <netinet6/udp6_var.h>
+#ifdef TCP6
+#include <netinet6/tcp6.h>
+#include <netinet6/tcp6_timer.h>
+#include <netinet6/tcp6_var.h>
+#endif
+#include <netinet6/pim6_var.h>
+#endif /* INET6 */
+
+#ifdef IPSEC
+#include <net/route.h>
+#include <netinet6/ipsec.h>
+#include <netkey/key_var.h>
+#endif /* IPSEC */
+
+#include <err.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+struct ctlname topname[] = CTL_NAMES;
+struct ctlname kernname[] = CTL_KERN_NAMES;
+struct ctlname vmname[] = CTL_VM_NAMES;
+struct ctlname vfsname[] = CTL_VFS_NAMES;
+struct ctlname netname[] = CTL_NET_NAMES;
+struct ctlname hwname[] = CTL_HW_NAMES;
+struct ctlname username[] = CTL_USER_NAMES;
+struct ctlname ddbname[] = CTL_DDB_NAMES;
+struct ctlname debugname[CTL_DEBUG_MAXID];
+#ifdef CTL_MACHDEP_NAMES
+struct ctlname machdepname[] = CTL_MACHDEP_NAMES;
+#endif
+/* this one is dummy, it's used only for '-a' or '-A' */
+struct ctlname procname[] = { {0, 0}, {"curproc", CTLTYPE_NODE} };
+
+char names[BUFSIZ];
+
+struct list {
+       struct  ctlname *list;
+       int     size;
+};
+struct list toplist = { topname, CTL_MAXID };
+struct list secondlevel[] = {
+       { 0, 0 },                       /* CTL_UNSPEC */
+       { kernname, KERN_MAXID },       /* CTL_KERN */
+       { vmname, VM_MAXID },           /* CTL_VM */
+       { vfsname, VFS_MAXID },         /* CTL_VFS */
+       { netname, NET_MAXID },         /* CTL_NET */
+       { 0, CTL_DEBUG_MAXID },         /* CTL_DEBUG */
+       { hwname, HW_MAXID },           /* CTL_HW */
+#ifdef CTL_MACHDEP_NAMES
+       { machdepname, CPU_MAXID },     /* CTL_MACHDEP */
+#else
+       { 0, 0 },                       /* CTL_MACHDEP */
+#endif
+       { username, USER_MAXID },       /* CTL_USER_NAMES */
+       { ddbname, DDBCTL_MAXID },      /* CTL_DDB_NAMES */
+       { procname, 2 },                /* dummy name */
+};
+
+int    Aflag, aflag, nflag, wflag;
+
+/*
+ * Variables requiring special processing.
+ */
+#define        CLOCK           0x00000001
+#define        BOOTTIME        0x00000002
+#define        CONSDEV         0x00000004
+
+/*
+ * A dummy type for limits, which requires special parsing
+ */
+#define CTLTYPE_LIMIT  ((~0x1) << 31)
+
+int main __P((int, char *[]));
+
+static void listall __P((char *, struct list *));
+static void parse __P((char *, int));
+static void debuginit __P((void));
+static int sysctl_inet __P((char *, char **, int[], int, int *));
+#ifdef INET6
+static int sysctl_inet6 __P((char *, char **, int[], int, int *));
+#endif
+#ifdef IPSEC
+static int sysctl_key __P((char *, char **, int[], int, int *));
+#endif
+static int sysctl_vfs __P((char *, char **, int[], int, int *));
+static int sysctl_vfsgen __P((char *, char **, int[], int, int *));
+static int sysctl_mbuf __P((char *, char **, int[], int, int *));
+static int sysctl_proc __P((char *, char **, int[], int, int *));
+static int findname __P((char *, char *, char **, struct list *));
+static void usage __P((void));
+
+int
+main(argc, argv)
+       int argc;
+       char *argv[];
+{
+       extern char *optarg;
+       extern int optind;
+       int ch, lvl1;
+
+       while ((ch = getopt(argc, argv, "Aanw")) != -1) {
+               switch (ch) {
+
+               case 'A':
+                       Aflag = 1;
+                       break;
+
+               case 'a':
+                       aflag = 1;
+                       break;
+
+               case 'n':
+                       nflag = 1;
+                       break;
+
+               case 'w':
+                       wflag = 1;
+                       break;
+
+               default:
+                       usage();
+               }
+       }
+       argc -= optind;
+       argv += optind;
+
+       if (Aflag || aflag) {
+               debuginit();
+               for (lvl1 = 1; lvl1 < CTL_MAXID; lvl1++)
+                       listall(topname[lvl1].ctl_name, &secondlevel[lvl1]);
+               return 0;
+       }
+       if (argc == 0)
+               usage();
+       while (argc-- > 0)
+               parse(*argv++, 1);
+       return 0;
+}
+
+/*
+ * List all variables known to the system.
+ */
+static void
+listall(prefix, lp)
+       char *prefix;
+       struct list *lp;
+{
+       int lvl2;
+       char *cp, name[BUFSIZ];
+
+       if (lp->list == 0)
+               return;
+       strcpy(name, prefix);
+       cp = &name[strlen(name)];
+       *cp++ = '.';
+       for (lvl2 = 0; lvl2 < lp->size; lvl2++) {
+               if (lp->list[lvl2].ctl_name == 0)
+                       continue;
+               strcpy(cp, lp->list[lvl2].ctl_name);
+               parse(name, Aflag);
+       }
+}
+
+/*
+ * Parse a name into a MIB entry.
+ * Lookup and print out the MIB entry if it exists.
+ * Set a new value if requested.
+ */
+static void
+parse(string, flags)
+       char *string;
+       int flags;
+{
+       int indx, type, state, len;
+       int special = 0;
+       void *newval = 0;
+       int intval, newsize = 0;
+       quad_t quadval;
+       size_t size;
+       struct list *lp;
+       int mib[CTL_MAXNAME];
+       char *cp, *bufp, buf[BUFSIZ];
+
+       bufp = buf;
+       snprintf(buf, BUFSIZ, "%s", string);
+       if ((cp = strchr(string, '=')) != NULL) {
+               if (!wflag)
+                       errx(2, "Must specify -w to set variables");
+               *strchr(buf, '=') = '\0';
+               *cp++ = '\0';
+               while (isspace((unsigned char) *cp))
+                       cp++;
+               newval = cp;
+               newsize = strlen(cp);
+       }
+       if ((indx = findname(string, "top", &bufp, &toplist)) == -1)
+               return;
+       mib[0] = indx;
+       if (indx == CTL_DEBUG)
+               debuginit();
+       if (mib[0] == CTL_PROC) {
+               type = CTLTYPE_NODE;
+               len = 1;
+       } else {



Home | Main Index | Thread Index | Old Index