Help/assistance needed when building kernel module

Hi all,
I'm trying to compile and include into kernel module nft_objref, but for some reason I can't do it via 'make kernel_menuconfig'. I've tried to update kernel config via 'make kernel_menuconfig CONFIG_TARGET=target' and selected nft_objref in '/Networking support/Networking options/Network packet filtering framework (Netfilter)/Core Netfilter Configuration/Netfilter nf_tables support/'. I've tried selecting it as built in kernel module (Y) and also to build it as stand alone module (M). After making 'Make V=s' and installing image on router nft_objref was not loaded, was not found in '/lib/modules/4.14.146', and searching througt whole partition file 'nft_objref.ko' was not found.
I've found out that when I make selection of desired module, it appears in 'target/linux/mvebu/config-4.14' as 'CONFIG_NFT_OBJREF=y' (or m depending on what was selected in kernel_menuconfig).
The only way I've found that really builds nft_objref module and loads it with kernel is to write 'CONFIG_NFT_OBJREF=y' into 'target/linux/generic/config-4.14' and also adding this line '$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NFT_OBJREF, $(P_XT)nft_objref),))' into 'include/netfilter.mk'.
So, my question is what I'm doing wrong in 'make kernel_menuconfig' that I can't get '.config' and '.mk' files updated automatically and get nft_objref built in into kernel?
I'd really appreciate your help.

As in openwrt almost all kmods (except the one needed to mount the rootfs and some essential drivers) are build as modules and packaged as ipk, you should add your module for packaging as ipk to:

For further assistance with packaging, checkout:
https://openwrt.org/docs/guide-developer/package-policies
https://openwrt.org/docs/guide-developer/dependencies

1 Like

Thanks for your reply. NFT_OBJREF is also one of standard netfilter modules, and I do not understand what is the point of enabling it in 'make kernel_menuconfig' if that does not built module together with kernel? I still need to add it manually to '*.mk' file. Shouldn't kernel module be added automatically to '*.mk' file after it is enabled in 'kernel_menuconfig'?

No, selecting anything as module in make kernel_menuconfig does not trigger a build of it as the kernel modules are build in another build stage than the kernel...
You know make modules and make image from the kernel build system?
Everything you need as module has to be added to the mk files in packages/kernel/linux/modules.
Kernel modules in the openwrt build system are only build by selecting it in make menuconfig and to show up in there it has to be added to the mentioned mk files.
If you select nft_objref as non module in make kernel_menuconfig then it's directly built into the kernel and doesn't show up in lsmod because it's not a module.

Add it properly to the mentioned mk file and create a pull request to make it available for everyone in make menuconfig or through opkg or built it directly into the kernel for your custom build!

1 Like

Thanks for the detailed answer. It answers my question.

You know make modules and make image from the kernel build system?

No, unfortunately I'm not familiar with it. Will try to find information on the internet and will read.

Add it properly to the mentioned mk file and create a pull request to make it available for everyone in make menuconfig or through opkg or built it directly into the kernel for your custom build!

I'll do some tests later today and see if I can reach what I need. nft_objref is not originally appearing in make menuconfig, so I need to do as you say and see how it works. Thanks again.

I have managed to do what I want by following @juppin post. All works fine. The only thing is that I also needed to add line $(eval $(if $(NF_KMOD),$(call nf_add,NFT_OBJREF,CONFIG_NFT_OBJREF, $(P_XT)nft_objref),)) to /include/netfilter.mk. Code that I have added to /package/kernel/linux/modules/netfilter.mk looks like this:

define KernelPackage/nft-objref
SUBMENU:=$(NF_MENU)
TITLE:=some title here
DEPENDS:=+kmod-nft-core
FILES:=$(LINUX_DIR)/net/netfilter/nft_objref.ko
AUTOLOAD:=$(call AutoProbe,$(notdir $(NFT_OBJREF-m)))
KCONFIG:=$(KCONFIG_NFT_OBJREF)
endef

$(eval $(call KernelPackage,nft-objref))

The problem I still have is that this code above was just copied from other entries in netfilter.mk. I do not really have big understanding on what call AutoProbe does and why we need AUTOLAOD and KCONFIG. So, my question is where I could find good information to read about making modules, makefiles and so on. I was searching in in different sites, but haven't really found any good information. I would really appreciate if you could share some information about it.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.