Openwrt build for >= v1.4.2

Description of problem:

A couple of problems arose while trying to get the meson build working in openwrt env for v1.4.2 tag.

protobuf

ninja: Entering directory `/home/build/build/build_dir/target-aarch64_generic_musl/ocserv-1.4.2/openwrt-build'
[1/161] /home/build/build/staging_dir/hostpkg/bin/protoc-c --c_out=src --proto_path=../src ../src/ipc.proto
[libprotobuf WARNING /home/build/build/build_dir/hostpkg/protobuf-c-1.5.2/protoc-gen-c/main.cc:45] `protoc-c` is deprecated. Please use `protoc` instead!
[2/161] /home/build/build/staging_dir/hostpkg/bin/protoc-c --c_out=src --proto_path=../src ../src/ctl.proto
[libprotobuf WARNING /home/build/build/build_dir/hostpkg/protobuf-c-1.5.2/protoc-gen-c/main.cc:45] `protoc-c` is deprecated. Please use `protoc` instead!

It seems protoc should be preferred over protoc-c (host build).

c bug

Maybe this has already been fixed?

../src/config.c: In function 'figure_acct_funcs':
../src/config.c:421:23: warning: comparison is always false due to limited range of data type [-Wtype-limits]
  421 |         for (i = 0; i < ARRAY_SIZE(avail_acct_types); i++) {
      |                       ^

ipcalc

There is a hard requirement on ipcalc (but it's only needed for tests which can be skipped), but openwrt does not provide it. It has ipcalc.sh whose output is:

ipcalc.sh [ -d | -x ] address/prefix [ start limit ]
root@host:~# ipcalc.sh 192.168.1.0/255.255.255.0
IP=192.168.1.0
NETMASK=255.255.255.0
BROADCAST=192.168.1.255
NETWORK=192.168.1.0
PREFIX=24
COUNT=256

and works identically, without the -p flag.

The nftables version of ocserv-fw-nftables invokes eval $(${IPCALC} -p "$1"); but the required ipcalc does not understand -p.

Debian ipcalc:

...
Usage: ipcalc [options] <ADDRESS>[[/]<NETMASK>] [NETMASK]

ipcalc takes an IP address and netmask and calculates the resulting
broadcast, network, Cisco wildcard mask, and host range. By giving a
second netmask, you can design sub- and supernetworks. It is also
intended to be a teaching tool and presents the results as
easy-to-understand binary values.

 -n --nocolor  Don't display ANSI color codes.
 -c --color    Display ANSI color codes (default).
 -b --nobinary Suppress the bitwise output.
 -c --class    Just print bit-count-mask of given address.
 -h --html     Display results as HTML (not finished in this version).
 -v --version  Print Version.
 -s --split n1 n2 n3
               Split into networks of size n1, n2, n3.
 -r --range    Deaggregate address range.
    --help     Longer help text.

Examples:

ipcalc 192.168.0.1/24
ipcalc 192.168.0.1/255.255.128.0
ipcalc 192.168.0.1 255.255.128.0 255.255.192.0
ipcalc 192.168.0.1 0.0.63.255


ipcalc <ADDRESS1> - <ADDRESS2>  deaggregate address range

ipcalc <ADDRESS>/<NETMASK> --s a b c
                                split network to subnets
				where a b c fits in.

! New HTML support not yet finished.

ipcalc 0.51

There is also the busybox ipcalc applet which I have not explored.

nftables / iptables

The openwrt default is nftables, but the meson build won't find nft and subsequently falls back to the iptables version. Specifying -Dfirewall-script=nftables still results in:

Program nft found: NO
Message: firewall script: iptables
...

DESTDIR="/home/build/build/build_dir/target-aarch64_generic_musl/ocserv-1.4.2/ipkg-install" MAKEFLAGS="" /home/build/build/staging_dir/host/bin/ninja -v -j1 -C /home/build/build/build_dir/target-aarch64_generic_musl/ocserv-1.4.2/openwrt-build install
ninja: Entering directory `/home/build/build/build_dir/target-aarch64_generic_musl/ocserv-1.4.2/openwrt-build'
[0/1] /home/build/build/staging_dir/host/bin/python3 /home/build/build/staging_dir/host/bin/meson.py install --no-rebuild
...
Installing /home/build/build/build_dir/target-aarch64_generic_musl/ocserv-1.4.2/src/ocserv-fw-iptables to /home/build/build/build_dir/target-aarch64_generic_musl/ocserv-1.4.2/ipkg-install/usr/libexec
...
ocserv-1.4.2/.built

The meson file looks correct for this nft part.