Klemens Nanni [Sat, 27 Jan 2024 05:44:35 +0000 (06:44 +0100)]
Hoist control socket handling, restrict runtime on OpenBSD
Use pledge(2) to prevent fork/exec, filesystem access and other
unused subsets of system calls, effectively leaving only shared
memory and networking capabilities at runtime.
(Those might be further reduced, but that warrants further analysis
and most likely more code shuffling.)
Klemens Nanni [Sat, 27 Jan 2024 04:36:29 +0000 (05:36 +0100)]
Hoist PTP socket handling, drop privileges on OpenBSD
bind(2)ing ports below 1024 is the only privileged operation NQPTP does.
Move its code up in main() before shared memory handling such that root
privileges can be dropped immediately after it; no currently supported
system does that, thus this should be a NOOP.
Do so on OpenBSD where shm_open(3) does not allow access to shared memory
objects by multiple UIDs, i.e. to communicate, shairport-sync and NQPTP
must create them and run as the very same user.
OpenBSD's official audio/shairport-sync user provides an rc.d(8) daemon
script that runs as `_shairport` user.
Mike Brady [Tue, 19 Sep 2023 10:08:27 +0000 (11:08 +0100)]
Improve some of the error messages. Remove the setcap command from Makefile.am, since we are now using an AmbientCapabilities setting in the systemd service file.
Mike Brady [Tue, 13 Dec 2022 09:07:02 +0000 (09:07 +0000)]
Add version string to initial debug message
Work out when the clock can be relied upon not to go to sleep, i.e. is "active". This is when SPS is playing (B) or paused (P) and for brief periods after the clock is selected (T) and after play ends (E).
SPS signals Play/Pause/End/Timer Select/Timer Release with B/P/E/T messages -- B for "Begin". "T <ip>" means select the clock at that address. "T" means release the clock.
Reset clock smoothing when the clock goes "active" but not at any other time.
Clamp reductions in the offset calculated as a uint64_t remote-time-now_ns - local-time-now_ns -- and which it is assumed are due to delays in the network when the clock is "active" -- to 2.5 mS.
Turn off clock updates when the clock is not "active" -- i.e. when SPS is not paying or paused.
Remove some redundant features and code.
Mike Brady [Sat, 10 Dec 2022 11:55:03 +0000 (11:55 +0000)]
Add ability to receive status information from SPS B/E/P for Begin/End/Pause play. Assume clocks don't sleep between Begin and End and are valid for short times after T and after E. More cleaning up to do.
Mike Brady [Wed, 7 Dec 2022 14:44:11 +0000 (14:44 +0000)]
Allow clock to resent if the grandmaster is the same as the master and it stops for two or more samples. Always send a wakeup to the master at the start.
* Bump NQPTP_SHM_STRUCTURES_VERSION to 8.
* Remove the ability to handle multiple instances of AirPlay-2-capable Shairport Sync on the same system -- it seems clear that clients can not use this facility.
* Greatly simplify NQPTP by only monitoring PTP information coming from the client, ignoring all other PTP information.
* Improve the accuracy of the clock by taking correction field information into account.
* In addition to trying to restart a clock that is silent, also send a restart to a clock if the clock's grandmaster appears to have stopped.
Squashed commit of the following:
Add some experimental exploratory code.
Ignore the INSTALL document. Let INSTALL always be autogenerated.
Enhanced and corrected ptp definitions.
Fix shm name to work with FreeBSD. Update the SHM version.
Change order of includes to avoid a compilation error in FreeBSD
Fix potential bugs in finding a clock ID in a FreeBSD device.
Only try to restart a stopped clock if it's the clock itself that has stopped and not a different grandmaster. Allow fast changes for up to one second after the start of mastership.
Make the code to restart a clock a separate function and call it if a clock gets stuck. Include the correction field in the calculation of the precise origin timestamp. If a new clock is out by more than -4 seconds, treat it as a discontinuity rather than noise.
Add a net-to-host converter for 64-bit arithmetic
Mike Brady [Mon, 12 Sep 2022 14:07:15 +0000 (15:07 +0100)]
* Bump NQPTP_SHM_STRUCTURES_VERSION to 8.
* Remove the ability to handle multiple instances of AirPlay-2-capable Shairport Sync on the same system -- it seems clear that clients can not use this facility.
* Greatly simplify NQPTP by only monitoring PTP information coming from the client, ignoring all other PTP information.
* Improve the accuracy of the clock by taking correction field information into account.
* In addition to trying to restart a clock that is silent, also send a restart to a clock if the clock's grandmaster appears to have stopped.
Squashed commit of the following:
Add some experimental exploratory code.
Ignore the INSTALL document. Let INSTALL always be autogenerated.
Enhanced and corrected ptp defiinitions.
Fix shm name to work with FreeBSD. Update the SHM version.
Change order of includes to avoid a compilation error in FreeBSD
Fix potential bugs in finding a clock ID in a FreeBSD device.
Only try to restart a stopped clock if it's the clock itself that has stopped and not a different grandmaster. Allow fast changes for up to one second after the start of mastership.
Mike Brady [Sun, 31 Jul 2022 11:35:30 +0000 (12:35 +0100)]
Add a handle_sync to see if a correctionfiled is ever used. Modify handle_follow_up to (mostly) only work on a master clock. Wait for a minute to restart a stopped clock. Always invalidate the clock when an empty peer list is sent.
Mike Brady [Thu, 14 Jul 2022 16:55:38 +0000 (17:55 +0100)]
Make the code to restart a clock a separate function and call it if a clock gets stuck. Include the correction field in the calculation of the precise origin timestamp. If a new clock is out by more than -4 seconds, treat it as a discontinuity rather than noise.
Mike Brady [Sat, 9 Jul 2022 09:02:35 +0000 (10:02 +0100)]
If the previous offset's grandmaster is different from the current one, discard all the smoothing stuff, including previous offset data, and work as if it was a completely new clock.
Mike Brady [Sat, 9 Jul 2022 09:00:18 +0000 (10:00 +0100)]
Add is a field to store the grandmaster the previous offset refers to. The idea is that if the new grandmaster is different from the previous one, start over.