Subject: Re: [PATCH 1/2] mac_pton: support MAC addresses with other delimiters

From: Stephen Hemminger <[email-masked]>
Date: Tue, 3 Oct 2023 09:58:32 -0700

On Mon, 02 Oct 2023 23:40:02 +0000
Michael Pratt <[email-masked]> wrote:

> From: Michael Pratt <[email-masked]>
> 
> Some network hardware vendors may do something unique
> when storing the MAC address into hardware in ASCII,
> like using hyphens as the delimiter.
> 
> Allow parsing of MAC addresses with a non-standard
> delimiter (punctuation other than a colon).
> 
> e.g. aa-bb-cc-dd-ee-ff
> 
> Signed-off-by: Michael Pratt <[email-masked]>
> ---
>  lib/net_utils.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/net_utils.c b/lib/net_utils.c
> index 42bb0473fb22..ecb7625e1dec 100644
> --- a/lib/net_utils.c
> +++ b/lib/net_utils.c
> @@ -18,7 +18,7 @@ bool mac_pton(const char *s, u8 *mac)
>  	for (i = 0; i < ETH_ALEN; i++) {
>  		if (!isxdigit(s[i * 3]) || !isxdigit(s[i * 3 + 1]))
>  			return false;
> -		if (i != ETH_ALEN - 1 && s[i * 3 + 2] != ':')
> +		if (i != ETH_ALEN - 1 && !ispunct(s[i * 3 + 2]))

Having looked at same thing in DPDK already, this looks overly broad.
There are only two common formats in the standards (isn't it fun
when standards disagree). IETF uses colon separator and IEEE uses
hyphen separator. Linux convention is colon, and  Windows convention
is hyphen. There is also the old Cisco 3 part format with periods
but adding that makes no sense.

Also, it would be bad to allow bogus values where two different
types of punctuation are used.