All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>,
	Daniel Borkmann <daniel@iogearbox.net>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux@rasmusvillemoes.dk, andriy.shevchenko@linux.intel.com,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] vsprintf: do not append unset Scope ID to IPv6
Date: Wed, 03 Feb 2016 13:47:52 -0800	[thread overview]
Message-ID: <1454536072.7291.133.camel@perches.com> (raw)
In-Reply-To: <CAHmME9qmdM6t8Gk6Ypw+OYFbYP7w4fRKT_44dKnmXbm93JF77g@mail.gmail.com>

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);
 	}

  reply	other threads:[~2016-02-03 21:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-03 10:41 [PATCH] vsprintf: do not append unset Scope ID to IPv6 Jason A. Donenfeld
2016-02-03 12:13 ` [PATCH] vsprintf: flowinfo in IPv6 is optional too Jason A. Donenfeld
2016-02-03 17:56   ` IRe: " Joe Perches
2016-02-03 21:09     ` Jason A. Donenfeld
2016-02-03 21:13       ` Andy Shevchenko
2016-02-03 21:13     ` IRe: " Daniel Borkmann
2016-02-03 21:15       ` Jason A. Donenfeld
2016-02-03 21:07 ` [PATCH] vsprintf: do not append unset Scope ID to IPv6 Daniel Borkmann
2016-02-03 21:14   ` Jason A. Donenfeld
2016-02-03 21:47     ` Joe Perches [this message]
2016-02-03 22:09       ` Daniel Borkmann
2016-02-03 22:42       ` Jason A. Donenfeld
2016-02-03 22:53       ` [PATCH] vsprintf: automatic parameters for %pIS via 'a' Jason A. Donenfeld
2016-02-03 23:05         ` Joe Perches
2016-02-03 23:25           ` Jason A. Donenfeld
2016-02-03 23:29           ` [PATCH v2] " Jason A. Donenfeld
2016-02-03 23:37             ` Joe Perches
2016-02-04  0:59               ` [PATCH v3] " Jason A. Donenfeld
2016-02-05  0:06             ` [PATCH v2] " Rasmus Villemoes
2016-02-05 13:06               ` Jason A. Donenfeld
2016-02-05 13:37               ` [PATCH] " Jason A. Donenfeld
2016-02-05 13:39               ` [PATCH v4] " Jason A. Donenfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1454536072.7291.133.camel@perches.com \
    --to=joe@perches.com \
    --cc=Jason@zx2c4.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.