kernel module reading config file, design/code question

hi folks,

i coded a simple module, which shall read a configuration file residing in userland. now, here i am stuck first in a design question and secondly on "how to implement such".

the module is intended to handle certain requests onto a permission configuration file, which i don't want and can put hardcoded into the code(the module shall on a configuration change not recompiled the whole time ;))

first, and most, i wonder what would be the common/suggested way for a kernel module to get some kind of configuration(is this even intended?):stud.
is it usual read it at runtime(after loaded, after refresh), is it more suggested to have a userland daemon which is communicating with the module or a possible device driver?

now, secondly, in regard to the design question what would be the proper functions to do such in kernelland? i know a bit about the uio stuff for device drivers and copyin/copyout as well.

regards,
 
You can set initial configuration via device.hints(9). And there are a lot of kernel modules reading sysctl's.
 
It depends on e.g. how large and complicated the config file would be. I'd start with sysctl. Then you could just put the configuration variables into /etc/sysctl.conf; there is an rc script to set these values at system startup. If you want to be able to set configuration first and load the module later, you could implement them as tunables (see kenv(1)). There is an API for easily accessing both in the kernel.
 
crsd said:
You can set initial configuration via device.hints(9). And there are a lot of kernel modules reading sysctl's.

Using /boot/loader.conf is a better solution. device.hints gets overwritten by mergemaster, while /boot/loader.conf doesn't get touched. Plus, it keeps everything nicely in one file.

Anything that can go in device.hints can also go into loader.conf.
 
hej guys,

first thank you for your input. wasn't a bit out of time. i decided to give it a first shot with sysctl and see how things are going and if the config gets not to complex.
i'll be back with module or thread here in some days i guess ;)

till then, best regards
 
ok, i implemented some basic's but i am somehow stuck on the sysctl issues. i added a new branch with SYSCTL_ADD_NODE, i can add there strings and it is, working almost fine.
now i am looking for adding additional node to the already created node, to achieve this tree:

Code:
application.node1
application.node1.family1
application.node1.family1.id=0
application.node1.family1.name=username
application.node1.family2
application.node1.family2.id=1
application.node1.family1.name=anothername

i tried to accomplish this through:

Code:
test2 = SYSCTL_ADD_NODE( NULL, SYSCTL_STATIC_CHILDREN(test1),OID_AUTO, "family", CTLFLAG_RW, 0, "test2");

and resulted into a compiler error message:

Code:
tester.c:314: error: 'sysctl_test1_children' undeclared (first use in this function)

i guess i made a basic mistake for SYSCTL declaration(do i need to use SYSCTL_DECL for instance?) or somekind of handler function(how would this look like?)

i wonder as well how i can implement a good way of searching through the sysctl values on module side to decide what actions to take. is there some kind like LIST_FOREACH mechanism?

additionally i figured after creating a node and not adding a string or integer results on my side with a kernel trap during kldload, is there a specifig reason for this?

someone can point me to a paper/book/self explaining module code for SYSCTL topic? :stud

best regards,
 
Back
Top