vmd: accept ethers(5) references in vm.conf lladdr

jslee <[email protected]>
Newsgroups gmane.os.openbsd.tech
Message-ID <[email protected]>
While setting up a home for some experiments I wanted to manage their
ethernet addresses in one place (/etc/ethers) rather than duplicate
them in /etc/dhcpd.conf and /etc/vm.conf and risk copypasta errors.

I'd also like to add some regress/ tests here, as it lacks coverage
for lladdr, and this change does make the directive more complicated.

However I'd never looked in regress/ until today and I'm not yet sure
how to write vmd tests that depend on external state, eg. here, check
that 'vmd -n' fails when configured to use an ethers(5) entry that has
an invalid MAC address, or simply doesn't exist at all.

If you know of some suitable prior art for regress/, point me at it?

I've tried assembling a chroot but it's ugly++ and I'm stuck. Yes
there is a ./chroot/dev and I have run MAKEDEV std ptm pts* tty* vmm
in it.

    # chroot chroot /usr/sbin/vmd -n -f /etc/vm.ok.conf
    vmd: vmd: getptmfd /dev/ptm: Device not configured

Anyway enough rambling. Diff:


Index: usr.sbin/vmd/parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/vmd/parse.y,v
diff -u -p -u -r1.74 parse.y
--- usr.sbin/vmd/parse.y	14 Apr 2026 21:41:19 -0000	1.74
+++ usr.sbin/vmd/parse.y	1 Jul 2026 08:58:51 -0000
@@ -729,16 +729,23 @@ string		: STRING string			{
 		;

 lladdr		: STRING			{
-			struct ether_addr *ea;
-
-			if ((ea = ether_aton($1)) == NULL) {
-				yyerror("invalid address: %s\n", $1);
+			struct ether_addr ea;
+			struct ether_addr *eap = NULL;
+			if (ether_hostton($1, &ea) == 0) {
+				eap = &ea;
+			}
+			if (eap == NULL) {
+				eap = ether_aton($1);
+			}
+			/* an address found in ethers(5) may be invalid */
+			if (eap == NULL || ether_ntoa(eap) == NULL) {
+				yyerror("invalid Ethernet address or ethers(5) entry: %s\n", $1);
 				free($1);
 				YYERROR;
 			}
 			free($1);

-			memcpy($$, ea, ETHER_ADDR_LEN);
+			memcpy($$, eap, ETHER_ADDR_LEN);
 		}
 		| /* empty */ {
 			memset($$, 0, ETHER_ADDR_LEN);
Index: usr.sbin/vmd/vm.conf.5
===================================================================
RCS file: /cvs/src/usr.sbin/vmd/vm.conf.5,v
diff -u -p -u -r1.69 vm.conf.5
--- usr.sbin/vmd/vm.conf.5	6 Jul 2025 15:45:02 -0000	1.69
+++ usr.sbin/vmd/vm.conf.5	1 Jul 2026 08:58:51 -0000
@@ -250,10 +250,13 @@ The
 must not be longer than 15 characters or end with a digit,
 as described in
 .Xr ifconfig 8 .
-.It Oo Ic locked Oc Ic lladdr Op Ar etheraddr
+.It Oo Ic locked Oc Ic lladdr Op Ar address
 Change the link layer address (MAC address) of the interface on the
-VM guest side.
-If not specified, a randomized address is assigned by
+VM guest side. The
+.Ar address
+can be a literal address, or a hostname corresponding to an
+.Xr ethers 5
+entry. If not specified, a randomized address is assigned by
 .Xr vmd 8 .
 If the
 .Ic locked
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.