From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933771AbcBCVHK (ORCPT ); Wed, 3 Feb 2016 16:07:10 -0500 Received: from www62.your-server.de ([213.133.104.62]:52909 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933664AbcBCVHH (ORCPT ); Wed, 3 Feb 2016 16:07:07 -0500 Message-ID: <56B26BF7.8070307@iogearbox.net> Date: Wed, 03 Feb 2016 22:07:03 +0100 From: Daniel Borkmann User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: "Jason A. Donenfeld" CC: akpm@linux-foundation.org, linux@rasmusvillemoes.dk, andriy.shevchenko@linux.intel.com, linux-kernel@vger.kernel.org, joe@perches.com Subject: Re: [PATCH] vsprintf: do not append unset Scope ID to IPv6 References: <1454496118-26370-1-git-send-email-Jason@zx2c4.com> In-Reply-To: <1454496118-26370-1-git-send-email-Jason@zx2c4.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/03/2016 11:41 AM, Jason A. Donenfeld wrote: > The sockaddr_in6 has the sin6_scope_id parameter. This contains the > netdev index of the output device. When set to 0, sin6_scope_id is > considered to be "unset" -- it has no Scope ID (see RFC4007). When it is > set to >0, it has a Scope ID. [...] > So, here, either it has Scope ID, in which case it's returned, or it > doesn't need a Scope ID, in which case 0 - "no scope id" - is returned. > > Therefore, vsprintf should treat the 0 Scope ID the same way the rest of > the v6 stack and the RFC treats it: 0 Scope ID means no Scope ID. And if > there is no Scope ID, there is nothing to be printed. I don't see an "issue" here. I.e. if the developer requested to append 's' to the specifier, then it's expected to dump what is in the scope id, even if that is 0 meaning "unset" scope. It would be principle of least surprise -- I could imagine if not dumped, then a developer would check the source code to find out whether he did a mistake or it's expected behavior, just to make sure. That's what I would do probably. Is this causing a _real_ issue somewhere (I couldn't parse one out of your commit message other than 'it would be nice to have')? > So, this patch only prints the Scope ID when one exists, and does not > print a Scope ID when one does not exist. > > It turns out, too, that this is what developers want. The most common > purpose of %pISpfsc is to show "what is in that sockaddr so that I can > have some idea of how to connect to it?" > > Signed-off-by: Jason A. Donenfeld > --- > lib/vsprintf.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index 48ff9c3..1b1b1c8 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -1194,7 +1194,7 @@ char *ip6_addr_string_sa(char *buf, char *end, const struct sockaddr_in6 *sa, > p = number(p, pend, ntohl(sa->sin6_flowinfo & > IPV6_FLOWINFO_MASK), spec); > } > - if (have_s) { > + if (have_s && sa->sin6_scope_id) { > *p++ = '%'; > p = number(p, pend, sa->sin6_scope_id, spec); > } >