From owner-dev-commits-src-main@freebsd.org  Wed Aug 11 18:06:51 2021
Return-Path: <owner-dev-commits-src-main@freebsd.org>
Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
 by mailman.nyi.freebsd.org (Postfix) with ESMTP id A8BB7658DD4;
 Wed, 11 Aug 2021 18:06:51 +0000 (UTC)
 (envelope-from ronald-lists@klop.ws)
Received: from smarthost1.greenhost.nl (smarthost1.greenhost.nl
 [195.190.28.88])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 4GlHp23WJ6z3njg;
 Wed, 11 Aug 2021 18:06:50 +0000 (UTC)
 (envelope-from ronald-lists@klop.ws)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=klop.ws;
 s=mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:MIME-Version:
 Date:Message-ID:From:References:To:Subject:Sender:Reply-To:Cc:Content-ID:
 Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
 :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
 List-Post:List-Owner:List-Archive;
 bh=zJOzvAn4iJIVrMb1rSEezJay6LdBegSoVy9Ess0ToxE=; b=CDYDwd7vNOGhSa+hfBBl6i7TFS
 uzE3Fb2eeD2Pwo2L6ctzTfkaISf924xeQpqhTi0o4Pio2UFDWqXpVArIhT1O7KWCkFi9RUV70cBro
 O8jCfLMFNwdcwGrnmNzc8TUDsLxNOLn5OCxNsEYH7oTji2ASNsWEUi00Ta6SDnmTmwFE=;
Subject: Re: git: 6c9506559080 - main - Escape any '.' characters in sysctl
 node names
To: Alan Somers <asomers@FreeBSD.org>, src-committers@FreeBSD.org,
 dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
References: <202107221623.16MGNZDu023290@gitrepo.freebsd.org>
From: Ronald Klop <ronald-lists@klop.ws>
Message-ID: <076f21f0-c6f5-1137-f1e6-b251e01b456a@klop.ws>
Date: Wed, 11 Aug 2021 20:06:39 +0200
User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:78.0) Gecko/20100101
 Thunderbird/78.13.0
MIME-Version: 1.0
In-Reply-To: <202107221623.16MGNZDu023290@gitrepo.freebsd.org>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Authenticated-As-Hash: 398f5522cb258ce43cb679602f8cfe8b62a256d1
X-Virus-Scanned: by clamav at smarthost1.greenhost.nl
X-Spam-Level: /
X-Spam-Score: -0.4
X-Spam-Status: No, score=-0.4 required=5.0 tests=ALL_TRUSTED, BAYES_50,
 DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF,
 NICE_REPLY_A autolearn=disabled version=3.4.2
X-Scan-Signature: a37d78a1f62179d0f8bbb55570e85dc4
X-Rspamd-Queue-Id: 4GlHp23WJ6z3njg
X-Spamd-Bar: -
Authentication-Results: mx1.freebsd.org;
 dkim=pass header.d=klop.ws header.s=mail header.b=CDYDwd7v;
 dmarc=pass (policy=none) header.from=klop.ws;
 spf=pass (mx1.freebsd.org: domain of ronald-lists@klop.ws designates
 195.190.28.88 as permitted sender) smtp.mailfrom=ronald-lists@klop.ws
X-Spamd-Result: default: False [-2.00 / 15.00]; ARC_NA(0.00)[];
 R_DKIM_ALLOW(-0.20)[klop.ws:s=mail]; FROM_HAS_DN(0.00)[];
 RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[];
 TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain];
 R_SPF_ALLOW(-0.20)[+ip4:195.190.28.64/27];
 DKIM_TRACE(0.00)[klop.ws:+];
 DMARC_POLICY_ALLOW(-0.50)[klop.ws,none];
 RCVD_IN_DNSWL_NONE(0.00)[195.190.28.88:from];
 NEURAL_HAM_SHORT(-1.00)[-0.999]; RCVD_COUNT_ZERO(0.00)[0];
 FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+];
 ASN(0.00)[asn:47172, ipnet:195.190.28.0/24, country:NL];
 MID_RHS_MATCH_FROM(0.00)[];
 MAILMAN_DEST(0.00)[dev-commits-src-main,dev-commits-src-all];
 RWL_MAILSPIKE_POSSIBLE(0.00)[195.190.28.88:from]
X-BeenThere: dev-commits-src-main@freebsd.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: Commit messages for the main branch of the src repository
 <dev-commits-src-main.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/dev-commits-src-main>, 
 <mailto:dev-commits-src-main-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/dev-commits-src-main/>
List-Post: <mailto:dev-commits-src-main@freebsd.org>
List-Help: <mailto:dev-commits-src-main-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main>, 
 <mailto:dev-commits-src-main-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Wed, 11 Aug 2021 18:06:51 -0000

On 7/22/21 6:23 PM, Alan Somers wrote:
> The branch main has been updated by asomers:
> 
> URL: https://cgit.FreeBSD.org/src/commit/?id=6c9506559080da2914749bf611225d7c0a153609
> 
> commit 6c9506559080da2914749bf611225d7c0a153609
> Author:     Alan Somers <asomers@FreeBSD.org>
> AuthorDate: 2021-07-21 21:11:00 +0000
> Commit:     Alan Somers <asomers@FreeBSD.org>
> CommitDate: 2021-07-22 16:22:48 +0000
> 
>      Escape any '.' characters in sysctl node names
>      
>      ZFS creates some sysctl nodes that include a pool name, and '.' is an
>      allowed character in pool names.  But it's the separator in the sysctl
>      tree, so it can't be included in a sysctl name.  Replace it with "%25".
>      Handily, "%" is illegal in ZFS pool names, so there's no ambiguity
>      there.


Hi,

Wouldn't it be cleaner to enumerate the pools as numbers/ids and put the name of the pool in a field as the data instead of the key?

Regards,
Ronald.



>      PR:             257316
>      MFC after:      3 weeks
>      Sponsored by:   Axcient
>      Reviewed by:    freqlabs
>      Differential Revision: https://reviews.freebsd.org/D31265
> ---
>   sys/kern/kern_sysctl.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
>   1 file changed, 46 insertions(+), 2 deletions(-)
> 
> diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
> index e46584758c9b..c472db18aac7 100644
> --- a/sys/kern/kern_sysctl.c
> +++ b/sys/kern/kern_sysctl.c
> @@ -122,6 +122,7 @@ static int sysctl_root(SYSCTL_HANDLER_ARGS);
>   /* Root list */
>   struct sysctl_oid_list sysctl__children = SLIST_HEAD_INITIALIZER(&sysctl__children);
>   
> +static char*	sysctl_escape_name(const char*);
>   static int	sysctl_remove_oid_locked(struct sysctl_oid *oidp, int del,
>   		    int recurse);
>   static int	sysctl_old_kernel(struct sysctl_req *, const void *, size_t);
> @@ -747,6 +748,46 @@ sysctl_remove_name(struct sysctl_oid *parent, const char *name,
>   	return (error);
>   }
>   
> +/*
> + * Duplicate the provided string, escaping any illegal characters.  The result
> + * must be freed when no longer in use.
> + *
> + * The list of illegal characters is ".".
> + */
> +static char*
> +sysctl_escape_name(const char* orig)
> +{
> +	int i, s = 0, d = 0, nillegals = 0;
> +	char *new;
> +
> +	/* First count the number of illegal characters */
> +	for (i = 0; orig[i] != '\0'; i++) {
> +		if (orig[i] == '.')
> +			nillegals++;
> +	}
> +
> +	/* Allocate storage for new string */
> +	new = malloc(i + 2 * nillegals + 1, M_SYSCTLOID, M_WAITOK);
> +
> +	/* Copy the name, escaping characters as we go */
> +	while (orig[s] != '\0') {
> +		if (orig[s] == '.') {
> +			/* %25 is the hexadecimal representation of '.' */
> +			new[d++] = '%';
> +			new[d++] = '2';
> +			new[d++] = '5';
> +			s++;
> +		} else {
> +			new[d++] = orig[s++];
> +		}
> +	}
> +
> +	/* Finally, nul-terminate */
> +	new[d] = '\0';
> +
> +	return (new);
> +}
> +
>   static int
>   sysctl_remove_oid_locked(struct sysctl_oid *oidp, int del, int recurse)
>   {
> @@ -828,14 +869,17 @@ sysctl_add_oid(struct sysctl_ctx_list *clist, struct sysctl_oid_list *parent,
>   	const char *label)
>   {
>   	struct sysctl_oid *oidp;
> +	char *escaped;
>   
>   	/* You have to hook up somewhere.. */
>   	if (parent == NULL)
>   		return(NULL);
> +	escaped = sysctl_escape_name(name);
>   	/* Check if the node already exists, otherwise create it */
>   	SYSCTL_WLOCK();
> -	oidp = sysctl_find_oidname(name, parent);
> +	oidp = sysctl_find_oidname(escaped, parent);
>   	if (oidp != NULL) {
> +		free(escaped, M_SYSCTLOID);
>   		if ((oidp->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
>   			oidp->oid_refcnt++;
>   			/* Update the context */
> @@ -854,7 +898,7 @@ sysctl_add_oid(struct sysctl_ctx_list *clist, struct sysctl_oid_list *parent,
>   	SLIST_INIT(&oidp->oid_children);
>   	oidp->oid_number = number;
>   	oidp->oid_refcnt = 1;
> -	oidp->oid_name = strdup(name, M_SYSCTLOID);
> +	oidp->oid_name = escaped;
>   	oidp->oid_handler = handler;
>   	oidp->oid_kind = CTLFLAG_DYN | kind;
>   	oidp->oid_arg1 = arg1;
> _______________________________________________
> dev-commits-src-all@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
> To unsubscribe, send any mail to "dev-commits-src-all-unsubscribe@freebsd.org"
>