From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965210AbcBCVr7 (ORCPT ); Wed, 3 Feb 2016 16:47:59 -0500 Received: from smtprelay0222.hostedemail.com ([216.40.44.222]:37245 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933192AbcBCVr4 (ORCPT ); Wed, 3 Feb 2016 16:47:56 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::,RULES_HIT:41:69:355:379:541:599:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:2828:3138:3139:3140:3141:3142:3355:3622:3865:3866:3867:3868:3870:3871:3872:3874:4321:5007:6261:9108:10004:10400:10848:11026:11232:11473:11658:11783:11914:12043:12296:12438:12517:12519:12555:12683:12740:13870:13894:14659:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: hall54_ab3fa1de4309 X-Filterd-Recvd-Size: 3673 Message-ID: <1454536072.7291.133.camel@perches.com> Subject: Re: [PATCH] vsprintf: do not append unset Scope ID to IPv6 From: Joe Perches To: "Jason A. Donenfeld" , Daniel Borkmann Cc: Andrew Morton , linux@rasmusvillemoes.dk, andriy.shevchenko@linux.intel.com, LKML Date: Wed, 03 Feb 2016 13:47:52 -0800 In-Reply-To: References: <1454496118-26370-1-git-send-email-Jason@zx2c4.com> <56B26BF7.8070307@iogearbox.net> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.3-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2016-02-03 at 22:14 +0100, Jason A. Donenfeld wrote: > The idea here is to be able to printk a sockaddr_in6, and have it show > something that looks like what the user would naturally pass to > getaddrinfo(3), which is entirely complete. > > However, I could be convinced that this kind of behavior belongs in > it's own flag. Maybe I'll cook up a flag for that instead. I think that'd be best. Maybe using something like %pISG for this that would optionally show these flow and scope values only when non-zero. Something like: ---  lib/vsprintf.c | 30 +++++++++++++++++++-----------  1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 6dc4288..2003c6f 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1147,7 +1147,8 @@ static noinline_for_stack  char *ip6_addr_string_sa(char *buf, char *end, const struct sockaddr_in6 *sa,    struct printf_spec spec, const char *fmt)  { - bool have_p = false, have_s = false, have_f = false, have_c = false; + u8 show_p = 0, show_s = 0, show_f = 0; + bool use_c = false;   char ip6_addr[sizeof("[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255]") +         sizeof(":12345") + sizeof("/123456789") +         sizeof("%1234567890")]; @@ -1160,43 +1161,50 @@ char *ip6_addr_string_sa(char *buf, char *end, const struct sockaddr_in6 *sa,   while (isalpha(*++fmt)) {   switch (*fmt) {   case 'p': - have_p = true; + show_p = 1;   break;   case 'f': - have_f = true; + show_f = 1;   break;   case 's': - have_s = true; + show_s = 1; + break; + case 'G': + show_p = 2; + show_f = 2; + show_s = 2;   break;   case 'c': - have_c = true; + use_c = true;   break;   }   }   - if (have_p || have_s || have_f) { + if (show_p || show_s || show_f) {   *p = '[';   off = 1;   }   - if (fmt6[0] == 'I' && have_c) + if (fmt6[0] == 'I' && use_c)   p = ip6_compressed_string(ip6_addr + off, addr);   else   p = ip6_string(ip6_addr + off, addr, fmt6);   - if (have_p || have_s || have_f) + if (show_p || show_s || show_f)   *p++ = ']';   - if (have_p) { + if (show_p) {   *p++ = ':';   p = number(p, pend, ntohs(sa->sin6_port), spec);   } - if (have_f) { + if (show_f == 1 || +     (show_f == 2 && (sa->sin6_flowinfo & IPV6_FLOWINFO_MASK))) {   *p++ = '/';   p = number(p, pend, ntohl(sa->sin6_flowinfo &     IPV6_FLOWINFO_MASK), spec);   } - if (have_s) { + if (show_s == 1 || +     (show_s == 2 && sa->sin6_scope_id)) {   *p++ = '%';   p = number(p, pend, sa->sin6_scope_id, spec);   }