On Sat, Dec 08, 2018 at 10:13:47AM +0100, Anton Lindqvist wrote:
> Hi,
> I've been trying out the new fake netboot feature in vmd. Overall, a
> great addition that removed the need for me to run dhcpd/rebound locally
> to achieve auto install. It would be convenient if the DHCP lease
> included a hostname inferred from the VM name in order to use dedicated
> response files for different VMs. Maybe this is a behavior that
> shouldn't be limited to just netboot? The res_hnok() validation is
> borrowed from dhclient.
>
> Comments? OK?
This is a cool idea.
ok ccardenas@
+--+
Carlos
>
> Index: dhcp.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/vmd/dhcp.c,v
> retrieving revision 1.7
> diff -u -p -r1.7 dhcp.c
> --- dhcp.c 6 Dec 2018 09:20:06 -0000 1.7
> +++ dhcp.c 8 Dec 2018 09:04:33 -0000
> @@ -24,6 +24,7 @@
> #include <netinet/if_ether.h>
> #include <arpa/inet.h>
>
> +#include <resolv.h>
> #include <stdlib.h>
> #include <string.h>
> #include <stddef.h>
> @@ -44,8 +45,10 @@ dhcp_request(struct vionet_dev *dev, cha
> struct packet_ctx pc;
> struct dhcp_packet req, resp;
> struct in_addr server_addr, mask, client_addr, requested_addr;
> - size_t resplen, o;
> + size_t len, resplen, o;
> uint32_t ltime;
> + struct vmd_vm *vm;
> + const char *hostname = NULL;
>
> if (buflen < (ssize_t)(BOOTP_MIN_LEN + sizeof(struct ether_header)))
> return (-1);
> @@ -108,8 +111,12 @@ dhcp_request(struct vionet_dev *dev, cha
> resp.hlen = req.hlen;
> resp.xid = req.xid;
>
> - if (dev->pxeboot)
> + if (dev->pxeboot) {
> strlcpy(resp.file, "auto_install", sizeof resp.file);
> + vm = vm_getbyvmid(dev->vm_vmid);
> + if (vm && res_hnok(vm->vm_params.vmc_params.vcp_name))
> + hostname = vm->vm_params.vmc_params.vcp_name;
> + }
>
> if ((client_addr.s_addr =
> vm_priv_addr(&env->vmd_cfg,
> @@ -205,6 +212,14 @@ dhcp_request(struct vionet_dev *dev, cha
> resp.options[o++] = sizeof(server_addr);
> memcpy(&resp.options[o], &server_addr, sizeof(server_addr));
> o += sizeof(server_addr);
> +
> + if (hostname != NULL) {
> + len = strlen(hostname);
> + resp.options[o++] = DHO_HOST_NAME;
> + resp.options[o++] = len;
> + memcpy(&resp.options[o], hostname, len);
> + o += len;
> + }
>
> resp.options[o++] = DHO_END;
>
>