Skip to content

Commit

Permalink
Merge pull request #899 from NordSecurity/LLT-5729_add_libtelio_build…
Browse files Browse the repository at this point in the history
…_qnap

Add support for qnap library build
  • Loading branch information
lcruz99 authored Nov 14, 2024
2 parents f8f772f + 0a6b5d6 commit 24377c5
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Cargo.lock
tcli
tcli.log
/.*/
!/.cargo
Expand All @@ -10,6 +11,7 @@ tcli.log
*.deb
*.nix
*.prepared*
*.dylib
/nat-lab/data/tcli*
/3rd-party/boringtun
/3rd-party/ci-helper-scripts/
Expand Down
Empty file added .unreleased/LLT-5729
Empty file.
2 changes: 1 addition & 1 deletion 3rd-party/rust_build_utils
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ hex = "0.4.3"
httparse = "1.8.0"
if-addrs = "0.12.0"
ipnet = { version = "2.3", features = ["serde"] }
ipnetwork = "0.18"
itertools = "0.10"
lazy_static = "1.4.0"
libc = "0.2.112"
Expand Down
55 changes: 53 additions & 2 deletions ci/build_libtelio.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,36 @@ def post_copy_darwin_debug_symbols_to_distribution_dir(config, args):
)


def post_qnap_build_wrap_binary_on_qpkg(config, args):
packages = LIBTELIO_CONFIG[config.target_os].get("packages", None)
if packages:
for _, bins in packages.items():
for _, bin in bins.items():
src_path = os.path.join(
PROJECT_CONFIG.get_distribution_path(
config.target_os, config.arch, "", config.debug
),
bin,
)
dst_path = os.path.join(
PROJECT_CONFIG.get_root_dir(),
f"qnap/{config.arch}",
)
if os.path.isfile(src_path):
shutil.copy2(src_path, dst_path)
rutils.run_command_with_output(
[
"qbuild",
"--root",
os.path.join(PROJECT_CONFIG.get_root_dir(), "qnap/"),
"--build-dir",
PROJECT_CONFIG.get_distribution_path(
config.target_os, config.arch, "", config.debug
),
]
)


"""
This local config is highly customizable as every project can have a different
local config depending on their needs.
Expand Down Expand Up @@ -261,6 +291,22 @@ def post_copy_darwin_debug_symbols_to_distribution_dir(config, args):
NAME: {f"lib{NAME}": f"lib{NAME}.so"},
},
},
"qnap": {
"archs": {
"x86_64": {
"env": {
"RUSTFLAGS": (
f" -L {PROJECT_ROOT}/3rd-party/libmoose/{LIBTELIO_ENV_MOOSE_RELEASE_TAG}/bin/common/qnap/{MOOSE_MAP['x86_64']} -l static=sqlite3",
"set",
)
},
},
},
"post_build": [post_qnap_build_wrap_binary_on_qpkg],
"packages": {
"tcli": {"tcli": "tcli"},
},
},
"macos": {
"packages": {
"tcli": {"tcli": "tcli"},
Expand Down Expand Up @@ -335,7 +381,12 @@ def main() -> None:
target_os = "macos" if args.command == "lipo" else args.os

packages = LIBTELIO_CONFIG[target_os].get("packages", None)
if args.debug and not args.tcli and "tcli" in packages:
if (
args.debug
and not args.tcli
and "tcli" in packages
and "qnap" not in args.os
):
LIBTELIO_CONFIG[target_os]["packages"].pop("tcli")

if args.command == "build":
Expand Down Expand Up @@ -462,7 +513,7 @@ def exec_build(args):
return

if args.moose:
if args.os in ["linux", "windows", "android"]:
if args.os in ["linux", "windows", "android", "qnap"]:
sys.path.append(f"{PROJECT_ROOT}/ci")
moose_utils.fetch_moose_dependencies(args.os, MOOSE_MAP[args.arch])

Expand Down
2 changes: 1 addition & 1 deletion ci/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
LIBTELIO_ENV_MOOSE_RELEASE_TAG = "v14.1.3-libtelioApp"
LIBTELIO_ENV_NAT_LAB_DEPS_TAG = "v0.0.30"
LIBTELIO_ENV_ANDROID_BUILDER_TAG = "v0.0.2"
LIBTELIO_ENV_LINUX_BUILDER_TAG = "v0.0.4"
LIBTELIO_ENV_LINUX_BUILDER_TAG = "v0.0.6"
LIBTELIO_ENV_WINDOWS_BUILDER_TAG = "v0.0.2"
LIBTELIO_ENV_UNIFFI_GENERATORS_TAG = "v0.25.0-8"

Expand Down
7 changes: 6 additions & 1 deletion ci/moose_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def _download_moose_file(opsys: str, arch: str, file_name: str):
if nexus_url is None:
raise ValueError("LIBTELIO_ENV_SEC_NEXUS_URL not set")

url = f"{nexus_url}/repository/ll-gitlab-release/{MOOSE_PROJECT_ID}/{LIBTELIO_ENV_MOOSE_RELEASE_TAG}/bin/common/{opsys}/{arch}/{file_name}"
if opsys == "qnap":
url = f"{nexus_url}/repository/ll-gitlab-release/{MOOSE_PROJECT_ID}/{LIBTELIO_ENV_MOOSE_RELEASE_TAG}/bin/common/linux/{arch}/{file_name}"
else:
url = f"{nexus_url}/repository/ll-gitlab-release/{MOOSE_PROJECT_ID}/{LIBTELIO_ENV_MOOSE_RELEASE_TAG}/bin/common/{opsys}/{arch}/{file_name}"

subprocess.check_call(
["curl", "-f", "-u", nexus_credentials, url, "-o", output_path]
Expand All @@ -52,6 +55,8 @@ def _download_moose_file(opsys: str, arch: str, file_name: str):
def fetch_moose_dependencies(opsys: str, arch: str):
if opsys == "windows":
_download_moose_file(opsys, arch, "sqlite3.dll")
elif opsys == "qnap":
_download_moose_file(opsys, arch, "libsqlite3.a")
else:
_download_moose_file(opsys, arch, "libsqlite3.so")

Expand Down
13 changes: 13 additions & 0 deletions crates/telio-pmtu/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
//! * the kernel does some things in an unpredicted way, for example `send()` and `recv()` calls spuriously report errors when sending packets larger than the kernel's PMTU guess
//! * the kernel can keep multiple error message
#[cfg(target_env = "musl")]
use std::mem::MaybeUninit;
use std::{ffi::c_int, io, net::IpAddr, os::fd::AsRawFd, time::Duration};

use pnet_packet::{icmp, icmpv6, Packet};
Expand Down Expand Up @@ -432,6 +434,7 @@ fn read_error_pmtu(sock: &impl AsRawFd, is_ipv6: bool) -> io::Result<u32> {

let mut controlbuf = [0u8; 128];

#[cfg(not(target_env = "musl"))]
let mut msghdr = libc::msghdr {
msg_name: std::ptr::null_mut(),
msg_namelen: 0,
Expand All @@ -441,6 +444,16 @@ fn read_error_pmtu(sock: &impl AsRawFd, is_ipv6: bool) -> io::Result<u32> {
msg_controllen: controlbuf.len() as _,
msg_flags: 0,
};
#[cfg(target_env = "musl")]
let mut msghdr = MaybeUninit::<libc::msghdr>::zeroed().assume_init();
#[cfg(target_env = "musl")]
{
msghdr.msg_name = std::ptr::null_mut();
msghdr.msg_iov = &mut iovec;
msghdr.msg_iovlen = 1;
msghdr.msg_control = controlbuf.as_mut_ptr().cast();
msghdr.msg_controllen = controlbuf.len() as _;
}

let mut last_value = None;

Expand Down
4 changes: 2 additions & 2 deletions qnap/qpkg.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Name of the packaged application.
QPKG_NAME="Nord Security Meshnet"
QPKG_NAME="NordSecMeshnet"
# Name of the display application.
QPKG_DISPLAY_NAME="Nord Security Meshnet"
# Version of the packaged application.
QPKG_VER="0.0.1-alpha"
QPKG_VER="0.0.1-test"
# Author or maintainer of the package
QPKG_AUTHOR="[email protected]"
# License for the packaged application
Expand Down

0 comments on commit 24377c5

Please sign in to comment.