Where are the .ko and source codes of a kernel module?

I have selected a kernel module after running make menuconfig, and run these two commands to compile it:

make target/linux/compile
make package/kernel/linux/compile

I got the .ipk file but I need its source code and .ko. How do I get them?

For example, I've selected kmod-nf-nathelper-extra from kernel Modules -> Netfilter Extensions. I got its .ipk by compiling it. Can anyone please tell me how can I get its source code and .ko file?
Reference: https://openwrt.org/docs/guide-developer/toolchain/single.package#kernel_modules
Edit:
I need to edit the above-mentioned kernel module, for this I need its source code and other stuff so that I can generate the .ipk/.ko after making the changes.

Source's in the Linux kernel?
ipk can be unpacked, to extract content.

Sorry. I didn't get you entirely. I need to get the source of this package, kmod-nf-nathelper-extra. Where does openwrt get the source from?

Most modules come from the Linux kernel.

But I don't find the kernel module kmod-nf-nathelper-extra in linux kernel.

define KernelPackage/nf-nathelper-extra
  SUBMENU:=$(NF_MENU)
  TITLE:=Extra Conntrack and NAT helpers
  KCONFIG:=$(KCONFIG_NF_NATHELPER_EXTRA)
  FILES:=$(foreach mod,$(NF_NATHELPER_EXTRA-m),$(LINUX_DIR)/net/$(mod).ko)
  AUTOLOAD:=$(call AutoProbe,$(notdir $(NF_NATHELPER_EXTRA-m)))
  DEPENDS:=+kmod-nf-nat +kmod-lib-textsearch +kmod-asn1-decoder
endef

They seem to be in the net/ directory as individual files.

-rw-r--r--	nf_nat_amanda.c	2518	
-rw-r--r--	nf_nat_core.c	31810	
-rw-r--r--	nf_nat_ftp.c	4127	
-rw-r--r--	nf_nat_helper.c	5900	
-rw-r--r--	nf_nat_irc.c	3493	
-rw-r--r--	nf_nat_masquerade.c	9087	
-rw-r--r--	nf_nat_proto.c	28554	
-rw-r--r--	nf_nat_redirect.c	3135	
-rw-r--r--	nf_nat_sip.c	21280	
-rw-r--r--	nf_nat_tftp.c	1477

-rw-r--r-- nf_nat_helper.c 5900
Actually, I need nf_nat_helper_extra.c. I would edit the source code and generate the .ipk/.ko file. So that I need the source code in the OpenWrt build system so that after making the changes I can run some commands to generate the .ipk/.ko file with the changes.

Good luck there. hnyman did list the source files for you.
Use git grep -i nathelper to find the OpenWrt Makefiles:

Search Linux source Makefiles to find which files the Kconfig options use (or use git grep in a linux git tree. First Kconfig option:

If you cannot work out the Makefiles, you can always check what is packaged: ls -R build_dir/*/linux-*/packages/*/kmod-nf-nathelper-extra/ or opkg files kmod-nf-nathelper-extra

Use quilt to patch Linux within the OpenWrt build tree: https://openwrt.org/docs/guide-developer/toolchain/use-patches-with-buildsystem#iteratively_modify_patches_without_cleaning_the_source_tree

1 Like

Although, I didn't get 100% of what you said. Maybe, I need to study each point you mentioned. So, far I'd like to ask, nf_nat_helper_extra.c is not just standalone file, it's just composed of these-

Am I right?

Search with:

find ./ -type f -exec grep -H 'your txt in files' {} \;
find ./ -name  'file.*'