diff options
| author | Alexey Dobriyan <adobriyan@gmail.com> | 2011-05-03 07:23:40 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2011-05-08 18:50:31 -0400 |
| commit | 47a0200d535f08ac8f784a709c48995ca0b10288 (patch) | |
| tree | f52f8b25710ea0017f66095ee7de7791df72f55f | |
| parent | 57cc71bc3c0cf18bfd1b7bc8cd0eb6c303da24c5 (diff) | |
pktgen: use %pI6c for printing IPv6 addresses
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
| -rw-r--r-- | net/core/pktgen.c | 109 |
1 files changed, 13 insertions, 96 deletions
diff --git a/net/core/pktgen.c b/net/core/pktgen.c index ff79d94b5944..d41d88b53e18 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c | |||
| @@ -449,7 +449,6 @@ static void pktgen_stop(struct pktgen_thread *t); | |||
| 449 | static void pktgen_clear_counters(struct pktgen_dev *pkt_dev); | 449 | static void pktgen_clear_counters(struct pktgen_dev *pkt_dev); |
| 450 | 450 | ||
| 451 | static unsigned int scan_ip6(const char *s, char ip[16]); | 451 | static unsigned int scan_ip6(const char *s, char ip[16]); |
| 452 | static unsigned int fmt_ip6(char *s, const char ip[16]); | ||
| 453 | 452 | ||
| 454 | /* Module parameters, defaults. */ | 453 | /* Module parameters, defaults. */ |
| 455 | static int pg_count_d __read_mostly = 1000; | 454 | static int pg_count_d __read_mostly = 1000; |
| @@ -556,21 +555,13 @@ static int pktgen_if_show(struct seq_file *seq, void *v) | |||
| 556 | pkt_dev->skb_priority); | 555 | pkt_dev->skb_priority); |
| 557 | 556 | ||
| 558 | if (pkt_dev->flags & F_IPV6) { | 557 | if (pkt_dev->flags & F_IPV6) { |
| 559 | char b1[128], b2[128], b3[128]; | ||
| 560 | fmt_ip6(b1, pkt_dev->in6_saddr.s6_addr); | ||
| 561 | fmt_ip6(b2, pkt_dev->min_in6_saddr.s6_addr); | ||
| 562 | fmt_ip6(b3, pkt_dev->max_in6_saddr.s6_addr); | ||
| 563 | seq_printf(seq, | 558 | seq_printf(seq, |
| 564 | " saddr: %s min_saddr: %s max_saddr: %s\n", b1, | 559 | " saddr: %pI6c min_saddr: %pI6c max_saddr: %pI6c\n" |
| 565 | b2, b3); | 560 | " daddr: %pI6c min_daddr: %pI6c max_daddr: %pI6c\n", |
| 566 | 561 | &pkt_dev->in6_saddr, | |
| 567 | fmt_ip6(b1, pkt_dev->in6_daddr.s6_addr); | 562 | &pkt_dev->min_in6_saddr, &pkt_dev->max_in6_saddr, |
| 568 | fmt_ip6(b2, pkt_dev->min_in6_daddr.s6_addr); | 563 | &pkt_dev->in6_daddr, |
| 569 | fmt_ip6(b3, pkt_dev->max_in6_daddr.s6_addr); | 564 | &pkt_dev->min_in6_daddr, &pkt_dev->max_in6_daddr); |
| 570 | seq_printf(seq, | ||
| 571 | " daddr: %s min_daddr: %s max_daddr: %s\n", b1, | ||
| 572 | b2, b3); | ||
| 573 | |||
| 574 | } else { | 565 | } else { |
| 575 | seq_printf(seq, | 566 | seq_printf(seq, |
| 576 | " dst_min: %s dst_max: %s\n", | 567 | " dst_min: %s dst_max: %s\n", |
| @@ -706,10 +697,9 @@ static int pktgen_if_show(struct seq_file *seq, void *v) | |||
| 706 | pkt_dev->cur_src_mac_offset); | 697 | pkt_dev->cur_src_mac_offset); |
| 707 | 698 | ||
| 708 | if (pkt_dev->flags & F_IPV6) { | 699 | if (pkt_dev->flags & F_IPV6) { |
| 709 | char b1[128], b2[128]; | 700 | seq_printf(seq, " cur_saddr: %pI6c cur_daddr: %pI6c\n", |
| 710 | fmt_ip6(b1, pkt_dev->cur_in6_daddr.s6_addr); | 701 | &pkt_dev->cur_in6_saddr, |
| 711 | fmt_ip6(b2, pkt_dev->cur_in6_saddr.s6_addr); | 702 | &pkt_dev->cur_in6_daddr); |
| 712 | seq_printf(seq, " cur_saddr: %s cur_daddr: %s\n", b2, b1); | ||
| 713 | } else | 703 | } else |
| 714 | seq_printf(seq, " cur_saddr: 0x%x cur_daddr: 0x%x\n", | 704 | seq_printf(seq, " cur_saddr: 0x%x cur_daddr: 0x%x\n", |
| 715 | pkt_dev->cur_saddr, pkt_dev->cur_daddr); | 705 | pkt_dev->cur_saddr, pkt_dev->cur_daddr); |
| @@ -1309,7 +1299,7 @@ static ssize_t pktgen_if_write(struct file *file, | |||
| 1309 | buf[len] = 0; | 1299 | buf[len] = 0; |
| 1310 | 1300 | ||
| 1311 | scan_ip6(buf, pkt_dev->in6_daddr.s6_addr); | 1301 | scan_ip6(buf, pkt_dev->in6_daddr.s6_addr); |
| 1312 | fmt_ip6(buf, pkt_dev->in6_daddr.s6_addr); | 1302 | snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->in6_daddr); |
| 1313 | 1303 | ||
| 1314 | ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->in6_daddr); | 1304 | ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->in6_daddr); |
| 1315 | 1305 | ||
| @@ -1332,7 +1322,7 @@ static ssize_t pktgen_if_write(struct file *file, | |||
| 1332 | buf[len] = 0; | 1322 | buf[len] = 0; |
| 1333 | 1323 | ||
| 1334 | scan_ip6(buf, pkt_dev->min_in6_daddr.s6_addr); | 1324 | scan_ip6(buf, pkt_dev->min_in6_daddr.s6_addr); |
| 1335 | fmt_ip6(buf, pkt_dev->min_in6_daddr.s6_addr); | 1325 | snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->min_in6_daddr); |
| 1336 | 1326 | ||
| 1337 | ipv6_addr_copy(&pkt_dev->cur_in6_daddr, | 1327 | ipv6_addr_copy(&pkt_dev->cur_in6_daddr, |
| 1338 | &pkt_dev->min_in6_daddr); | 1328 | &pkt_dev->min_in6_daddr); |
| @@ -1355,7 +1345,7 @@ static ssize_t pktgen_if_write(struct file *file, | |||
| 1355 | buf[len] = 0; | 1345 | buf[len] = 0; |
| 1356 | 1346 | ||
| 1357 | scan_ip6(buf, pkt_dev->max_in6_daddr.s6_addr); | 1347 | scan_ip6(buf, pkt_dev->max_in6_daddr.s6_addr); |
| 1358 | fmt_ip6(buf, pkt_dev->max_in6_daddr.s6_addr); | 1348 | snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->max_in6_daddr); |
| 1359 | 1349 | ||
| 1360 | if (debug) | 1350 | if (debug) |
| 1361 | printk(KERN_DEBUG "pktgen: dst6_max set to: %s\n", buf); | 1351 | printk(KERN_DEBUG "pktgen: dst6_max set to: %s\n", buf); |
| @@ -1376,7 +1366,7 @@ static ssize_t pktgen_if_write(struct file *file, | |||
| 1376 | buf[len] = 0; | 1366 | buf[len] = 0; |
| 1377 | 1367 | ||
| 1378 | scan_ip6(buf, pkt_dev->in6_saddr.s6_addr); | 1368 | scan_ip6(buf, pkt_dev->in6_saddr.s6_addr); |
| 1379 | fmt_ip6(buf, pkt_dev->in6_saddr.s6_addr); | 1369 | snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->in6_saddr); |
| 1380 | 1370 | ||
| 1381 | ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &pkt_dev->in6_saddr); | 1371 | ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &pkt_dev->in6_saddr); |
| 1382 | 1372 | ||
| @@ -2898,79 +2888,6 @@ static unsigned int scan_ip6(const char *s, char ip[16]) | |||
| 2898 | return len; | 2888 | return len; |
| 2899 | } | 2889 | } |
| 2900 | 2890 | ||
| 2901 | static char tohex(char hexdigit) | ||
| 2902 | { | ||
| 2903 | return hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0'; | ||
| 2904 | } | ||
| 2905 | |||
| 2906 | static int fmt_xlong(char *s, unsigned int i) | ||
| 2907 | { | ||
| 2908 | char *bak = s; | ||
| 2909 | *s = tohex((i >> 12) & 0xf); | ||
| 2910 | if (s != bak || *s != '0') | ||
| 2911 | ++s; | ||
| 2912 | *s = tohex((i >> 8) & 0xf); | ||
| 2913 | if (s != bak || *s != '0') | ||
| 2914 | ++s; | ||
| 2915 | *s = tohex((i >> 4) & 0xf); | ||
| 2916 | if (s != bak || *s != '0') | ||
| 2917 | ++s; | ||
| 2918 | *s = tohex(i & 0xf); | ||
| 2919 | return s - bak + 1; | ||
| 2920 | } | ||
| 2921 | |||
| 2922 | static unsigned int fmt_ip6(char *s, const char ip[16]) | ||
| 2923 | { | ||
| 2924 | unsigned int len; | ||
| 2925 | unsigned int i; | ||
| 2926 | unsigned int temp; | ||
| 2927 | unsigned int compressing; | ||
| 2928 | int j; | ||
| 2929 | |||
| 2930 | len = 0; | ||
| 2931 | compressing = 0; | ||
| 2932 | for (j = 0; j < 16; j += 2) { | ||
| 2933 | |||
| 2934 | #ifdef V4MAPPEDPREFIX | ||
| 2935 | if (j == 12 && !memcmp(ip, V4mappedprefix, 12)) { | ||
| 2936 | inet_ntoa_r(*(struct in_addr *)(ip + 12), s); | ||
| 2937 | temp = strlen(s); | ||
| 2938 | return len + temp; | ||
| 2939 | } | ||
| 2940 | #endif | ||
| 2941 | temp = ((unsigned long)(unsigned char)ip[j] << 8) + | ||
| 2942 | (unsigned long)(unsigned char)ip[j + 1]; | ||
| 2943 | if (temp == 0) { | ||
| 2944 | if (!compressing) { | ||
| 2945 | compressing = 1; | ||
| 2946 | if (j == 0) { | ||
| 2947 | *s++ = ':'; | ||
| 2948 | ++len; | ||
| 2949 | } | ||
| 2950 | } | ||
| 2951 | } else { | ||
| 2952 | if (compressing) { | ||
| 2953 | compressing = 0; | ||
| 2954 | *s++ = ':'; | ||
| 2955 | ++len; | ||
| 2956 | } | ||
| 2957 | i = fmt_xlong(s, temp); | ||
| 2958 | len += i; | ||
| 2959 | s += i; | ||
| 2960 | if (j < 14) { | ||
| 2961 | *s++ = ':'; | ||
| 2962 | ++len; | ||
| 2963 | } | ||
| 2964 | } | ||
| 2965 | } | ||
| 2966 | if (compressing) { | ||
| 2967 | *s++ = ':'; | ||
| 2968 | ++len; | ||
| 2969 | } | ||
| 2970 | *s = 0; | ||
| 2971 | return len; | ||
| 2972 | } | ||
| 2973 | |||
| 2974 | static struct sk_buff *fill_packet_ipv6(struct net_device *odev, | 2891 | static struct sk_buff *fill_packet_ipv6(struct net_device *odev, |
| 2975 | struct pktgen_dev *pkt_dev) | 2892 | struct pktgen_dev *pkt_dev) |
| 2976 | { | 2893 | { |
