Add a convenience shorthand --dhcp-boot FILE that sets the boot
file name (DHCP option 67) for network boot. This is equivalent
to --dhcp-opt 67,FILE.
Per RFC 2132, Section 9.5, the boot file name is placed in the
'file' header field of the DHCP reply.
Link: https://bugs.passt.top/show_bug.cgi?id=192
Signed-off-by: Anshu Kumari
---
v7:
- moved ```has_bootfile``` declaration and initialization in
this patch.
v6:
- no changes.
v5:
- replaced conf_dhcp_option() to dhcp_set_opt().
v4:
- Changed argument name from URL to FILE in usage and man page.
- Fixed UEFI HTTP boot wording in man page
v3:
- case 32 now calls dhcp_add_option(c, 67, optarg).
- Handles duplicate codes: --dhcp-boot and --dhcp-opt 67 coexist
correctly, last value wins.
v2:
- Removed separate dhcp_boot[PATH_MAX] field — --dhcp-boot foo
now stores into custom_opts[] as code 67 (same as --dhcp-opt 67,foo)
---
conf.c | 5 +++++
dhcp.c | 10 ++++++++++
passt.1 | 7 +++++++
3 files changed, 22 insertions(+)
diff --git a/conf.c b/conf.c
index c12a9335..37720bb5 100644
--- a/conf.c
+++ b/conf.c
@@ -634,6 +634,7 @@ static void usage(const char *name, FILE *f, int status)
" a single, empty option disables the DNS search list\n"
" -H, --hostname NAME Hostname to configure client with\n"
" --fqdn NAME FQDN to configure client with\n"
+ " --dhcp-boot FILE Boot file name for network boot\n"
" --dhcp-opt CODE,VAL Set DHCP option CODE to VAL\n");
if (strstr(name, "pasta"))
FPRINTF(f, " default: don't use any search list\n");
@@ -1354,6 +1355,7 @@ void conf(struct ctx *c, int argc, char **argv)
{"stats", required_argument, NULL, 31 },
{"conf-path", required_argument, NULL, 'c' },
{"chroot-fallback", no_argument, NULL, 32 },
+ {"dhcp-boot", required_argument, NULL, 33 },
{"dhcp-opt", required_argument, NULL, 34 },
{ 0 },
};
@@ -1596,6 +1598,9 @@ void conf(struct ctx *c, int argc, char **argv)
case 32:
c->chroot_fallback = true;
break;
+ case 33:
+ dhcp_set_opt(67, optarg);
+ break;
case 34: {
unsigned long optcode;
diff --git a/dhcp.c b/dhcp.c
index dd3ab6c6..4dccae7b 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -600,6 +600,7 @@ int dhcp(const struct ctx *c, struct iov_tail *data)
const struct udphdr *uh;
struct msg m_storage;
struct msg const *m;
+ bool has_bootfile;
struct msg reply;
unsigned int i;
@@ -772,8 +773,17 @@ int dhcp(const struct ctx *c, struct iov_tail *data)
if (!c->no_dhcp_dns_search)
opt_set_dns_search(c, sizeof(m->o));
+ /* RFC 2132, Section 9.5: put boot file name in the 'file' header
+ * field.
+ */
+ has_bootfile = opts[67].slen > 0 &&
+ (size_t)opts[67].slen < sizeof(reply.file);
+
dlen = offsetof(struct msg, o) + fill(&reply);
+ if (has_bootfile)
+ memcpy(reply.file, opts[67].s, opts[67].slen);
+
if (m->flags & FLAG_BROADCAST)
dst = in4addr_broadcast;
else
diff --git a/passt.1 b/passt.1
index 2bfe7d50..fdbe3d2c 100644
--- a/passt.1
+++ b/passt.1
@@ -440,6 +440,13 @@ Send \fIname\fR as DHCP option 12 (hostname).
FQDN to configure the client with.
Send \fIname\fR as Client FQDN: DHCP option 81 and DHCPv6 option 39.
+.TP
+.BR \-\-dhcp-boot " " \fIfile
+Convenience shorthand for \fB\-\-dhcp-opt\fR 67,\fIfile\fR.
+Sets the boot file name (DHCP option 67) for network boot.
+For UEFI HTTP boot, the vendor class identifier also needs to be set using
+\fB\-\-dhcp-opt\fR 60,HTTPClient.
+
.TP
.BR \-\-dhcp-opt " " \fICODE\fR,\fIVALUE\fR
Set DHCP option \fICODE\fR (1\-254) to \fIVALUE\fR. The value format depends
--
2.55.0