Skip to content

Add DHCP relay agent with option 82 - #1820

Open
troglobit wants to merge 20 commits into
mainfrom
dhcp-relay
Open

troglobit wants to merge 20 commits into
mainfrom
dhcp-relay

Conversation

@troglobit

@troglobit troglobit commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

A camera on port 3 breaks. Someone unscrews it, mounts the spare, and the spare has to come up with the address of the old one, or the video system does not find it. Until now that meant looking up the MAC address of the spare and editing the DHCP server before the swap.

With this PR the address belongs to the port. A relay agent in the switch tags each DHCP request with the port it came in on, option 82, and the DHCP server hands out the address set for that port, also when the lease of the old device has not expired.

Fixes #438
Fixes #705

Setting it up

In the WebUI, a device where DHCP is not set up shows one card under Configuration > DHCP:

not yet set up

Set up asks what the device should do, in the words of the person standing in front of it. Nobody has to know what a relay agent is, or that this case needs both a relay agent and a server:

wizard

The wizard stages the result as any other change, so it can be read in the changes pane before it is applied. For the bridge above that is a static host for each port, matched on the circuit-id the relay agent adds, with preempt set so the spare takes over the address at once:

static hosts

and the relay agent on the same bridge, with every port relayed from and the port name as circuit-id:

relay ports

After that the page is the full view, where a port can be left out, trusted, or given another circuit-id, and where the server gets its other subnets, pools and options. Status > DHCP shows it working, here with the device on p1 holding the first address:

status relay

The same is available without a browser: show dhcp-relay in the CLI, and the relay agent and its state over NETCONF and RESTCONF.

Relay agent

New model infix-dhcp-relay, DHCPv4 only, backed by dhcprelayd 3.0, our fork of the Westermo dhcp-helper.

  • Relays from any interface with an address. On a bridge, or a VLAN interface on top of a bridge, requests are relayed per bridge port
  • Option 82 with circuit-id, default the port name, and remote-id, default the base MAC address. Both can be set as str or hex, the remote-id also as gateway address or hostname
  • policy for requests that already carry option 82: replace (default), keep or drop
  • Per port: enabled, trusted for ports towards other relay agents, and circuit-id
  • Global server list, with an optional list per interface that replaces it
  • force-server-identity, RFC 5107, so renewals also pass the relay agent

Its state is in the operational datastore: the gateway address of each interface, counters for each interface, port and server, and the client a request was last relayed for on each port, with the address it got. dhcprelayd replaces a status file when something changes and yangerd follows it with inotify, nothing is polled.

admin@example:/> show dhcp-relay
br0              : gateway address 192.168.1.1

INTERFACE  PORT  REQUESTS  RELAYED  DROPPED  REPLIES  CLIENT             ADDRESS       LAST REQUEST
br0                     2        2        0        2
           e2           0        0        0        0
           e8           2        2        0        2  00:a0:85:00:01:05  192.168.1.42  2026-12-01 13:13:54

SERVER       INTERFACE  REQUESTS  REPLIES  LAST REPLY
192.168.2.2                    2        2  2026-12-01 13:13:54

A dropped request is logged with the client, the port and the reason.

DHCP server

  • A static host can match on option 82, circuit-id, remote-id or both
  • preempt on a static host lets a new client take over the address before the old lease has expired. This is a new preempt keyword for dhcp-host in dnsmasq, carried as a patch
  • A subnet with only static hosts is now served, it used to need a pool
  • The relay agent and the server can run on the same device, with the server at 127.0.0.1. It is added, with option 82, when the first interface is set up and the DHCP server has a subnet

One change in behavior: every new /24 subnet now gets the .100 to .250 pool, not only the first one, and removing the server no longer leaves its default options behind.

Switch drivers

A switch floods a broadcast before the CPU sees it, so a request leaks past the relay agent to the other ports of the bridge. Three kernel patches trap DHCP requests to the CPU on user ports and leave the forwarding to the software bridge, where the relay agent drops them:

Driver Chips How
mv88e6xxx those with port policy Opt82 port policy set to trap
mt7530 MT7531, MT7988 DHCP Control register, forward to CPU only
sparx5 SparX-5, lan969x VCAP IS2 rule per port

A fourth patch is a fix found on the way: a bridge of lan969x ports with ieee-group-forward forwarded, e.g., LLDP to a veth port but not to its other switch ports. The driver marked reserved link-local multicast as already forwarded, although the switch sends it to the CPU only. The LLDP IEEE Group Forward test would have caught it, but is skipped on the Tactical rig, whose topology has no ieee-mc links.

WebUI

The Configuration > DHCP page is new, and holds both the server and the relay agent, as Status > DHCP does. The two are counterparts, so the tabs in the top bar switch between them.

  • The setup wizard has three goals: hand out addresses on a network, a fixed address per port, and pass requests on to a server on another network. Advanced adds a switch in a chain or ring of switches, static hosts only, and option 82 for the plain relay
  • A server without a subnet, and a relay agent with nothing to relay, is one card with the Set up button. Show settings opens the cards for those who prefer to do it by hand
  • An option that takes an address or auto has a checkbox for auto, not a keyword to type. The rule is now in the WebUI README
  • Fix: the changes pane was not refreshed after a save on most configuration pages, until the page was reloaded. htmx does not mark a reply with HX-Location as successful, the pane now goes by the status of the reply
  • Fix: a dialog that was closed and opened again could show the fields of what was selected last

Other

  • CLI: nodes with a when expression that refers to another subtree were never offered, which hid the port list. Fixed in klish-plugin-sysrepo
  • Manual: new DHCP Relay page, Address per Port in the DHCP server page, and an introduction to DHCP, BOOTP and DHCP options in the IP page

Checklist

Tick relevant boxes, this PR is-a or has-a:

  • Bugfix
    • Regression tests
    • ChangeLog updates (for next release)
  • Feature
    • YANG model change => revision updated?
    • Regression tests added?
    • ChangeLog updates (for next release)
    • Documentation added?
  • Test changes
    • Checked in changed Readme.adoc (make test-spec)
    • Added new test to group Readme.adoc and yaml file
  • Code style update (formatting, renaming)
  • Refactoring (please detail in commit messages)
  • Build related changes
  • Documentation content changes
    • ChangeLog updated (for major changes)
  • Other (please describe):

@troglobit troglobit changed the title Dhcp relay agent Add support for DHCP relay agent Nov 25, 2026
@troglobit
troglobit force-pushed the dhcp-relay branch 2 times, most recently from 2df7118 to e2e08ba Compare December 1, 2026 17:59
@troglobit troglobit changed the title Add support for DHCP relay agent Add DHCP relay agent with option 82, and address per port in the DHCP server Dec 1, 2026
@troglobit troglobit changed the title Add DHCP relay agent with option 82, and address per port in the DHCP server Add DHCP relay agent with option 82 Dec 1, 2026
@troglobit
troglobit marked this pull request as ready for review December 1, 2026 18:06
@troglobit
troglobit requested review from mattiaswal and wkz December 3, 2026 12:57
DHCP relay agent with option 82, for an IP address per port on a
switch.  Installed as an available Finit service, to be enabled when a
relay is configured.

Enabled in all defconfigs that have the DHCP server.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
A node with a when expression that refers to another subtree was never
offered for completion, e.g. a list that only applies when the
interface its parent names is a bridge.  Bump klish-plugin-sysrepo,
which now evaluates the expression against the candidate datastore.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
The address of a static host is not used while another client has a
lease on it.  With a host that matches on the port a client is
connected to, option 82, a device that replaces a broken one does not
get the address of the port until the lease of the old device expires.

With preempt on the dhcp-host the new client takes over the address at
once.  Issue #705

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
dnsmasq binds UDP port 67 on the wildcard address without allowing
another socket on the port, so a relay agent on the same system cannot
bind it on its gateway addresses.  With bind-dynamic it can.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
A subnet in the DHCP server without a pool, only static hosts, was not
served at all: no client got an address from it.  The model allows it,
and it is the natural setup when every address is reserved.

dnsmasq only serves a subnet it has a dhcp-range for, and the range was
written from the pool.  Write a static range for a subnet without one.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
A static host in the DHCP server can be matched on MAC address,
hostname or client-id, all of which follow the device.  With a DHCP
relay agent that adds option 82, the server can instead hand out an
address per port, whatever is connected to it.

Add an option82 case to the host match, with circuit-id and remote-id
as string or hex, and a preempt setting, which lets a device that
replaces a broken one take over the address before the old lease has
expired.  Issue #705

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Clients cannot get an address from a DHCP server on another subnet, and
a server cannot hand out an address per port, without a relay agent
that tells it where a request came from, option 82.

Add the infix-dhcp-relay model and generate the configuration for
dhcprelayd from it.  An interface that is a bridge, or a VLAN interface
on a bridge, relays per bridge port: all ports of a bridge, or the
ports with the VLAN as PVID and its tagged members.  The port list of
an interface only holds the exceptions: a port that should not relay,
a trusted port towards another relay agent, or a circuit-id other than
the port name.

For a server on the device itself, at 127.0.0.1, the server identifier
override is always on, or the clients would be told that their server
is 127.0.0.1.

An interface to relay from is refused without a server, and 127.0.0.1
without option 82.  So when the DHCP server on the device has a subnet,
the first interface gets 127.0.0.1 as server if none is configured, and
a local server enables option 82:

    admin@example:/config/dhcp-relay/> set interface br0
    admin@example:/config/dhcp-relay/> show
    server 127.0.0.1
    option82
    interface br0

Fixes #438

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Five tests, one for each way the relay agent is meant to be used: to a
server on another subnet, to a server on the device itself with a
replaced client, from an interface that is not a bridge without option
82, in a chain of two switches where the first gets its own address
through the second, and on a VLAN filtering bridge with an access port
and a trunk port.

The first test also listens on a second port of the bridge.  No request
from a relayed port may show up there, since a switch that floods the
broadcast before the CPU sees it leaks it past the relay agent.  With
relaying disabled on the port, the request must show up.

The topologies have fixed node positions, so they fit an A4 page of the
test report and render the same with old and new Graphviz.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Only the first subnet of a DHCP server got the default pool, and a
removed server came back with two options:

    admin@example:/config/> no dhcp-server
    admin@example:/config/> show dhcp-server
    option dns-server {

The candidate hook ran on any change to the server.  With no global
options it added them, also when the server had just been removed, and
with global options it returned before it got to the pool.

Run the inference for the subnets a change creates: every new /24
subnet gets a pool, and the options are added with the first one.  A
pool or an option the user removes now stays removed.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
The relay agent could only be set up in the advanced editor.  The new
page lists the interfaces relayed from.  For a bridge, or a VLAN
interface on a bridge, the fold-out shows the ports the device relays
from, where a port can be left out, trusted, or given a circuit-id.
Only ports that differ from the defaults are saved in the port list.

The DHCP servers, option 82, the remote-id and the policy are in the
cards above the list.

The page is the counterpart of Status > DHCP, so the tabs in the top
bar switch between the two.

Issue #438

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
The DHCP server had a status page but could only be set up in the
advanced editor.  The page now lists the subnets, above the relay
agent, with the pool and lease time of each in a fold-out, and below
them the static hosts of the subnet.  A host is matched on MAC address,
hostname, client-id, or the option 82 a relay agent adds, and can have
preempt set, so an address per port is set up without the CLI.

Options, the default gateway and DNS server among them, are a list for
the server and one for each subnet.  Network boot and the options of a
host are left to the advanced editor, which the fold-out links to.

Issue #705

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
With a subnet in the DHCP server of the device and no server in the
relay agent, the server to relay to is most often 127.0.0.1.  Start
the add form of the server list with it.

Issue #438

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
A bridge of LAN969x ports with LLDP in ieee-group-forward forwards LLDP
to a veth port, but not to its other switch ports.  The switch sends
reserved link-local multicast to the CPU only, and the driver marked it
as already forwarded.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
The relay agent could only be followed in the log.  Add its state to
the operational datastore: the gateway address of each interface, the
requests received, relayed and dropped and the replies relayed for each
interface and bridge port, the client a request was last relayed for
with the address it got, and for each server the requests sent to it
and the replies from it.

dhcprelayd replaces its status file when something changed, which is
followed with inotify, nothing is polled.  Needs the status file of
dhcprelayd v3.0.

The DHCP Relay test now also verifies the address of the client in the
state of its port.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
List the interfaces and ports the relay agent relays from, with their
counters and the last client of each port, and the servers:

    admin@example:/> show dhcp-relay
    br0              : gateway address 192.168.1.1

    INTERFACE  PORT  REQUESTS  RELAYED  DROPPED  REPLIES  CLIENT             ADDRESS
    br0                     2        2        0        2
               e8           2        2        0        2  00:a0:85:00:01:05  192.168.1.42

The manual gets a Status section on how to read it, in place of the
table of log messages.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
The DHCP status page only had the server.  Add the relay agent below
it: for each interface its gateway address, and for each port the
requests received, relayed and dropped, the replies relayed, and the
client a request was last relayed for with the address it got.  The
servers are listed with the requests sent to them and the replies
received.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
After a save on most configuration pages, the pane to the right kept
showing the changes from before the save until the page was reloaded.

The pane fetches its diffs again when a write succeeds, and went by
the successful flag of htmx.  Most handlers answer a save with 204 and
an HX-Location header, and htmx returns from such a reply before it
sets the flag.  Go by the status of the reply.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
A text field that takes a value or a keyword, e.g., an address or the
word auto, only works for a user who knows the word.  Write down the
rule the DHCP option form follows: a word the model takes in place of
a value is a checkbox, with the label and help of the schema.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Setting up DHCP on the page took knowing what a relay agent is and
when one is needed, and the page listed the cards of both the server
and the relay agent on a device that uses one of them, or neither.

Set up now opens a dialog that asks what the device should do: hand
out addresses on a network, give the device on each port a fixed
address, or pass requests on to a server on another network.  Advanced
adds the switch in a chain or ring, static hosts only, and option 82.
Each goal stages what the matching section of the manual describes,
and turns on a server or relay agent that was disabled.

A server without a subnet, and a relay agent without servers,
interfaces or option 82, is one card with the Set up button.  With
neither set up, that card is the whole page.  Show settings opens the
cards, and they stay open over a save until the user leaves the page.

A dialog that was closed and opened again showed the fields of the
goal selected last under the first goal, since a form reset fires no
change event.  Fields shown by another field are now updated when a
dialog opens, and a selected radio button that gets hidden gives way
to the first one left.

Issue #438
Issue #705

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Extend DHCP server with Option 82 matching support Add DHCP relay agent, with Option 82 support

1 participant