Subject: Easier vendor specific sysctl
To: None <tech-kern@netbsd.org>
From: None <bdev@hss.hns.com>
List: tech-kern
Date: 11/28/2003 02:59:02
--0__=EABBE778DFE75CFE8f9e8a93df938690918cEABBE778DFE75CFE
Content-type: text/plain; charset=US-ASCII
Hi all !
I was adding a vendor specific sysctl to my system :
NetBSD bobthebuilder.hss.hns.com 1.6.1 NetBSD 1.6.1 (GENERIC) #0: Tue Apr
8 12:05:52 UTC 2003
autobuild@tgm.daemon.org:/autobuild/netbsd-1-6/i386/OBJ/autobuild/netbsd-1-6/src/sys/arch/i386/compile/GENERIC
i386)
and was wondering that there was no prepared interface to insert vendor
specific sysctls. I have implemented the following generic code to the
system
for kern_sysctl.c
--- /sys/kern/kern_sysctl.c Tue May 14 08:28:32 2002
+++ kern_sysctl.c Fri Nov 28 02:46:35 2003
@@ -120,6 +120,7 @@
#if NPTY > 0
static int sysctl_pty(void *, size_t *, void *, size_t);
#endif
+static int vendor_specific_sysctl(int *, u_int, void *, size_t *, void *, size_t , struct proc *) ;
/*
* The `sysctl_memlock' is intended to keep too many processes from
@@ -208,6 +209,11 @@
case CTL_EMUL:
fn = emul_sysctl;
break;
+
+ case CTL_VENDOR:
+ fn = vendor_specific_sysctl ;
+ break ;
+
default:
return (EOPNOTSUPP);
}
@@ -1969,3 +1975,35 @@
return (EOPNOTSUPP);
}
}
+
+
+
+static int
+vendor_specific_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
+ void *newp, size_t newlen, struct proc *p)
+ {
+
+ sysctlfn *vendor_callbacks[] = CTL_VENDOR_FUNC_MAP ;
+ int num_of_vendors ;
+ int vendor_name ;
+
+ /* All members here are nodes */
+ if ( namelen < 2)
+ return (ENOTDIR);
+
+
+ num_of_vendors = sizeof (vendor_callbacks) / sizeof (sysctlfn *) ;
+
+ vendor_name = name[0] ;
+
+ if (vendor_name > (num_of_vendors - 1))
+ return (EOPNOTSUPP);
+
+
+
+ if (vendor_callbacks[vendor_name])
+ return ((*(vendor_callbacks[vendor_name]))(name+1,namelen-1,oldp,oldlenp,newp,newlen,p)) ;
+ else
+ return (EOPNOTSUPP);
+
+ }
For sysctl.h
--- /sys/sys/sysctl.h Wed Mar 20 05:53:46 2002
+++ sysctl.h Fri Nov 28 02:39:27 2003
@@ -642,6 +642,24 @@
{ "linux", CTLTYPE_NODE }, \
}
+
+#define CTL_VENDOR_FOO 1 /* FOO Corporation */
+#define CTL_VENDOR_MAXID 2 /* Maxid */
+
+/* CTL_VENDOR definitions */
+#define CTL_VENDOR_NAMES { \
+ { 0, 0 }, \
+ { "foo", CTLTYPE_NODE }, \
+}
+
+#define CTL_VENDOR_FUNC_MAP { \
+ 0, \
+ foo_sysctl, \
+}
+
+
+
+
#ifdef _KERNEL
/*
* CTL_DEBUG variables.
@@ -708,6 +726,9 @@
int net_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *);
int cpu_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *);
int emul_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *);
+
+/* Vendor specifc callbacks */
+int foo_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *);
/* ddb_sysctl() declared in ddb_var.h */
I was thinking that it would be a good idea to actually include this in the main source tree ( without the foo corporation of course ) as it would
allow us to control vendor specific ctls in a more unified
manner directly from sysctl.h and we would not need to change kern_sysctl.c for vendor specifc changes.
Regards
Bashuman
(See attached file: sysctl.h.diff)(See attached file: kern_sysctl.c.diff)
"DISCLAIMER: This message is proprietary to Hughes Software Systems Limited
(HSS) and is intended solely for the use of the individual to whom it is
addressed. It may contain privileged or confidential information and
should not be circulated or used for any purpose other than for what it is
intended. If you have received this message in error, please notify the
originator immediately. If you are not the intended recipient, you are
notified that you are strictly prohibited from using, copying, altering, or
disclosing the contents of this message. HSS accepts no responsibility for
loss or damage arising from the use of the information transmitted by this
email including damage from virus."
--0__=EABBE778DFE75CFE8f9e8a93df938690918cEABBE778DFE75CFE
Content-type: application/octet-stream;
name="sysctl.h.diff"
Content-Disposition: attachment; filename="sysctl.h.diff"
Content-transfer-encoding: base64
LS0tIC9zeXMvc3lzL3N5c2N0bC5oCVdlZCBNYXIgMjAgMDU6NTM6NDYgMjAwMgorKysgc3lzY3Rs
LmgJRnJpIE5vdiAyOCAwMjozOToyNyAyMDAzCkBAIC02NDIsNiArNjQyLDI0IEBACiAJeyAibGlu
dXgiLCBDVExUWVBFX05PREUgfSwgXAogfQogCisKKyNkZWZpbmUgQ1RMX1ZFTkRPUl9GT08JMSAv
KiBGT08gQ29ycG9yYXRpb24gKi8KKyNkZWZpbmUgQ1RMX1ZFTkRPUl9NQVhJRCAyIC8qIE1heGlk
ICovCisKKy8qIENUTF9WRU5ET1IgZGVmaW5pdGlvbnMgKi8KKyNkZWZpbmUJQ1RMX1ZFTkRPUl9O
QU1FUyB7IFwKKwl7IDAsIDAgfSwgXAorCXsgImZvbyIsIENUTFRZUEVfTk9ERSB9LCBcCit9CisK
KyNkZWZpbmUgQ1RMX1ZFTkRPUl9GVU5DX01BUCB7IFwKKwkwLCBcCisJZm9vX3N5c2N0bCwgXAor
fQorCQorCSAKKworCiAjaWZkZWYJX0tFUk5FTAogLyoKICAqIENUTF9ERUJVRyB2YXJpYWJsZXMu
CkBAIC03MDgsNiArNzI2LDkgQEAKIGludCBuZXRfc3lzY3RsKGludCAqLCB1X2ludCwgdm9pZCAq
LCBzaXplX3QgKiwgdm9pZCAqLCBzaXplX3QsIHN0cnVjdCBwcm9jICopOwogaW50IGNwdV9zeXNj
dGwoaW50ICosIHVfaW50LCB2b2lkICosIHNpemVfdCAqLCB2b2lkICosIHNpemVfdCwgc3RydWN0
IHByb2MgKik7CiBpbnQgZW11bF9zeXNjdGwoaW50ICosIHVfaW50LCB2b2lkICosIHNpemVfdCAq
LCB2b2lkICosIHNpemVfdCwgc3RydWN0IHByb2MgKik7CisKKy8qIFZlbmRvciBzcGVjaWZjIGNh
bGxiYWNrcyAqLworaW50IGZvb19zeXNjdGwoaW50ICosIHVfaW50LCB2b2lkICosIHNpemVfdCAq
LCB2b2lkICosIHNpemVfdCwgc3RydWN0IHByb2MgKik7CiAKIC8qIGRkYl9zeXNjdGwoKSBkZWNs
YXJlZCBpbiBkZGJfdmFyLmggKi8KIAo=
--0__=EABBE778DFE75CFE8f9e8a93df938690918cEABBE778DFE75CFE
Content-type: application/octet-stream;
name="kern_sysctl.c.diff"
Content-Disposition: attachment; filename="kern_sysctl.c.diff"
Content-transfer-encoding: base64
LS0tIC9zeXMva2Vybi9rZXJuX3N5c2N0bC5jCVR1ZSBNYXkgMTQgMDg6Mjg6MzIgMjAwMgorKysg
a2Vybl9zeXNjdGwuYwlGcmkgTm92IDI4IDAyOjQ2OjM1IDIwMDMKQEAgLTEyMCw2ICsxMjAsNyBA
QAogI2lmIE5QVFkgPiAwCiBzdGF0aWMgaW50IHN5c2N0bF9wdHkodm9pZCAqLCBzaXplX3QgKiwg
dm9pZCAqLCBzaXplX3QpOwogI2VuZGlmCitzdGF0aWMgaW50IHZlbmRvcl9zcGVjaWZpY19zeXNj
dGwoaW50ICosIHVfaW50LCB2b2lkICosIHNpemVfdCAqLCB2b2lkICosIHNpemVfdCAsIHN0cnVj
dCBwcm9jICopIDsKIAogLyoKICAqIFRoZSBgc3lzY3RsX21lbWxvY2snIGlzIGludGVuZGVkIHRv
IGtlZXAgdG9vIG1hbnkgcHJvY2Vzc2VzIGZyb20KQEAgLTIwOCw2ICsyMDksMTEgQEAKIAljYXNl
IENUTF9FTVVMOgogCQlmbiA9IGVtdWxfc3lzY3RsOwogCQlicmVhazsKKworCWNhc2UgQ1RMX1ZF
TkRPUjoKKwkJZm4gPSB2ZW5kb3Jfc3BlY2lmaWNfc3lzY3RsIDsKKwkJYnJlYWsgOworCiAJZGVm
YXVsdDoKIAkJcmV0dXJuIChFT1BOT1RTVVBQKTsKIAl9CkBAIC0xOTY5LDMgKzE5NzUsMzUgQEAK
IAkJcmV0dXJuIChFT1BOT1RTVVBQKTsKIAl9CiB9CisKKworCitzdGF0a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