Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - fsackur

#1
Development and Code Review / How to lint
April 23, 2025, 12:27:47 PM
What am I doing wrong with the linters?

I had a tiny PR looked at by Franco and Ad. They found lint which wasn't found by `make lint` or `make style`.

In fact, make style gave this output, which looks wrong to me:

FILE: /gitroot/core/src/opnsense/mvc/tests/app/config/config.php
----------------------------------------------------------------------
FOUND 17 ERRORS AFFECTING 1 LINE
----------------------------------------------------------------------
 2 | ERROR | [x] Expected at least 1 space before "."; 0 found
 2 | ERROR | [x] Expected at least 1 space after "."; 0 found
 2 | ERROR | [x] Expected at least 1 space before "."; 0 found
 2 | ERROR | [x] Expected at least 1 space after "."; 0 found
   ...etc...

Deleting the doc comment didn't change the result.

The lint was at https://github.com/opnsense/core/pull/8567/files/65329ce3311d87cb9b3b458149be83103da7f88d#diff-07480bce72d334fe48601b41482cb74c83f5fa9152017c4e1460ab787654e453

Each ascii `.` has a single ascii space each side.
#2
That endpoint takes parameters: specifically, path parameters for host and backup.

The relevant endpoints are:
GET /core/backup/backups/{host} - list available backups for selected host
GET /core/backup/download/{host}/{backup} - download specified backup, when left empty the latest is offered

`host` needs to be the magic string `this` for the local host.

If you just want the latest endpoint, your URI should be `https://192.168.0.1:443/api/backup/download/this`
#3
My current dev work is mostly parsing the source code, so I'm developing locally for the most part.

In my first quick-and-dirty hacking, I did a bunch of symlinking and rsync. Don't do that, it was miserable.

I fantasise about being an emacs/tmux wizard, but in the real world I'm just a VSCode user. There was a brief window when you could VSCode SSH to BSD, but that window is gone. BOO. I've also tried the SSHFS extension, but there are too many files for it to cope. So it's necessary to mount the source code into the VM.

I spent time looking into `virtio` so I could use qemu filesystem sharing, but concluded that you need to actually get to grips with BSD to make it work. So I use NFS instead. Here are the steps:

#region virtual host =============================================
dnf install -y nfs-utils  # Fedora is life

pushd /gitroot/opnsense-root  # my local dev folder, you can use /my-little-pony if you prefer
git clone opnsense/core opnsense/plugins opnsense/tools  # whatever

# serve to libvirt subnet
export="/gitroot/opnsense-root 192.168.124.0/24(rw,sync,fsid=0,no_subtree_check,no_root_squash,insecure)"
echo "$export" >> /etc/exports.d/opnsense.exports
systemctl enable --now nfs-server

firewall-cmd --zone=libvirt --permanent --add-service=nfs
firewall-cmd --zone=libvirt --permanent --add-service=mountd
firewall-cmd --zone=libvirt --permanent --add-service=rpc-bind
firewall-cmd --reload

# should show the share
exportfs
#endregion virtual host =============================================


#region BSD VM =============================================
# check yer host firewall ports:
rpcinfo -p 192.168.124.1
#    program vers proto  port  service
#    100000    4  tcp    111  rpcbind
#    100000    3  tcp    111  rpcbind
#      ...etc...
# It's possible for all services to be shown but still get RPC errors. In that case,
# try adding more services: nfs3, portmap. I tested on F41 / BSD14.2.

# You REALLY want bgnow, because mount comes before networking.
# Skip that option and your box won't boot.
#
#      Device                               Mountpoint  FStype  Options                Dump  Pass
mount="192.168.124.1:/gitroot/opnsense-root /gitroot    nfs     rw,bgnow,soft,noatime  0    3"
echo "$Mount" | sudo tee -a /etc/fstab
# yeah I installed sudo on BSD. I never claimed to be a good person.

git config --global --add safe.directory /gitroot/core
git config --global --add safe.directory /gitroot/plugins
git config --global --add safe.directory /gitroot/tools

# Use script from https://medium.com/@mihakralj/the-direct-route-installing-freebsd-packages-on-opnsense-d002ac0c56b8
# Update script packagesite.txz => packagesite.tzst
./sideload.sh py311-pip 
# output:
# pkg add https://pkg.freebsd.org/FreeBSD:14:amd64/latest/All/py311-pip-23.3.2_4.pkg
# then you can do:
pip install libfoo
# ...but, for awareness, the OS packages will be 99 versions behind pypi, so you
# can't easily release on these versions

# If you can live with old versions, do:
./sideload.sh py311-libfoo
# or you can vendor in the libraries, but upstream might not be best pleased!

#endregion BSD VM =============================================

After doing that, I just dev locally. If you're developing `core`, cd into the repo and do `make mount`. If you're developing a plugin, cd into the dir containing your `src` and your `Makefile` and do `make install && service configd restart && configctl foo bar`.

The PHP extensions I've tried in Code thrash my poor little box. I can have the plugins repo open, but not the core repo, or my poor little host starts whining like a jumbo jet. Half the time I'm doing text search instead of using the LSP because the fan noise is just silly.

One other thing, delete `/tmp/opnsense_menu_cache.xml` if you create a `Menu.xml`, or you'll be forever wondering why it doesn't show up.