netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pktgen: use %pI6c for printing IPv6 addresses
@ 2011-05-03 21:23 Alexey Dobriyan
  2011-05-03 22:11 ` Joe Perches
  2011-05-03 23:25 ` Joe Perches
  0 siblings, 2 replies; 4+ messages in thread
From: Alexey Dobriyan @ 2011-05-03 21:23 UTC (permalink / raw)
  To: davem; +Cc: netdev

I don't know why %pI6 doesn't compress, but the format specifier is
kernel-standard, so use it.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 net/core/pktgen.c |  109 ++++++------------------------------------------------
 1 file changed, 13 insertions(+), 96 deletions(-)

--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -449,7 +449,6 @@ static void pktgen_stop(struct pktgen_thread *t);
 static void pktgen_clear_counters(struct pktgen_dev *pkt_dev);
 
 static unsigned int scan_ip6(const char *s, char ip[16]);
-static unsigned int fmt_ip6(char *s, const char ip[16]);
 
 /* Module parameters, defaults. */
 static int pg_count_d __read_mostly = 1000;
@@ -556,21 +555,13 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
 			   pkt_dev->skb_priority);
 
 	if (pkt_dev->flags & F_IPV6) {
-		char b1[128], b2[128], b3[128];
-		fmt_ip6(b1, pkt_dev->in6_saddr.s6_addr);
-		fmt_ip6(b2, pkt_dev->min_in6_saddr.s6_addr);
-		fmt_ip6(b3, pkt_dev->max_in6_saddr.s6_addr);
 		seq_printf(seq,
-			   "     saddr: %s  min_saddr: %s  max_saddr: %s\n", b1,
-			   b2, b3);
-
-		fmt_ip6(b1, pkt_dev->in6_daddr.s6_addr);
-		fmt_ip6(b2, pkt_dev->min_in6_daddr.s6_addr);
-		fmt_ip6(b3, pkt_dev->max_in6_daddr.s6_addr);
-		seq_printf(seq,
-			   "     daddr: %s  min_daddr: %s  max_daddr: %s\n", b1,
-			   b2, b3);
-
+			   "     saddr: %pI6c  min_saddr: %pI6c  max_saddr: %pI6c\n"
+			   "     daddr: %pI6c  min_daddr: %pI6c  max_daddr: %pI6c\n",
+			   &pkt_dev->in6_saddr,
+			   &pkt_dev->min_in6_saddr, &pkt_dev->max_in6_saddr,
+			   &pkt_dev->in6_daddr,
+			   &pkt_dev->min_in6_daddr, &pkt_dev->max_in6_daddr);
 	} else {
 		seq_printf(seq,
 			   "     dst_min: %s  dst_max: %s\n",
@@ -706,10 +697,9 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
 		   pkt_dev->cur_src_mac_offset);
 
 	if (pkt_dev->flags & F_IPV6) {
-		char b1[128], b2[128];
-		fmt_ip6(b1, pkt_dev->cur_in6_daddr.s6_addr);
-		fmt_ip6(b2, pkt_dev->cur_in6_saddr.s6_addr);
-		seq_printf(seq, "     cur_saddr: %s  cur_daddr: %s\n", b2, b1);
+		seq_printf(seq, "     cur_saddr: %pI6c  cur_daddr: %pI6c\n",
+				&pkt_dev->cur_in6_saddr,
+				&pkt_dev->cur_in6_daddr);
 	} else
 		seq_printf(seq, "     cur_saddr: 0x%x  cur_daddr: 0x%x\n",
 			   pkt_dev->cur_saddr, pkt_dev->cur_daddr);
@@ -1309,7 +1299,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		buf[len] = 0;
 
 		scan_ip6(buf, pkt_dev->in6_daddr.s6_addr);
-		fmt_ip6(buf, pkt_dev->in6_daddr.s6_addr);
+		snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->in6_daddr);
 
 		ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->in6_daddr);
 
@@ -1332,7 +1322,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		buf[len] = 0;
 
 		scan_ip6(buf, pkt_dev->min_in6_daddr.s6_addr);
-		fmt_ip6(buf, pkt_dev->min_in6_daddr.s6_addr);
+		snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->min_in6_daddr);
 
 		ipv6_addr_copy(&pkt_dev->cur_in6_daddr,
 			       &pkt_dev->min_in6_daddr);
@@ -1355,7 +1345,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		buf[len] = 0;
 
 		scan_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
-		fmt_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
+		snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->max_in6_daddr);
 
 		if (debug)
 			printk(KERN_DEBUG "pktgen: dst6_max set to: %s\n", buf);
@@ -1376,7 +1366,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		buf[len] = 0;
 
 		scan_ip6(buf, pkt_dev->in6_saddr.s6_addr);
-		fmt_ip6(buf, pkt_dev->in6_saddr.s6_addr);
+		snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->in6_saddr);
 
 		ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &pkt_dev->in6_saddr);
 
@@ -2898,79 +2888,6 @@ static unsigned int scan_ip6(const char *s, char ip[16])
 	return len;
 }
 
-static char tohex(char hexdigit)
-{
-	return hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0';
-}
-
-static int fmt_xlong(char *s, unsigned int i)
-{
-	char *bak = s;
-	*s = tohex((i >> 12) & 0xf);
-	if (s != bak || *s != '0')
-		++s;
-	*s = tohex((i >> 8) & 0xf);
-	if (s != bak || *s != '0')
-		++s;
-	*s = tohex((i >> 4) & 0xf);
-	if (s != bak || *s != '0')
-		++s;
-	*s = tohex(i & 0xf);
-	return s - bak + 1;
-}
-
-static unsigned int fmt_ip6(char *s, const char ip[16])
-{
-	unsigned int len;
-	unsigned int i;
-	unsigned int temp;
-	unsigned int compressing;
-	int j;
-
-	len = 0;
-	compressing = 0;
-	for (j = 0; j < 16; j += 2) {
-
-#ifdef V4MAPPEDPREFIX
-		if (j == 12 && !memcmp(ip, V4mappedprefix, 12)) {
-			inet_ntoa_r(*(struct in_addr *)(ip + 12), s);
-			temp = strlen(s);
-			return len + temp;
-		}
-#endif
-		temp = ((unsigned long)(unsigned char)ip[j] << 8) +
-		    (unsigned long)(unsigned char)ip[j + 1];
-		if (temp == 0) {
-			if (!compressing) {
-				compressing = 1;
-				if (j == 0) {
-					*s++ = ':';
-					++len;
-				}
-			}
-		} else {
-			if (compressing) {
-				compressing = 0;
-				*s++ = ':';
-				++len;
-			}
-			i = fmt_xlong(s, temp);
-			len += i;
-			s += i;
-			if (j < 14) {
-				*s++ = ':';
-				++len;
-			}
-		}
-	}
-	if (compressing) {
-		*s++ = ':';
-		++len;
-	}
-	*s = 0;
-	return len;
-}
-
 static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
 					struct pktgen_dev *pkt_dev)
 {

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

* Re: [PATCH] pktgen: use %pI6c for printing IPv6 addresses
  2011-05-03 21:23 [PATCH] pktgen: use %pI6c for printing IPv6 addresses Alexey Dobriyan
@ 2011-05-03 22:11 ` Joe Perches
  2011-05-08 22:50   ` David Miller
  2011-05-03 23:25 ` Joe Perches
  1 sibling, 1 reply; 4+ messages in thread
From: Joe Perches @ 2011-05-03 22:11 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: davem, netdev

On Wed, 2011-05-04 at 00:23 +0300, Alexey Dobriyan wrote:
> I don't know why %pI6 doesn't compress, but the format specifier is
> kernel-standard, so use it.

Because seq_printf output using %pI6 has a known
output style and shouldn't be changed to avoid
breaking user applications.



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

* Re: [PATCH] pktgen: use %pI6c for printing IPv6 addresses
  2011-05-03 21:23 [PATCH] pktgen: use %pI6c for printing IPv6 addresses Alexey Dobriyan
  2011-05-03 22:11 ` Joe Perches
@ 2011-05-03 23:25 ` Joe Perches
  1 sibling, 0 replies; 4+ messages in thread
From: Joe Perches @ 2011-05-03 23:25 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: davem, netdev, Robert Olsson

On Wed, 2011-05-04 at 00:23 +0300, Alexey Dobriyan wrote:
> I don't know why %pI6 doesn't compress, but the format specifier is
> kernel-standard, so use it.

Hi again Alexey.

I doubt it matters but the old routine compresses the first
0 it finds rather than the longest consecutive 0 match so
the output could be a bit different.

given:	"0:1:0:0:0:0:0:7"
old:	"::1:0:0:0:0:0:7"
new:	"0:1::7"

I think the patch is an improvement.

> -static unsigned int fmt_ip6(char *s, const char ip[16])
> -{
> -	unsigned int len;
> -	unsigned int i;
> -	unsigned int temp;
> -	unsigned int compressing;
> -	int j;
> -
> -	len = 0;
> -	compressing = 0;
> -	for (j = 0; j < 16; j += 2) {
> -
> -#ifdef V4MAPPEDPREFIX
> -		if (j == 12 && !memcmp(ip, V4mappedprefix, 12)) {
> -			inet_ntoa_r(*(struct in_addr *)(ip + 12), s);
> -			temp = strlen(s);
> -			return len + temp;
> -		}
> -#endif
> -		temp = ((unsigned long)(unsigned char)ip[j] << 8) +
> -		    (unsigned long)(unsigned char)ip[j + 1];
> -		if (temp == 0) {
> -			if (!compressing) {
> -				compressing = 1;
> -				if (j == 0) {
> -					*s++ = ':';
> -					++len;
> -				}
> -			}
> -		} else {
> -			if (compressing) {
> -				compressing = 0;
> -				*s++ = ':';
> -				++len;
> -			}
> -			i = fmt_xlong(s, temp);
> -			len += i;
> -			s += i;
> -			if (j < 14) {
> -				*s++ = ':';
> -				++len;
> -			}
> -		}
> -	}
> -	if (compressing) {
> -		*s++ = ':';
> -		++len;
> -	}
> -	*s = 0;
> -	return len;
> -}



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

* Re: [PATCH] pktgen: use %pI6c for printing IPv6 addresses
  2011-05-03 22:11 ` Joe Perches
@ 2011-05-08 22:50   ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2011-05-08 22:50 UTC (permalink / raw)
  To: joe; +Cc: adobriyan, netdev

From: Joe Perches <joe@perches.com>
Date: Tue, 03 May 2011 15:11:54 -0700

> On Wed, 2011-05-04 at 00:23 +0300, Alexey Dobriyan wrote:
>> I don't know why %pI6 doesn't compress, but the format specifier is
>> kernel-standard, so use it.
> 
> Because seq_printf output using %pI6 has a known
> output style and shouldn't be changed to avoid
> breaking user applications.

I've applied Alexey's patch to net-next-2.6

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

end of thread, other threads:[~2011-05-08 22:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-03 21:23 [PATCH] pktgen: use %pI6c for printing IPv6 addresses Alexey Dobriyan
2011-05-03 22:11 ` Joe Perches
2011-05-08 22:50   ` David Miller
2011-05-03 23:25 ` Joe Perches

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