39 Commits

Author SHA1 Message Date
timmy b15bede430 Best practices 2026-07-12 14:12:15 -07:00
Ami Fischman 294c93fa17 cmd/ntp: preserve system time in /perm across reboots (#359)
Why? Reduce the wall time during which the system believes it's 1970.
Makes syslog timestamps more sensible.
2026-01-23 10:40:04 +01:00
Ami Fischman d5f6656be1 dhcp: os.Exit(125) after applying static config
Rationale: saves ~16.6MiB of RSS and mildly simplifies the operating conditions of a gokrazy appliance.
Before: `892.4 MiB total, 808.1 MiB available`
After: `892.4 MiB total, 824.7 MiB available`

(cf. https://github.com/gokrazy/gokrazy/discussions/354#discussioncomment-15421711)
2026-01-06 21:59:18 +01:00
Berk D. Demir 7acb85f429 ntp: Allow alternative NTP servers as arguments (#244)
When the gokrazy deployment doesn't have internet access and the network
lacks NTP traffic re-routing to the local time servers, instances may
either have downright wrong clock (e.g. Raspberry Pi with no RTC) or
experience divergence due to drift.

This add the ability to override the default NTP Pool Vendor Zone for
gokrazy with servers supplied as command line arguments.

e.g.
```
    "PackageConfig": {
        "github.com/gokrazy/gokrazy/cmd/ntp": {
            "CommandLineFlags": [
                "time1.local",
                "time2.local",
                "10.1.2.123"
            ]
        }
    }
```
2024-01-18 08:20:56 +01:00
Berk D. Demir 620adabf26 dhcp: Allow -static_network_config to read from a file (#241)
It might be more desirable to deploy the static network configuration as
its own JSON file instead of needing to deal with string quoting it to
fit into `config.json`.

- Add a simple heuristic for checking if the flag value is a JSON string.
  - If the value is JSON, preserve the original behavior
  - If not, treat it value as a file path and load the JSON from there.

- Set lease source string to reflect the source of static configuration.
2024-01-07 11:56:56 +01:00
Michael Stapelberg 078e242069 dhcp: implement resolv.conf trampling protection
Otherwise, when Tailscale updates /tmp/resolv.conf,
gokrazy/dhcp would undo its changes.

See also https://tailscale.com/s/dns-fight

related to https://github.com/gokrazy/gokrazy/issues/209
2023-07-23 17:19:42 +02:00
Daniel Kertesz cd43e0606a dhcp: wait indefinitely for interface to appear (#187)
On systems without an ethernet interface (like the Raspberry Pi Zero)
the `dhcp` program goes into a crash loop because it can't find eth0.

This PR adds an initial loop to wait for the given interface name to
appear before continuing with the rest of the program.

Fixes #144
2023-04-06 12:00:44 +02:00
Michael Stapelberg bd0e160a71 heartbeat: include hostname 2023-02-07 20:03:23 +01:00
Damiano Donati 36ef7f154e move readSBOM to the gokrazy package (#169) 2023-02-05 21:53:53 +01:00
Michael Stapelberg d33c97e94a add cmd/heartbeat (no-op if not configured)
If the --gus_server command line flag is configured,
this program will periodically check in with GUS (gokrazy Update Service).

related to https://github.com/gokrazy/gokrazy/issues/167
2023-02-05 15:59:49 +01:00
Michael Stapelberg fb63ef71df ntp: remove go1.9 stubs, we are at go1.19 2023-01-15 15:24:43 +01:00
Michael Stapelberg 77d1e48813 ntp: randomly select a pool address every time
In particular, only pool 2.gokrazy.pool.ntp.org has IPv6 addresses, so this
fixes setting the time via NTP in IPv6-only environments.
2023-01-15 15:18:33 +01:00
Michael Stapelberg 26498e13c5 ntp: also apply jitter when setting the time failed
for friendlier backoff behavior
2023-01-15 15:18:13 +01:00
Michael Stapelberg d5cbca1b90 Revert "dhcp: use landlock to remove ambient file access"
This reverts commit fbb7618c25.

landlock depends on psx. When cgo is enabled, psx uses a cgo
implementation, which is undesired in setups which use cgo
(e.g. scan2drive with turbojpeg), but don’t come with a libc:
the dhcp client doesn’t start, which means the device is no
longer reachable over the network.
2022-10-14 19:20:10 +02:00
Michael Stapelberg fbb7618c25 dhcp: use landlock to remove ambient file access 2022-10-09 22:36:47 +02:00
Michael Stapelberg e92d116fc1 dhcp: add -extra_route_priority flag to influence interface priority
This is helpful for dual-homed devices where one interface should be preferred,
for example the WiFi interface that’s connected to the out-of-band mobile uplink.
2022-06-19 17:20:26 +02:00
Michael Stapelberg 4c37518767 dhcp: configure route priority to eth* = 1, wlan* = 5, down = 1024
This results in seamless handover between ethernet and wifi when both interfaces
are connected to the same IP network.
2022-03-05 21:54:17 +01:00
Matt Layher 63413ccafb go.mod: switch to github.com/mdlayher/packet@v1.0.0 (#109)
* go.mod: switch to github.com/mdlayher/packet@v1.0.0
* go.mod: bump github.com/rtr7/dhcp4

Signed-off-by: Matt Layher <mdlayher@gmail.com>
2022-02-21 23:24:03 +01:00
Anup Chenthamarakshan 42dba82d7a dhcp: allow builds on non-64-bit architectures (#99)
Move build constraint to internal/iface which clearly shows the Linux dependency
2021-11-28 11:12:33 +01:00
Michael Stapelberg 9250323c5f use Go 1.17 in GitHub Actions 2021-08-18 09:57:24 +02:00
Michael Stapelberg 373c7438b8 dhcp: add -static_network_config override flag 2021-05-28 09:13:44 +02:00
Michael Stapelberg 546057ad9b ntp: log a message after setting the clock
related to https://github.com/gokrazy/tools/issues/15
2020-06-21 07:42:00 +02:00
Michael Stapelberg 9e57e3cf2e dhcp: make network interface name configurable
related to https://github.com/gokrazy/gokrazy/issues/57
2020-05-27 08:24:50 +02:00
Michael Stapelberg 520b8ca41d dhcp: use SetReadDeadline, not SetDeadline
related to https://github.com/mdlayher/raw/issues/42
2019-03-21 09:16:44 +01:00
Michael Stapelberg 856c5b62d4 dhcp: request domain name, too 2019-01-01 17:17:02 +01:00
Michael Stapelberg 3af32e1d14 dhcp: resolve a few TODOs in comments 2018-11-21 08:46:16 +01:00
Michael Stapelberg 14287515bc dhcp: switch to github.com/rtr7/dhcp4
All existing DHCPv4 packages I looked at were unappealing for one reason or
another, so we’re now using a little helper to glue github.com/google/gopacket
and github.com/mdlayher/raw together, which suffices for our use-case and gives
us more control.
2018-11-21 08:43:49 +01:00
Michael Stapelberg 835dae6a18 add randomd (carries entropy across restarts) 2018-07-13 23:44:47 +02:00
Michael Stapelberg 9a14ab0d8d dhcp: add note to prevent future mistakes 2018-06-22 09:02:53 +02:00
Michael Stapelberg 4a126f13af init+dhcp changes for Squashfs root file systems
We can do away with a bunch of hacks now, but we’ll keep them around for a
little while to make updates easier (i.e. to boot with old and new gokr-packer
versions, just in case people don’t update both at the same time).
2018-06-21 23:21:51 +02:00
Michael Stapelberg 6c059494af ntp: set real-time clock (hwclock) if present 2018-06-13 23:51:31 +02:00
Tobias Klauser 50b9390a43 dhcp: simplify Utsname conversion (#36)
Utsname from golang.org/x/sys/unix contains byte array members instead of
int8/uint8. This allows to simplify the NULL byte indexing in
addHostname.
2018-03-29 12:09:08 +02:00
Michael Stapelberg 32e8b6dd34 dhcp: persist domain name to resolv.conf if specified 2017-09-19 14:48:36 +02:00
Michael Stapelberg 6127f9566e dhcp: set client id (option 61), some routers need it
E.g. /etc/kresd/dhcp_host_domain_ng.sh on a turris omnia incorrectly deletes
DHCP hostname mappings when more than one client does not send a client id.
2017-09-05 09:52:53 +02:00
Michael Stapelberg 3ed1e381b5 ntp: drop privileges to nobody/nogroup, retain CAP_SYS_TIME 2017-09-03 22:21:00 +02:00
Michael Stapelberg 83adedae5d ntp: use gokrazy vendor zone
fixes #34
2017-08-25 09:24:15 +02:00
Michael Stapelberg eb8f1753b3 ntp: react to breaking API change
See https://github.com/beevik/ntp/pull/14
2017-08-23 09:51:01 +02:00
Michael Stapelberg 13173460da dhcp: set hostname for renewal packets as well
Otherwise, router restarts might result in the hostname getting
lost (observed using dnsmasq on OpenWrt).
2017-07-01 11:29:10 +02:00
Michael Stapelberg 38af7fd18d Initial commit 2017-03-04 11:22:48 +01:00