Add --dhcp-option-pxe config.

This acts almost exactly like --dhcp-option except that the defined option
is only sent when replying to PXE clients. More importantly, these
options are sent in reply PXE clients when dnsmasq in acting in PXE
proxy mode. In PXE proxy mode, the set of options sent is defined by
the PXE standard and the normal set of options is not sent. This config
allows arbitrary options in PXE-proxy replies. A typical use-case is
to send option 175 to iPXE. Thanks to Jason Berry for finding the
requirement for this.
This commit is contained in:
Simon Kelley
2024-12-05 17:07:40 +00:00
parent 5a1f2c577d
commit 7199531ff1
8 changed files with 126 additions and 49 deletions

View File

@@ -192,6 +192,7 @@ struct myoption {
#define LOPT_NO_DHCP4 383
#define LOPT_MAX_PROCS 384
#define LOPT_DNSSEC_LIMITS 385
#define LOPT_PXE_OPT 386
#ifdef HAVE_GETOPT_LONG
static const struct option opts[] =
@@ -297,6 +298,7 @@ static const struct myoption opts[] =
{ "bridge-interface", 1, 0 , LOPT_BRIDGE },
{ "shared-network", 1, 0, LOPT_SHARED_NET },
{ "dhcp-option-force", 1, 0, LOPT_FORCE },
{ "dhcp-option-pxe", 1, 0, LOPT_PXE_OPT },
{ "tftp-no-blocksize", 0, 0, LOPT_NOBLOCK },
{ "log-dhcp", 0, 0, LOPT_LOG_OPTS },
{ "log-async", 2, 0, LOPT_MAX_LOGS },
@@ -450,6 +452,7 @@ static struct {
{ 'o', OPT_ORDER, NULL, gettext_noop("Use nameservers strictly in the order given in %s."), RESOLVFILE },
{ 'O', ARG_DUP, "<optspec>", gettext_noop("Specify options to be sent to DHCP clients."), NULL },
{ LOPT_FORCE, ARG_DUP, "<optspec>", gettext_noop("DHCP option sent even if the client does not request it."), NULL},
{ LOPT_PXE_OPT, ARG_DUP, "<optspec>", gettext_noop("DHCP option sent only to PCE clients."), NULL},
{ 'p', ARG_ONE, "<integer>", gettext_noop("Specify port to listen for DNS requests on (defaults to 53)."), NULL },
{ 'P', ARG_ONE, "<integer>", gettext_noop("Maximum supported UDP packet size for EDNS.0 (defaults to %s)."), "*" },
{ 'q', ARG_DUP, NULL, gettext_noop("Log DNS queries."), NULL },
@@ -1941,7 +1944,10 @@ static int parse_dhcp_opt(char *errstr, char *arg, int flags)
(new->len > 253 && (new->flags & (DHOPT_VENDOR | DHOPT_ENCAPSULATE))) ||
(new->len > 250 && (new->flags & DHOPT_RFC3925))))
goto_err(_("dhcp-option too long"));
if (flags == DHOPT_PXE_OPT && (new->flags & DHOPT_VENDOR))
goto_err(_("No vendor-encap options allowed in dhcp-option-pxe"));
if (flags == DHOPT_MATCH)
{
if ((new->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR)) ||
@@ -4261,12 +4267,14 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
case 'O': /* --dhcp-option */
case LOPT_FORCE: /* --dhcp-option-force */
case LOPT_PXE_OPT: /* --dhcp-option-pxe */
case LOPT_OPTS:
case LOPT_MATCH: /* --dhcp-match */
return parse_dhcp_opt(errstr, arg,
option == LOPT_FORCE ? DHOPT_FORCE :
(option == LOPT_MATCH ? DHOPT_MATCH :
(option == LOPT_OPTS ? DHOPT_BANK : 0)));
(option == LOPT_OPTS ? DHOPT_BANK :
(option == LOPT_PXE_OPT ? DHOPT_PXE_OPT : 0))));
case LOPT_NAME_MATCH: /* --dhcp-name-match */
{
@@ -4661,8 +4669,8 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
daemon->override_relays = new;
arg = comma;
}
break;
break;
case LOPT_PXE_VENDOR: /* --dhcp-pxe-vendor */
{
while (arg) {