Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions board/common/rootfs/etc/dnsmasq.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
domain-needed
dhcp-authoritative

# Lets the DHCP relay agent share UDP port 67 with the DHCP server
bind-dynamic

# Allow configuration and cache clear over D-Bus
enable-dbus

Expand Down
1 change: 1 addition & 0 deletions configs/aarch64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ BR2_PACKAGE_CURIOS_NFTABLES=y
BR2_PACKAGE_GENCERT=y
BR2_PACKAGE_STATD=y
BR2_PACKAGE_SUPPORT_ENCRYPT=y
BR2_PACKAGE_DHCPRELAYD=y
BR2_PACKAGE_FACTORY=y
BR2_PACKAGE_FINIT_PLUGIN_HOTPLUG=y
BR2_PACKAGE_FINIT_PLUGIN_HOOK_SCRIPTS=y
Expand Down
1 change: 1 addition & 0 deletions configs/aarch64_minimal_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ BR2_PACKAGE_CONFD_TEST_MODE=y
BR2_PACKAGE_GENCERT=y
BR2_PACKAGE_STATD=y
BR2_PACKAGE_SUPPORT=y
BR2_PACKAGE_DHCPRELAYD=y
BR2_PACKAGE_FACTORY=y
BR2_PACKAGE_FINIT_PLUGIN_HOTPLUG=y
BR2_PACKAGE_FINIT_PLUGIN_HOOK_SCRIPTS=y
Expand Down
1 change: 1 addition & 0 deletions configs/arm_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ BR2_PACKAGE_CONFD_TEST_MODE=y
BR2_PACKAGE_GENCERT=y
BR2_PACKAGE_STATD=y
BR2_PACKAGE_SUPPORT_ENCRYPT=y
BR2_PACKAGE_DHCPRELAYD=y
BR2_PACKAGE_FACTORY=y
BR2_PACKAGE_FINIT_PLUGIN_HOTPLUG=y
BR2_PACKAGE_FINIT_PLUGIN_HOOK_SCRIPTS=y
Expand Down
1 change: 1 addition & 0 deletions configs/arm_minimal_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ BR2_PACKAGE_CONFD_TEST_MODE=y
BR2_PACKAGE_GENCERT=y
BR2_PACKAGE_STATD=y
BR2_PACKAGE_SUPPORT=y
BR2_PACKAGE_DHCPRELAYD=y
BR2_PACKAGE_FACTORY=y
BR2_PACKAGE_FINIT_PLUGIN_HOTPLUG=y
BR2_PACKAGE_FINIT_PLUGIN_HOOK_SCRIPTS=y
Expand Down
1 change: 1 addition & 0 deletions configs/riscv64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ BR2_PACKAGE_CONFD_TEST_MODE=y
BR2_PACKAGE_GENCERT=y
BR2_PACKAGE_STATD=y
BR2_PACKAGE_SUPPORT_ENCRYPT=y
BR2_PACKAGE_DHCPRELAYD=y
BR2_PACKAGE_FACTORY=y
BR2_PACKAGE_FINIT_PLUGIN_HOTPLUG=y
BR2_PACKAGE_FINIT_PLUGIN_HOOK_SCRIPTS=y
Expand Down
1 change: 1 addition & 0 deletions configs/x86_64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ BR2_PACKAGE_CURIOS_NFTABLES=y
BR2_PACKAGE_GENCERT=y
BR2_PACKAGE_STATD=y
BR2_PACKAGE_SUPPORT_ENCRYPT=y
BR2_PACKAGE_DHCPRELAYD=y
BR2_PACKAGE_FACTORY=y
BR2_PACKAGE_FINIT_PLUGIN_HOTPLUG=y
BR2_PACKAGE_FINIT_PLUGIN_HOOK_SCRIPTS=y
Expand Down
1 change: 1 addition & 0 deletions configs/x86_64_minimal_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ BR2_PACKAGE_CONFD_TEST_MODE=y
BR2_PACKAGE_GENCERT=y
BR2_PACKAGE_STATD=y
BR2_PACKAGE_SUPPORT=y
BR2_PACKAGE_DHCPRELAYD=y
BR2_PACKAGE_FACTORY=y
BR2_PACKAGE_FINIT_PLUGIN_HOTPLUG=y
BR2_PACKAGE_FINIT_PLUGIN_HOOK_SCRIPTS=y
Expand Down
10 changes: 10 additions & 0 deletions doc/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ All notable changes to the project are documented in this file.
action on the Ethernet container of the interface, which the `show
interface <port>` command and the WebUI interface page run. The octet
counters of an interface remain in the operational datastore
- New DHCP relay agent, with support for option 82, the relay agent
information option. It relays per bridge port, to a server in the
network or on the device itself, see [DHCP Relay][dhcp-relay], issue
#438
- DHCP server: a static host can match on option 82, circuit-id and
remote-id, for an address per port, and has a `preempt` setting that
lets a replacement device take over the address at once, see
[DHCP Server][dhcp-port], issue #705
- Banana Pi BPI-R64: the board identity, base MAC address included, can
be stored in `/mnt/aux/vpd.bin`, see [VPD][vpd]. The ports then get
permanent addresses derived from the chassis MAC instead of random
Expand Down Expand Up @@ -338,6 +346,8 @@ All notable changes to the project are documented in this file.
[pppoe]: https://www.kernelkit.org/infix/latest/pppoe/
[modem]: https://www.kernelkit.org/infix/latest/modem/
[alarms]: https://www.kernelkit.org/infix/latest/alarms/
[dhcp-relay]: https://www.kernelkit.org/infix/latest/dhcp-relay/
[dhcp-port]: https://www.kernelkit.org/infix/latest/dhcp/#address-per-port
[vpd]: https://www.kernelkit.org/infix/latest/vpd/#vpd-file-on-the-aux-partition
[usb]: https://www.kernelkit.org/infix/latest/hardware/#usb-ports
[gps]: https://www.kernelkit.org/infix/latest/hardware/#anchor-a-gps-receiver-to-a-usb-port
Expand Down
1 change: 1 addition & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ regression test system solely relies on NETCONF and RESTCONF.
- [Network Configuration](networking.md)
- [Wi-Fi](wifi.md)
- [DHCP Server](dhcp.md)
- [DHCP Relay](dhcp-relay.md)
- [TFTP Server](tftp.md)
- [SNMP](snmp.md)
- [Cellular Modem (WWAN)](modem.md)
Expand Down
188 changes: 188 additions & 0 deletions doc/dhcp-relay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
DHCP Relay
==========

A DHCP relay agent lets clients get their address from a DHCP server
they cannot reach with a broadcast, or from one that needs to know
where in the network a client is connected. The relay agent picks up
the clients' requests, sends them on to one or more servers, and relays
the replies back.

The relay agent can add the relay agent information option, option 82,
to each request. It tells the server which port the request arrived
on, the *circuit-id*, and which relay agent sent it, the *remote-id*.
The server can then hand out an address per port instead of per device:
the camera on port `e2` always gets the same address, and so does the
camera that replaces it.

Only DHCPv4 is supported.


## Basic Configuration

The clients are connected to the ports of bridge `br0`, which has the
address 192.168.1.1/24. The DHCP server, 192.168.2.2, is on another
network that the device has a route to:

<pre class="cli"><code>admin@example:/> <b>configure</b>
admin@example:/config/> <b>edit dhcp-relay</b>
admin@example:/config/dhcp-relay/> <b>set server 192.168.2.2</b>
admin@example:/config/dhcp-relay/> <b>set interface br0</b>
admin@example:/config/dhcp-relay/> <b>leave</b>
</code></pre>

Requests from all ports of the bridge are now relayed. The address of
the interface, here 192.168.1.1, is the *gateway address*: the server
sends its replies to it and uses it to select the subnet to hand out an
address from. The server therefore needs a route back to it.

Any other interface, or a VLAN interface, can be relayed from as well,
see [VLANs](#vlans) below. When more than one server is set, requests
are sent to all of them. A server set for an interface replaces the
global ones for that interface.

> [!NOTE]
> Requests on a bridge port that is relayed from are not forwarded by
> the bridge. A DHCP server connected to another port of the same
> bridge only sees the relayed requests.


## Option 82

Enable option 82 for all interfaces:

<pre class="cli"><code>admin@example:/config/> <b>edit dhcp-relay</b>
admin@example:/config/dhcp-relay/> <b>set option82</b>
admin@example:/config/dhcp-relay/> <b>leave</b>
</code></pre>

The circuit-id is by default the name of the port, e.g., `e2`, and the
remote-id the base MAC address of the device. Both can be set to a
string, `str`, or to binary data, `hex`, of at most 50 bytes:

<pre class="cli"><code>admin@example:/config/dhcp-relay/> <b>set option82 remote-id str switch-17</b>
admin@example:/config/dhcp-relay/> <b>edit interface br0</b>
admin@example:/config/dhcp-relay/…/br0/> <b>set port e2 circuit-id str camera-18</b>
admin@example:/config/dhcp-relay/…/br0/> <b>leave</b>
</code></pre>

The remote-id can also be the gateway address or the hostname, with
`set option82 remote-id type giaddr` or `hostname`.

A client should never send option 82 itself. What happens to a request
that has it is set with `policy`:

| **Policy** | **Description** |
|------------|---------------------------------------------------------|
| `replace` | Replace it with the relay agent's own, the default |
| `keep` | Relay the request with the option it has |
| `drop` | Drop the request |

To relay from one interface without adding option 82, while it is
enabled for the others:

<pre class="cli"><code>admin@example:/config/dhcp-relay/> <b>set interface e5 option82 false</b>
</code></pre>


## Port Settings

All ports of a bridge are relayed from. The `port` list of an
interface holds the exceptions. It is only available for a bridge and
for a VLAN interface on top of a bridge.

| **Setting** | **Description** |
|--------------|---------------------------------------------------------------|
| `enabled` | Set to false to not relay from the port. DHCP on it is then forwarded by the bridge as any other traffic |
| `trusted` | Set to true for a port where another relay agent, or a switch that adds option 82, is connected |
| `circuit-id` | Circuit-id of the port, default the port name |

Disable relaying on the port a DHCP server is connected to, if nothing
else on the port needs an address:

<pre class="cli"><code>admin@example:/config/dhcp-relay/…/br0/> <b>set port e8 enabled false</b>
</code></pre>


## Chains and Rings of Switches

When several switches in the same subnet relay to the same server, each
switch adds option 82 for its own access ports, and the ports between
the switches are set as trusted:

<pre class="cli"><code>admin@example:/config/dhcp-relay/…/br0/> <b>set port e7 trusted true</b>
admin@example:/config/dhcp-relay/…/br0/> <b>set port e8 trusted true</b>
</code></pre>

On a trusted port:

- option 82 in a request is kept, whatever the `policy`
- a request already relayed by another relay agent is accepted. From
other ports such requests are dropped, since a client could send them
to pick its own circuit-id
- a request without option 82 gets the option of this switch. A
neighboring switch that gets its own address with DHCP is thereby
identified by the port it is connected to

A switch that gets its own address with DHCP starts to relay as soon
as it has its address.

> [!NOTE]
> In a ring, a switch that gets its address with DHCP is connected to
> two neighbors, and both relay its request, with different circuit-ids.
> Match such a switch on something else in the server, e.g., its MAC
> address.


## VLANs

On a VLAN filtering bridge, relay from the VLAN interfaces on top of
the bridge. The address of the VLAN interface is the gateway address,
so each VLAN gets its addresses from its own subnet:

<pre class="cli"><code>admin@example:/config/dhcp-relay/> <b>set interface vlan10</b>
admin@example:/config/dhcp-relay/> <b>set interface vlan20</b>
</code></pre>

The ports of a VLAN interface are the bridge ports with that VLAN as
PVID, and the tagged members of the VLAN. A trunk port is relayed from
in each of its VLANs.


## DHCP Server on the Same Device

The DHCP server can run on the device itself, so a single device hands
out an address per port. Use 127.0.0.1 as server:

<pre class="cli"><code>admin@example:/config/> <b>edit dhcp-relay</b>
admin@example:/config/dhcp-relay/> <b>set server 127.0.0.1</b>
admin@example:/config/dhcp-relay/> <b>set option82</b>
admin@example:/config/dhcp-relay/> <b>set interface br0</b>
admin@example:/config/dhcp-relay/> <b>end</b>
admin@example:/config/> <b>edit dhcp-server subnet 192.168.1.0/24</b>
admin@example:/config/dhcp-server/…/192.168.1.0/24/> <b>set host 192.168.1.42 match option82 circuit-id str e2</b>
admin@example:/config/dhcp-server/…/192.168.1.0/24/> <b>set host 192.168.1.42 preempt true</b>
admin@example:/config/dhcp-server/…/192.168.1.0/24/> <b>leave</b>
</code></pre>

Whatever is connected to port `e2` now gets 192.168.1.42. See [DHCP
Server](dhcp.md#address-per-port) for the `match` and `preempt`
settings.

> [!IMPORTANT]
> Option 82 must be enabled with a server on the same device. The
> clients then also renew their leases through the relay agent.


## Forcing Renewals Through the Relay Agent

A client renews its lease directly with the server, so a renewal does
not pass the relay agent and has no option 82. A server that hands out
addresses by option 82 handles that, but some need the option in every
request:

<pre class="cli"><code>admin@example:/config/dhcp-relay/> <b>set force-server-identity true</b>
</code></pre>

The clients are then told that the relay agent is their server, and
send their renewals to it. The server must support the server
identifier override sub-option, RFC 5107. Option 82 must be enabled.
26 changes: 26 additions & 0 deletions doc/dhcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,32 @@ ASCII string "c0:ff:ee", eight bytes, is used.
> `htype` field of the option to `00`. See RFC 2132 for details.


## Address per Port

A host can also be matched on the relay agent information, option 82,
that a [DHCP relay agent](dhcp-relay.md) adds to the requests it
relays. The circuit-id identifies the port the client is connected to
and the remote-id the relay agent. Whatever is connected to that port
then gets the address, without anyone having to know its MAC address:

<pre class="cli"><code>admin@example:/config/dhcp-server/…/192.168.1.0/24/> <b>edit host 192.168.1.42</b>
admin@example:/config/dhcp-server/…/192.168.1.42/> <b>set match option82 circuit-id str camera-18</b>
admin@example:/config/dhcp-server/…/192.168.1.42/> <b>set match option82 remote-id str switch-17</b>
admin@example:/config/dhcp-server/…/192.168.1.42/> <b>set preempt true</b>
admin@example:/config/dhcp-server/…/192.168.1.42/> <b>leave</b>
</code></pre>

Set the circuit-id, the remote-id, or both, in which case both must
match. Use `hex` instead of `str` for binary values, e.g., a remote-id
that is a MAC address.

A lease is normally kept for the client that got it until it expires.
When a device is replaced, the new one would not get the address of
the port until then. With `preempt` the new client takes over the
address at once. Only one client at a time can have the address, so
use it for ports where a single device is connected.


## Custom DHCP Options

Configure additional DHCP options globally, per subnet, or per host:
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ nav:
- Cellular Modem (wwan): modem.md
- Services:
- Device Discovery: discovery.md
- DHCP Relay: dhcp-relay.md
- DHCP Server: dhcp.md
- NTP Server: ntp.md
- PTP (IEEE 1588/802.1AS): ptp.md
Expand Down
1 change: 1 addition & 0 deletions package/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ source "$BR2_EXTERNAL_INFIX_PATH/package/gencert/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/statd/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/support/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/yangerd/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/dhcprelayd/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/factory/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/faux/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/finit/Config.in"
Expand Down
10 changes: 10 additions & 0 deletions package/dhcprelayd/Config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
config BR2_PACKAGE_DHCPRELAYD
bool "dhcprelayd"
select BR2_PACKAGE_LIBCONFUSE
select BR2_PACKAGE_LIBEV
select BR2_PACKAGE_NFTABLES # runtime, on bridge ports
help
DHCP relay agent with option 82 support, for an IP address
per port on a switch.

https://github.com/kernelkit/dhcprelayd
5 changes: 5 additions & 0 deletions package/dhcprelayd/dhcprelayd.hash
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# From https://github.com/kernelkit/dhcprelayd/releases/tag/v3.0-rc3
sha256 5f2ecad80f60b80749ae381bf17216eb248b105c3f2630dcebb0c5de8f7d8751 dhcprelayd-3.0-rc3.tar.gz

# Locally calculated
sha256 ab15fd526bd8dd18a9e77ebc139656bf4d33e97fc7238cd11bf60e2b9b8666c6 COPYING
21 changes: 21 additions & 0 deletions package/dhcprelayd/dhcprelayd.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
################################################################################
#
# dhcprelayd
#
################################################################################

DHCPRELAYD_VERSION = 3.0-rc3
DHCPRELAYD_SITE = https://github.com/kernelkit/dhcprelayd/releases/download/v$(DHCPRELAYD_VERSION)
DHCPRELAYD_LICENSE = GPL-2.0 or GPL-3.0
DHCPRELAYD_LICENSE_FILES = COPYING
DHCPRELAYD_DEPENDENCIES = host-pkgconf libconfuse libev
DHCPRELAYD_CONF_OPTS = --disable-silent-rules

define DHCPRELAYD_INSTALL_FINIT_SVC
$(INSTALL) -D -m 0644 $(DHCPRELAYD_PKGDIR)/dhcprelayd.svc \
$(FINIT_D)/available/dhcprelayd.conf
endef

DHCPRELAYD_POST_INSTALL_TARGET_HOOKS += DHCPRELAYD_INSTALL_FINIT_SVC

$(eval $(autotools-package))
1 change: 1 addition & 0 deletions package/dhcprelayd/dhcprelayd.svc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service [2345] dhcprelayd -- DHCP relay agent
2 changes: 1 addition & 1 deletion package/klish-plugin-sysrepo/klish-plugin-sysrepo.hash
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Locally calculated
sha256 9d9d33b873917ca5d0bdcc47a36d2fd385971ab0c045d1472fcadf95ee5bcf5b LICENCE
sha256 bf7c99617c6ca6e2e25a1f42fe27af3d40a98b2aaae12fda80e3b52fe0e72054 klish-plugin-sysrepo-6f783b4b3f5a36808fbfc21f9d0e42cc7131a0ea-git4.tar.gz
sha256 ac46a4b45fec6451caf3bdeca14af60dcce0da2bfa85d66d02f75cea9270e079 klish-plugin-sysrepo-d324923396215bafa152c4d8291744be5c34e1cb-git4.tar.gz
2 changes: 1 addition & 1 deletion package/klish-plugin-sysrepo/klish-plugin-sysrepo.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
################################################################################

KLISH_PLUGIN_SYSREPO_VERSION = 6f783b4b3f5a36808fbfc21f9d0e42cc7131a0ea
KLISH_PLUGIN_SYSREPO_VERSION = d324923396215bafa152c4d8291744be5c34e1cb
KLISH_PLUGIN_SYSREPO_SITE = https://github.com/kernelkit/klish-plugin-sysrepo.git
KLISH_PLUGIN_SYSREPO_SITE_METHOD = git
KLISH_PLUGIN_SYSREPO_LICENSE = BSD-3
Expand Down
Loading