From: Vlad Yasevich <vyasevich@gmail.com>
To: Daniel Borkmann <dborkman@redhat.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org, linux-sctp@vger.kernel.org
Subject: Re: [PATCH net-next 1/2] lib: vsprintf: add IPv4/v6 generic %pig/%pIg format specifier
Date: Wed, 26 Jun 2013 13:27:19 -0400 [thread overview]
Message-ID: <51CB2477.6070903@gmail.com> (raw)
In-Reply-To: <1372266073-11998-2-git-send-email-dborkman@redhat.com>
On 06/26/2013 01:01 PM, Daniel Borkmann wrote:
> In order to avoid making code that deals with printing both, IPv4 and
> IPv6 addresses, unnecessary complicated as for example ...
>
> if (sa.sa_family == AF_INET6)
> printk("... %pI6 ...", sin6_addr);
> else
> printk("... %pI4 ...", sin_addr.s_addr);
>
> ... it would be better to introduce a format specifier that can deal
> with those kind of situations internally; just as we have a "struct
> sockaddr" for generic mapping into "struct sockaddr_in" or "struct
> sockaddr_in6" as e.g. done in "union sctp_addr". Then, we could
> reduce the above statement into something like:
>
> printk("... %pIg ..", &sockaddr);
>
> While we're at it, support for both %pig/%pIg, where 'g' stands for
> generic, comes for free. In case our pointer is NULL, pointer() then
> deals with that already at an earlier point in time internally.
>
> Likely, there are many other areas than just SCTP in the kernel to make
> use of this extension as well.
>
> Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
> ---
> lib/vsprintf.c | 18 ++++++++++++++++--
> 1 file changed, 16 insertions(+), 2 deletions(-)
I think you should also update Documentation/printk-formats.txt
-vlad
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index e149c64..7243742 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -1004,10 +1004,10 @@ int kptr_restrict __read_mostly;
> * - 'MF' For a 6-byte MAC FDDI address, it prints the address
> * with a dash-separated hex notation
> * - '[mM]R' For a 6-byte MAC address, Reverse order (Bluetooth)
> - * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
> + * - 'I' [46g] for IPv4/IPv6 addresses printed in the usual way
> * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
> * IPv6 uses colon separated network-order 16 bit hex with leading 0's
> - * - 'i' [46] for 'raw' IPv4/IPv6 addresses
> + * - 'i' [46g] for 'raw' IPv4/IPv6 addresses
> * IPv6 omits the colons (01020304...0f)
> * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006)
> * - '[Ii]4[hnbl]' IPv4 addresses in host, network, big or little endian order
> @@ -1093,6 +1093,18 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
> return ip6_addr_string(buf, end, ptr, spec, fmt);
> case '4':
> return ip4_addr_string(buf, end, ptr, spec, fmt);
> + case 'g':
> + {
> + const struct sockaddr *sa = ptr;
> +
> + if (sa->sa_family == AF_INET6) {
> + ptr = &((struct sockaddr_in6 *) sa)->sin6_addr;
> + return ip6_addr_string(buf, end, ptr, spec, fmt);
> + } else {
> + ptr = &((struct sockaddr_in *) sa)->sin_addr.s_addr;
> + return ip4_addr_string(buf, end, ptr, spec, fmt);
> + }
> + }
> }
> break;
> case 'U':
> @@ -1370,6 +1382,8 @@ qualifier:
> * %pI6 print an IPv6 address with colons
> * %pi6 print an IPv6 address without colons
> * %pI6c print an IPv6 address as specified by RFC 5952
> + * %pIg depending on sa_family of 'struct sockaddr *' switch to %pI6/%pI4
> + * %pig depending on sa_family of 'struct sockaddr *' switch to %pi6/%pi4
> * %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper
> * case.
> * %*ph[CDN] a variable-length hex string with a separator (supports up to 64
>
next prev parent reply other threads:[~2013-06-26 17:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-26 17:01 [PATCH net-next 0/2] Rework SCTP debugging framework Daniel Borkmann
2013-06-26 17:01 ` [PATCH net-next 1/2] lib: vsprintf: add IPv4/v6 generic %pig/%pIg format specifier Daniel Borkmann
2013-06-26 17:27 ` Vlad Yasevich [this message]
2013-06-26 18:35 ` Daniel Borkmann
2013-06-27 11:00 ` Neil Horman
2013-06-27 1:05 ` Joe Perches
2013-06-27 7:53 ` Daniel Borkmann
2013-06-27 1:37 ` Cong Wang
2013-06-27 7:47 ` Daniel Borkmann
2013-06-26 17:01 ` [PATCH net-next 2/2] net: sctp: rework debugging framework to use pr_debug and friends Daniel Borkmann
2013-06-27 2:32 ` Vlad Yasevich
2013-06-26 20:26 ` [PATCH net-next 0/2] Rework SCTP debugging framework David Miller
2013-06-26 20:53 ` Daniel Borkmann
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=51CB2477.6070903@gmail.com \
--to=vyasevich@gmail.com \
--cc=davem@davemloft.net \
--cc=dborkman@redhat.com \
--cc=linux-sctp@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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 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).