I have enabled a number of config options on a machine in order to take advantage of the newly-included wireguard module in Linux 5.6.0-rc1.

This was somewhat laborious: I had a minimal working config and guided by the errors I received while trying to put up the wireguard network interface I had to enable, one by one, kernel config options I was not familiar with, until wireguard worked (options like, say, CONFIG_IP_NF_MANGLE).

I now want to automate the replication of this process on another machine as much as possible. That other laptop, in turn, has a relatively small custom-configured kernel; it is an entirely different machine, so make localmodconfig on the current machine is not really an option, because I would then somehow have to merge the two configs anyway.

What I would like to achieve

I would like to have a process that takes a module name as input, as listed by lsmod (e.g. iptable_mangle) and gives me back the kernel option(s) relevant to enabling it (presumably CONFIG_IP_NF_MANGLE=m in this case?).

I have tried

  • grepping for the kernel module iptable_mangle in the Linux source (github clone) in the hope of maybe finding something that links it to the corresponding kernel option;

  • running modinfo <target module name> on the current machine, hoping that the displayed info would mention the kernel config option.

Neither of these works: the output doesn't mention CONFIG_IP_NF_MANGLE in either case.


Aha! I believe I have found something reasonably reliable.

Poking around through the Linux tree after configuring and grepping recursively for my module name (e.g. iptable_raw or xt_addrtype or what have you) always produces, among the many matching lines, exactly one of the form

<whatever>/Makefile:obj-$(<RELEVANT KERNEL CONFIG OPTION>) += <module name>.o`

Concretely, running

grep -rE '\+\=\s*nf_defrag_ipv6'

in the root of the source tree produces

net/ipv6/netfilter/Makefile:obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o

This tells me thatCONFIG_NF_DEFRAG_IPV6 is the kernel option that enables nf_defrag_ipv6.

I have tried this on multiple modules, and there's always a unique line of this form returned by grep. This seems eminently scriptable now, to produce, roughly speaking, a hash with

  • module names returned by lsmod as keys
  • matching kernel config options as values


A word on documentation: the above pattern was, in principle, discoverable through grepping as described, but what actually tipped me off was the += <object file name> syntax mentioned in the Kconfig documentation, which I was perusing for inspiration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.