SlideShare a Scribd company logo
1 of 20
Download to read offline
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 <bsd.kmodule.mk>
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/...

More Related Content

What's hot

Systemd: the modern Linux init system you will learn to love
Systemd: the modern Linux init system you will learn to loveSystemd: the modern Linux init system you will learn to love
Systemd: the modern Linux init system you will learn to loveAlison Chaiken
 
FreeBSD and Drivers
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and DriversKernel TLV
 
2. Vagin. Linux containers. June 01, 2013
2. Vagin. Linux containers. June 01, 20132. Vagin. Linux containers. June 01, 2013
2. Vagin. Linux containers. June 01, 2013ru-fedora-moscow-2013
 
Kernel Recipes 2015 - Porting Linux to a new processor architecture
Kernel Recipes 2015 - Porting Linux to a new processor architectureKernel Recipes 2015 - Porting Linux to a new processor architecture
Kernel Recipes 2015 - Porting Linux to a new processor architectureAnne Nicolas
 
Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup. Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup. Neeraj Shrimali
 
Containers with systemd-nspawn
Containers with systemd-nspawnContainers with systemd-nspawn
Containers with systemd-nspawnGábor Nyers
 
Full system roll-back and systemd in SUSE Linux Enterprise 12
Full system roll-back and systemd in SUSE Linux Enterprise 12Full system roll-back and systemd in SUSE Linux Enterprise 12
Full system roll-back and systemd in SUSE Linux Enterprise 12Gábor Nyers
 
Kernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkKernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkAnne Nicolas
 
Linux Locking Mechanisms
Linux Locking MechanismsLinux Locking Mechanisms
Linux Locking MechanismsKernel TLV
 
Systemd for developers
Systemd for developersSystemd for developers
Systemd for developersAlison Chaiken
 
Linux cgroups and namespaces
Linux cgroups and namespacesLinux cgroups and namespaces
Linux cgroups and namespacesLocaweb
 
Linux Kernel Init Process
Linux Kernel Init ProcessLinux Kernel Init Process
Linux Kernel Init ProcessKernel TLV
 
Introduction to linux containers
Introduction to linux containersIntroduction to linux containers
Introduction to linux containersGoogle
 
Cgroup resource mgmt_v1
Cgroup resource mgmt_v1Cgroup resource mgmt_v1
Cgroup resource mgmt_v1sprdd
 
Linux containers-namespaces(Dec 2014)
Linux containers-namespaces(Dec 2014)Linux containers-namespaces(Dec 2014)
Linux containers-namespaces(Dec 2014)Ralf Dannert
 
Linux Containers From Scratch
Linux Containers From ScratchLinux Containers From Scratch
Linux Containers From Scratchjoshuasoundcloud
 
Kvm performance optimization for ubuntu
Kvm performance optimization for ubuntuKvm performance optimization for ubuntu
Kvm performance optimization for ubuntuSim Janghoon
 

What's hot (20)

Systemd: the modern Linux init system you will learn to love
Systemd: the modern Linux init system you will learn to loveSystemd: the modern Linux init system you will learn to love
Systemd: the modern Linux init system you will learn to love
 
FreeBSD and Drivers
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and Drivers
 
2. Vagin. Linux containers. June 01, 2013
2. Vagin. Linux containers. June 01, 20132. Vagin. Linux containers. June 01, 2013
2. Vagin. Linux containers. June 01, 2013
 
Kernel Recipes 2015 - Porting Linux to a new processor architecture
Kernel Recipes 2015 - Porting Linux to a new processor architectureKernel Recipes 2015 - Porting Linux to a new processor architecture
Kernel Recipes 2015 - Porting Linux to a new processor architecture
 
Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup. Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup.
 
Containers with systemd-nspawn
Containers with systemd-nspawnContainers with systemd-nspawn
Containers with systemd-nspawn
 
Full system roll-back and systemd in SUSE Linux Enterprise 12
Full system roll-back and systemd in SUSE Linux Enterprise 12Full system roll-back and systemd in SUSE Linux Enterprise 12
Full system roll-back and systemd in SUSE Linux Enterprise 12
 
Kernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkKernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver framework
 
First steps on CentOs7
First steps on CentOs7First steps on CentOs7
First steps on CentOs7
 
Linux Locking Mechanisms
Linux Locking MechanismsLinux Locking Mechanisms
Linux Locking Mechanisms
 
Systemd for developers
Systemd for developersSystemd for developers
Systemd for developers
 
Linux cgroups and namespaces
Linux cgroups and namespacesLinux cgroups and namespaces
Linux cgroups and namespaces
 
Basic of Systemd
Basic of SystemdBasic of Systemd
Basic of Systemd
 
systemd
systemdsystemd
systemd
 
Linux Kernel Init Process
Linux Kernel Init ProcessLinux Kernel Init Process
Linux Kernel Init Process
 
Introduction to linux containers
Introduction to linux containersIntroduction to linux containers
Introduction to linux containers
 
Cgroup resource mgmt_v1
Cgroup resource mgmt_v1Cgroup resource mgmt_v1
Cgroup resource mgmt_v1
 
Linux containers-namespaces(Dec 2014)
Linux containers-namespaces(Dec 2014)Linux containers-namespaces(Dec 2014)
Linux containers-namespaces(Dec 2014)
 
Linux Containers From Scratch
Linux Containers From ScratchLinux Containers From Scratch
Linux Containers From Scratch
 
Kvm performance optimization for ubuntu
Kvm performance optimization for ubuntuKvm performance optimization for ubuntu
Kvm performance optimization for ubuntu
 

Viewers also liked

NetBSD/evbarm (APC9750) への道
NetBSD/evbarm (APC9750) への道NetBSD/evbarm (APC9750) への道
NetBSD/evbarm (APC9750) への道tokudahiroshi
 
Running lagopus on Xeon D
Running lagopus on Xeon DRunning lagopus on Xeon D
Running lagopus on Xeon DMasaru Oki
 
Ngfkbm intro for pastor dudley
Ngfkbm intro for pastor dudleyNgfkbm intro for pastor dudley
Ngfkbm intro for pastor dudleyjentracy2
 
8 Colorful Ideas for My Country (Filipinization)
8 Colorful Ideas for My Country (Filipinization)8 Colorful Ideas for My Country (Filipinization)
8 Colorful Ideas for My Country (Filipinization)Jose Radin Garduque
 
Islamic Art by Jose Radin L. Garduque
Islamic Art by Jose Radin L. GarduqueIslamic Art by Jose Radin L. Garduque
Islamic Art by Jose Radin L. GarduqueJose Radin Garduque
 
Volcanic Eruption Communication Model (Final Revision)
Volcanic Eruption Communication Model (Final Revision)Volcanic Eruption Communication Model (Final Revision)
Volcanic Eruption Communication Model (Final Revision)Jose Radin Garduque
 
Singapore (Socio-Cultural Setting)
Singapore (Socio-Cultural Setting)Singapore (Socio-Cultural Setting)
Singapore (Socio-Cultural Setting)Jose Radin Garduque
 
8 Questions to My Opponents in Pilipinas Debates 2016
8 Questions to My Opponents in Pilipinas Debates 20168 Questions to My Opponents in Pilipinas Debates 2016
8 Questions to My Opponents in Pilipinas Debates 2016Jose Radin Garduque
 
Lagopus on small arm board
Lagopus on small arm boardLagopus on small arm board
Lagopus on small arm boardMasaru Oki
 
PARADIGMAS URBANOS. Guía sitio 2016
PARADIGMAS URBANOS. Guía sitio 2016PARADIGMAS URBANOS. Guía sitio 2016
PARADIGMAS URBANOS. Guía sitio 2016Arquitectura Civil
 
Project and pitch in 10 min
Project and pitch in 10 minProject and pitch in 10 min
Project and pitch in 10 minWALID RAS
 

Viewers also liked (20)

NetBSD/evbarm (APC9750) への道
NetBSD/evbarm (APC9750) への道NetBSD/evbarm (APC9750) への道
NetBSD/evbarm (APC9750) への道
 
Running lagopus on Xeon D
Running lagopus on Xeon DRunning lagopus on Xeon D
Running lagopus on Xeon D
 
Ngfkbm intro for pastor dudley
Ngfkbm intro for pastor dudleyNgfkbm intro for pastor dudley
Ngfkbm intro for pastor dudley
 
K overview
K overviewK overview
K overview
 
8 Colorful Ideas for My Country (Filipinization)
8 Colorful Ideas for My Country (Filipinization)8 Colorful Ideas for My Country (Filipinization)
8 Colorful Ideas for My Country (Filipinization)
 
Texto de tic's franccy
Texto de tic's franccyTexto de tic's franccy
Texto de tic's franccy
 
Dracula presentation
Dracula presentationDracula presentation
Dracula presentation
 
apps of nanotech
apps of nanotechapps of nanotech
apps of nanotech
 
Singapore (Political Setting)
Singapore (Political Setting)Singapore (Political Setting)
Singapore (Political Setting)
 
Islamic Art by Jose Radin L. Garduque
Islamic Art by Jose Radin L. GarduqueIslamic Art by Jose Radin L. Garduque
Islamic Art by Jose Radin L. Garduque
 
Volcanic Eruption Communication Model (Final Revision)
Volcanic Eruption Communication Model (Final Revision)Volcanic Eruption Communication Model (Final Revision)
Volcanic Eruption Communication Model (Final Revision)
 
Singapore (Socio-Cultural Setting)
Singapore (Socio-Cultural Setting)Singapore (Socio-Cultural Setting)
Singapore (Socio-Cultural Setting)
 
8 Questions to My Opponents in Pilipinas Debates 2016
8 Questions to My Opponents in Pilipinas Debates 20168 Questions to My Opponents in Pilipinas Debates 2016
8 Questions to My Opponents in Pilipinas Debates 2016
 
Myanmar (Political Setting)
Myanmar (Political Setting)Myanmar (Political Setting)
Myanmar (Political Setting)
 
Lagopus on small arm board
Lagopus on small arm boardLagopus on small arm board
Lagopus on small arm board
 
bls
blsbls
bls
 
PARADIGMAS URBANOS. Guía sitio 2016
PARADIGMAS URBANOS. Guía sitio 2016PARADIGMAS URBANOS. Guía sitio 2016
PARADIGMAS URBANOS. Guía sitio 2016
 
Myanmar: Socio-Cultural Setting
Myanmar: Socio-Cultural SettingMyanmar: Socio-Cultural Setting
Myanmar: Socio-Cultural Setting
 
Cambodia
CambodiaCambodia
Cambodia
 
Project and pitch in 10 min
Project and pitch in 10 minProject and pitch in 10 min
Project and pitch in 10 min
 

Similar to Modern net bsd kernel module

Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modulesdibyajyotig
 
Advanced Node.JS Meetup
Advanced Node.JS MeetupAdvanced Node.JS Meetup
Advanced Node.JS MeetupLINAGORA
 
Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel ProgrammingNalin Sharma
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modulesHao-Ran Liu
 
Java 9 Module System
Java 9 Module SystemJava 9 Module System
Java 9 Module SystemHasan Ünal
 
Kernel module programming
Kernel module programmingKernel module programming
Kernel module programmingVandana Salve
 
Lecture 5 Kernel Development
Lecture 5 Kernel DevelopmentLecture 5 Kernel Development
Lecture 5 Kernel DevelopmentMohammed Farrag
 
Linux kernel code
Linux kernel codeLinux kernel code
Linux kernel codeGanesh Naik
 
Linux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesungLinux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesungdns -
 
Node Session - 2
Node Session - 2Node Session - 2
Node Session - 2Bhavin Shah
 
uRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orguRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orgAgelos Pikoulas
 
Linux Kernel Module - For NLKB
Linux Kernel Module - For NLKBLinux Kernel Module - For NLKB
Linux Kernel Module - For NLKBshimosawa
 
lesson03.ppt
lesson03.pptlesson03.ppt
lesson03.pptIraqReshi
 

Similar to Modern net bsd kernel module (20)

Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 
Advanced Node.JS Meetup
Advanced Node.JS MeetupAdvanced Node.JS Meetup
Advanced Node.JS Meetup
 
Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel Programming
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modules
 
Java9
Java9Java9
Java9
 
JavaScript Module Loaders
JavaScript Module LoadersJavaScript Module Loaders
JavaScript Module Loaders
 
Java 9 Module System
Java 9 Module SystemJava 9 Module System
Java 9 Module System
 
Kernel module programming
Kernel module programmingKernel module programming
Kernel module programming
 
Lecture 5 Kernel Development
Lecture 5 Kernel DevelopmentLecture 5 Kernel Development
Lecture 5 Kernel Development
 
NodeJs Modules1.pdf
NodeJs Modules1.pdfNodeJs Modules1.pdf
NodeJs Modules1.pdf
 
Linux kernel code
Linux kernel codeLinux kernel code
Linux kernel code
 
Linux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesungLinux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesung
 
Node Session - 2
Node Session - 2Node Session - 2
Node Session - 2
 
NodeJs Session02
NodeJs Session02NodeJs Session02
NodeJs Session02
 
uRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orguRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.org
 
Lecture 4 Cluster Computing
Lecture 4 Cluster ComputingLecture 4 Cluster Computing
Lecture 4 Cluster Computing
 
Linux Kernel Module - For NLKB
Linux Kernel Module - For NLKBLinux Kernel Module - For NLKB
Linux Kernel Module - For NLKB
 
What's New in Java 9
What's New in Java 9What's New in Java 9
What's New in Java 9
 
lesson03.ppt
lesson03.pptlesson03.ppt
lesson03.ppt
 
Java 9
Java 9Java 9
Java 9
 

More from Masaru Oki

NetBSD移植の昔話
NetBSD移植の昔話NetBSD移植の昔話
NetBSD移植の昔話Masaru Oki
 
Lagopusとvagrant
LagopusとvagrantLagopusとvagrant
LagopusとvagrantMasaru Oki
 
OpenFlowでいろんなプロトコルを 話そうとするとどうなるか
OpenFlowでいろんなプロトコルを 話そうとするとどうなるかOpenFlowでいろんなプロトコルを 話そうとするとどうなるか
OpenFlowでいろんなプロトコルを 話そうとするとどうなるかMasaru Oki
 
今よりも少し(?)昔、 Windowsを作ろうとした話
今よりも少し(?)昔、 Windowsを作ろうとした話今よりも少し(?)昔、 Windowsを作ろうとした話
今よりも少し(?)昔、 Windowsを作ろうとした話Masaru Oki
 
Onieで遊んでみようとした話
Onieで遊んでみようとした話Onieで遊んでみようとした話
Onieで遊んでみようとした話Masaru Oki
 
GPD WINが来た!
GPD WINが来た!GPD WINが来た!
GPD WINが来た!Masaru Oki
 
新生Lagopus2017(仮称)
新生Lagopus2017(仮称)新生Lagopus2017(仮称)
新生Lagopus2017(仮称)Masaru Oki
 
Lagopus as open flow hybrid switch 実践編
Lagopus as open flow hybrid switch 実践編Lagopus as open flow hybrid switch 実践編
Lagopus as open flow hybrid switch 実践編Masaru Oki
 
LagopusでPPPoEを使えるか考えてみた件
LagopusでPPPoEを使えるか考えてみた件LagopusでPPPoEを使えるか考えてみた件
LagopusでPPPoEを使えるか考えてみた件Masaru Oki
 
Lagopus どれだけ速いのか
Lagopus どれだけ速いのかLagopus どれだけ速いのか
Lagopus どれだけ速いのかMasaru Oki
 
Ryu+Lagopusで OpenFlowの動きを見てみよう
Ryu+Lagopusで OpenFlowの動きを見てみようRyu+Lagopusで OpenFlowの動きを見てみよう
Ryu+Lagopusで OpenFlowの動きを見てみようMasaru Oki
 
Lagopus match improvements
Lagopus match improvementsLagopus match improvements
Lagopus match improvementsMasaru Oki
 
Open flow tunnel extension on lagopus vswitch
Open flow tunnel extension on lagopus vswitchOpen flow tunnel extension on lagopus vswitch
Open flow tunnel extension on lagopus vswitchMasaru Oki
 
Lagopus as open flow hybrid switch
Lagopus as open flow hybrid switchLagopus as open flow hybrid switch
Lagopus as open flow hybrid switchMasaru Oki
 
Net bsd advent calendar 2015 bpf
Net bsd advent calendar 2015 bpfNet bsd advent calendar 2015 bpf
Net bsd advent calendar 2015 bpfMasaru Oki
 
Using rump on NetBSD 7.0
Using rump on NetBSD 7.0Using rump on NetBSD 7.0
Using rump on NetBSD 7.0Masaru Oki
 

More from Masaru Oki (20)

NetBSD移植の昔話
NetBSD移植の昔話NetBSD移植の昔話
NetBSD移植の昔話
 
Rust-DPDK
Rust-DPDKRust-DPDK
Rust-DPDK
 
Rust-DPDK
Rust-DPDKRust-DPDK
Rust-DPDK
 
Lagopusとvagrant
LagopusとvagrantLagopusとvagrant
Lagopusとvagrant
 
OpenFlowでいろんなプロトコルを 話そうとするとどうなるか
OpenFlowでいろんなプロトコルを 話そうとするとどうなるかOpenFlowでいろんなプロトコルを 話そうとするとどうなるか
OpenFlowでいろんなプロトコルを 話そうとするとどうなるか
 
今よりも少し(?)昔、 Windowsを作ろうとした話
今よりも少し(?)昔、 Windowsを作ろうとした話今よりも少し(?)昔、 Windowsを作ろうとした話
今よりも少し(?)昔、 Windowsを作ろうとした話
 
Onieで遊んでみようとした話
Onieで遊んでみようとした話Onieで遊んでみようとした話
Onieで遊んでみようとした話
 
GPD WINが来た!
GPD WINが来た!GPD WINが来た!
GPD WINが来た!
 
新生Lagopus2017(仮称)
新生Lagopus2017(仮称)新生Lagopus2017(仮称)
新生Lagopus2017(仮称)
 
Lagopus as open flow hybrid switch 実践編
Lagopus as open flow hybrid switch 実践編Lagopus as open flow hybrid switch 実践編
Lagopus as open flow hybrid switch 実践編
 
LagopusでPPPoEを使えるか考えてみた件
LagopusでPPPoEを使えるか考えてみた件LagopusでPPPoEを使えるか考えてみた件
LagopusでPPPoEを使えるか考えてみた件
 
Lagopus どれだけ速いのか
Lagopus どれだけ速いのかLagopus どれだけ速いのか
Lagopus どれだけ速いのか
 
Lagopus 0.2.7
Lagopus 0.2.7Lagopus 0.2.7
Lagopus 0.2.7
 
Ryu+Lagopusで OpenFlowの動きを見てみよう
Ryu+Lagopusで OpenFlowの動きを見てみようRyu+Lagopusで OpenFlowの動きを見てみよう
Ryu+Lagopusで OpenFlowの動きを見てみよう
 
Lagopus match improvements
Lagopus match improvementsLagopus match improvements
Lagopus match improvements
 
Lagopus 0.2.4
Lagopus 0.2.4Lagopus 0.2.4
Lagopus 0.2.4
 
Open flow tunnel extension on lagopus vswitch
Open flow tunnel extension on lagopus vswitchOpen flow tunnel extension on lagopus vswitch
Open flow tunnel extension on lagopus vswitch
 
Lagopus as open flow hybrid switch
Lagopus as open flow hybrid switchLagopus as open flow hybrid switch
Lagopus as open flow hybrid switch
 
Net bsd advent calendar 2015 bpf
Net bsd advent calendar 2015 bpfNet bsd advent calendar 2015 bpf
Net bsd advent calendar 2015 bpf
 
Using rump on NetBSD 7.0
Using rump on NetBSD 7.0Using rump on NetBSD 7.0
Using rump on NetBSD 7.0
 

Modern net bsd kernel module

  • 1. Modern NetBSD Kernel Module Mar 14, 2014 Masaru OKI (@masaru0714)
  • 2. Contents Self introduction Introduction of kernel module Using kernel module Creating kernel module Problems
  • 3. 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 :-)
  • 4. 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.
  • 5. 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))
  • 6. 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’.
  • 7. 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 - -
  • 8. 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.
  • 9. Unload module modunload <name> unloading module specified name. modunload example Unloading module in use? error … fine, no problem. but no error, caused panic.
  • 10. 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
  • 11. 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()
  • 12. 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”);
  • 13. 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
  • 14. <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)
  • 15. Writing Makefile Simple. KMOD= example SRCS= example.c .include <bsd.kmodule.mk>
  • 16. Other item requires for compile Kernel source needed. ● extract to /usr/src/sys ● other place, specify e.g. S=/foo/src
  • 17. 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; }
  • 18. 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.
  • 19. 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?
  • 20. 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/...