Skip to content

Add nat20lib kernel module example and br environment.#98

Merged
werwurm merged 8 commits into
mainfrom
werwurm/linux_example_nat20lib
May 7, 2026
Merged

Add nat20lib kernel module example and br environment.#98
werwurm merged 8 commits into
mainfrom
werwurm/linux_example_nat20lib

Conversation

@werwurm
Copy link
Copy Markdown
Contributor

@werwurm werwurm commented Apr 29, 2026

Add a kernel module that provides libnat20 functionality to linux kernel
modules. Also add a configuration to build a minimal linux image with
buildroot and run in on qemu and a workflow to test build nat20lib.ko

Add a kernel module that provides libnat20 functionality to linux kernel
modules. Also add a configuration to build a minimal linux image with
buildroot and run in on qemu and a workflow to test build nat20lib.ko
@werwurm werwurm requested a review from a team as a code owner April 29, 2026 16:35
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 29, 2026

LCOV of commit 3ded408 during lcov-test-coverage-report #188

Summary coverage rate:
  lines......: 95.7% (3013 of 3147 lines)
  functions..: 99.1% (230 of 232 functions)
  branches...: 87.2% (1646 of 1887 branches)

Files changed coverage rate: n/a

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Linux kernel-module packaging of libnat20 (as an example) and a Buildroot external tree + QEMU run tooling to build/test the module in CI.

Changes:

  • Introduces examples/linux/nat20lib kernel module sources/build files and exports libnat20 symbols.
  • Adds a Buildroot br_external tree (package definition, configs, bootstrap + dev helper scripts, QEMU runner) to build a minimal image/module.
  • Adds a GitHub Actions workflow to build and verify nat20lib.ko, plus expands license-check patterns for the new file types.

Reviewed changes

Copilot reviewed 14 out of 16 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
examples/linux/nat20lib/mod.c New kernel module entry/exit and symbol exports for libnat20.
examples/linux/nat20lib/Makefile Wrapper Makefile for building/installing the external module.
examples/linux/nat20lib/Kbuild Kbuild definition compiling nat20 sources into nat20lib.ko.
examples/linux/br_external/utils/envsetup.sh Dev environment helper script for building/rebuilding Buildroot artifacts.
examples/linux/br_external/run-qemu.sh Script to boot the built kernel/rootfs in QEMU.
examples/linux/br_external/package/nat20lib/nat20lib.mk Buildroot package definition for the nat20lib kernel module.
examples/linux/br_external/package/nat20lib/Config.in Buildroot config option for enabling nat20lib.
examples/linux/br_external/external.mk Buildroot external tree package include.
examples/linux/br_external/external.desc Buildroot external tree descriptor.
examples/linux/br_external/configs/qemu_linux_defconfig Kernel defconfig used by the Buildroot environment.
examples/linux/br_external/bootstrap.sh Bootstrap script to set up out-of-tree Buildroot build directory.
examples/linux/br_external/Config.in Top-level Buildroot external Config.in sourcing nat20lib package.
.github/workflows/linux-kmod-build.yml CI workflow to build and verify nat20lib.ko via Buildroot.
.github/license-check/license-config.json Adds license-check patterns for new file extensions/paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/linux/br_external/run-qemu.sh Outdated
Comment thread examples/linux/br_external/package/nat20lib/nat20lib.mk
Comment thread examples/linux/br_external/external.desc Outdated
Comment thread examples/linux/br_external/utils/envsetup.sh Outdated
Comment thread examples/linux/br_external/bootstrap.sh Outdated
Comment thread examples/linux/nat20lib/Makefile Outdated
Comment thread examples/linux/nat20lib/Makefile Outdated
Copy link
Copy Markdown

@smacdude smacdude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert on all of this, but Claude found some issues that I think should at least be questioned.

Comment thread .github/workflows/linux-kmod-build.yml Outdated
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 #v4.3.0
with:
path: ${{ runner.temp }}/buildroot.build
key: buildroot-${{ hashFiles('examples/linux/br_external/configs/qemu_br_defconfig', 'examples/linux/br_external/configs/qemu_linux_defconfig') }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Claude:
cache key is incomplete. hashFiles(...) covers only the two defconfigs. The Buildroot version (2025.08.1) is hardcoded in bootstrap.sh, so bumping it won't invalidate the cache → stale toolchain. Include bootstrap.sh (and probably the br_external/** tree) in the key

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added bootstra.sh. I don't think we need br_external/**. It will just add noise.

ensure_popd make linux-rebuild nat20lib-rebuild all
;;
*)
ensure_popd make $1-rebuild all
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this line contain quotes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes much of a difference. Make targets shouldn't have spaces. Apparently, it is technically possible, but do we want to encourage this?

Comment thread examples/linux/nat20lib/Kbuild Outdated

obj-m := nat20lib.o
ccflags-y := -I $(src)/../../../include
ccflags-y += -I $(srctree)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line and the next line changing compiler options for the Linux source, and if so, is that safe?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed for newer kernels which use gnu11. But this code won't compile with gnu90. So we may have a problem with older kernels. I'll remove this for now.

Comment thread examples/linux/br_external/package/nat20lib/nat20lib.mk
Comment thread examples/linux/br_external/package/nat20lib/nat20lib.mk Outdated
@werwurm werwurm requested a review from smacdude May 5, 2026 20:52
Copy link
Copy Markdown
Member

@timhirsh timhirsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving GH Actions 👍

# <https://www.gnu.org/licenses/>.

name: NAT20
desc: Provides NAT20 related packages package.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
desc: Provides NAT20 related packages package.
desc: Provides NAT20 related packages.

Looks like this co-pilot finding wasn't resolved.

@werwurm werwurm merged commit a7286d9 into main May 7, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants