From nobody Mon Apr 10 23:13:35 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PwPsr04gxz44wT1; Mon, 10 Apr 2023 23:13:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PwPsq6dnpz3yg3; Mon, 10 Apr 2023 23:13:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681168415; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Qct/Lqbse/cFcMbwTbg7crbqrDYaeoRbj2olDvUht1U=; b=Hckz1H4QWhH0UNH5BM97PgXNWRANksmj58xketmKevp/iKoK6aVSfzKt1mI5TsOC9FrLIO 20BTnGx+FrF9yVFaEfABwxy1ohvD6SBdMpcIsSCOT1Vb8kbTltN8LV3kq+fnPBWyfQ7S7X QLza4EQFcZ7tgsJcG21bFAdwJnPmqtFwVOTBdvIbhCrspyvxv8VEac7AnvAlBrHs7tr2GZ lHgDbx/23BxhZpFY8embTXMolb0mWDvyB+wlIduDPTDZ8FeeZp9rEo8gwWN3k/8H42QMLO O/0BdlfswUZh8sPnuJCwRqOhSEnjlMxWbpY0Jke0sGdTOf7Jh0Qx+k6OwahFhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681168415; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Qct/Lqbse/cFcMbwTbg7crbqrDYaeoRbj2olDvUht1U=; b=dXzvWjJxjLblcmyAJ8E/+qp72+57s0HYyymvhb1tykS90B3cP+0TRouovgwIsd91eTHSda LFgtBLrZwn0yCK+saB9BKGvHhni+xts1iwKR6m1P9u7bELiQ7MCpGbXpSZ0u/tf9Ae/iMi cNKtDH2wX8cS9TAKA7eItN4w8dZhReFshuQeBd42aalayOi0ojYaJuaFuCkmZbD/x9312g Dqxswh+ppoyejziucCZA+WwRjCUbmqbEuztvk1l2H7QmxpSW8MsDHOsYB3aJlOSDRblyJk X09MZZy+gZ7wQTvsX2xPmcjv12IIrP9nUqOLV+YTnZ5VJs7/o81p3WRovwpYCQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1681168415; a=rsa-sha256; cv=none; b=E3481QJ0lw4x4ZvHg9Cuk9Q2WodwI2rXLDJ82VuIXj+tIk7jMv7yAtCKQ3bjYblbfNcb4t zeuP1Iq8x2gfvJKIbo95uFaMf6bYss/z8CdM5XHFux09QERL3XgMbaReINBT2Kw+QBVusz hPSHlj+K8QiWqjSyWhdTHrfXf3GpRgtZiP5kAAWoxCqytk4v8Lk+ClErqveveBWol6EgH9 Yme8GbrwyJgDdC6AQd05kuX4k9LFDMBSM0a79mf9PZvGaKRtMAlSMo87uryAni7aSp+RFf wvNkpOryOqsLa6W97UfehlUyAG7UExz8NKRWpIdIZXaIPJb/W1R+PsKK5q4XWw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PwPsq5dDSz18t2; Mon, 10 Apr 2023 23:13:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 33ANDZGs016972; Mon, 10 Apr 2023 23:13:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33ANDZuX016971; Mon, 10 Apr 2023 23:13:35 GMT (envelope-from git) Date: Mon, 10 Apr 2023 23:13:35 GMT Message-Id: <202304102313.33ANDZuX016971@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Allan Jude Subject: git: 461ccb55d50c - main - dhclient: add ability to ignore options in offers List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: allanjude X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 461ccb55d50ccf1b5bcfe1310fe32d72f8b0ecdd Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by allanjude: URL: https://cgit.FreeBSD.org/src/commit/?id=461ccb55d50ccf1b5bcfe1310fe32d72f8b0ecdd commit 461ccb55d50ccf1b5bcfe1310fe32d72f8b0ecdd Author: Rob Norris AuthorDate: 2023-03-14 22:07:18 +0000 Commit: Allan Jude 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 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 && \