git: 461ccb55d50c - main - dhclient: add ability to ignore options in offers
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 10 Apr 2023 23:13:35 UTC
The branch main has been updated by allanjude: URL: https://cgit.FreeBSD.org/src/commit/?id=461ccb55d50ccf1b5bcfe1310fe32d72f8b0ecdd commit 461ccb55d50ccf1b5bcfe1310fe32d72f8b0ecdd Author: Rob Norris <rob.norris@klarasystems.com> AuthorDate: 2023-03-14 22:07:18 +0000 Commit: Allan Jude <allanjude@FreeBSD.org> CommitDate: 2023-04-10 23:13:18 +0000 dhclient: add ability to ignore options in offers A machine might exist on multiple networks, all of which offer, say, default routes or name servers. There's no easy way to indicate in the config that those options are only valid for a single interface. Now, we can write: interface "lan0" { request routers; require routers; } interface "lan1" { ignore routers; } And only take action on default routes offered on lan0. Tested by: Jose Luis Duran <jlduran at gmail dot com> MFC after: 2 months Reviewed by: allanjude, imp Sponsored by: Zenith Electronics LLC Sponsored by: Klara, Inc. Pull Request: #693 --- sbin/dhclient/clparse.c | 4 ++++ sbin/dhclient/conflex.c | 2 ++ sbin/dhclient/dhclient.c | 13 +++++++++++-- sbin/dhclient/dhclient.conf.5 | 7 ++++++- sbin/dhclient/dhcpd.h | 1 + sbin/dhclient/dhctoken.h | 1 + 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index c7b02a073aa3..295a800a7328 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -186,6 +186,7 @@ read_client_leases(void) * hardware-declaration | * REQUEST option-list | * REQUIRE option-list | + * IGNORE option-list | * TIMEOUT number | * RETRY number | * REBOOT number | @@ -249,6 +250,9 @@ parse_client_statement(FILE *cfile, struct interface_info *ip, sizeof(config->required_options)); parse_option_list(cfile, config->required_options); return; + case IGNORE: + parse_option_list(cfile, config->ignored_options); + return; case TIMEOUT: parse_lease_time(cfile, &config->timeout); return; diff --git a/sbin/dhclient/conflex.c b/sbin/dhclient/conflex.c index c11c9189527e..3a6824a9a815 100644 --- a/sbin/dhclient/conflex.c +++ b/sbin/dhclient/conflex.c @@ -413,6 +413,8 @@ intern(char *atom, int dfv) return (HOSTNAME); break; case 'i': + if (!strcasecmp(atom + 1, "gnore")) + return (IGNORE); if (!strcasecmp(atom + 1, "nitial-interval")) return (INITIAL_INTERVAL); if (!strcasecmp(atom + 1, "nterface")) diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index da9a567fad04..4261251b6b78 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1039,7 +1039,6 @@ dhcpoffer(struct packet *packet) note("%s from %s", name, piaddr(packet->client_addr)); - /* If this lease doesn't supply the minimum required parameters, blow it off. */ for (i = 0; ip->client->config->required_options[i]; i++) { @@ -1141,8 +1140,9 @@ dhcpoffer(struct packet *packet) struct client_lease * packet_to_lease(struct packet *packet) { + struct interface_info *ip = packet->interface; struct client_lease *lease; - int i; + int i, j; lease = malloc(sizeof(struct client_lease)); @@ -1156,6 +1156,15 @@ packet_to_lease(struct packet *packet) /* Copy the lease options. */ for (i = 0; i < 256; i++) { if (packet->options[i].len) { + int ignored = 0; + for (j = 0; ip->client->config->ignored_options[j]; j++) + if (i == + ip->client->config->ignored_options[j]) { + ignored = 1; + break; + } + if (ignored) + continue; lease->options[i].data = malloc(packet->options[i].len + 1); if (!lease->options[i].data) { diff --git a/sbin/dhclient/dhclient.conf.5 b/sbin/dhclient/dhclient.conf.5 index 14a0de4111dd..39a00fd0f207 100644 --- a/sbin/dhclient/dhclient.conf.5 +++ b/sbin/dhclient/dhclient.conf.5 @@ -38,7 +38,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 21, 2021 +.Dd March 17, 2023 .Dt DHCLIENT.CONF 5 .Os .Sh NAME @@ -200,6 +200,11 @@ option other than the default requested lease time, which is two hours. The other obvious use for this statement is to send information to the server that will allow it to differentiate between this client and other clients or kinds of clients. +.It Ic ignore Oo Ar option Oc Oo , Ar ... option Oc ; +The +.Ic ignore +statement causes the client to disregard the specified options in any offer +received, as though the server had never sent them at all. .El .Sh OPTION MODIFIERS In some cases, a client may receive option data from the server which diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index b151daa90a1c..580fdabaf367 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -159,6 +159,7 @@ struct client_config { u_int8_t required_options[256]; u_int8_t requested_options[256]; int requested_option_count; + u_int8_t ignored_options[256]; u_int vlan_pcp; time_t timeout; time_t initial_interval; diff --git a/sbin/dhclient/dhctoken.h b/sbin/dhclient/dhctoken.h index c929307c7e06..dc8008e23be9 100644 --- a/sbin/dhclient/dhctoken.h +++ b/sbin/dhclient/dhctoken.h @@ -134,6 +134,7 @@ #define TOKEN_NOT 334 #define ALWAYS_REPLY_RFC1048 335 #define VLAN_PCP 336 +#define IGNORE 337 #define is_identifier(x) ((x) >= FIRST_TOKEN && \ (x) != STRING && \