25 Commits

Author SHA1 Message Date
timmy b15bede430 Best practices 2026-07-12 14:12:15 -07: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 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 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 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 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
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 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