LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [RFC PATCH 1/5] printk: add %p6 format specifier for IPv6 addresses
@ 2008-10-28  4:05 Harvey Harrison
  2008-10-28 18:49 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Harvey Harrison @ 2008-10-28  4:05 UTC (permalink / raw)
  To: David Miller; +Cc: Johannes Berg, Joe Perches, LKML

Takes a pointer to a IPv6 address and formats it in the usual
colon-separated hex format:
xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx

Each 16 bit word is printed in network-endian byteorder.

%#p6 is also supported and will omit the colons.

%p6 is a replacement for NIP6_FMT and NIP6()
%#p6 is a replacement for NIP6_SEQFMT and NIP6()

Note that NIP6() took a struct in6_addr whereas this takes a pointer
to a struct in6_addr.

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
Dave, I haven't seen the %pM ones hit your tree yet, but this should
be pretty trivial to put on top.

Regardless, I found what looks like a pretty blatent bug that is
separated in patch 2/5.  Consider this a beta as I haven't done
more than trivial tests thus far.  But it would be good to get
another set of eyes.

 lib/vsprintf.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 2025305..034e605 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -598,6 +598,24 @@ static char *mac_address(char *buf, char *end, u8 *addr, int field_width,
 	return string(buf, end, mac_addr, field_width, precision, flags & ~SPECIAL);
 }
 
+static char *ip6_addr_string(char *buf, char *end, u8 *addr, int field_width,
+			 int precision, int flags)
+{
+	char ip6_addr[8 * 5]; /* (8 * 4 hex digits), 7 colons and trailing zero */
+	char *p = ip6_addr;
+	int i;
+
+	for (i = 0; i < 8; i++) {
+		p = pack_hex_byte(p, addr[2 * i]);
+		p = pack_hex_byte(p, addr[2 * i + 1]);
+		if (!(flags & SPECIAL) && i != 7)
+			*p++ = ':';
+	}
+	*p = '\0';
+
+	return string(buf, end, ip6_addr, field_width, precision, flags & ~SPECIAL);
+}
+
 /*
  * Show a '%p' thing.  A kernel extension is that the '%p' is followed
  * by an extra set of alphanumeric characters that are extended format
@@ -611,6 +629,8 @@ static char *mac_address(char *buf, char *end, u8 *addr, int field_width,
  *       addresses (not the name nor the flags)
  * - 'M' For a 6-byte MAC address, it prints the address in the
  *       usual colon-separated hex notation
+ * - '6' For a IPv6 address prints the address in network-ordered 16 bit hex
+ *       with colon separators
  *
  * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
  * function pointers are really function descriptors, which contain a
@@ -628,6 +648,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field
 		return resource_string(buf, end, ptr, field_width, precision, flags);
 	case 'M':
 		return mac_address(buf, end, ptr, field_width, precision, flags);
+	case '6':
+		return ip6_addr_string(buf, end, ptr, field_width, precision, flags);
 	}
 	flags |= SMALL;
 	if (field_width == -1) {
-- 
1.6.0.3.729.g6ea410



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

* Re: [RFC PATCH 1/5] printk: add %p6 format specifier for IPv6 addresses
  2008-10-28  4:05 [RFC PATCH 1/5] printk: add %p6 format specifier for IPv6 addresses Harvey Harrison
@ 2008-10-28 18:49 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2008-10-28 18:49 UTC (permalink / raw)
  To: harvey.harrison; +Cc: johannes, joe, linux-kernel


Harvey please at least CC: these patches to netdev@vger.kernel.org so
that they can be properly archived at:

	http://patchwork.ozlabs.org/project/netdev/list/

and thus don't get lost.

I'm deleting this stuff from my inbox, please resubmit properly so I
can add it to the net-next-2.6 tree.

Thanks.


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

end of thread, other threads:[~2008-10-28 18:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-28  4:05 [RFC PATCH 1/5] printk: add %p6 format specifier for IPv6 addresses Harvey Harrison
2008-10-28 18:49 ` David Miller

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).