Skip to content

Commit a7286d9

Browse files
authored
Add nat20lib kernel module example and br environment. (#98)
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
1 parent cd118d0 commit a7286d9

16 files changed

Lines changed: 8634 additions & 1 deletion

File tree

.github/license-check/license-config.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
"**/*.yml",
55
"**/CMakeLists.txt",
66
"**/*.cmake.in",
7+
"**/*.mk",
8+
"**/*.sh",
9+
"**/Config.in",
10+
"**/Kbuild",
11+
"examples/linux/br_external/external.desc",
12+
"examples/linux/**/Makefile",
713
".clang-format",
814
".gitignore"
915
],
@@ -26,7 +32,8 @@
2632
{
2733
"include": [
2834
"**/*.md",
29-
"**/*.txt"
35+
"**/*.txt",
36+
"examples/linux/br_external/configs/*"
3037
],
3138
"exclude": [
3239
"**/CMakeLists.txt"
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Copyright 2026 Aurora Operations, Inc.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0
4+
#
5+
# This work is dual licensed.
6+
# You may use it under Apache-2.0 or GPL-2.0 at your option.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
# OR
21+
#
22+
# This program is free software; you can redistribute it and/or
23+
# modify it under the terms of the GNU General Public License
24+
# as published by the Free Software Foundation; either version 2
25+
# of the License, or (at your option) any later version.
26+
#
27+
# This program is distributed in the hope that it will be useful,
28+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
29+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30+
# GNU General Public License for more details.
31+
#
32+
# You should have received a copy of the GNU General Public License
33+
# along with this program; if not, see
34+
# <https://www.gnu.org/licenses/>.
35+
36+
37+
name: linux-kmod-build
38+
39+
on:
40+
push:
41+
branches:
42+
- main
43+
pull_request:
44+
45+
jobs:
46+
build-nat20lib-kmod:
47+
name: Build nat20lib kernel module (Buildroot)
48+
runs-on: ubuntu-22.04
49+
steps:
50+
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b #v4.1.5
51+
52+
- name: Install Buildroot dependencies
53+
run: |
54+
sudo apt-get update
55+
sudo apt-get install -y \
56+
build-essential \
57+
bc \
58+
cpio \
59+
file \
60+
git \
61+
libncurses-dev \
62+
python3 \
63+
rsync \
64+
unzip \
65+
wget
66+
67+
- name: Cache Buildroot toolchain and kernel
68+
id: cache-buildroot
69+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 #v4.3.0
70+
with:
71+
path: ${{ runner.temp }}/buildroot.build
72+
key: buildroot-${{ hashFiles('examples/linux/br_external/configs/qemu_br_defconfig', 'examples/linux/br_external/configs/qemu_linux_defconfig', 'examples/linux/br_external/bootstrap.sh') }}
73+
74+
- name: Bootstrap Buildroot
75+
if: steps.cache-buildroot.outputs.cache-hit != 'true'
76+
run: examples/linux/br_external/bootstrap.sh qemu ${{ runner.temp }}/buildroot.build "${{ github.workspace }}"
77+
78+
- name: Build toolchain and kernel
79+
if: steps.cache-buildroot.outputs.cache-hit != 'true'
80+
run: make -C ${{ runner.temp }}/buildroot.build/buildroot linux -j $(( $(nproc) + 1 ))
81+
82+
- name: Build nat20lib kernel module
83+
env:
84+
NAT20LIB_OVERRIDE_SRCDIR: ${{ github.workspace }}
85+
run: |
86+
cd ${{ runner.temp }}/buildroot.build/buildroot
87+
make nat20lib-dirclean
88+
make nat20lib -j $(( $(nproc) + 1 ))
89+
90+
- name: Verify nat20lib.ko was produced
91+
run: |
92+
find ${{ runner.temp }}/buildroot.build -name 'nat20lib.ko' | grep -q nat20lib.ko
93+
echo "nat20lib.ko built successfully:"
94+
find ${{ runner.temp }}/buildroot.build -name 'nat20lib.ko' -exec ls -la {} \;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2026 Aurora Operations, Inc.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0
4+
#
5+
# This work is dual licensed.
6+
# You may use it under Apache-2.0 or GPL-2.0 at your option.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
# OR
21+
#
22+
# This program is free software; you can redistribute it and/or
23+
# modify it under the terms of the GNU General Public License
24+
# as published by the Free Software Foundation; either version 2
25+
# of the License, or (at your option) any later version.
26+
#
27+
# This program is distributed in the hope that it will be useful,
28+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
29+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30+
# GNU General Public License for more details.
31+
#
32+
# You should have received a copy of the GNU General Public License
33+
# along with this program; if not, see
34+
# <https://www.gnu.org/licenses/>.
35+
36+
source "$BR2_EXTERNAL_NAT20_PATH/package/nat20lib/Config.in"
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/bin/bash
2+
3+
# Copyright 2026 Aurora Operations, Inc.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0
6+
#
7+
# This work is dual licensed.
8+
# You may use it under Apache-2.0 or GPL-2.0 at your option.
9+
#
10+
# Licensed under the Apache License, Version 2.0 (the "License");
11+
# you may not use this file except in compliance with the License.
12+
# You may obtain a copy of the License at
13+
#
14+
# http://www.apache.org/licenses/LICENSE-2.0
15+
#
16+
# Unless required by applicable law or agreed to in writing, software
17+
# distributed under the License is distributed on an "AS IS" BASIS,
18+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
# See the License for the specific language governing permissions and
20+
# limitations under the License.
21+
#
22+
# OR
23+
#
24+
# This program is free software; you can redistribute it and/or
25+
# modify it under the terms of the GNU General Public License
26+
# as published by the Free Software Foundation; either version 2
27+
# of the License, or (at your option) any later version.
28+
#
29+
# This program is distributed in the hope that it will be useful,
30+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
31+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32+
# GNU General Public License for more details.
33+
#
34+
# You should have received a copy of the GNU General Public License
35+
# along with this program; if not, see
36+
# <https://www.gnu.org/licenses/>.
37+
38+
PROJECT="$1"
39+
LIBNAT20_BR_BUILD_DIR="$2"
40+
LIBNAT20_ROOT="${3:-$(pwd)}"
41+
LIBNAT20_ROOT="$(readlink -f "${LIBNAT20_ROOT}")"
42+
43+
usage() {
44+
echo "Usage: bootstrap.sh <project> <buildroot_build_dir> <libnat20_root>"
45+
echo
46+
echo "This script bootstraps the Buildroot environment for the Dice project."
47+
echo
48+
echo "This script may be run from any directory, as long as the libnat20 root"
49+
echo "directory is specified correctly. The first parameter specifies the project."
50+
echo "See valid options below."
51+
echo "The second parameter specifies the out of tree Buildroot build directory."
52+
echo "The third parameter specifies the libnat20 root directory."
53+
echo "It uses the current working directory by default."
54+
echo
55+
echo "Available projects:"
56+
echo " qemu - Setup Buildroot for the QEMU-based Dice emulator"
57+
}
58+
59+
case "$PROJECT" in
60+
qemu)
61+
;;
62+
*)
63+
usage
64+
exit 0
65+
;;
66+
esac
67+
68+
if [ -z "${LIBNAT20_BR_BUILD_DIR}" ]; then
69+
echo "Error: buildroot_build_dir must be specified."
70+
echo
71+
usage
72+
exit 1
73+
fi
74+
75+
LIBNAT20_BR_BUILD_DIR="$(readlink -f "${LIBNAT20_BR_BUILD_DIR}")"
76+
77+
case "${LIBNAT20_BR_BUILD_DIR}" in
78+
"${LIBNAT20_ROOT}"|"${LIBNAT20_ROOT}"/*)
79+
echo "Error: buildroot_build_dir must not be inside libnat20_root."
80+
echo " buildroot_build_dir: ${LIBNAT20_BR_BUILD_DIR}"
81+
echo " libnat20_root: ${LIBNAT20_ROOT}"
82+
exit 1
83+
;;
84+
esac
85+
86+
if [ -e "${LIBNAT20_BR_BUILD_DIR}" ]; then
87+
echo "Buildroot build directory ${LIBNAT20_BR_BUILD_DIR} already exists."
88+
exit 1
89+
fi
90+
91+
if [ ! -d "${LIBNAT20_ROOT}/examples/linux/br_external" ]; then
92+
echo "Directory ${LIBNAT20_ROOT}/examples/linux/br_external does not exist."
93+
echo "Please make sure \"${LIBNAT20_ROOT}\" points to the libnat20 root directory."
94+
exit 1
95+
fi
96+
97+
mkdir -p "${LIBNAT20_BR_BUILD_DIR}"
98+
pushd ${LIBNAT20_BR_BUILD_DIR}
99+
100+
echo "LIBNAT20_BR_BUILD_DIR=${LIBNAT20_BR_BUILD_DIR}" | tee .env
101+
echo "LIBNAT20_ROOT=${LIBNAT20_ROOT}" | tee -a .env
102+
103+
cp ${LIBNAT20_ROOT}/examples/linux/br_external/utils/envsetup.sh ./
104+
105+
# Checkout buildroot
106+
git clone --depth 1 --branch "2025.08.1" https://gitlab.com/buildroot.org/buildroot.git
107+
108+
# Install the buildroot config
109+
case "$PROJECT" in
110+
qemu)
111+
cp ${LIBNAT20_ROOT}/examples/linux/br_external/configs/qemu_br_defconfig buildroot/.config
112+
cp ${LIBNAT20_ROOT}/examples/linux/br_external/run-qemu.sh ./
113+
;;
114+
esac
115+
116+
pushd buildroot
117+
118+
make BR2_EXTERNAL=${LIBNAT20_ROOT}/examples/linux/br_external oldconfig
119+
120+
popd
121+
popd
122+
123+
echo
124+
echo "Now enter buildroot and run make:"
125+
echo " $ cd ${LIBNAT20_BR_BUILD_DIR}/buildroot"
126+
echo ' $ make'

0 commit comments

Comments
 (0)