0

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.

1 Answer 1

1

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

Edit:

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.

1
  • As a note, I was able to get it to do what I needed with find /usr/src/linux/ -name "Makefile" -exec grep "CONFIG_<whichever config set as a module>" {} \; which got all the modules I needed for Docker except for CONFIG_IP_NF_TARGET_MASQUERADE. Going the other way, I think it would just be find /usr/src/linux -name "Makefile" -exec grep " += <module file name>" {} \;
    – B.Kaatz
    Sep 2, 2021 at 2:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .