linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vsprintf: do not append unset Scope ID to IPv6
@ 2016-02-03 10:41 Jason A. Donenfeld
  2016-02-03 12:13 ` [PATCH] vsprintf: flowinfo in IPv6 is optional too Jason A. Donenfeld
  2016-02-03 21:07 ` [PATCH] vsprintf: do not append unset Scope ID to IPv6 Daniel Borkmann
  0 siblings, 2 replies; 22+ messages in thread
From: Jason A. Donenfeld @ 2016-02-03 10:41 UTC (permalink / raw)
  To: akpm, linux, andriy.shevchenko, linux-kernel, dborkman; +Cc: Jason A. Donenfeld

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.

Other parts of the kernel respect htis. For example, code like this is
sometimes used to populate a sockaddr_in6 from a skb:

  sin6->sin6_scope_id = ipv6_iface_scope_id(ipv6_hdr(skb)->saddr, skb->skb_iif);

Such a code example makes a call to the ipv6_iface_scope_id function
which is defined as follows (in ipv6.h):

static inline __u32 ipv6_iface_scope_id(const struct in6_addr *addr, int iface)
{
	return __ipv6_addr_needs_scope_id(__ipv6_addr_type(addr)) ? iface : 0;
}

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.

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 <Jason@zx2c4.com>
---
 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);
 	}
-- 
2.7.0

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2016-02-05 13:38 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).