From patchwork Tue Oct 28 19:53:32 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Harrison X-Patchwork-Id: 6145 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 0CF88DDDF6 for ; Wed, 29 Oct 2008 06:53:44 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752257AbYJ1Txi (ORCPT ); Tue, 28 Oct 2008 15:53:38 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752073AbYJ1Txh (ORCPT ); Tue, 28 Oct 2008 15:53:37 -0400 Received: from wf-out-1314.google.com ([209.85.200.172]:47380 "EHLO wf-out-1314.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751883AbYJ1Txh (ORCPT ); Tue, 28 Oct 2008 15:53:37 -0400 Received: by wf-out-1314.google.com with SMTP id 27so2778520wfd.4 for ; Tue, 28 Oct 2008 12:53:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:cc :content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=5Qgd6sWK20T+Qy/HDBSVVXKWhHNKqRxsjIwEALpxJiU=; b=IsOx1vnLl3XpMj7TsVLXv0iwalRIJqXakPPcLP4FB1M8LZJPPelLsA5nVisaM8k00s cqT1n/HeXZkk51vzuqM5VfMuHzXPMgLD1FI+XxuHRVw3Snl15rk1zmhDBeqLsrRWUYU6 KMDaU7xfuLj512LF0pMwAqwE7z/cBB62BKk00= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; b=dfnYO/no/ZGTwWCYyouzg6M5SFfyWi8A58cOwncgVIayIshDsoQtzRYLXMUT3SuZvn 9aAgYCWfa8tAEe/w6aXtuP6tXrRPoPWOZJzs++6Vtc8FkXOHXwJNB3v70vHOAZODF7Fh 73yATaNRU6EtrtwIPe/mKinKWjxbwHsP9Qijc= Received: by 10.142.170.16 with SMTP id s16mr3548668wfe.215.1225223616032; Tue, 28 Oct 2008 12:53:36 -0700 (PDT) Received: from ?192.168.1.108? (216-19-190-48.dyn.novuscom.net [216.19.190.48]) by mx.google.com with ESMTPS id 24sm4516020wff.17.2008.10.28.12.53.35 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 28 Oct 2008 12:53:35 -0700 (PDT) Subject: [PATCH 1/6] printk: add %p6 format specifier for IPv6 addresses From: Harvey Harrison To: David Miller Cc: linux-netdev , Joe Perches Date: Tue, 28 Oct 2008 12:53:32 -0700 Message-Id: <1225223612.11483.34.camel@brick> Mime-Version: 1.0 X-Mailer: Evolution 2.24.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- Dave, based against net-next. I've broken it up into more digestible pieces, feel free to squash them together as you see fit. lib/vsprintf.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 0deaaaf..cb5bc04 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -598,6 +598,24 @@ static char *mac_address_string(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_string(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_string(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) {