diff --git a/board/common/rootfs/etc/dnsmasq.conf b/board/common/rootfs/etc/dnsmasq.conf index 1850d8026..946aa5249 100644 --- a/board/common/rootfs/etc/dnsmasq.conf +++ b/board/common/rootfs/etc/dnsmasq.conf @@ -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 diff --git a/configs/aarch64_defconfig b/configs/aarch64_defconfig index 44488a81b..b3b3afc26 100644 --- a/configs/aarch64_defconfig +++ b/configs/aarch64_defconfig @@ -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 diff --git a/configs/aarch64_minimal_defconfig b/configs/aarch64_minimal_defconfig index 9350ea07e..20ec1e331 100644 --- a/configs/aarch64_minimal_defconfig +++ b/configs/aarch64_minimal_defconfig @@ -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 diff --git a/configs/arm_defconfig b/configs/arm_defconfig index 756d37f8a..c0c6a28ea 100644 --- a/configs/arm_defconfig +++ b/configs/arm_defconfig @@ -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 diff --git a/configs/arm_minimal_defconfig b/configs/arm_minimal_defconfig index 0399a709d..37b0a4505 100644 --- a/configs/arm_minimal_defconfig +++ b/configs/arm_minimal_defconfig @@ -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 diff --git a/configs/riscv64_defconfig b/configs/riscv64_defconfig index 0fe732fc6..a8f234bcb 100644 --- a/configs/riscv64_defconfig +++ b/configs/riscv64_defconfig @@ -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 diff --git a/configs/x86_64_defconfig b/configs/x86_64_defconfig index bbaa30325..f2fa45705 100644 --- a/configs/x86_64_defconfig +++ b/configs/x86_64_defconfig @@ -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 diff --git a/configs/x86_64_minimal_defconfig b/configs/x86_64_minimal_defconfig index b1a6f6ae9..fd3f34ce5 100644 --- a/configs/x86_64_minimal_defconfig +++ b/configs/x86_64_minimal_defconfig @@ -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 diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 8bbb7babe..68662f516 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -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 ` 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 @@ -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 diff --git a/doc/README.md b/doc/README.md index c449648f5..ed16fc316 100644 --- a/doc/README.md +++ b/doc/README.md @@ -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) diff --git a/doc/dhcp-relay.md b/doc/dhcp-relay.md new file mode 100644 index 000000000..1d01f8272 --- /dev/null +++ b/doc/dhcp-relay.md @@ -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: + +
admin@example:/> configure
+admin@example:/config/> edit dhcp-relay
+admin@example:/config/dhcp-relay/> set server 192.168.2.2
+admin@example:/config/dhcp-relay/> set interface br0
+admin@example:/config/dhcp-relay/> leave
+
+ +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: + +
admin@example:/config/> edit dhcp-relay
+admin@example:/config/dhcp-relay/> set option82
+admin@example:/config/dhcp-relay/> leave
+
+ +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: + +
admin@example:/config/dhcp-relay/> set option82 remote-id str switch-17
+admin@example:/config/dhcp-relay/> edit interface br0
+admin@example:/config/dhcp-relay/…/br0/> set port e2 circuit-id str camera-18
+admin@example:/config/dhcp-relay/…/br0/> leave
+
+ +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: + +
admin@example:/config/dhcp-relay/> set interface e5 option82 false
+
+ + +## 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: + +
admin@example:/config/dhcp-relay/…/br0/> set port e8 enabled false
+
+ + +## 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: + +
admin@example:/config/dhcp-relay/…/br0/> set port e7 trusted true
+admin@example:/config/dhcp-relay/…/br0/> set port e8 trusted true
+
+ +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: + +
admin@example:/config/dhcp-relay/> set interface vlan10
+admin@example:/config/dhcp-relay/> set interface vlan20
+
+ +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: + +
admin@example:/config/> edit dhcp-relay
+admin@example:/config/dhcp-relay/> set server 127.0.0.1
+admin@example:/config/dhcp-relay/> set option82
+admin@example:/config/dhcp-relay/> set interface br0
+admin@example:/config/dhcp-relay/> end
+admin@example:/config/> edit dhcp-server subnet 192.168.1.0/24
+admin@example:/config/dhcp-server/…/192.168.1.0/24/> set host 192.168.1.42 match option82 circuit-id str e2
+admin@example:/config/dhcp-server/…/192.168.1.0/24/> set host 192.168.1.42 preempt true
+admin@example:/config/dhcp-server/…/192.168.1.0/24/> leave
+
+ +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: + +
admin@example:/config/dhcp-relay/> set force-server-identity true
+
+ +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. diff --git a/doc/dhcp.md b/doc/dhcp.md index 8cafecc00..4574b724a 100644 --- a/doc/dhcp.md +++ b/doc/dhcp.md @@ -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: + +
admin@example:/config/dhcp-server/…/192.168.1.0/24/> edit host 192.168.1.42
+admin@example:/config/dhcp-server/…/192.168.1.42/> set match option82 circuit-id str camera-18
+admin@example:/config/dhcp-server/…/192.168.1.42/> set match option82 remote-id str switch-17
+admin@example:/config/dhcp-server/…/192.168.1.42/> set preempt true
+admin@example:/config/dhcp-server/…/192.168.1.42/> leave
+
+ +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: diff --git a/mkdocs.yml b/mkdocs.yml index c3572d840..d0bec0c7c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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 diff --git a/package/Config.in b/package/Config.in index 093d83032..d7d23637d 100644 --- a/package/Config.in +++ b/package/Config.in @@ -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" diff --git a/package/dhcprelayd/Config.in b/package/dhcprelayd/Config.in new file mode 100644 index 000000000..c522bfc9a --- /dev/null +++ b/package/dhcprelayd/Config.in @@ -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 diff --git a/package/dhcprelayd/dhcprelayd.hash b/package/dhcprelayd/dhcprelayd.hash new file mode 100644 index 000000000..1ad5122f0 --- /dev/null +++ b/package/dhcprelayd/dhcprelayd.hash @@ -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 diff --git a/package/dhcprelayd/dhcprelayd.mk b/package/dhcprelayd/dhcprelayd.mk new file mode 100644 index 000000000..ac3327a78 --- /dev/null +++ b/package/dhcprelayd/dhcprelayd.mk @@ -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)) diff --git a/package/dhcprelayd/dhcprelayd.svc b/package/dhcprelayd/dhcprelayd.svc new file mode 100644 index 000000000..9a10ae201 --- /dev/null +++ b/package/dhcprelayd/dhcprelayd.svc @@ -0,0 +1 @@ +service [2345] dhcprelayd -- DHCP relay agent diff --git a/package/klish-plugin-sysrepo/klish-plugin-sysrepo.hash b/package/klish-plugin-sysrepo/klish-plugin-sysrepo.hash index 9ddbfd31d..031a3b535 100644 --- a/package/klish-plugin-sysrepo/klish-plugin-sysrepo.hash +++ b/package/klish-plugin-sysrepo/klish-plugin-sysrepo.hash @@ -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 diff --git a/package/klish-plugin-sysrepo/klish-plugin-sysrepo.mk b/package/klish-plugin-sysrepo/klish-plugin-sysrepo.mk index e67cbc41c..152866190 100644 --- a/package/klish-plugin-sysrepo/klish-plugin-sysrepo.mk +++ b/package/klish-plugin-sysrepo/klish-plugin-sysrepo.mk @@ -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 diff --git a/patches/dnsmasq/2.93/0001-Add-preempt-keyword-to-dhcp-host.patch b/patches/dnsmasq/2.93/0001-Add-preempt-keyword-to-dhcp-host.patch new file mode 100644 index 000000000..83d23d570 --- /dev/null +++ b/patches/dnsmasq/2.93/0001-Add-preempt-keyword-to-dhcp-host.patch @@ -0,0 +1,154 @@ +From ba644f3db7129b079209355048a10e000b1ecb35 Mon Sep 17 00:00:00 2001 +From: Joachim Wiberg +Date: Mon, 23 Nov 2026 17:06:04 +0100 +Subject: [PATCH] Add preempt keyword to --dhcp-host. +Organization: Wires + +An address given with --dhcp-host is not used while another client has +a lease on it, the client gets one from the dynamic range instead: + + not using configured address 192.168.0.13 because it is leased to ... + +That is right when the host is a certain machine. With a host that +matches on where the client is connected, e.g. a tag set by +--dhcp-circuitid and a wildcard MAC address, the machine replacing a +broken one does not get the address of its port until the lease of the +old machine has expired. + +With preempt, drop the lease of the other client and use the address, +in DHCPDISCOVER, DHCPREQUEST and BOOTP. A client which holds another +address is told to start over, as when a static address has been +configured for it. + +Signed-off-by: Joachim Wiberg +--- + man/dnsmasq.8 | 15 ++++++++++++++- + src/dnsmasq.h | 1 + + src/option.c | 2 ++ + src/rfc2131.c | 27 +++++++++++++++++++++++++-- + 4 files changed, 42 insertions(+), 3 deletions(-) + +diff --git a/man/dnsmasq.8 b/man/dnsmasq.8 +index 5b01e63..2234b85 100644 +--- a/man/dnsmasq.8 ++++ b/man/dnsmasq.8 +@@ -1159,7 +1159,7 @@ is also included, as described in RFC-3775 section 7.3. + tells dnsmasq to advertise the prefix without the on-link (aka L) bit set. + + .TP +-.B \-G, --dhcp-host=[][,id:|*][,set:][,tag:][,][,][,][,ignore] ++.B \-G, --dhcp-host=[][,id:|*][,set:][,tag:][,][,][,][,ignore][,preempt] + Specify per host parameters for the DHCP server. This allows a machine + with a particular hardware address to be always allocated the same + hostname, IP address and lease time. A hostname specified like this +@@ -1245,6 +1245,19 @@ example: \fB--dhcp-host=00:20:e0:3b:13:af,ignore\fP. + This can be useful when there is another DHCP server on the network which should + be used by some machines. + ++The special keyword \fBpreempt\fP lets a client take over the address ++of the \fB--dhcp-host\fP while another client still has a lease on ++it. The lease of the other client is dropped. Without it the address ++is not used until that lease has expired, and the client gets an ++address from the dynamic range, if there is one. ++This is for a \fB--dhcp-host\fP which matches whatever is connected ++at a certain place rather than a certain machine, like one with a tag ++set by \fB--dhcp-circuitid\fP, so that a machine which replaces a ++broken one gets the same address at once. For ++example: \fB--dhcp-host=tag:port3,*:*:*:*:*:*,192.168.0.13,preempt\fP. ++Only one client at a time can use the address; two clients which ++both match will keep taking it from each other. DHCPv4 and BOOTP only. ++ + The \fBset:\fP construct sets the tag + whenever this \fB--dhcp-host\fP directive is in use. This can be used to + selectively send DHCP options just for this host. More than one tag +diff --git a/src/dnsmasq.h b/src/dnsmasq.h +index ebb8d15..a90ea2d 100644 +--- a/src/dnsmasq.h ++++ b/src/dnsmasq.h +@@ -955,6 +955,7 @@ struct dhcp_config { + #define CONFIG_BANK 2048 /* from dhcp hosts file */ + #define CONFIG_ADDR6 4096 + #define CONFIG_ADDR6_HOSTS 16384 /* address added by from /etc/hosts */ ++#define CONFIG_PREEMPT 32768 /* address may be taken over from another client */ + + struct dhcp_opt { + int opt, len, flags; +diff --git a/src/option.c b/src/option.c +index 274732f..47c09f7 100644 +--- a/src/option.c ++++ b/src/option.c +@@ -4203,6 +4203,8 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma + } + else if (strcmp(arg, "ignore") == 0) + new->flags |= CONFIG_DISABLE; ++ else if (strcmp(arg, "preempt") == 0) ++ new->flags |= CONFIG_PREEMPT; + else if (new->hostname) + { + dhcp_config_free(new); +diff --git a/src/rfc2131.c b/src/rfc2131.c +index 7b58e69..0a80d49 100644 +--- a/src/rfc2131.c ++++ b/src/rfc2131.c +@@ -72,6 +72,15 @@ static int is_pxe_client(struct dhcp_packet *mess, size_t sz, const char **pxe_v + static int do_opt(struct dhcp_opt *opt, unsigned char *p, struct dhcp_context *context, int null_term); + static void handle_encap(struct dhcp_packet *mess, unsigned char *end, unsigned char *req_options, int null_term, struct dhcp_netid *tagif, int pxemode); + ++/* Take the address from the client holding it, for a host configured with preempt. */ ++static void abandon_lease(struct dhcp_lease *lease, time_t now) ++{ ++ inet_ntop(AF_INET, &lease->addr, daemon->addrbuff, ADDRSTRLEN); ++ my_syslog(MS_DHCP | LOG_INFO, _("abandoning lease to %s of %s"), ++ print_mac(lease->hwaddr, lease->hwaddr_len), daemon->addrbuff); ++ lease_prune(lease, now); ++} ++ + size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index, + size_t sz, time_t now, int unicast_dest, int loopback, + int *is_inform, int pxe, struct in_addr fallback, time_t recvtime, struct in_addr leasequery_source) +@@ -628,7 +637,15 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index, + (lease->hwaddr_len != mess->hlen || + lease->hwaddr_type != mess->htype || + memcmp(lease->hwaddr, mess->chaddr, lease->hwaddr_len) != 0)) +- message = _("address in use"); ++ { ++ if (have_config(config, CONFIG_PREEMPT)) ++ { ++ abandon_lease(lease, now); ++ lease = NULL; ++ } ++ else ++ message = _("address in use"); ++ } + } + else + { +@@ -1307,6 +1324,7 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index, + + if ((ltmp = lease_find_by_addr(config->addr)) && + ltmp != lease && ++ !have_config(config, CONFIG_PREEMPT) && + !config_has_mac(config, ltmp->hwaddr, ltmp->hwaddr_len, ltmp->hwaddr_type)) + { + int len; +@@ -1522,7 +1540,8 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index, + (!have_config(config, CONFIG_DECLINED) || + difftime(now, config->decline_time) > (float)DECLINE_BACKOFF) && + config->addr.s_addr != mess->yiaddr.s_addr && +- (!(ltmp = lease_find_by_addr(config->addr)) || ltmp == lease)) ++ (!(ltmp = lease_find_by_addr(config->addr)) || ltmp == lease || ++ have_config(config, CONFIG_PREEMPT))) + message = _("static lease available"); + + /* Check to see if the address is reserved as a static address for another host */ +@@ -1541,6 +1560,10 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index, + daemon->addrbuff); + lease = ltmp; + } ++ /* With preempt the client is another host, which gets a lease of its own. */ ++ else if (have_config(config, CONFIG_PREEMPT) && have_config(config, CONFIG_ADDR) && ++ config->addr.s_addr == mess->yiaddr.s_addr) ++ abandon_lease(ltmp, now); + else + message = _("address in use"); + } diff --git a/src/confd/src/Makefile.am b/src/confd/src/Makefile.am index f5cd55262..ba25969bb 100644 --- a/src/confd/src/Makefile.am +++ b/src/confd/src/Makefile.am @@ -75,6 +75,7 @@ confd_plugin_la_SOURCES = \ dhcp-common.c \ dhcp-client.c \ dhcpv6-client.c \ + dhcp-relay.c \ dhcp-server.c \ factory.c \ firewall.c \ diff --git a/src/confd/src/core.c b/src/confd/src/core.c index 444b68a12..52fc370b7 100644 --- a/src/confd/src/core.c +++ b/src/confd/src/core.c @@ -380,6 +380,10 @@ static int change_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *mod if ((rc = dhcp_server_change(session, config, diff, event, confd))) goto free_diff; + /* infix-dhcp-relay */ + if ((rc = dhcp_relay_change(session, config, diff, event, confd))) + goto free_diff; + /* infix-firewall */ if ((rc = firewall_change(session, config, diff, event, confd))) goto free_diff; @@ -553,6 +557,11 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv) ERROR("Failed to subscribe to infix-dhcp-server"); goto err; } + rc = subscribe_model("infix-dhcp-relay", &confd, 0); + if (rc) { + ERROR("Failed to subscribe to infix-dhcp-relay"); + goto err; + } rc = subscribe_model("ietf-routing", &confd, 0); if (rc) { ERROR("Failed to subscribe to ietf-routing"); diff --git a/src/confd/src/core.h b/src/confd/src/core.h index a1ba9549d..3e1a9ccb8 100644 --- a/src/confd/src/core.h +++ b/src/confd/src/core.h @@ -285,6 +285,9 @@ int dhcp_client_change(sr_session_ctx_t *session, struct lyd_node *config, struc /* dhcpv6-client.c */ int dhcpv6_client_change(sr_session_ctx_t *session, struct lyd_node *config, struct lyd_node *diff, sr_event_t event, struct confd *confd); +/* dhcp-relay.c */ +int dhcp_relay_change(sr_session_ctx_t *session, struct lyd_node *config, struct lyd_node *diff, sr_event_t event, struct confd *confd); + /* dhcp-server.c */ int dhcp_server_candidate_init(struct confd *confd); int dhcp_server_rpc_init(struct confd *confd); diff --git a/src/confd/src/dhcp-relay.c b/src/confd/src/dhcp-relay.c new file mode 100644 index 000000000..f3e653d87 --- /dev/null +++ b/src/confd/src/dhcp-relay.c @@ -0,0 +1,305 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#include + +#include +#include + +#include "core.h" +#include "interfaces.h" + +#define CFG_XPATH "/infix-dhcp-relay:dhcp-relay" +#define IFS_XPATH "/ietf-interfaces:interfaces" +#define RELAY_CONF "/etc/dhcprelayd.conf" +#define RELAY_NEXT RELAY_CONF "+" + +/* Quoted string, the file format takes \" and \\ */ +static void gen_str(FILE *fp, const char *str) +{ + fputc('"', fp); + for (; *str; str++) { + if (*str == '"' || *str == '\\') + fputc('\\', fp); + fputc(*str, fp); + } + fputc('"', fp); +} + +static void gen_servers(FILE *fp, struct lyd_node *parent, const char *indent) +{ + struct lyd_node *server; + + LYX_LIST_FOR_EACH(lyd_child(parent), server, "server") + fprintf(fp, "%sserver %s {\n%s port = %s\n%s}\n", indent, + lydx_get_cattr(server, "address"), indent, + lydx_get_cattr(server, "port"), indent); +} + +/* + * A server on this system answers as 127.0.0.1, which a client cannot + * renew its lease with, so it must be told the gateway address instead. + */ +static int has_local_server(struct lyd_node *relay) +{ + struct lyd_node *rif, *server; + + LYX_LIST_FOR_EACH(lyd_child(relay), server, "server") { + if (!strncmp(lydx_get_cattr(server, "address"), "127.", 4)) + return 1; + } + LYX_LIST_FOR_EACH(lyd_child(relay), rif, "interface") { + LYX_LIST_FOR_EACH(lyd_child(rif), server, "server") { + if (!strncmp(lydx_get_cattr(server, "address"), "127.", 4)) + return 1; + } + } + + return 0; +} + +/* The str or hex of a circuit-id or remote-id container */ +static void gen_id(FILE *fp, struct lyd_node *id, const char *key, const char *indent) +{ + const char *str = lydx_get_cattr(id, "str"); + const char *hex = lydx_get_cattr(id, "hex"); + + if (str) { + fprintf(fp, "%s%s = ", indent, key); + gen_str(fp, str); + fputc('\n', fp); + } else if (hex) { + fprintf(fp, "%s%s-hex = %s\n", indent, key, hex); + } +} + +static void gen_option82(FILE *fp, struct lyd_node *relay, struct confd *confd) +{ + struct lyd_node *opt82 = lydx_get_child(relay, "option82"); + struct lyd_node *rid; + const char *type; + + if (!opt82) + return; + + fprintf(fp, "option82 {\n policy = %s\n", lydx_get_cattr(opt82, "policy")); + + rid = lydx_get_child(opt82, "remote-id"); + type = lydx_get_cattr(rid, "type"); + if (type && !strcmp(type, "mac")) { + const char *mac = json_string_value(json_object_get(confd->root, "mac-address")); + + if (mac) { + fprintf(fp, " remote-id-hex = %s\n", mac); + } else { + WARN("No base MAC address for remote-id, using hostname"); + fprintf(fp, " remote-id-type = hostname\n"); + } + } else if (type) { + fprintf(fp, " remote-id-type = %s\n", type); + } else { + gen_id(fp, rid, "remote-id", " "); + } + + fprintf(fp, "}\n"); +} + +/* Bridge port @name of @rif, with the settings it may have in its port list */ +static int gen_port(FILE *fp, struct lyd_node *rif, const char *name, int tagged) +{ + struct lyd_node *port = lydx_find_by_name(rif, "port", name); + + if (port && !lydx_is_enabled(port, "enabled")) + return 0; + + fprintf(fp, " port "); + gen_str(fp, name); + fprintf(fp, " {\n"); + if (tagged) + fprintf(fp, " tagged = true\n"); + if (port && lydx_is_enabled(port, "trusted")) + fprintf(fp, " trusted = true\n"); + if (port) + gen_id(fp, lydx_get_child(port, "circuit-id"), "circuit-id", " "); + fprintf(fp, " }\n"); + + return 1; +} + +/* + * The ports of @bridge that requests in VLAN @vid arrive on: untagged + * on ports with that PVID, tagged on the other members of the VLAN, + * when there is a VLAN interface to relay them on. With @vid 0 all + * ports of the bridge relay. + */ +static int gen_ports(FILE *fp, struct lyd_node *rif, struct lyd_node *ifs, + struct lyd_node *bridge, int vid, int vlanif) +{ + const char *brname = lydx_get_cattr(bridge, "name"); + struct lyd_node *cif, *vlan, *member; + int num = 0; + + LYX_LIST_FOR_EACH(lyd_child(ifs), cif, "interface") { + struct lyd_node *bp = lydx_get_child(cif, "bridge-port"); + const char *master = lydx_get_cattr(bp, "bridge"); + + if (!master || strcmp(master, brname)) + continue; + if (vid && atoi(lydx_get_cattr(bp, "pvid") ?: "0") != vid) + continue; + + num += gen_port(fp, rif, lydx_get_cattr(cif, "name"), 0); + } + + if (!vlanif) + return num; + + vlan = lydx_get_descendant(lyd_child(bridge), "bridge", "vlans", "vlan", NULL); + LYX_LIST_FOR_EACH(vlan, vlan, "vlan") { + if (atoi(lydx_get_cattr(vlan, "vid")) != vid) + continue; + + LYX_LIST_FOR_EACH(lyd_child(vlan), member, "tagged") { + const char *name = lyd_get_value(member); + struct lyd_node *bp; + + /* Listed above when the VLAN is also the PVID of the port */ + bp = lydx_get_child(lydx_find_by_name(ifs, "interface", name), "bridge-port"); + if (!strcmp(name, brname) || atoi(lydx_get_cattr(bp, "pvid") ?: "0") == vid) + continue; + + num += gen_port(fp, rif, name, 1); + } + } + + return num; +} + +/* Returns the number of sections written, 0 for a bridge without ports to relay from */ +static int gen_interface(FILE *fp, struct lyd_node *rif, struct lyd_node *ifs) +{ + const char *ifname = lydx_get_cattr(rif, "name"); + struct lyd_node *cif = lydx_find_by_name(ifs, "interface", ifname); + struct lyd_node *bridge = NULL, *vlan; + int vid = 0, vlanif = 0, num = 1; + char *ports = NULL; + size_t len = 0; + FILE *pfp; + + vlan = lydx_get_child(cif, "vlan"); + if (iftype_from_iface(cif) == IFT_BRIDGE) { + bridge = cif; + /* Only untagged requests reach a VLAN filtering bridge itself */ + if (lydx_get_descendant(lyd_child(cif), "bridge", "vlans", NULL)) + vid = atoi(lydx_get_cattr(lydx_get_child(cif, "bridge-port"), "pvid") ?: "0") ?: -1; + } else if (vlan) { + bridge = lydx_find_by_name(ifs, "interface", lydx_get_cattr(vlan, "lower-layer-if")); + if (bridge && iftype_from_iface(bridge) == IFT_BRIDGE) { + vid = atoi(lydx_get_cattr(vlan, "id")); + vlanif = 1; + } else { + bridge = NULL; + } + } + + if (bridge) { + pfp = open_memstream(&ports, &len); + if (!pfp) + return 0; + num = gen_ports(pfp, rif, ifs, bridge, vid, vlanif); + fclose(pfp); + } + + if (!num) { + NOTE("DHCP relay: no bridge ports to relay from on %s", ifname); + } else { + fprintf(fp, "interface "); + gen_str(fp, ifname); + fprintf(fp, " {\n"); + if (!lydx_is_enabled(rif, "option82")) + fprintf(fp, " option82 = false\n"); + gen_servers(fp, rif, " "); + fputs(ports ?: "", fp); + fprintf(fp, "}\n"); + } + free(ports); + + return num ? 1 : 0; +} + +/* Returns the number of interfaces to relay from, 0 when disabled, -1 on error */ +static int gen(struct lyd_node *relay, struct lyd_node *config, struct confd *confd) +{ + struct lyd_node *ifs = lydx_get_descendant(config, "interfaces", NULL); + struct lyd_node *rif; + int num = 0; + FILE *fp; + + if (!lydx_is_enabled(relay, "enabled")) + return 0; + + fp = fopen(RELAY_NEXT, "w"); + if (!fp) { + ERRNO("Failed creating %s", RELAY_NEXT); + return -1; + } + + gen_servers(fp, relay, ""); + if (lydx_is_enabled(relay, "force-server-identity") || has_local_server(relay)) + fprintf(fp, "force-server-identity = true\n"); + gen_option82(fp, relay, confd); + + LYX_LIST_FOR_EACH(lyd_child(relay), rif, "interface") + num += gen_interface(fp, rif, ifs); + + fclose(fp); + + return num; +} + +static int same(const char *a, const char *b) +{ + return !systemf("cmp -s %s %s", a, b); +} + +int dhcp_relay_change(sr_session_ctx_t *session, struct lyd_node *config, struct lyd_node *diff, + sr_event_t event, struct confd *confd) +{ + struct lyd_node *relay = lydx_get_descendant(config, "dhcp-relay", NULL); + int num; + + if (event != SR_EV_DONE) + return SR_ERR_OK; + + if (!lydx_get_xpathf(diff, CFG_XPATH)) { + /* The ports to relay from follow the bridges and their VLANs */ + if (!relay || !lydx_get_xpathf(diff, IFS_XPATH)) + return SR_ERR_OK; + } + + num = relay ? gen(relay, config, confd) : 0; + if (num < 0) + return SR_ERR_SYS; + + if (!num) { + finit_disable("dhcprelayd"); + erase(RELAY_NEXT); + erase(RELAY_CONF); + return SR_ERR_OK; + } + + /* Most interface changes are not about the ports relayed from */ + if (same(RELAY_NEXT, RELAY_CONF)) { + erase(RELAY_NEXT); + return SR_ERR_OK; + } + + if (rename(RELAY_NEXT, RELAY_CONF)) { + ERRNO("Failed installing %s", RELAY_CONF); + return SR_ERR_SYS; + } + + finit_enable("dhcprelayd"); + finit_reload("dhcprelayd"); + + return SR_ERR_OK; +} diff --git a/src/confd/src/dhcp-server.c b/src/confd/src/dhcp-server.c index 2127acb16..af8d38279 100644 --- a/src/confd/src/dhcp-server.c +++ b/src/confd/src/dhcp-server.c @@ -183,15 +183,73 @@ static const char *host_match(struct lyd_node *match, const char **id, int *quot return NULL; } +/* Colon separated hex, a single byte with a trailing colon or dnsmasq takes it as text */ +static void fput_id(FILE *fp, struct lyd_node *id) +{ + const char *str = lydx_get_cattr(id, "str"); + const char *hex = lydx_get_cattr(id, "hex"); + int single; + + if (str) { + single = !str[1]; + for (; *str; str++) + fprintf(fp, "%02x%s", (unsigned char)*str, str[1] ? ":" : ""); + } else { + single = !strchr(hex, ':'); + fputs(hex, fp); + } + + if (single) + fputc(':', fp); +} + +/* + * Tags for the sub-options of option 82 to match on, in dhcp-host with + * any MAC address. Returns the dhcp-host match, NULL if nothing is set. + */ +static const char *option82_match(FILE *fp, struct lyd_node *opt82, const char *tag) +{ + static const char *sub[][2] = { + { "circuit-id", "dhcp-circuitid" }, + { "remote-id", "dhcp-remoteid" }, + }; + static char match[256]; + size_t len = 0; + + for (size_t i = 0; i < NELEMS(sub); i++) { + struct lyd_node *id = lydx_get_child(opt82, sub[i][0]); + + if (!lydx_get_child(id, "str") && !lydx_get_child(id, "hex")) + continue; + + fprintf(fp, "%s=set:%s-%s,", sub[i][1], tag, sub[i][0]); + fput_id(fp, id); + fputc('\n', fp); + len += snprintf(match + len, sizeof(match) - len, "tag:%s-%s,", tag, sub[i][0]); + } + if (!len) + return NULL; + + snprintf(match + len, sizeof(match) - len, "*:*:*:*:*:*"); + + return match; +} + /* the address is a key in the host node, so is guaranteed to be set */ static int configure_host(FILE *fp, struct lyd_node *host, const char *subnet) { const char *ip = lydx_get_cattr(host, "address"); const char *tag = host_tag(NULL, ip); - const char *match, *id, *name; + struct lyd_node *opt82 = lydx_get_descendant(lyd_child(host), "match", "option82", NULL); + const char *match, *id = NULL, *name; int quote = 0; - match = host_match(lydx_get_child(host, "match"), &id, "e); + if (opt82) { + fprintf(fp, "\n# Host %s option 82 match\n", ip); + match = option82_match(fp, opt82, tag); + } else { + match = host_match(lydx_get_child(host, "match"), &id, "e); + } if (!match) return -1; @@ -212,8 +270,9 @@ static int configure_host(FILE *fp, struct lyd_node *host, const char *subnet) fputq(match, fp); else fputs(match, fp); - fprintf(fp, ",set:%s,set:%s,%s,%s%s%s\n", tag, subnet, ip, - name ?: "", name ? "," : "", lydx_get_cattr(host, "lease-time")); + fprintf(fp, ",set:%s,set:%s,%s,%s%s%s%s\n", tag, subnet, ip, + name ?: "", name ? "," : "", lydx_get_cattr(host, "lease-time"), + lydx_is_enabled(host, "preempt") ? ",preempt" : ""); return 0; } @@ -265,6 +324,17 @@ static void add(const char *subnet, struct lyd_node *cfg) ifname ?: "", ifname ? "," : "", tag, start, end, lydx_get_cattr(node, "lease-time")); } + } else { + unsigned int a, b, c, d, len; + struct in_addr mask; + + /* Without a range the subnet is not served at all */ + if (sscanf(subnet, "%u.%u.%u.%u/%u", &a, &b, &c, &d, &len) == 5 && len <= 32) { + mask.s_addr = len ? htonl(~0U << (32 - len)) : 0; + fprintf(fp, "\n# Static hosts only\n"); + fprintf(fp, "dhcp-range=%s%sset:%s,%u.%u.%u.%u,static,%s\n", + ifname ?: "", ifname ? "," : "", tag, a, b, c, d, inet_ntoa(mask)); + } } err: diff --git a/src/confd/yang/confd.inc b/src/confd/yang/confd.inc index adfafc136..55ee838e7 100644 --- a/src/confd/yang/confd.inc +++ b/src/confd/yang/confd.inc @@ -31,7 +31,8 @@ MODULES=( "infix-dhcp-common@2025-12-21.yang" "infix-dhcp-client@2026-10-18.yang" "infix-dhcpv6-client@2025-11-09.yang" - "infix-dhcp-server@2026-10-18.yang" + "infix-dhcp-server@2026-11-23.yang" + "infix-dhcp-relay@2026-11-19.yang" "infix-firewall@2026-07-02.yang" "infix-firewall-services@2025-04-26.yang" "infix-firewall-icmp-types@2025-04-26.yang" diff --git a/src/confd/yang/confd/infix-dhcp-relay.yang b/src/confd/yang/confd/infix-dhcp-relay.yang new file mode 100644 index 000000000..c341003a9 --- /dev/null +++ b/src/confd/yang/confd/infix-dhcp-relay.yang @@ -0,0 +1,299 @@ +module infix-dhcp-relay { + yang-version 1.1; + namespace "urn:infix:params:xml:ns:yang:dhcp-relay"; + prefix dhcp-relay; + + import ietf-inet-types { + prefix inet; + } + import ietf-interfaces { + prefix if; + } + import iana-if-type { + prefix ianaift; + } + import infix-interfaces { + prefix infix-if; + } + import infix-dhcp-common { + prefix dhcp; + } + + organization "KernelKit"; + contact "kernelkit@googlegroups.com"; + description "This module implements a DHCPv4 relay agent with + support for the Relay Agent Information option (82)."; + + revision 2026-11-19 { + description "Initial revision."; + reference "internal"; + } + + grouping server-group { + description "DHCP servers to relay requests to."; + + list server { + description "DHCP server to relay requests to. + + Requests are sent to all servers in the list."; + key "address"; + + leaf address { + description "IPv4 address of the DHCP server. + + Use 127.0.0.1 for the DHCP server on this system, which + requires option 82."; + type inet:ipv4-address-no-zone; + must "not(starts-with(., '127.')) or /dhcp-relay/option82" { + error-message "A DHCP server on this system requires option 82."; + } + } + + leaf port { + description "UDP port of the DHCP server."; + type inet:port-number; + default 67; + } + } + } + + container dhcp-relay { + description "DHCPv4 relay agent configuration."; + + leaf enabled { + description "Globally enable or disable the DHCP relay agent."; + type boolean; + default true; + } + + uses server-group { + refine "server" { + description "Default DHCP servers, used by interfaces that do not + have their own server list. + + Requests are sent to all servers in the list."; + } + } + + leaf force-server-identity { + description "Make clients send all requests through the relay agent. + + Adds the server identifier override sub-option to option + 82, with the gateway address. The server then gives the + gateway address as its own, so renewals are relayed too + and get option 82. The server must support the + sub-option. Always done for a server on this system, + at 127.0.0.1."; + reference "RFC 5107: DHCP Server Identifier Override Suboption"; + must ". = 'false' or ../option82" { + error-message "Requires option 82."; + } + type boolean; + default false; + } + + container option82 { + presence "Enable the Relay Agent Information option (82)."; + description "Relay Agent Information option (82). + + When enabled, the relay agent adds a circuit-id, identifying + the port the request arrived on, and a remote-id, identifying + this relay agent, to each request it relays. The option is + removed from server replies before they are sent to the + client."; + reference "RFC 3046: DHCP Relay Agent Information Option"; + + leaf policy { + description "Handling of requests that already carry option 82. + + Applies to requests from clients. On trusted ports + option 82 is always kept."; + reference "RFC 3046, sec. 2.1"; + type enumeration { + enum keep { + description "Forward the request with the existing option 82."; + } + enum replace { + description "Replace it with the option 82 of this relay agent."; + } + enum drop { + description "Drop the request."; + } + } + default replace; + } + + container remote-id { + description "Remote-id sub-option (2), identifies this relay agent."; + + choice id { + default type; + + case type { + leaf type { + description "Value derived from the system."; + type enumeration { + enum mac { + description "Base MAC address of the system."; + } + enum giaddr { + description "Gateway address used when relaying."; + } + enum hostname { + description "Hostname of the system."; + } + } + default mac; + } + } + case str { + leaf str { + description "Fixed string value. + + Example: switch-17"; + type string { + length "1..50"; + pattern '[^\p{Cc}]+'; + } + } + } + case hex { + leaf hex { + description "Fixed binary value as colon-separated pairs of hex digits. + + Example: c0:ff:ee"; + type dhcp:octet-string { + length "2..149"; + } + } + } + } + } + } + + list interface { + description "Interface to relay DHCP requests from. + + The address of the interface is used as gateway address, + which the servers reply to and select the subnet from. + + On a bridge, or a VLAN interface on top of a bridge, the + requests are relayed per bridge port. All bridge ports + relay, see the port list for exceptions. On any other + interface, requests received on the interface are relayed."; + key "name"; + must "server or ../server" { + error-message "No DHCP server for the interface."; + } + + leaf name { + description "Interface name."; + type if:interface-ref; + } + + leaf option82 { + description "Add option 82 to requests from this interface. + + Only has effect when option 82 is enabled. Disable for + an interface that should only relay."; + type boolean; + default true; + } + + uses server-group { + refine "server" { + description "DHCP servers for this interface, overrides the global list. + + Requests are sent to all servers in the list."; + } + } + + list port { + when "derived-from-or-self(/if:interfaces/if:interface" + + "[if:name = current()/../name]/if:type, 'ianaift:bridge') or " + + "derived-from-or-self(/if:interfaces/if:interface" + + "[if:name = /if:interfaces/if:interface" + + "[if:name = current()/../name]/infix-if:vlan/infix-if:lower-layer-if]" + + "/if:type, 'ianaift:bridge')" { + description "Only for a bridge, or a VLAN interface on a bridge."; + } + description "Bridge port with other settings than the default. + + A bridge port that is not in this list relays requests, + is not trusted, and has its name as circuit-id."; + key "name"; + + leaf name { + description "Name of the bridge port."; + type if:interface-ref; + must "/if:interfaces/if:interface[if:name = current()]" + + "/infix-if:bridge-port/infix-if:bridge = ../../name or " + + "/if:interfaces/if:interface[if:name = current()]" + + "/infix-if:bridge-port/infix-if:bridge = " + + "/if:interfaces/if:interface[if:name = current()/../../name]" + + "/infix-if:vlan/infix-if:lower-layer-if" { + error-message "Must be a port of the bridge."; + } + } + + leaf enabled { + description "Relay requests from this port. + + When disabled, DHCP on the port is bridged as any + other traffic. Disable for a port where a DHCP server + is connected."; + type boolean; + default true; + } + + leaf trusted { + description "Trust the relay agent information in requests. + + Enable where another relay agent, or a switch that adds + option 82, is connected. Option 82 in a request is then + kept, regardless of the option 82 policy, and requests + already relayed by another relay agent are forwarded + unmodified. The client hardware address in a request is + not checked against the sender of the frame. + + When disabled, the option 82 policy applies and requests + already relayed by another relay agent are dropped, since + a client could send such requests too."; + reference "RFC 3046, sec. 2.1"; + type boolean; + default false; + } + + container circuit-id { + description "Circuit-id sub-option (1), identifies the port. + + Defaults to the name of the port."; + + choice id { + case str { + leaf str { + description "Fixed string value. + + Example: camera-18"; + type string { + length "1..50"; + pattern '[^\p{Cc}]+'; + } + } + } + case hex { + leaf hex { + description "Fixed binary value as colon-separated pairs of hex digits. + + Example: c0:ff:ee"; + type dhcp:octet-string { + length "2..149"; + } + } + } + } + } + } + } + } +} diff --git a/src/confd/yang/confd/infix-dhcp-relay@2026-11-19.yang b/src/confd/yang/confd/infix-dhcp-relay@2026-11-19.yang new file mode 120000 index 000000000..bcc6e5f68 --- /dev/null +++ b/src/confd/yang/confd/infix-dhcp-relay@2026-11-19.yang @@ -0,0 +1 @@ +infix-dhcp-relay.yang \ No newline at end of file diff --git a/src/confd/yang/confd/infix-dhcp-server.yang b/src/confd/yang/confd/infix-dhcp-server.yang index b1637fa6f..90cdf8505 100644 --- a/src/confd/yang/confd/infix-dhcp-server.yang +++ b/src/confd/yang/confd/infix-dhcp-server.yang @@ -20,6 +20,12 @@ module infix-dhcp-server { contact "kernelkit@googlegroups.com"; description "This module implements a DHCPv4 server"; + revision 2026-11-23 { + description "Add static-host match on relay agent information, option + 82, and the preempt setting for static hosts."; + reference "internal"; + } + revision 2026-10-18 { description "Allow any character except control characters in the static-host match client-id string."; @@ -50,6 +56,32 @@ module infix-dhcp-server { reference "internal"; } + grouping option82-id { + description "Value of an option 82 sub-option to match on."; + + choice id { + case str { + leaf str { + description "String value. + + Example: camera-18"; + type string { + length "1..255"; + pattern '[^\p{Cc}]+'; + } + } + } + case hex { + leaf hex { + description "Binary data as colon-separated pairs of hex digits. + + Example: c0:ff:ee"; + type dhcp:octet-string; + } + } + } + } + typedef dhcp-lease-time { description "The lease time in seconds, with a minimum of 2 minutes (120 seconds). For static host entries, the value 'infinite' may be used."; @@ -337,11 +369,49 @@ module infix-dhcp-server { } } } - /* case option82 here ... */ + case option82 { + container option82 { + description "Match on relay agent information, DHCP option 82. + + A relay agent adds the option to the requests it + relays. The circuit-id identifies the port the + client is connected to and the remote-id the relay + agent. With both set, both must match."; + reference "RFC 3046: DHCP Relay Agent Information Option"; + must "circuit-id/str or circuit-id/hex or remote-id/str or remote-id/hex" { + error-message "Set circuit-id, remote-id, or both."; + } + + container circuit-id { + description "Circuit-id sub-option (1)."; + uses option82-id; + } + + container remote-id { + description "Remote-id sub-option (2)."; + uses option82-id; + } + } + } } /* More advanced match rules, e.g., option82 + client-id are not supported. */ } + leaf preempt { + description "Let a new client take over the address at once. + + A lease is otherwise kept for the client that got it + until it expires, and another client matching this + host does not get the address until then. Enable + when the match identifies a place in the network, like + a port, rather than a device, so that a replacement + for a broken device gets the same address at once. + + Only one client at a time can have the address."; + type boolean; + default false; + } + leaf hostname { description "Optional hostname to assign with the lease. diff --git a/src/confd/yang/confd/infix-dhcp-server@2026-10-18.yang b/src/confd/yang/confd/infix-dhcp-server@2026-11-23.yang similarity index 100% rename from src/confd/yang/confd/infix-dhcp-server@2026-10-18.yang rename to src/confd/yang/confd/infix-dhcp-server@2026-11-23.yang diff --git a/test/case/dhcp/Readme.adoc b/test/case/dhcp/Readme.adoc index 3c0734542..115faccce 100644 --- a/test/case/dhcp/Readme.adoc +++ b/test/case/dhcp/Readme.adoc @@ -15,6 +15,11 @@ Tests verifying DHCPv4/DHCPv6 client and server functionality: - DHCPv4 server with host-specific IP reservations - DHCPv4 server with multiple subnet configurations - DHCPv4 server network boot parameters, per subnet and per host + - DHCPv4 relay with option 82 to a server on another subnet + - DHCPv4 relay to a server on the same device, address per port + - DHCPv4 relay from an interface that is not a bridge, without option 82 + - DHCPv4 relay in a chain of switches, with a switch as DHCP client + - DHCPv4 relay on a VLAN filtering bridge, with access and trunk ports include::client_basic/Readme.adoc[] @@ -61,3 +66,23 @@ include::server_subnets/Readme.adoc[] <<< include::server_boot/Readme.adoc[] + +<<< + +include::relay_basic/Readme.adoc[] + +<<< + +include::relay_local/Readme.adoc[] + +<<< + +include::relay_plain/Readme.adoc[] + +<<< + +include::relay_chain/Readme.adoc[] + +<<< + +include::relay_vlan/Readme.adoc[] diff --git a/test/case/dhcp/all.yaml b/test/case/dhcp/all.yaml index 0ebf9f4a1..ec1235362 100644 --- a/test/case/dhcp/all.yaml +++ b/test/case/dhcp/all.yaml @@ -4,3 +4,6 @@ - name: DHCP Server Tests suite: dhcp_server.yaml + +- name: DHCP Relay Tests + suite: dhcp_relay.yaml diff --git a/test/case/dhcp/dhcp_relay.yaml b/test/case/dhcp/dhcp_relay.yaml new file mode 100644 index 000000000..f479c8284 --- /dev/null +++ b/test/case/dhcp/dhcp_relay.yaml @@ -0,0 +1,18 @@ +--- +- settings: + test-spec: Readme.adoc + +- name: DHCP Relay + case: relay_basic/test.py + +- name: DHCP Relay with Local Server + case: relay_local/test.py + +- name: DHCP Relay without Option 82 + case: relay_plain/test.py + +- name: DHCP Relay Chain + case: relay_chain/test.py + +- name: DHCP Relay with VLANs + case: relay_vlan/test.py diff --git a/test/case/dhcp/relay_basic/Readme.adoc b/test/case/dhcp/relay_basic/Readme.adoc new file mode 120000 index 000000000..ae32c8412 --- /dev/null +++ b/test/case/dhcp/relay_basic/Readme.adoc @@ -0,0 +1 @@ +test.adoc \ No newline at end of file diff --git a/test/case/dhcp/relay_basic/test.adoc b/test/case/dhcp/relay_basic/test.adoc new file mode 100644 index 000000000..7f6d26fe1 --- /dev/null +++ b/test/case/dhcp/relay_basic/test.adoc @@ -0,0 +1,25 @@ +=== DHCP Relay + +ifdef::topdoc[:imagesdir: {topdoc}../../test/case/dhcp/relay_basic] + +==== Description + +Verify that the relay agent relays requests from a bridge port to a +DHCP server on another subnet, and adds option 82 to them. The port +has a configured circuit-id, and the relay agent a remote-id. The +server has a static host that matches both, and a pool of one other +address, which the client gets if option 82 is missing or wrong. + +==== Topology + +image::topology.svg[DHCP Relay topology, align=center, scaledwidth=75%] + +==== Sequence + +. Set up topology and attach to client, relay and server DUTs +. Configure DHCP server with static host for circuit-id camera-18 +. Configure bridge and DHCP relay with circuit-id camera-18 +. Enable DHCP client on client +. Verify client gets the address for camera-18, 192.168.1.42 + + diff --git a/test/case/dhcp/relay_basic/test.py b/test/case/dhcp/relay_basic/test.py new file mode 100755 index 000000000..4c6e775df --- /dev/null +++ b/test/case/dhcp/relay_basic/test.py @@ -0,0 +1,145 @@ +#!/usr/bin/env python3 +"""DHCP Relay Basic + +Verify that the relay agent relays requests from a bridge port to a +DHCP server on another subnet, and adds option 82 to them. The port +has a configured circuit-id, and the relay agent a remote-id. The +server has a static host that matches both, and a pool of one other +address, which the client gets if option 82 is missing or wrong. + +""" +import infamy +import infamy.iface as iface +from infamy.util import parallel, until + + +with infamy.Test() as test: + POOL = '192.168.1.100' + ADDRESS = '192.168.1.42' + CIRCUIT = 'camera-18' + REMOTE = 'switch-17' + + with test.step("Set up topology and attach to client, relay and server DUTs"): + env = infamy.Env() + client, relay, server = parallel(lambda: env.attach("client", "mgmt"), + lambda: env.attach("relay", "mgmt"), + lambda: env.attach("server", "mgmt")) + + with test.step("Configure DHCP server with static host for circuit-id camera-18"): + server.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [{ + "name": server["link"], + "ipv4": { + "address": [{ + "ip": "192.168.2.2", + "prefix-length": 24 + }] + } + }] + } + }, + "ietf-routing": { + "routing": { + "control-plane-protocols": { + "control-plane-protocol": [{ + "type": "infix-routing:static", + "name": "default", + "static-routes": { + "ipv4": { + "route": [{ + "destination-prefix": "192.168.1.0/24", + "next-hop": { + "next-hop-address": "192.168.2.1" + } + }] + } + } + }] + } + } + }, + "infix-dhcp-server": { + "dhcp-server": { + "subnet": [{ + "subnet": "192.168.1.0/24", + "pool": { + "start-address": POOL, + "end-address": POOL + }, + "host": [{ + "address": ADDRESS, + "match": { + "option82": { + "circuit-id": {"str": CIRCUIT}, + "remote-id": {"str": REMOTE} + } + } + }] + }] + } + }}) + + with test.step("Configure bridge and DHCP relay with circuit-id camera-18"): + relay.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [{ + "name": "br0", + "type": "infix-if-type:bridge", + "ipv4": { + "address": [{ + "ip": "192.168.1.1", + "prefix-length": 24 + }] + } + }, { + "name": relay["link1"], + "infix-interfaces:bridge-port": { + "bridge": "br0" + } + }, { + "name": relay["link2"], + "ipv4": { + "address": [{ + "ip": "192.168.2.1", + "prefix-length": 24 + }] + } + }] + } + }, + "infix-dhcp-relay": { + "dhcp-relay": { + "server": [{"address": "192.168.2.2"}], + "option82": { + "remote-id": {"str": REMOTE} + }, + "interface": [{ + "name": "br0", + "port": [{ + "name": relay["link1"], + "circuit-id": {"str": CIRCUIT} + }] + }] + } + }}) + + with test.step("Enable DHCP client on client"): + client.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [{ + "name": client["link"], + "ipv4": { + "infix-dhcp-client:dhcp": {} + } + }] + } + }}) + + with test.step("Verify client gets the address for camera-18, 192.168.1.42"): + until(lambda: iface.address_exist(client, client["link"], ADDRESS)) + + test.succeed() diff --git a/test/case/dhcp/relay_basic/topology.dot b/test/case/dhcp/relay_basic/topology.dot new file mode 100644 index 000000000..b03512b73 --- /dev/null +++ b/test/case/dhcp/relay_basic/topology.dot @@ -0,0 +1,42 @@ +graph "relay basic" { + layout="neato"; + overlap="false"; + esep="+40"; + + node [shape=record, fontname="DejaVu Sans Mono, Book"]; + edge [color="cornflowerblue", penwidth="2", fontname="DejaVu Serif, Book"]; + + host [ + label="host | { mgmt1 | mgmt0 | mgmt2 }", + pos="0,12!", + requires="controller", + ]; + + relay [ + label="{ link1 | mgmt | link2 } | relay", + pos="15,12!", + + requires="infix", + ]; + + client [ + label="{ mgmt | link} | client", + pos="15,18!", + + requires="infix", + ]; + + server [ + label="{ link | mgmt } | server", + pos="15,6!", + + requires="infix", + ]; + + host:mgmt0 -- relay:mgmt [requires="mgmt", color=lightgrey] + host:mgmt1 -- client:mgmt [requires="mgmt", color=lightgrey] + host:mgmt2 -- server:mgmt [requires="mgmt", color=lightgrey] + + relay:link1 -- client:link [color=black, fontcolor=black, taillabel="br0 192.168.1.1/24"] + relay:link2 -- server:link [color=black, fontcolor=black, taillabel="192.168.2.1/24", headlabel="192.168.2.2/24"] +} diff --git a/test/case/dhcp/relay_basic/topology.svg b/test/case/dhcp/relay_basic/topology.svg new file mode 100644 index 000000000..e48d201b9 --- /dev/null +++ b/test/case/dhcp/relay_basic/topology.svg @@ -0,0 +1,84 @@ + + + + + + +relay basic + + + +host + +host + +mgmt1 + +mgmt0 + +mgmt2 + + + +relay + +link1 + +mgmt + +link2 + +relay + + + +host:mgmt0--relay:mgmt + + + + +client + +mgmt + +link + +client + + + +host:mgmt1--client:mgmt + + + + +server + +link + +mgmt + +server + + + +host:mgmt2--server:mgmt + + + + +relay:link1--client:link + +br0 192.168.1.1/24 + + + +relay:link2--server:link + +192.168.2.2/24 +192.168.2.1/24 + + + diff --git a/test/case/dhcp/relay_chain/Readme.adoc b/test/case/dhcp/relay_chain/Readme.adoc new file mode 120000 index 000000000..ae32c8412 --- /dev/null +++ b/test/case/dhcp/relay_chain/Readme.adoc @@ -0,0 +1 @@ +test.adoc \ No newline at end of file diff --git a/test/case/dhcp/relay_chain/test.adoc b/test/case/dhcp/relay_chain/test.adoc new file mode 100644 index 000000000..b3515a512 --- /dev/null +++ b/test/case/dhcp/relay_chain/test.adoc @@ -0,0 +1,35 @@ +=== DHCP Relay Chain + +ifdef::topdoc[:imagesdir: {topdoc}../../test/case/dhcp/relay_chain] + +==== Description + +Verify relay agents in a chain of two switches, with the DHCP server +at the end of the chain and everything in the same subnet. Both +switches add option 82, so the server can hand out an address per +switch and port: + + - sw1 gets its own address with DHCP. Its request has no option 82 + when it arrives on the trusted port of sw2, which adds its own. + - The client is connected to sw1, which relays its request to the + server through sw2. The replies from the server arrive on a port + that sw1 relays from. + +The server has a pool of one other address, which sw1 or the client +gets if option 82 is missing or wrong. + +==== Topology + +image::topology.svg[DHCP Relay Chain topology, align=center, scaledwidth=75%] + +==== Sequence + +. Set up topology and attach to client, sw1, sw2 and server DUTs +. Configure DHCP server with static hosts 192.168.1.3 for sw1 and 192.168.1.42 for the client +. Configure sw2 with address 192.168.1.2 and DHCP relay, port to sw1 trusted +. Configure sw1 with DHCP client and DHCP relay, port to sw2 trusted +. Verify sw1 gets the address for its port on sw2, 192.168.1.3 +. Enable DHCP client on client +. Verify client gets the address for its port on sw1, 192.168.1.42 + + diff --git a/test/case/dhcp/relay_chain/test.py b/test/case/dhcp/relay_chain/test.py new file mode 100755 index 000000000..bee0f6289 --- /dev/null +++ b/test/case/dhcp/relay_chain/test.py @@ -0,0 +1,156 @@ +#!/usr/bin/env python3 +"""DHCP Relay Chain + +Verify relay agents in a chain of two switches, with the DHCP server +at the end of the chain and everything in the same subnet. Both +switches add option 82, so the server can hand out an address per +switch and port: + + - sw1 gets its own address with DHCP. Its request has no option 82 + when it arrives on the trusted port of sw2, which adds its own. + - The client is connected to sw1, which relays its request to the + server through sw2. The replies from the server arrive on a port + that sw1 relays from. + +The server has a pool of one other address, which sw1 or the client +gets if option 82 is missing or wrong. + +""" +import infamy +import infamy.iface as iface +from infamy.util import parallel, until + + +def bridge(dut, address=None): + """Bridge br0 with ports down and up, with a static address or DHCP""" + if address: + ipv4 = {"address": [{"ip": address, "prefix-length": 24}]} + else: + ipv4 = {"infix-dhcp-client:dhcp": {}} + + return { + "interfaces": { + "interface": [{ + "name": "br0", + "type": "infix-if-type:bridge", + "ipv4": ipv4 + }, { + "name": dut["down"], + "infix-interfaces:bridge-port": {"bridge": "br0"} + }, { + "name": dut["up"], + "infix-interfaces:bridge-port": {"bridge": "br0"} + }] + } + } + + +def relay(server, remote_id, ports): + """Relay from br0 to server, with settings for some ports""" + return { + "dhcp-relay": { + "server": [{"address": server}], + "option82": { + "remote-id": {"str": remote_id} + }, + "interface": [{ + "name": "br0", + "port": ports + }] + } + } + + +def host(address, remote_id, circuit_id): + """Static host for a port of a switch""" + return { + "address": address, + "match": { + "option82": { + "circuit-id": {"str": circuit_id}, + "remote-id": {"str": remote_id} + } + } + } + + +with infamy.Test() as test: + SERVER = '192.168.1.1' + SW2 = '192.168.1.2' + SW1 = '192.168.1.3' + CLIENT = '192.168.1.42' + POOL = '192.168.1.100' + + with test.step("Set up topology and attach to client, sw1, sw2 and server DUTs"): + env = infamy.Env() + client, sw1, sw2, server = parallel(lambda: env.attach("client", "mgmt"), + lambda: env.attach("sw1", "mgmt"), + lambda: env.attach("sw2", "mgmt"), + lambda: env.attach("server", "mgmt")) + + with test.step("Configure DHCP server with static hosts 192.168.1.3 for sw1 and 192.168.1.42 for the client"): + server.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [{ + "name": server["link"], + "ipv4": { + "address": [{ + "ip": SERVER, + "prefix-length": 24 + }] + } + }] + } + }, + "infix-dhcp-server": { + "dhcp-server": { + "subnet": [{ + "subnet": "192.168.1.0/24", + "pool": { + "start-address": POOL, + "end-address": POOL + }, + "host": [ + host(SW1, "sw2", sw2["down"]), + host(CLIENT, "sw1", sw1["down"]), + ] + }] + } + }}) + + with test.step("Configure sw2 with address 192.168.1.2 and DHCP relay, port to sw1 trusted"): + sw2.put_config_dicts({ + "ietf-interfaces": bridge(sw2, SW2), + "infix-dhcp-relay": relay(SERVER, "sw2", [ + {"name": sw2["down"], "trusted": True}, + {"name": sw2["up"], "enabled": False}, + ])}) + + with test.step("Configure sw1 with DHCP client and DHCP relay, port to sw2 trusted"): + sw1.put_config_dicts({ + "ietf-interfaces": bridge(sw1), + "infix-dhcp-relay": relay(SERVER, "sw1", [ + {"name": sw1["up"], "trusted": True}, + ])}) + + with test.step("Verify sw1 gets the address for its port on sw2, 192.168.1.3"): + until(lambda: iface.address_exist(sw1, "br0", SW1)) + + with test.step("Enable DHCP client on client"): + client.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [{ + "name": client["link"], + "ipv4": { + "infix-dhcp-client:dhcp": {} + } + }] + } + }}) + + with test.step("Verify client gets the address for its port on sw1, 192.168.1.42"): + until(lambda: iface.address_exist(client, client["link"], CLIENT)) + + test.succeed() diff --git a/test/case/dhcp/relay_chain/topology.dot b/test/case/dhcp/relay_chain/topology.dot new file mode 100644 index 000000000..62772e9e5 --- /dev/null +++ b/test/case/dhcp/relay_chain/topology.dot @@ -0,0 +1,51 @@ +graph "relay chain" { + layout="neato"; + overlap="false"; + esep="+40"; + + node [shape=record, fontname="DejaVu Sans Mono, Book"]; + edge [color="cornflowerblue", penwidth="2", fontname="DejaVu Serif, Book"]; + + host [ + label="host | { mgmt1 | mgmt2 | mgmt3 | mgmt4 }", + pos="0,12!", + requires="controller", + ]; + + client [ + label="{ mgmt | link } | client", + pos="15,21!", + + requires="infix", + ]; + + sw1 [ + label="{ mgmt | down | up } | sw1", + pos="15,15!", + + requires="infix", + ]; + + sw2 [ + label="{ mgmt | down | up } | sw2", + pos="15,9!", + + requires="infix", + ]; + + server [ + label="{ mgmt | link } | server", + pos="15,3!", + + requires="infix", + ]; + + host:mgmt1 -- client:mgmt [requires="mgmt", color=lightgrey] + host:mgmt2 -- sw1:mgmt [requires="mgmt", color=lightgrey] + host:mgmt3 -- sw2:mgmt [requires="mgmt", color=lightgrey] + host:mgmt4 -- server:mgmt [requires="mgmt", color=lightgrey] + + client:link -- sw1:down [color=black] + sw1:up -- sw2:down [color=black] + sw2:up -- server:link [color=black, fontcolor=black, headlabel="192.168.1.1/24"] +} diff --git a/test/case/dhcp/relay_chain/topology.svg b/test/case/dhcp/relay_chain/topology.svg new file mode 100644 index 000000000..4c0a21f02 --- /dev/null +++ b/test/case/dhcp/relay_chain/topology.svg @@ -0,0 +1,106 @@ + + + + + + +relay chain + + + +host + +host + +mgmt1 + +mgmt2 + +mgmt3 + +mgmt4 + + + +client + +mgmt + +link + +client + + + +host:mgmt1--client:mgmt + + + + +sw1 + +mgmt + +down + +up + +sw1 + + + +host:mgmt2--sw1:mgmt + + + + +sw2 + +mgmt + +down + +up + +sw2 + + + +host:mgmt3--sw2:mgmt + + + + +server + +mgmt + +link + +server + + + +host:mgmt4--server:mgmt + + + + +client:link--sw1:down + + + + +sw1:up--sw2:down + + + + +sw2:up--server:link + +192.168.1.1/24 + + + diff --git a/test/case/dhcp/relay_local/Readme.adoc b/test/case/dhcp/relay_local/Readme.adoc new file mode 120000 index 000000000..ae32c8412 --- /dev/null +++ b/test/case/dhcp/relay_local/Readme.adoc @@ -0,0 +1 @@ +test.adoc \ No newline at end of file diff --git a/test/case/dhcp/relay_local/test.adoc b/test/case/dhcp/relay_local/test.adoc new file mode 100644 index 000000000..5c4263106 --- /dev/null +++ b/test/case/dhcp/relay_local/test.adoc @@ -0,0 +1,29 @@ +=== DHCP Relay with Local Server + +ifdef::topdoc[:imagesdir: {topdoc}../../test/case/dhcp/relay_local] + +==== Description + +Verify that a device can hand out an address per port: the relay agent +adds option 82 to requests from a bridge port and relays them to the +DHCP server on the same device, which has a static host matching the +circuit-id of the port, by default the name of the port. + +The static host has preempt enabled. When the client is replaced, here +by changing the MAC address of the client, the new one gets the same +address at once, even though the lease of the old one has not expired. + +==== Topology + +image::topology.svg[DHCP Relay with Local Server topology, align=center, scaledwidth=75%] + +==== Sequence + +. Set up topology and attach to client and relay DUTs +. Configure relay with br0, DHCP relay to 127.0.0.1 and static host 192.168.1.42 for the port +. Enable DHCP client on client +. Verify client gets the address of the port, 192.168.1.42 +. Change MAC address of client to 02:00:00:00:00:99 +. Verify lease for 192.168.1.42 is held by 02:00:00:00:00:99 + + diff --git a/test/case/dhcp/relay_local/test.py b/test/case/dhcp/relay_local/test.py new file mode 100755 index 000000000..a53df60e4 --- /dev/null +++ b/test/case/dhcp/relay_local/test.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 +"""DHCP Relay with Local Server + +Verify that a device can hand out an address per port: the relay agent +adds option 82 to requests from a bridge port and relays them to the +DHCP server on the same device, which has a static host matching the +circuit-id of the port, by default the name of the port. + +The static host has preempt enabled. When the client is replaced, here +by changing the MAC address of the client, the new one gets the same +address at once, even though the lease of the old one has not expired. + +""" +import infamy +import infamy.iface as iface +from infamy.util import parallel, until + + +def lease_mac(server, address): + """MAC address of the client holding the lease for address""" + data = server.get_data("/infix-dhcp-server:dhcp-server/leases") + if not data: + return None + for lease in data["dhcp-server"].get("leases", {}).get("lease", []): + if lease["address"] == address: + return lease["phys-address"] + return None + + +with infamy.Test() as test: + POOL = '192.168.1.100' + ADDRESS = '192.168.1.42' + NEWMAC = '02:00:00:00:00:99' + + with test.step("Set up topology and attach to client and relay DUTs"): + env = infamy.Env() + client, relay = parallel(lambda: env.attach("client", "mgmt"), + lambda: env.attach("relay", "mgmt")) + + with test.step("Configure relay with br0, DHCP relay to 127.0.0.1 and static host 192.168.1.42 for the port"): + relay.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [{ + "name": "br0", + "type": "infix-if-type:bridge", + "ipv4": { + "address": [{ + "ip": "192.168.1.1", + "prefix-length": 24 + }] + } + }, { + "name": relay["link"], + "infix-interfaces:bridge-port": { + "bridge": "br0" + } + }] + } + }, + "infix-dhcp-relay": { + "dhcp-relay": { + "server": [{"address": "127.0.0.1"}], + "option82": {}, + "interface": [{"name": "br0"}] + } + }, + "infix-dhcp-server": { + "dhcp-server": { + "subnet": [{ + "subnet": "192.168.1.0/24", + "pool": { + "start-address": POOL, + "end-address": POOL + }, + "host": [{ + "address": ADDRESS, + "match": { + "option82": { + "circuit-id": {"str": relay["link"]} + } + }, + "preempt": True + }] + }] + } + }}) + + with test.step("Enable DHCP client on client"): + client.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [{ + "name": client["link"], + "ipv4": { + "infix-dhcp-client:dhcp": {} + } + }] + } + }}) + + with test.step("Verify client gets the address of the port, 192.168.1.42"): + until(lambda: iface.address_exist(client, client["link"], ADDRESS)) + + with test.step("Change MAC address of client to 02:00:00:00:00:99"): + client.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [{ + "name": client["link"], + "infix-interfaces:custom-phys-address": { + "static": NEWMAC + } + }] + } + }}) + + with test.step("Verify lease for 192.168.1.42 is held by 02:00:00:00:00:99"): + until(lambda: lease_mac(relay, ADDRESS) == NEWMAC) + + test.succeed() diff --git a/test/case/dhcp/relay_local/topology.dot b/test/case/dhcp/relay_local/topology.dot new file mode 100644 index 000000000..e19daada0 --- /dev/null +++ b/test/case/dhcp/relay_local/topology.dot @@ -0,0 +1,33 @@ +graph "relay local" { + layout="neato"; + overlap="false"; + esep="+60"; + + node [shape=record, fontname="DejaVu Sans Mono, Book"]; + edge [color="cornflowerblue", penwidth="2", fontname="DejaVu Serif, Book"]; + + host [ + label="host | { mgmt1 | mgmt2 }", + pos="0,12!", + requires="controller", + ]; + + relay [ + label="{ link | mgmt } | relay", + pos="15,6!", + + requires="infix", + ]; + + client [ + label="{ mgmt | link} | client", + pos="15,18!", + + requires="infix", + ]; + + host:mgmt1 -- client:mgmt [requires=mgmt, color=lightgrey] + host:mgmt2 -- relay:mgmt [requires=mgmt, color=lightgrey] + + relay:link -- client:link [color=black, fontcolor=black, taillabel="br0 192.168.1.1/24"] +} diff --git a/test/case/dhcp/relay_local/topology.svg b/test/case/dhcp/relay_local/topology.svg new file mode 100644 index 000000000..6c6df9390 --- /dev/null +++ b/test/case/dhcp/relay_local/topology.svg @@ -0,0 +1,58 @@ + + + + + + +relay local + + + +host + +host + +mgmt1 + +mgmt2 + + + +relay + +link + +mgmt + +relay + + + +host:mgmt2--relay:mgmt + + + + +client + +mgmt + +link + +client + + + +host:mgmt1--client:mgmt + + + + +relay:link--client:link + +br0 192.168.1.1/24 + + + diff --git a/test/case/dhcp/relay_plain/Readme.adoc b/test/case/dhcp/relay_plain/Readme.adoc new file mode 120000 index 000000000..ae32c8412 --- /dev/null +++ b/test/case/dhcp/relay_plain/Readme.adoc @@ -0,0 +1 @@ +test.adoc \ No newline at end of file diff --git a/test/case/dhcp/relay_plain/test.adoc b/test/case/dhcp/relay_plain/test.adoc new file mode 100644 index 000000000..5132f5fdf --- /dev/null +++ b/test/case/dhcp/relay_plain/test.adoc @@ -0,0 +1,32 @@ +=== DHCP Relay without Option 82 + +ifdef::topdoc[:imagesdir: {topdoc}../../test/case/dhcp/relay_plain] + +==== Description + +Verify that the relay agent relays requests from an interface that is +not a bridge, and that option 82 can be turned off for one interface +while it is enabled for the relay agent. The server has a static host +that matches the default circuit-id of the interface, its name, and a +pool of one other address. + +The client first gets the address of the static host. With option 82 +turned off for the interface, a new client, here the same one with +another MAC address, gets the pool address. + +==== Topology + +image::topology.svg[DHCP Relay without Option 82 topology, align=center, scaledwidth=75%] + +==== Sequence + +. Set up topology and attach to client, relay and server DUTs +. Configure DHCP server with pool 192.168.1.100 and static host 192.168.1.42 for the relay interface +. Configure DHCP relay with option 82 on the client interface +. Enable DHCP client on client +. Verify client gets the address of the static host, 192.168.1.42 +. Disable option 82 for the client interface on relay +. Change MAC address of client to 02:00:00:00:00:99 +. Verify client gets the pool address, 192.168.1.100 + + diff --git a/test/case/dhcp/relay_plain/test.py b/test/case/dhcp/relay_plain/test.py new file mode 100755 index 000000000..0e733cad5 --- /dev/null +++ b/test/case/dhcp/relay_plain/test.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python3 +"""DHCP Relay without Option 82 + +Verify that the relay agent relays requests from an interface that is +not a bridge, and that option 82 can be turned off for one interface +while it is enabled for the relay agent. The server has a static host +that matches the default circuit-id of the interface, its name, and a +pool of one other address. + +The client first gets the address of the static host. With option 82 +turned off for the interface, a new client, here the same one with +another MAC address, gets the pool address. + +""" +import infamy +import infamy.iface as iface +from infamy.util import parallel, until + + +with infamy.Test() as test: + POOL = '192.168.1.100' + ADDRESS = '192.168.1.42' + NEWMAC = '02:00:00:00:00:99' + + with test.step("Set up topology and attach to client, relay and server DUTs"): + env = infamy.Env() + client, relay, server = parallel(lambda: env.attach("client", "mgmt"), + lambda: env.attach("relay", "mgmt"), + lambda: env.attach("server", "mgmt")) + + with test.step("Configure DHCP server with pool 192.168.1.100 and static host 192.168.1.42 for the relay interface"): + server.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [{ + "name": server["link"], + "ipv4": { + "address": [{ + "ip": "192.168.2.2", + "prefix-length": 24 + }] + } + }] + } + }, + "ietf-routing": { + "routing": { + "control-plane-protocols": { + "control-plane-protocol": [{ + "type": "infix-routing:static", + "name": "default", + "static-routes": { + "ipv4": { + "route": [{ + "destination-prefix": "192.168.1.0/24", + "next-hop": { + "next-hop-address": "192.168.2.1" + } + }] + } + } + }] + } + } + }, + "infix-dhcp-server": { + "dhcp-server": { + "subnet": [{ + "subnet": "192.168.1.0/24", + "pool": { + "start-address": POOL, + "end-address": POOL + }, + "host": [{ + "address": ADDRESS, + "match": { + "option82": { + "circuit-id": {"str": relay["link1"]} + } + } + }] + }] + } + }}) + + with test.step("Configure DHCP relay with option 82 on the client interface"): + relay.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [{ + "name": relay["link1"], + "ipv4": { + "address": [{ + "ip": "192.168.1.1", + "prefix-length": 24 + }] + } + }, { + "name": relay["link2"], + "ipv4": { + "address": [{ + "ip": "192.168.2.1", + "prefix-length": 24 + }] + } + }] + } + }, + "infix-dhcp-relay": { + "dhcp-relay": { + "server": [{"address": "192.168.2.2"}], + "option82": {}, + "interface": [{ + "name": relay["link1"] + }] + } + }}) + + with test.step("Enable DHCP client on client"): + client.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [{ + "name": client["link"], + "ipv4": { + "infix-dhcp-client:dhcp": {} + } + }] + } + }}) + + with test.step("Verify client gets the address of the static host, 192.168.1.42"): + until(lambda: iface.address_exist(client, client["link"], ADDRESS)) + + with test.step("Disable option 82 for the client interface on relay"): + relay.put_config_dicts({ + "infix-dhcp-relay": { + "dhcp-relay": { + "interface": [{ + "name": relay["link1"], + "option82": False + }] + } + }}) + + with test.step("Change MAC address of client to 02:00:00:00:00:99"): + client.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [{ + "name": client["link"], + "infix-interfaces:custom-phys-address": { + "static": NEWMAC + } + }] + } + }}) + + with test.step("Verify client gets the pool address, 192.168.1.100"): + until(lambda: iface.address_exist(client, client["link"], POOL)) + + test.succeed() diff --git a/test/case/dhcp/relay_plain/topology.dot b/test/case/dhcp/relay_plain/topology.dot new file mode 100644 index 000000000..52a171153 --- /dev/null +++ b/test/case/dhcp/relay_plain/topology.dot @@ -0,0 +1,42 @@ +graph "relay plain" { + layout="neato"; + overlap="false"; + esep="+40"; + + node [shape=record, fontname="DejaVu Sans Mono, Book"]; + edge [color="cornflowerblue", penwidth="2", fontname="DejaVu Serif, Book"]; + + host [ + label="host | { mgmt1 | mgmt0 | mgmt2 }", + pos="0,12!", + requires="controller", + ]; + + relay [ + label="{ link1 | mgmt | link2 } | relay", + pos="15,12!", + + requires="infix", + ]; + + client [ + label="{ mgmt | link} | client", + pos="15,18!", + + requires="infix", + ]; + + server [ + label="{ link | mgmt } | server", + pos="15,6!", + + requires="infix", + ]; + + host:mgmt0 -- relay:mgmt [requires="mgmt", color=lightgrey] + host:mgmt1 -- client:mgmt [requires="mgmt", color=lightgrey] + host:mgmt2 -- server:mgmt [requires="mgmt", color=lightgrey] + + relay:link1 -- client:link [color=black, fontcolor=black, taillabel="192.168.1.1/24"] + relay:link2 -- server:link [color=black, fontcolor=black, taillabel="192.168.2.1/24", headlabel="192.168.2.2/24"] +} diff --git a/test/case/dhcp/relay_plain/topology.svg b/test/case/dhcp/relay_plain/topology.svg new file mode 100644 index 000000000..7a0a71931 --- /dev/null +++ b/test/case/dhcp/relay_plain/topology.svg @@ -0,0 +1,84 @@ + + + + + + +relay plain + + + +host + +host + +mgmt1 + +mgmt0 + +mgmt2 + + + +relay + +link1 + +mgmt + +link2 + +relay + + + +host:mgmt0--relay:mgmt + + + + +client + +mgmt + +link + +client + + + +host:mgmt1--client:mgmt + + + + +server + +link + +mgmt + +server + + + +host:mgmt2--server:mgmt + + + + +relay:link1--client:link + +192.168.1.1/24 + + + +relay:link2--server:link + +192.168.2.2/24 +192.168.2.1/24 + + + diff --git a/test/case/dhcp/relay_vlan/Readme.adoc b/test/case/dhcp/relay_vlan/Readme.adoc new file mode 120000 index 000000000..ae32c8412 --- /dev/null +++ b/test/case/dhcp/relay_vlan/Readme.adoc @@ -0,0 +1 @@ +test.adoc \ No newline at end of file diff --git a/test/case/dhcp/relay_vlan/test.adoc b/test/case/dhcp/relay_vlan/test.adoc new file mode 100644 index 000000000..0eb8c2890 --- /dev/null +++ b/test/case/dhcp/relay_vlan/test.adoc @@ -0,0 +1,30 @@ +=== DHCP Relay with VLANs + +ifdef::topdoc[:imagesdir: {topdoc}../../test/case/dhcp/relay_vlan] + +==== Description + +Verify the relay agent on a VLAN filtering bridge, with the DHCP server +on the same device and a subnet per VLAN. Port link1 is an access port +in VLAN 10 and port link2 a trunk port with VLAN 10 and 20. The server +has a static host per port and VLAN: + + - client1, untagged on the access port, gets 192.168.10.42 + - client2, tagged with VLAN 10 on the trunk port, gets 192.168.10.43 + - client2, tagged with VLAN 20 on the trunk port, gets 192.168.20.43 + +==== Topology + +image::topology.svg[DHCP Relay with VLANs topology, align=center, scaledwidth=75%] + +==== Sequence + +. Set up topology and attach to relay, client1 and client2 DUTs +. Configure relay with bridge br0, VLAN 10 and 20, access port link1 and trunk port link2 +. Configure DHCP relay on vlan10 and vlan20, and DHCP server with a static host per port and VLAN +. Enable DHCP client on client1, and on VLAN 10 and 20 of client2 +. Verify client1 gets 192.168.10.42 +. Verify client2 gets 192.168.10.43 on VLAN 10 +. Verify client2 gets 192.168.20.43 on VLAN 20 + + diff --git a/test/case/dhcp/relay_vlan/test.py b/test/case/dhcp/relay_vlan/test.py new file mode 100755 index 000000000..d360eaf5c --- /dev/null +++ b/test/case/dhcp/relay_vlan/test.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python3 +"""DHCP Relay with VLANs + +Verify the relay agent on a VLAN filtering bridge, with the DHCP server +on the same device and a subnet per VLAN. Port link1 is an access port +in VLAN 10 and port link2 a trunk port with VLAN 10 and 20. The server +has a static host per port and VLAN: + + - client1, untagged on the access port, gets 192.168.10.42 + - client2, tagged with VLAN 10 on the trunk port, gets 192.168.10.43 + - client2, tagged with VLAN 20 on the trunk port, gets 192.168.20.43 + +""" +import infamy +import infamy.iface as iface +from infamy.util import parallel, until + + +def vlan(name, vid, lower, ipv4): + """VLAN interface on top of lower""" + return { + "name": name, + "type": "infix-if-type:vlan", + "vlan": { + "id": vid, + "lower-layer-if": lower + }, + "ipv4": ipv4 + } + + +def address(ip): + """Static IPv4 address""" + return {"address": [{"ip": ip, "prefix-length": 24}]} + + +def subnet(net, hosts): + """DHCP subnet with static hosts, address by circuit-id""" + return { + "subnet": net, + "host": [{ + "address": addr, + "match": { + "option82": { + "circuit-id": {"str": port} + } + } + } for addr, port in hosts] + } + + +with infamy.Test() as test: + ACCESS10 = '192.168.10.42' + TRUNK10 = '192.168.10.43' + TRUNK20 = '192.168.20.43' + DHCP = {"infix-dhcp-client:dhcp": {}} + + with test.step("Set up topology and attach to relay, client1 and client2 DUTs"): + env = infamy.Env() + relay, client1, client2 = parallel(lambda: env.attach("relay", "mgmt"), + lambda: env.attach("client1", "mgmt"), + lambda: env.attach("client2", "mgmt")) + + with test.step("Configure relay with bridge br0, VLAN 10 and 20, access port link1 and trunk port link2"): + access = relay["link1"] + trunk = relay["link2"] + relay.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [ + { + "name": "br0", + "type": "infix-if-type:bridge", + "bridge": { + "vlans": { + "vlan": [{ + "vid": 10, + "untagged": [access], + "tagged": [trunk, "br0"] + }, { + "vid": 20, + "tagged": [trunk, "br0"] + }] + } + } + }, { + "name": access, + "infix-interfaces:bridge-port": { + "pvid": 10, + "bridge": "br0" + } + }, { + "name": trunk, + "infix-interfaces:bridge-port": { + "bridge": "br0" + } + }, + vlan("vlan10", 10, "br0", address("192.168.10.1")), + vlan("vlan20", 20, "br0", address("192.168.20.1")), + ] + } + }}) + + with test.step("Configure DHCP relay on vlan10 and vlan20, and DHCP server with a static host per port and VLAN"): + relay.put_config_dicts({ + "infix-dhcp-relay": { + "dhcp-relay": { + "server": [{"address": "127.0.0.1"}], + "option82": {}, + "interface": [ + {"name": "vlan10"}, + {"name": "vlan20"}, + ] + } + }, + "infix-dhcp-server": { + "dhcp-server": { + "subnet": [ + subnet("192.168.10.0/24", [(ACCESS10, access), (TRUNK10, trunk)]), + subnet("192.168.20.0/24", [(TRUNK20, trunk)]), + ] + } + }}) + + with test.step("Enable DHCP client on client1, and on VLAN 10 and 20 of client2"): + link = client2["link"] + parallel( + lambda: client1.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [{ + "name": client1["link"], + "ipv4": DHCP + }] + } + }}), + lambda: client2.put_config_dicts({ + "ietf-interfaces": { + "interfaces": { + "interface": [ + vlan(f"{link}.10", 10, link, DHCP), + vlan(f"{link}.20", 20, link, DHCP), + ] + } + }}), + ) + + with test.step("Verify client1 gets 192.168.10.42"): + until(lambda: iface.address_exist(client1, client1["link"], ACCESS10)) + + with test.step("Verify client2 gets 192.168.10.43 on VLAN 10"): + until(lambda: iface.address_exist(client2, f"{link}.10", TRUNK10)) + + with test.step("Verify client2 gets 192.168.20.43 on VLAN 20"): + until(lambda: iface.address_exist(client2, f"{link}.20", TRUNK20)) + + test.succeed() diff --git a/test/case/dhcp/relay_vlan/topology.dot b/test/case/dhcp/relay_vlan/topology.dot new file mode 100644 index 000000000..23b850e66 --- /dev/null +++ b/test/case/dhcp/relay_vlan/topology.dot @@ -0,0 +1,42 @@ +graph "relay vlan" { + layout="neato"; + overlap="false"; + esep="+40"; + + node [shape=record, fontname="DejaVu Sans Mono, Book"]; + edge [color="cornflowerblue", penwidth="2", fontname="DejaVu Serif, Book"]; + + host [ + label="host | { mgmt1 | mgmt0 | mgmt2 }", + pos="0,12!", + requires="controller", + ]; + + relay [ + label="{ link1 | mgmt | link2 } | relay", + pos="15,12!", + + requires="infix", + ]; + + client1 [ + label="{ mgmt | link} | client1", + pos="15,18!", + + requires="infix", + ]; + + client2 [ + label="{ link | mgmt } | client2", + pos="15,6!", + + requires="infix", + ]; + + host:mgmt0 -- relay:mgmt [requires="mgmt", color=lightgrey] + host:mgmt1 -- client1:mgmt [requires="mgmt", color=lightgrey] + host:mgmt2 -- client2:mgmt [requires="mgmt", color=lightgrey] + + relay:link1 -- client1:link [color=black, fontcolor=black, taillabel="VLAN 10"] + relay:link2 -- client2:link [color=black, fontcolor=black, taillabel="VLAN 10, 20 tagged"] +} diff --git a/test/case/dhcp/relay_vlan/topology.svg b/test/case/dhcp/relay_vlan/topology.svg new file mode 100644 index 000000000..b6edd322c --- /dev/null +++ b/test/case/dhcp/relay_vlan/topology.svg @@ -0,0 +1,83 @@ + + + + + + +relay vlan + + + +host + +host + +mgmt1 + +mgmt0 + +mgmt2 + + + +relay + +link1 + +mgmt + +link2 + +relay + + + +host:mgmt0--relay:mgmt + + + + +client1 + +mgmt + +link + +client1 + + + +host:mgmt1--client1:mgmt + + + + +client2 + +link + +mgmt + +client2 + + + +host:mgmt2--client2:mgmt + + + + +relay:link1--client1:link + +VLAN 10 + + + +relay:link2--client2:link + +VLAN 10, 20 tagged + + +