Commit Graph

61 Commits

Author SHA1 Message Date
Herbert Wolverson
93e8afae71 Replace unsafe bpf_num_possible_cpus() with safe Rust function.
Port the C from `bpf_num_possible_cpus()` over to safe Rust,
with proper error handling and unit tests to ensure that it
is giving the correct answers. Change usages to the new safe
function.
2023-03-22 14:32:31 +00:00
Herbert Wolverson
130c888e22 Heimdall now only watches those who request to be watched by default. 2023-03-22 14:32:30 +00:00
Herbert Wolverson
26efcdb208 Proof of concept with a tiny webserver 2023-03-20 19:17:21 +00:00
Herbert Wolverson
b19b8b356b Truly minimal stats server, but it works. 2023-03-20 19:17:21 +00:00
Herbert Wolverson
ef5ffa4e64 Start to add sqlite db - we'll probably use postgres, but I wanted something for testing. 2023-03-20 19:17:21 +00:00
Herbert Wolverson
c1c5f3bba4 Initial stats collection protocol. 2023-03-20 19:17:20 +00:00
Herbert Wolverson
adc3bb8eeb dpkg setup adds an auto-generated node-id 2023-03-20 19:16:07 +00:00
Herbert Wolverson
beead5a303 Backport the TC_HANDLE parser to main.
Replace C code with native Rust, including unit tests to find the
edge-cases.
2023-03-20 17:40:03 +00:00
Herbert Wolverson
bbbe1e5b83 The watched queues structure no longer RwLocks - it's an interior mutable DashMap now. 2023-03-08 18:17:17 +00:00
Herbert Wolverson
c5dca04ade Update tree tracker RTT store to use a DashSet for lock-free access. 2023-03-08 18:01:10 +00:00
Herbert Wolverson
ae1d5efb4a Throughput tracker refactor part 1: raw_data is now a DashMap (no locking required). 2023-03-08 17:19:35 +00:00
Herbert Wolverson
67cc8d8e99 Large batch of improvements:
* The JavaScript RingBuffer structure updated correctly.
* Replaced the funnel graph with text - easier to read.
* Discovered that the current "parking_lot" could become unstable
  under very heavy load, and only with "fat" LTO. Since it's
  no longer recommended (recent change), removed it.
* Replaced the "lazy_static" macro suite with the newly recommended
  "once_cell" system. Less code.
* Full source format.
* Update some dependency versions.
2023-03-07 21:37:23 +00:00
Herbert Wolverson
78a45515e6 Update to latest crate dependencies. 2023-03-06 16:04:43 +00:00
Herbert Wolverson
f64862a8ff Network funnel - work in progress
Step 1 of the network funnel

* network.json reader now tags throughput entries with their tree
  location and parents to whom data should be applied.
* Data flows "up the tree", giving totals all the way up.
* Simple network map page for displaying the data while it's worked
  on.
2023-03-04 16:58:17 +00:00
Herbert Wolverson
42c2c63f55 In lqosd, replace lazy_static with once_cell, per Rust best practices
These days the Rust team are recommending "once_cell", which has
simpler syntax and does the same thing.
2023-03-03 20:26:14 +00:00
Herbert Wolverson
433e7ac877 Consolidate hex string to u32 conversion
Rather than having lots of "cpu.replace("0x", "").str_radix(...)
calls around, move to a single, unit-tested function in lqos_utils
and use it repeatedly.
2023-03-03 14:17:31 +00:00
Herbert Wolverson
ca2cb0dcec Update cargo.lock versions again 2023-03-01 14:51:39 +00:00
Herbert Wolverson
6eb9c80a3b Update Cargo.lock to latest versions 2023-02-24 17:41:51 +00:00
Herbert Wolverson
3e9ff0c0f5 (Very alpha!) Add dpkg builder and initial configurator
* Adds a new Rust program, `lqos_setup`.
    * If no /etc/lqos.conf is found, prompts for interfaces and
      creates a dual-interface XDP bridge setup.
    * If no /opt/libreqos/src/ispConfig.py is found, prompts
      for bandwidth and creates one (using the interfaces also)
    * Same for ShapedDevices.csv and network.json
    * If no webusers are found, prompts to make one.
* Adds build_dbpkg.sh
    * Creates a new directory named `dist`
    * Builds the Rust components in a portable mode.
    * Creates a list of dependencies and DEBIAN directory
      with control and postinst files.
    * Handles PIP dependencies in postinst
    * Calls the new `lqos_setup` program for final
      configuration.
    * Sets up the daemons in systemd and enables them.

In very brief testing, I had a working XDP bridge with
1 fake user and a total bandwidth limit configured and
working after running:

dpkg -i 1.4-1.dpkg
apt -f install

Could still use some tweaking.
2023-02-21 20:26:34 +00:00
Herbert Wolverson
dcb0ae8444 Add an additional NUM_CPUS atomic to store the actual size. CPU
utilization is updated in a lock-free array of atomics. Another
lock removed (and another unmeasurably small gain)
2023-02-14 21:27:37 +00:00
Dave Taht
8ba5aed14e lqusers: change name of web admin tool from webusers to lqusers
lqusers is consistent with the prefix used elsewhere in LibreQos.

Something one character shorter than that came to mind, but
I resisted.
2023-02-09 15:21:02 +00:00
Herbert Wolverson
51c369b9b5 Update dependencies. 2023-02-09 14:36:47 +00:00
Herbert Wolverson
38a2a78062 Finish Rust package update cycle per ISSUE #229 2023-02-01 19:13:23 +00:00
Herbert Wolverson
d198c0feac Update Tokio and all dependency versions based on local run
of cargo audit and cargo outdated.

Part of ISSUE #229
2023-02-01 18:44:38 +00:00
Herbert Wolverson
9ad1de6ef5 Add safegaurd against running LibreQoS.py more than once at a time.
ISSUE #52

* Added file locking commands to the Python/Rust library.
* When LibreQoS.py starts, it checks that /var/run/libreqos.lock
  does not exist. If it does, it checks that it contains a PID
  and that PID is not still running with a python process.
* If the lock file exists and is valid, execution aborts.
* If the lock file exists and is invalid, it is cleaned.
* Cleans the lock on termination.
2023-02-01 17:09:42 +00:00
Herbert Wolverson
74101655d8 ISSUE #209 - Full error pass on lqos_queue_tracker module
* Replace every value unwrap with unwrap_or to not panic.
* Replace Anyhow errors with specific errors and log entries.
2023-01-31 21:31:03 +00:00
Herbert Wolverson
982e7314c1 Thorough error-handling pass on lqos_bus crate.
ISSUE #209

Replace "anyhow" with "thiserror". Add logging for all errors,
and only allow pass-through for errors that have already been
converted to a local error type and reported.
2023-01-31 19:33:22 +00:00
Herbert Wolverson
816ca7e651 Refactor the multiple "notify" systems into a single helper
structure.

* Creates FileWatcher, in lqos_utils.
* Removes "notify" dependency from other crates.

FileWatcher is designed to watch a file. If the file doesn't exist,
then an optional callback is called - and the watcher waits,
periodically checking to see if the file has appeared yet. When the
file appears, another optional callback is executed.

Once the file exists, a `notify` system is started (it uses Linux's
`inotify` system internally) for that file. When the file changes,
the process sleeps briefly and then executes an `on_change` callback.
Further messages are then suppressed for a short period to avoid
duplicates.

All uses of notify have been updated to use this system. Errors are
handled cleanly, per ISSUE #209.
2023-01-31 17:52:35 +00:00
Herbert Wolverson
c911d8c190 Fix a chicken & egg problem with queueingStructure.json monitor
ISSUE #209

Using the inode watcher on a file that doesn't exist fails, and
was previously failing silently! This would result in queue
mappings not updating when LibreQoS.py was executed - even though
the queueingStructure.json file became available.

* Replace "anyhow" with specific errors.
* Track and log each step of the file monitor process for
  queueingStructure.json
* If the watcher cannot start because the file doesn't exist,
  the watcher loop sleeps for 30 seconds at a time (to keep
  load very low) and checks if the file exists yet. If it does,
  it loads it and then commences watching.
2023-01-31 15:49:29 +00:00
Herbert Wolverson
39e2689707 ISSUE #209: CSV ShapedDevices reader now uses this_error format for more specific errors and contains more logging. 2023-01-30 22:44:22 +00:00
Herbert Wolverson
a29391c25c ISSUE #209 : Add full error checking and custom error type to EtcLqos load system. 2023-01-30 17:57:15 +00:00
Herbert Wolverson
ee20023027 Refactor fd timer wait into a "periodic" function in lqos_utils,
only available for non-async use at this time. Adjust the two
non-async usages of timer-fd based timers to use the more
canonical setup.
2023-01-30 17:45:17 +00:00
Herbert Wolverson
7d32c720f0 Rocket web server's ring-buffer update timer is now a Linux
file descriptor.

* Remove the Tokio timer system.
* Replace with Linux's timer fd system.
* Add a watchdog to alert if we've somehow overrun the timer.
2023-01-30 17:22:28 +00:00
Herbert Wolverson
6b6bdc1395 Improved queue watching system
* Queue timing is now provided by Linux "timer file descriptors"
  instead of Tokio timers.
* Added an atomic bool to track "we're going faster than we should"
  (it's true while executing), skip cycles if we ran out of time and
  issue a warning.
* Queue tracking is no longer async, but is locked to its very own
  thread.
* Queue watcher is now more verbose about any issues it encounters.
* Queue structures with children will now correctly track all the
  children, avoiding the blank queue data issue.
2023-01-30 16:55:42 +00:00
Herbert Wolverson
ec5baaf866 Move netlink-testing out of main - it's in a branch, where it belongs. 2023-01-30 15:28:23 +00:00
Dave Taht
40758ffe6b lq_utils: Move packet scaling routines to library
This moves the packet scaling routines for g/m/k gps and
g/m/k bytes to a shared library.
2023-01-21 20:41:37 +00:00
Herbert Wolverson
37355189b9 Work in progress: transmute netlink cake stats to readable data. Currently uses bytemuck, should be using zerocopy. 2023-01-21 03:31:48 +00:00
Herbert Wolverson
14e49ce183 Super incomplete hacking away at netlink access for queues. 2023-01-20 21:52:56 +00:00
Herbert Wolverson
f742acafda Merge branch 'main' of https://github.com/LibreQoE/LibreQoS 2023-01-20 19:29:04 +00:00
Herbert Wolverson
922ddd602f A bit of a hybrid commit, sorry. Provides various default pre-allocations that seem reasonable, and fixup on bus permissions. 2023-01-20 19:28:54 +00:00
Dave Taht
3c6f438e06 queue_tracker: use info_once on new fields
Modern linuxes add fields all the time. On a kernel upgrade we
shouldn't crash just because there's a new json field.

Also there are some further optimizations to represent the kernel
structures themselves. Some fields can overflow which would lead
to some surprizing behaviors in polling the json over time.

FIXME - always check for overflow elsewhere, in packets, overlimits
etc. Could that be a trait?
2023-01-20 18:37:23 +00:00
Herbert Wolverson
287ddb6e10 Global allocator and compilation flags update
On systems that support it, `jemallocator` will replace the default
allocator for `lqosd` and `lqos_node_manager`. The Jem allocator
is a LOT more friendly to Rust's preferred vector allocation patterns,
and actually cares about your cache.

Enable "fat" Link-Time Optimization. This slows down compilation a lot,
but results in smaller binaries and permits the LLVM optimizer to
cross crate boundaries when inlining, optimizing tail calls and a
few other optimizations.
2023-01-20 18:06:41 +00:00
Herbert Wolverson
ed07a4666b Add file locking to lqosd
The file locking is "smart": it checks to see if a lock is
valid before refusing to run (and updates the lock if
it can run anyway).

The locking mechanism will fail if you manually create
the lock file and dump random data into it that doesn't
readily convert to an i32.

Affects issue #54 and issue #52

* Add a new structure `FileLock` to `lqosd`.
* FileLock first checks /run/lqos/lqosd.lock. If it exists,
  it opens it and attempts to read a PID from it. If that PID
  is running and the associated name includes "lqosd", the
  FileLock returns an error.
* If no lock exists, then a file is created in
  /run/lqos/lqosd.lock containing the running PID.
* Includes Drop and signal termination support.
2023-01-20 16:05:55 +00:00
Herbert Wolverson
7a0f066c63 Display errors when loading ShapedDevices 2023-01-19 20:16:20 +00:00
Herbert Wolverson
3e12e95f66 Create lqos_utils as a repository for useful macros. Move the string table macro. Start working on some command wrappers for easier use. 2023-01-19 17:52:19 +00:00
Herbert Wolverson
da6a8f08a2 Move the socketserver into the bus crate also, makes more sense there. 2023-01-18 22:28:15 +00:00
Herbert Wolverson
58c692425b Benchmark suite includes local socket round-trip. 2023-01-18 22:01:58 +00:00
Herbert Wolverson
6c52fceb7f WIP - Use a UNIX stream socket rather than TCP for local bus communications. 2023-01-18 21:21:42 +00:00
Herbert Wolverson
f9351757ca Remove per-tick printing
Cap number of watched queues at (CPU cores * 2), per belyivulk
2023-01-17 20:06:33 +00:00
Herbert Wolverson
6269f41b67 Use Rayon to parallelize the queue reader 2023-01-17 19:53:59 +00:00