diff mbox

[3/7] net: replace NIPQUAD() in net/netfilter/

Message ID 1225734196.5361.5.camel@brick
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Harvey Harrison Nov. 3, 2008, 5:43 p.m. UTC
On Mon, 2008-11-03 at 17:56 +0100, Julius Volz wrote:
> Hi,
> I just noticed that this breaks IPv4 addresses in IPVS debug output
> (didn't check in other places). It seems that during integer to ASCII
> conversion, the converted digits are output the wrong way around (not
> endianness though). For example, 10.0.0.254 is output as 01.0.0.452.
> Could something be wrong with ip4_addr_string() or put_dec_trunc() in
> lib/vsprintf.c?

Mea Culpa, I was testing with a too-simple case, it does reverse the digits,
can you try this:

From: Harvey Harrison <harvey.harrison@gmail.com>
[PATCH] printk: ipv4 address digits printed in reverse order

put_dec_trunc prints the digits in reverse order and is reversed
inside number(). Continue using put_dec_trunc, but reverse each quad
in ip4_addr_string.

[Noticed by Julius Volz]

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
 lib/vsprintf.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

Comments

Julius Volz Nov. 3, 2008, 10:52 p.m. UTC | #1
Hi,

On Mon, Nov 3, 2008 at 6:43 PM, Harvey Harrison
<harvey.harrison@gmail.com> wrote:
> On Mon, 2008-11-03 at 17:56 +0100, Julius Volz wrote:
>> Hi,
>> I just noticed that this breaks IPv4 addresses in IPVS debug output
>> (didn't check in other places). It seems that during integer to ASCII
>> conversion, the converted digits are output the wrong way around (not
>> endianness though). For example, 10.0.0.254 is output as 01.0.0.452.
>> Could something be wrong with ip4_addr_string() or put_dec_trunc() in
>> lib/vsprintf.c?
>
> Mea Culpa, I was testing with a too-simple case, it does reverse the digits,
> can you try this:
>
> From: Harvey Harrison <harvey.harrison@gmail.com>
> [PATCH] printk: ipv4 address digits printed in reverse order
>
> put_dec_trunc prints the digits in reverse order and is reversed
> inside number(). Continue using put_dec_trunc, but reverse each quad
> in ip4_addr_string.
>
> [Noticed by Julius Volz]
>
> Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
> ---
>  lib/vsprintf.c |    8 ++++++--
>  1 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index dd7cc7f..6897724 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -620,11 +620,15 @@ static char *ip4_addr_string(char *buf, char *end, u8 *addr, int field_width,
>                         int precision, int flags)
>  {
>        char ip4_addr[4 * 4]; /* (4 * 3 decimal digits), 3 dots and trailing zero */
> +       char temp[3];   /* hold each IP quad in reverse order */
>        char *p = ip4_addr;
> -       int i;
> +       int i, digits;
>
>        for (i = 0; i < 4; i++) {
> -               p = put_dec_trunc(p, addr[i]);
> +               digits = put_dec_trunc(temp, addr[i]) - temp;
> +               /* reverse the digits in the quad */
> +               while (digits--)
> +                       *p++ = temp[digits];
>                if (i != 3)
>                        *p++ = '.';
>        }
> --
> 1.6.0.3.756.gb776d

Yes, that does the trick! Thanks!

Julius
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Nov. 4, 2008, 1:10 a.m. UTC | #2
From: Harvey Harrison <harvey.harrison@gmail.com>
Date: Mon, 03 Nov 2008 09:43:16 -0800

> [PATCH] printk: ipv4 address digits printed in reverse order
> 
> put_dec_trunc prints the digits in reverse order and is reversed
> inside number(). Continue using put_dec_trunc, but reverse each quad
> in ip4_addr_string.
> 
> [Noticed by Julius Volz]
> 
> Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>

Applied, thanks for fixing this Harvey, and thanks to
Julius for the report and testing the fix.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index dd7cc7f..6897724 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -620,11 +620,15 @@  static char *ip4_addr_string(char *buf, char *end, u8 *addr, int field_width,
 			 int precision, int flags)
 {
 	char ip4_addr[4 * 4]; /* (4 * 3 decimal digits), 3 dots and trailing zero */
+	char temp[3];	/* hold each IP quad in reverse order */
 	char *p = ip4_addr;
-	int i;
+	int i, digits;
 
 	for (i = 0; i < 4; i++) {
-		p = put_dec_trunc(p, addr[i]);
+		digits = put_dec_trunc(temp, addr[i]) - temp;
+		/* reverse the digits in the quad */
+		while (digits--)
+			*p++ = temp[digits];
 		if (i != 3)
 			*p++ = '.';
 	}