Re: vmd: set dhcp hostname option during netboot
On Tue, Dec 11, 2018 at 08:08:38AM +0100, Anton Lindqvist wrote: > On Mon, Dec 10, 2018 at 09:40:41PM -0800, Mike Larkin wrote: > > On Mon, Dec 10, 2018 at 07:27:40PM -0800, Carlos Cardenas wrote: > > > 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 > > > > > > > I am not opposed to this, but doesn't this assume that the vm name is > > the same as the desired hostname? (maybe that's ok?) > > Not necessarily. The DHCP hostname is used to construct one of the URLs > used to probe for install.conf during autoinstall. The same hostname > will also be used as the default answer to the "System hostname" > question. Thus, the desired hostname can be overwritten in install.conf. > Also worth noting is that the final hostname written to /etc/myname is > joined together with the answer to the "DNS domain name" question. > I see. No objections here, I'll let you decide if you want to wait for reyk to comment. -ml > > > > reyk@, what do you think? > > > > -ml > > > > > > > > > > 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 - 1.7 > > > > +++ dhcp.c 8 Dec 2018 09:04:33 - > > > > @@ -24,6 +24,7 @@ > > > > #include > > > > #include > > > > > > > > +#include > > > > #include > > > > #include > > > > #include > > > > @@ -44,8 +45,10 @@ dhcp_request(struct vionet_dev *dev, cha > > > > struct packet_ctxpc; > > > > 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; > > > > > > > > > > > >
Re: vmd: set dhcp hostname option during netboot
On Mon, Dec 10, 2018 at 09:40:41PM -0800, Mike Larkin wrote: > On Mon, Dec 10, 2018 at 07:27:40PM -0800, Carlos Cardenas wrote: > > 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 > > > > I am not opposed to this, but doesn't this assume that the vm name is > the same as the desired hostname? (maybe that's ok?) Not necessarily. The DHCP hostname is used to construct one of the URLs used to probe for install.conf during autoinstall. The same hostname will also be used as the default answer to the "System hostname" question. Thus, the desired hostname can be overwritten in install.conf. Also worth noting is that the final hostname written to /etc/myname is joined together with the answer to the "DNS domain name" question. > > reyk@, what do you think? > > -ml > > > > > > > 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.c6 Dec 2018 09:20:06 - 1.7 > > > +++ dhcp.c8 Dec 2018 09:04:33 - > > > @@ -24,6 +24,7 @@ > > > #include > > > #include > > > > > > +#include > > > #include > > > #include > > > #include > > > @@ -44,8 +45,10 @@ dhcp_request(struct vionet_dev *dev, cha > > > struct packet_ctxpc; > > > 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; > > > > > > > >
Re: vmd: set dhcp hostname option during netboot
On Mon, Dec 10, 2018 at 07:27:40PM -0800, Carlos Cardenas wrote: > 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 > I am not opposed to this, but doesn't this assume that the vm name is the same as the desired hostname? (maybe that's ok?) reyk@, what do you think? -ml > > > > 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 - 1.7 > > +++ dhcp.c 8 Dec 2018 09:04:33 - > > @@ -24,6 +24,7 @@ > > #include > > #include > > > > +#include > > #include > > #include > > #include > > @@ -44,8 +45,10 @@ dhcp_request(struct vionet_dev *dev, cha > > struct packet_ctxpc; > > 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; > > > > >
Re: vmd: set dhcp hostname option during netboot
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.c6 Dec 2018 09:20:06 - 1.7 > +++ dhcp.c8 Dec 2018 09:04:33 - > @@ -24,6 +24,7 @@ > #include > #include > > +#include > #include > #include > #include > @@ -44,8 +45,10 @@ dhcp_request(struct vionet_dev *dev, cha > struct packet_ctxpc; > 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; > >
vmd: set dhcp hostname option during netboot
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? 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 - 1.7 +++ dhcp.c 8 Dec 2018 09:04:33 - @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -44,8 +45,10 @@ dhcp_request(struct vionet_dev *dev, cha struct packet_ctxpc; 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;