From nobody Sat Sep 17 19:42:07 2022 X-Original-To: virtualization@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MVLtX5y0Vz4cDBv; Sat, 17 Sep 2022 19:42:12 +0000 (UTC) (envelope-from mad@madpilot.net) Received: from mail.madpilot.net (vogon.madpilot.net [159.69.1.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4MVLtW6cczz3r6f; Sat, 17 Sep 2022 19:42:11 +0000 (UTC) (envelope-from mad@madpilot.net) Received: from mail (mail [192.168.254.3]) by mail.madpilot.net (Postfix) with ESMTP id 4MVLtV1qsxz6dbZ; Sat, 17 Sep 2022 21:42:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=madpilot.net; h= content-transfer-encoding:content-type:content-type:in-reply-to :subject:subject:from:from:content-language:references:date:date :message-id:received; s=bjowvop61wgh; t=1663443728; x= 1665258129; bh=gKy4YWUcWwrpjK37K0H04lwyOrEJX2CM6uhFVvamRd0=; b=h dY89X/DEfrSGupgKDom5XOi2PW9NiHR1pMgHLaw+Kp+as4QV2+4ArxK3g4424yr1 Hzi+HvEZsQQUqf4zfAt360HPDrH2xSJ/F+nnTM+BYOVphjGyYo71pqwQ+VRm60pJ HwqqbgHkuVxNPH1O93Cs9AbB52AsL2fonmpASLFYir/ZVhlx53cwcem4FabDmNPf NGiPfm1aZwI9LAetI1ioYKQf978YWifFPR4ePmSS3Hd/stGU726dAotskUR9fjJs EKNuP3DZKp30kWVCORfpdb2fxuprvpNZPc9rjgKNIr9/NmRr4aqBaYmGZFDnkO6s c2Im62RjJWfN0LY0UqRmA== Received: from mail.madpilot.net ([192.168.254.3]) by mail (mail.madpilot.net [192.168.254.3]) (amavisd-new, port 10026) with ESMTP id IO32pqeGtppr; Sat, 17 Sep 2022 21:42:08 +0200 (CEST) Message-ID: <1fa4124e-4542-f710-2545-cc8b8a1dea63@madpilot.net> Date: Sat, 17 Sep 2022 21:42:07 +0200 To: John Kennedy Cc: freebsd-hackers@freebsd.org, virtualization@freebsd.org References: Content-Language: en-US From: Guido Falsi Subject: Re: Dynamic hostname in rc.conf (for bhyve VMs) In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4MVLtW6cczz3r6f X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=pass header.d=madpilot.net header.s=bjowvop61wgh header.b="h dY89X/"; dmarc=pass (policy=quarantine) header.from=madpilot.net; spf=pass (mx1.freebsd.org: domain of mad@madpilot.net designates 159.69.1.99 as permitted sender) smtp.mailfrom=mad@madpilot.net X-Spamd-Result: default: False [-1.27 / 15.00]; MISSING_MIME_VERSION(2.00)[]; NEURAL_HAM_SHORT(-1.00)[-0.996]; NEURAL_HAM_MEDIUM(-0.97)[-0.966]; DMARC_POLICY_ALLOW(-0.50)[madpilot.net,quarantine]; NEURAL_HAM_LONG(-0.31)[-0.308]; R_SPF_ALLOW(-0.20)[+mx:c]; R_DKIM_ALLOW(-0.20)[madpilot.net:s=bjowvop61wgh]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_LAST(0.00)[]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org,virtualization@freebsd.org]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_TRACE(0.00)[madpilot.net:+]; RCPT_COUNT_THREE(0.00)[3]; ASN(0.00)[asn:24940, ipnet:159.69.0.0/16, country:DE]; TO_DN_SOME(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-ThisMailContainsUnwantedMimeParts: N List-Id: Discussion List-Archive: https://lists.freebsd.org/archives/freebsd-virtualization List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-virtualization@freebsd.org X-BeenThere: freebsd-virtualization@freebsd.org On 17/09/22 21:22, John Kennedy wrote: > On Sat, Sep 10, 2022 at 10:52:01AM +0200, Guido Falsi wrote: >> Since rc.conf is just a shell script I'd like to be able to set hostname >> dynamically. > > AFAIK, not a shell-script (although variables are set in that syntax). I'm sure about this, rc.conf is sourced through the shell. So it is a shell script. You can verify this by checking the load_rc_config() function in /etc/rc.subr which runs (beyond a lot of other things): . /etc/rc.conf I was wrong about vm-bhyve machine configuration file, which is a simple key/value pair file. > > I wasn't trying to do exactly what you are, but one thing I did was set the > MAC address as one of the bhyve options: > > ... > -s 5,virtio-net,tap2,mac=00:01:02:03:04:05 > ... > > (Changed the MAC address in the example, but pick a safe one for your setup) > > Should be able to provide your own rc.d configuration file that does > something like do a switch on MAC and call the hostname script directly. > > I already succeeded by adding "-e bhyve_vm_name=${_name}" (where _name contains the name of the vm) to bhyveload arguments, then reading it with kenv from rc.conf: hostname="$(/bin/kenv bhyve_vm_name).internal.vms" Works like a charm. -- Guido Falsi