Modern net bsd kernel module

100 %
0 %
Information about Modern net bsd kernel module

Published on March 14, 2014

Author: masaruoki9


Modern NetBSD Kernel Module Mar 14, 2014 Masaru OKI (@masaru0714)

Contents Self introduction Introduction of kernel module Using kernel module Creating kernel module Problems

Self introduction Name 沖 勝 (Masaru OKI) oki@n.o History 1993 Port NetBSD to Sharp X68030 2001- IIJ SEIL team 2013- Stratosphere SDN related job Last week touch kernel module :-)

What is kernel module? Add or remove kernel function dynamically. ● filesystem ● device driver ● etc. No kernel module case, we need edit kernel configuration, compile kernel, replacement kernel binary, and reboot.

modern? historical: LKM (Loadable Kernel Module) reesrved entry in the table. fixed limit number of entries. no loading at bootstrap. modern: options MODULAR framework no reserved entry loading at bootstrap (see boot.cfg(5))

placement of kernel module /starnd/<arch>/<ver>/modules/<name>/<name>.kmod <arch> amd64, i386, <ver> 6.0, 6.1, <name> iscsi, zfs, compat_linux, wbsio, kernel module is also in NetBSD kernel binary, there are named ‘builtin module’.

Show status modstat(8) NAME CLASS SOURCE REFS SIZE REQUIRES accf_dataready misc builtin 0 - - accf_httpready misc builtin 0 - - acpiacad driver builtin 0 - - acpibat driver builtin 0 - - acpibut driver builtin 0 - - acpicpu driver builtin 0 - - acpidalb driver builtin 0 - - acpifan driver builtin 0 - -

Load kernel module modload <name> loading /stand/…/<name>/<name>.kmod. modload example modload <path> loading specified file. modload ~/src/example/example.kmod securitylevel <= 0 only.

Unload module modunload <name> unloading module specified name. modunload example Unloading module in use? error … fine, no problem. but no error, caused panic.

Loading at bootstrap /boot.cfg (amd64, i386 only) menu=Boot normally:rndseed /var/db/entropy-file;boot netbsd menu=Boot single user:rndseed /var/db/entropy-file;boot netbsd -s menu=Boot with module foo:load /foo.kmod;boot # always load example module load=/foo/bar/example.kmod

Writing kernel module, easy? Yes, easy! also easy panic reboot... but don’t worry. kernel module needs two definitions MODULE(<class>, <name>, <required>); <name>_modcmd()

MODULE() Declare kernel module. MODULE(<class>, <name>, <required>) class Module class. name name of module required required module string if needed MODULE(MODULE_CLASS_DRIVER, vnd, ”zlib”);

MODULE(): class MODULE_CLASS_DRIVER device driver MODULE_CLASS_EXEC executable image handler MODULE_CLASS_MISC moscellaneous module MODULE_CLASS_SECMODEL security model MODULE_CLASS_VFS virtual filesystem

<name>_modcmd() module command API. <name>_modcmd(<cmd>, <data>) value of <cmd> MODULE_CMD_INIT Initialize MODULE_CMD_FINI Clean-up MODULE_CMD_AUTOUNLOAD Notify (option) MODULE_CMD_STAT Status (not implemented)

Writing Makefile Simple. KMOD= example SRCS= example.c .include <>

Other item requires for compile Kernel source needed. ● extract to /usr/src/sys ● other place, specify e.g. S=/foo/src

Example (do nothing) test by modload, modstat and modunload. #include <sys/module.h> MODULE(MODULE_CLASS_MISC, example, NULL); static int example_modcmd(modcmd_t cmd, void *arg) { return 0; }

Add sysctl static struct sysctl_log *sysctl_log; static int testvar; MODULE(MODULE_CLASS_MISC, example, NULL); static int example_modcmd(modcmd_t cmd, void *arg) { switch (cmd) { case MODULE_CMD_INIT: sysctl_createv(&sysctl_log, 0, NULL, NULL, CTLFLAG_READWRITE, CTLTYPE_INT, “example”, SYSCTL_DESCR(“Test.”), NULL, 0, &testvar, 0, CTL_HW, CTL_CREATE, CTL_EOL); break; case MODULE_CMD_FINI: sysctl_teardown(&sysctl_log); break; } return 0; } hw.example is created by load module. it can read/write by sysctl hw.example is destroyed by unload module.

Problems No parameter with loading module static resource allocation at bootstrap case workaround: after bootstrap, use sysctl? kenv is available at FreeBSD (/boot/loader.conf) No API for create device node (/dev/<name>) major is fixed at loading module mknod in module? (not recommended by module(7)) mknod -l?

Not only API, but commands are different. Appendix: compares with other OSs OS NetBSD FreeBSD Linux suffix .kmod .ko .ko load modload kldload insmod unload modunload kldunload rmmod status modstat kldstat lsmod placement /stand/... /boot/kernel/ /lib/modules/...

Add a comment

Related presentations

Related pages

Introduction to NetBSD loadable kernel modules - Unix-AG

Introduction. Loadable kernel modules (LKMs) are quite popular on most modern operating systems such as GNU/Linux, FreeBSD and of course Microsoft ...
Read more

GitHub - freebsd/freebsd: FreeBSD src tree

freebsd - FreeBSD src tree. Skip to ... ino64 projects/intel_net_refactor projects /iosched ... build and install the kernel and the modules ...
Read more

View, load, or unload a kernel module - Reed Media

... load, or unload a kernel module Edit; RecentChanges; ... load and unload kernel modules on each BSD system but should be aware that kernel modules ...
Read more

Kernel modules - ArchWiki - Arch Linux

Kernel modules can be ... # Load virtio-net.ko at boot virtio-net. See man modules-load ... To pass a parameter to a kernel module, ...
Read more

4. Comparing BSD and Linux - The FreeBSD Project

Comparing BSD and Linux; ... The BSD kernels are developed and ... BSD handles library version upgrades by providing compatibility modules for ...
Read more

NetBSD - Wikipedia, the free encyclopedia

All of the NetBSD kernel and most of the core ... As with other BSD projects, NetBSD separates those in its ... Rewritten Loadable kernel module ...
Read more

FreeBSD - Wikipedia, the free encyclopedia

Monolithic with dynamically loadable modules: Userland: BSD: ... public version of BSD – was released. After releasing Net ... FreeBSD kernel has also a ...
Read more

NetBSD Documentation: Kernel

NetBSD Documentation: Kernel ... Integrating ATM Networking into BSD; ... Introduction to NetBSD loadable kernel modules;
Read more