Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


I have selected a number of modules from the Netfilter package for this example. The dependency file
modules.depincludes the following dependencies found when the modules were compiled^10 :

ip_tables.ko:
iptable_nat.ko: ip_conntrack.ko ip_tables.ko
ip_nat_ftp.ko: iptable_nat.ko ip_tables.ko ip_conntrack.ko
ip_conntrack.ko:
ip_conntrack_ftp.ko: ip_conntrack.ko
Althoughip_nat_ftpandip_conntrack_ftpdepend on several other modules, they do not have any
modules that dependon them, which is why themodules_which_use_meelement of theirmoduleinstance
is a null pointer.

ip_tablesdoes not have any dependencies on other modules and can therefore be loaded into the kernel
on its own. However, there are two modules that depend onip_tables:iptable_natandip_nat_ftp.
An instance ofmodule_useis created for each; these are placed in the list of themodules_which_use_me
element ofip_tables.Theirmodule_which_usepointers point toip_nat_ftpandiptable_nat,as
shown in Figure 7-3.

Three modules depend onip_conntrack,whichiswhyitsmodules_which_use_melist contains three
instances ofmodule_usewith pointers toiptable_nat,ip_nat_ftp,andip_conntrack_ftp.

The kernel data structures indicate only which other modules depend on a
particular module — they are not suitable (at least not without looking through the
list of all modules and reanalyzing the information in the list) for finding out which
modules already need to be resident in the kernel before a specific new module can
be loaded. However, this is not necessary because it is sufficient that the
information is present in userspace; and, thanks tomodules.dep,thisisthecase.

If an attempt is made to load a module for which it was not possible to resolve all symbols because
dependent modules are not present, the kernel returns an error code and aborts loading. However, no
effort is made to load the prerequisite modules from the kernel side. This is the sole responsibility of the
modprobeuserspace tool.

Only two calls ofmodprobeare needed to insert the displayed modules into the kernel:

wolfgang@meitner>/sbin/modprobe ip_nat_ftp
wolfgang@meitner>/sbin/modprobe ip_conntrack_ftp
Whenip_nat_ftpis inserted,ip_conntrack,ip_tablesandiptable_natare automatically added
because they are listed as prerequisites inmodules.dep.ip_conntrack_ftpcan then be added with-
out explicit resolution of dependencies because the requisiteip_conntrackmodule was automatically
inserted into the kernel whenip_nat_ftpwas loaded.

ManipulatingData Structures


The kernel provides thealready_usesfunction to test whether module A requires another module B:

kernel/module.c
/* Does a already use b? */
static int already_uses(struct module *a, struct module *b)

(^10) To improve readability, I have not specified the files with their full pathnames as they would appear inmodules.dep. Addition-
ally, the example is slightly simplified.

Free download pdf