From owner-freebsd-newbies Fri Apr 23 14:13:17 1999 Delivered-To: freebsd-newbies@freebsd.org Received: from mail03-oak.pilot.net (mail-oak-3.pilot.net [198.232.147.18]) by hub.freebsd.org (Postfix) with ESMTP id 8AE0214D3B for ; Fri, 23 Apr 1999 14:13:09 -0700 (PDT) (envelope-from honig@sprynet.com) Received: from idt.com (unknown-5-20.idt.com [157.165.5.20] (may be forged)) by mail03-oak.pilot.net with ESMTP id OAA10978 for ; Fri, 23 Apr 1999 14:12:38 -0700 (PDT) Received: from stgsmtp.corp.idt.com ([157.165.146.162]) by idt.com (8.8.5/8.7.5) with SMTP id OAA03030 for ; Fri, 23 Apr 1999 14:10:27 -0700 (PDT) Received: from [157.165.146.225] (HELO sprynet.com) by stgsmtp.corp.idt.com (Stalker SMTP Server 1.7) with ESMTP id S.0000101351 for ; Fri, 23 Apr 1999 13:13:24 -0800 Message-ID: <3720E1A1.64266105@sprynet.com> Date: Fri, 23 Apr 1999 14:09:54 -0700 From: Claude Shannon Organization: Entropy, Inc X-Mailer: Mozilla 4.5 [en] (X11; U; FreeBSD 3.0-RELEASE i386) X-Accept-Language: en MIME-Version: 1.0 To: freebsd-newbies@freebsd.org Subject: a tutorial (donation to freebsd) on sysctl Content-Type: multipart/mixed; boundary="------------C7DF50165012C069796EFA4F" Sender: owner-freebsd-newbies@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org This is a multi-part message in MIME format. --------------C7DF50165012C069796EFA4F Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I've attached a short html file which explains the sysctl interface and kernel hacking to newbies (like myself, who just figured it out). I have tried these instructions, they work. I used SunOS for years and I love BSD. David Honig honig@sprynet.com --------------C7DF50165012C069796EFA4F Content-Type: text/html; charset=us-ascii; name="sysctl.html" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="sysctl.html"

How to Add  sysctl Variables to Your FreeBSD 3. Kernel

With BSD, you have the kernel source, and so can experiment with the kernel.  With BSD's sysctl tool, you can get and set kernel variables on a running system.


Adding a Variable          Adding a Root Node          sysctl          Kernel Building

Adding a Sysctl Variable to an Existing Parent Node


Find the kernel file you are interested in.  I will choose /usr/src/sys/i386/isa/random_machdep.c.

In that file, add the following:

#include <sys/kernel.h>
#include <sys/sysctrl.h>
Now declare a variable you want to monitor and/or control, like so:
static int my_var=0;
SYSCTL_INT( _net, OID_AUTO, my_var, CTLFLAG_RW, &my_var, 0, "");
Note that there are other "parent" nodes besides _net.  You can make your own.

Note that there are other types of variables:  See /usr/src/sys/sys/sysctl.h
(link is good only if this page is hosted on a BSD system!)

Finally, rebuild the kernel and reboot.  The new variable should be visible with the sysctl utility.


How to Declare a New Root Parent Node:


In /usr/src/sys/sys/sysctl.h add a new CTL_node like so:

/*
 * Top-level identifiers
 */
#define CTL_UNSPEC      0               /* unused */
#define CTL_KERN        1               /* "high kernel": proc, limits */
#define CTL_VM          2               /* virtual memory */
#define CTL_VFS         3               /* file system, mount type is next */
#define CTL_NET         4               /* network, see socket.h */
#define CTL_DEBUG       5               /* debugging parameters */
#define CTL_HW          6               /* generic cpu/io */
#define CTL_MACHDEP     7               /* machine dependent */
#define CTL_USER        8               /* user-level */
#define CTL_P1003_1B    9               /* POSIX 1003.1B */
#define CTL_EXPER  10     /* DAH EXPERIMENTAL */
#define CTL_MAXID      11              /* number of valid top-level ids */

/* DAH MODIFIED TO INCLUDE "EXPER" NODE *******/
#define CTL_NAMES { \
        { 0, 0 }, \
        { "kern", CTLTYPE_NODE }, \
        { "vm", CTLTYPE_NODE }, \
        { "vfs", CTLTYPE_NODE }, \
        { "net", CTLTYPE_NODE }, \
        { "debug", CTLTYPE_NODE }, \
        { "hw", CTLTYPE_NODE }, \
        { "machdep", CTLTYPE_NODE }, \
        { "user", CTLTYPE_NODE }, \
        { "p1003_1b", CTLTYPE_NODE }, \
        { "exper", CTLTYPE_NODE }, \
}
 

Then initialize that new node without a parent, like so:

SYSCTL_NODE( , CTL_EXPER, exper, CTLFLAG_RW, 0, "description");
(As seen in /usr/src/sys/kern/kern_mib.c)


KERNEL BUILDING


To reconfigure and rebuild a kernel, do the following.
To rebuild after a simple source-file change, start after the config step.

# cd /usr/src/sys/i386/conf
#      cp CURRENT NEWKERN
#      edit NEWKERN
# config NEWKERN

# cd ../../compile/NEWKERN
# make depend
# make
# make install
# reboot
(old kernel is /kernel.old if you need it!)


Sysctl

Sysctl is a command-line utility for inspecting and setting kernel variables.  There is also a sysctl API.

sysctl variable
sysctl -a
sysctl -w var=value               note: you must be root to set a variable



author --------------C7DF50165012C069796EFA4F-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-newbies" in the body of the message