Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/license-check/license-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"**/Kbuild",
"examples/linux/br_external/external.desc",
"examples/linux/**/Makefile",
"examples/linux/nat20cli/openssl_dice.cnf",
".clang-format",
".gitignore"
],
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/linux-kmod-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,29 @@ jobs:
echo "libnat20.a built successfully:"
find ${{ runner.temp }}/buildroot.build -name 'libnat20.a' -exec ls -la {} \;

- name: Build nat20cli userspace cli tool
env:
LIBNAT20_OVERRIDE_SRCDIR: ${{ github.workspace }}
NAT20CLI_OVERRIDE_SRCDIR: ${{ github.workspace }}
run: |
cd ${{ runner.temp }}/buildroot.build/buildroot
make nat20cli-dirclean
make nat20cli -j $(( $(nproc) + 1 ))

- name: Verify nat20cli was produced
run: |
find ${{ runner.temp }}/buildroot.build -name 'nat20cli' | grep -q nat20cli
echo "nat20cli built successfully:"
find ${{ runner.temp }}/buildroot.build -name 'nat20cli' -exec ls -la {} \;

- name: Build rootfs image
env:
NAT20LIB_OVERRIDE_SRCDIR: ${{ github.workspace }}
NAT20DEVICE_OVERRIDE_SRCDIR: ${{ github.workspace }}
NAT20CRYPTO_OVERRIDE_SRCDIR: ${{ github.workspace }}
NAT20SW_OVERRIDE_SRCDIR: ${{ github.workspace }}
LIBNAT20_OVERRIDE_SRCDIR: ${{ github.workspace }}
NAT20CLI_OVERRIDE_SRCDIR: ${{ github.workspace }}
NAT20TEST_OVERRIDE_SRCDIR: ${{ github.workspace }}
run: make -C ${{ runner.temp }}/buildroot.build/buildroot -j $(( $(nproc) + 1 ))

Expand Down Expand Up @@ -188,3 +204,28 @@ jobs:
cat qemu_output.log
exit 1
fi

- name: Run nat20cli tests in QEMU
timeout-minutes: 5
run: |
BUILDROOT_DIR="${{ runner.temp }}/buildroot.build/buildroot"
KERNEL="${BUILDROOT_DIR}/output/images/bzImage"
ROOTFS="${BUILDROOT_DIR}/output/images/rootfs.ext2"

qemu-system-x86_64 \
-M pc \
-kernel "${KERNEL}" \
-drive file="${ROOTFS}",if=virtio,format=raw \
-append "rootwait root=/dev/vda console=ttyS0 init=/usr/bin/nat20cli_qemu_init.sh" \
-nographic \
-no-reboot \
-net none \
2>&1 | tee qemu_output.log

if grep -q "NAT20CLI_TESTS_PASSED" qemu_output.log; then
echo "NAT20CLI tests passed."
else
echo "NAT20CLI tests failed. QEMU output:"
cat qemu_output.log
exit 1
fi
1 change: 1 addition & 0 deletions examples/linux/br_external/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# along with this program; if not, see
# <https://www.gnu.org/licenses/>.

source "$BR2_EXTERNAL_NAT20_PATH/package/nat20cli/Config.in"
source "$BR2_EXTERNAL_NAT20_PATH/package/nat20crypto/Config.in"
source "$BR2_EXTERNAL_NAT20_PATH/package/nat20device/Config.in"
source "$BR2_EXTERNAL_NAT20_PATH/package/nat20sw/Config.in"
Expand Down
1 change: 1 addition & 0 deletions examples/linux/br_external/configs/qemu_br_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3976,6 +3976,7 @@ BR2_TARGET_UBOOT_CUSTOM_PATCH_DIR=""
#
# Provides NAT20 related packages.
#
BR2_PACKAGE_NAT20CLI=y
BR2_PACKAGE_NAT20CRYPTO=y
BR2_PACKAGE_NAT20DEVICE=y
BR2_PACKAGE_NAT20SW=y
Expand Down
41 changes: 41 additions & 0 deletions examples/linux/br_external/package/nat20cli/Config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2026 Aurora Operations, Inc.
#
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0
#
# This work is dual licensed.
# You may use it under Apache-2.0 or GPL-2.0 at your option.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# OR
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see
# <https://www.gnu.org/licenses/>.

config BR2_PACKAGE_NAT20CLI
bool "nat20cli"
depends on BR2_PACKAGE_LIBNAT20
Comment thread
werwurm marked this conversation as resolved.
select BR2_PACKAGE_NAT20SW
help
Enable building the nat20cli tool.
51 changes: 51 additions & 0 deletions examples/linux/br_external/package/nat20cli/nat20cli.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2026 Aurora Operations, Inc.
#
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0
#
# This work is dual licensed.
# You may use it under Apache-2.0 or GPL-2.0 at your option.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# OR
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see
# <https://www.gnu.org/licenses/>.

# In CI NAT20CLI_OVERRIDE_SRCDIR is set to the root of the repository,
# so that the source under test is always the current branch.
# Integrators who use this configuration should pin the version
# to a specific commit or branch to avoid breakages when the main branch changes.
NAT20CLI_VERSION = origin/main
NAT20CLI_SITE = https://github.com/aurora-opensource/libnat20.git
NAT20CLI_SITE_METHOD = git
NAT20CLI_LICENSE = Apache-2.0 OR GPL-2.0
NAT20CLI_LICENSE_FILES = LICENSE-Apache-2.0.txt LICENSE-GPL-2.0.txt

NAT20CLI_SUBDIR = examples/linux/nat20cli

NAT20CLI_INSTALL_TARGET = YES
NAT20CLI_DEPENDENCIES += libnat20

$(eval $(cmake-package))
8 changes: 7 additions & 1 deletion examples/linux/br_external/utils/envsetup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fi

source .env

export NAT20CLI_OVERRIDE_SRCDIR="$LIBNAT20_ROOT"
export NAT20CRYPTO_OVERRIDE_SRCDIR="$LIBNAT20_ROOT"
export NAT20SW_OVERRIDE_SRCDIR="$LIBNAT20_ROOT"
export NAT20DEVICE_OVERRIDE_SRCDIR="$LIBNAT20_ROOT"
Expand Down Expand Up @@ -73,6 +74,7 @@ function brrebuild() {
echo "Available targets:"
echo " all - Rebuild all components"
echo " linux - Rebuild the linux kernel"
echo " nat20cli - Rebuild the Dice CLI"
echo " nat20crypto - Rebuild the nat20crypto module"
echo " libnat20 - Rebuild the libnat20 library"
echo " nat20device - Rebuild the nat20device module"
Expand All @@ -85,7 +87,7 @@ function brrebuild() {

case "$1" in
all)
ensure_popd make linux-rebuild nat20lib-rebuild nat20crypto-rebuild nat20device-rebuild nat20sw-rebuild libnat20-rebuild nat20test-rebuild all
ensure_popd make linux-rebuild nat20lib-rebuild nat20crypto-rebuild nat20device-rebuild nat20sw-rebuild libnat20-rebuild nat20cli-rebuild nat20test-rebuild all
;;
*)
ensure_popd make $1-rebuild all
Expand Down Expand Up @@ -115,3 +117,7 @@ function run-qemu() {
function run-nat20test-test() {
run-qemu "/usr/bin/nat20test_qemu_init.sh"
}

function run-nat20cli-test() {
run-qemu "/usr/bin/nat20cli_qemu_init.sh"
}
83 changes: 83 additions & 0 deletions examples/linux/nat20cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright 2026 Aurora Operations, Inc.
#
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0
#
# This work is dual licensed.
# You may use it under Apache-2.0 or GPL-2.0 at your option.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# OR
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see
# <https://www.gnu.org/licenses/>.

cmake_minimum_required(VERSION 3.22)

project(NAT20CLI VERSION 0.0.1 LANGUAGES C)

# The C standard shall be C11.
set(CMAKE_C_STANDARD 11)

# CMake shall generate a compile_commands.json file for
# the benefit of clangd based IDE support.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

###################################################################################################
# The following section defines all the groups of source files.
# All files must be specified explicitly; no globbing or other generation is allowed.

set(NAT20CLI_SOURCES
# Add the core library source files here.
src/main.c
)

###################################################################################################

###################################################################################################
# The nat20_service library is also part of the product of this project.
# It will always be compiled.
add_executable(nat20cli)

find_package(LibNat20 REQUIRED)

target_sources(nat20cli
PRIVATE ${NAT20CLI_SOURCES}
)

target_link_libraries(nat20cli PRIVATE LibNat20::nat20 LibNat20::nat20_service LibNat20::nat20_crypto_nat20)

target_compile_options(nat20cli
PRIVATE -pedantic
PRIVATE -Wall
PRIVATE -Wextra
PRIVATE -Werror
)

install(TARGETS nat20cli RUNTIME DESTINATION bin)
install(PROGRAMS nat20cli_test.sh DESTINATION bin)
install(PROGRAMS nat20cli_qemu_init.sh DESTINATION bin)
install(FILES openssl_dice.cnf DESTINATION bin)

###################################################################################################
60 changes: 60 additions & 0 deletions examples/linux/nat20cli/nat20cli_qemu_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh

# Copyright 2026 Aurora Operations, Inc.
#
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0
#
# This work is dual licensed.
# You may use it under Apache-2.0 or GPL-2.0 at your option.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# OR
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see
# <https://www.gnu.org/licenses/>.

# Init wrapper for running nat20cli_test.sh in a QEMU VM.
# This script is intended to be used as the init process (PID 1).
# It mounts the necessary filesystems, runs the nat20cli test suite,
# prints a machine-parseable result marker, and powers off the VM.

export PATH="/usr/bin:/bin:/sbin:/usr/sbin"

mount -t proc none /proc
mount -t sysfs none /sys
mount -t tmpfs none /tmp

cd /tmp

nat20cli_test.sh
rc=$?

if [ $rc -eq 0 ]; then
echo "NAT20CLI_TESTS_PASSED"
else
echo "NAT20CLI_TESTS_FAILED (exit code: $rc)"
fi

poweroff -f
Loading
Loading