Files
oc2r-native-networking/freebsd-notes.md
Jika 27ad967f41
Some checks failed
build / build (push) Has been cancelled
Add support for FreeBSD
2025-10-31 16:29:40 +01:00

3.0 KiB
Raw Permalink Blame History

FreeBSD Support Improvements

  • Native Build Artefacts
    Update oc2r-native-networking/build.sh so producing liboc2rnet-bsd-{x86_64,arm64}.so is part of the normal build pipeline. At the moment the script never emits BSD binaries, so new resources would be missing from CI outputs.

Build and install (FreeBSD)

  1. Install prerequisites

    pkg install openjdk17 clang gmake
    export JAVA_HOME=/usr/local/openjdk17      # adjust if your JDK lives elsewhere
    
  2. Build the FreeBSD JNI bridge

    cd oc2r-native-networking
    ./build-freebsd.sh
    cp build/liboc2rnet-bsd-*.so ../oc2r/src/main/resources/natives/bsd/ # Adjust to your oc2r sources location
    
  3. Compile and install the helper

    cc -O2 -Wall -Wextra -pedantic oc2rnet-helper.c -o oc2rnet-helper
    install -o root -g wheel -m 0755 oc2rnet-helper /usr/local/libexec/oc2rnet-helper
    chmod u+s /usr/local/libexec/oc2rnet-helper
    

Launch helper and validation

  1. Launch the helper

    • Foreground check:
      /usr/local/libexec/oc2rnet-helper
      
    • Background:
      daemon -r -f /usr/local/libexec/oc2rnet-helper
      
  2. Validate the socket and raw privileges

    ls -l /var/run/oc2rnet-helper.sock
    sockstat -l | grep oc2rnet
    
  3. Test the jni against helper

     cc -DCLITEST -O2 -Wall -Wextra -pedantic -Ijni-headers -I"$JAVA_HOME/include" -I"$JAVA_HOME/include/freebsd" bsd_impl.c -o pingtest
    ./pingtest 9.9.9.9
    

    Expect a successful payload echo when the helper is reachable; a NULL result signals the helper was unavailable, matching the mods fallback behaviour.

  4. (optional) Kill daemon

    kill "$(pgrep -fx 'daemon -r -f /usr/local/libexec/oc2rnet-helper')"
    
    

Recompile java mod with freebsd compat

  1. If not already done copy the so file(s) compiled in step 2 of the build section

  2. (optional) Change o2cr mod version in gradle.properties

  3. Run ./gradlew build in the oc2r sources files modified to support FreeBSD

  4. Get the file located in ./build/libs/oc2r-*-all.jar and put it in your mods directory

Important note

Run the helper with daemon(8) or an rc.d script so it stays available. The JNI bridge will fall back to returning null if the helper is unreachable.

Optional helper configuration

Set these environment variables before launching the helper to adjust runtime behaviour:

  • OC2RNET_SOCKET_MODE (octal, default 0666) — override the UNIX socket mode.
  • OC2RNET_SOCKET_GROUP — chown the socket to this group after bind(2).
  • OC2RNET_DROP_USER (default nobody) — unprivileged account the helper switches to once initialisation is complete.
  • OC2RNET_SOCK (default /var/run/oc2rnet-helper.sock) — alternate socket path for jails or non-standard hierarchies.
  • OC2RNET_NO_CAPSICUM — set to any value to skip cap_enter() when Capsicum blocks raw sockets on older releases.