diff options
author | Amerigo Wang <amwang@redhat.com> | 2012-10-09 13:48:20 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-10-10 22:33:30 -0400 |
commit | c468fb1375f1b4de851e3e0dbe9d1293d414a160 (patch) | |
tree | 3cba4fd06f4ad6967663fd46dabcc397afc58c4a /net/core | |
parent | 4c139b8ccebaecdfad58eb068d61ef386f1a58ed (diff) |
pktgen: replace scan_ip6() with in6_pton()
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Cong Wang <amwang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/pktgen.c | 101 |
1 files changed, 4 insertions, 97 deletions
diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 47fe18e6a8e4..d1dc14c2aac4 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c | |||
@@ -449,8 +449,6 @@ static void pktgen_stop_all_threads_ifs(void); | |||
449 | static void pktgen_stop(struct pktgen_thread *t); | 449 | static void pktgen_stop(struct pktgen_thread *t); |
450 | static void pktgen_clear_counters(struct pktgen_dev *pkt_dev); | 450 | static void pktgen_clear_counters(struct pktgen_dev *pkt_dev); |
451 | 451 | ||
452 | static unsigned int scan_ip6(const char *s, char ip[16]); | ||
453 | |||
454 | /* Module parameters, defaults. */ | 452 | /* Module parameters, defaults. */ |
455 | static int pg_count_d __read_mostly = 1000; | 453 | static int pg_count_d __read_mostly = 1000; |
456 | static int pg_delay_d __read_mostly; | 454 | static int pg_delay_d __read_mostly; |
@@ -1299,7 +1297,7 @@ static ssize_t pktgen_if_write(struct file *file, | |||
1299 | return -EFAULT; | 1297 | return -EFAULT; |
1300 | buf[len] = 0; | 1298 | buf[len] = 0; |
1301 | 1299 | ||
1302 | scan_ip6(buf, pkt_dev->in6_daddr.s6_addr); | 1300 | in6_pton(buf, -1, pkt_dev->in6_daddr.s6_addr, -1, NULL); |
1303 | snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->in6_daddr); | 1301 | snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->in6_daddr); |
1304 | 1302 | ||
1305 | pkt_dev->cur_in6_daddr = pkt_dev->in6_daddr; | 1303 | pkt_dev->cur_in6_daddr = pkt_dev->in6_daddr; |
@@ -1322,7 +1320,7 @@ static ssize_t pktgen_if_write(struct file *file, | |||
1322 | return -EFAULT; | 1320 | return -EFAULT; |
1323 | buf[len] = 0; | 1321 | buf[len] = 0; |
1324 | 1322 | ||
1325 | scan_ip6(buf, pkt_dev->min_in6_daddr.s6_addr); | 1323 | in6_pton(buf, -1, pkt_dev->min_in6_daddr.s6_addr, -1, NULL); |
1326 | snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->min_in6_daddr); | 1324 | snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->min_in6_daddr); |
1327 | 1325 | ||
1328 | pkt_dev->cur_in6_daddr = pkt_dev->min_in6_daddr; | 1326 | pkt_dev->cur_in6_daddr = pkt_dev->min_in6_daddr; |
@@ -1344,7 +1342,7 @@ static ssize_t pktgen_if_write(struct file *file, | |||
1344 | return -EFAULT; | 1342 | return -EFAULT; |
1345 | buf[len] = 0; | 1343 | buf[len] = 0; |
1346 | 1344 | ||
1347 | scan_ip6(buf, pkt_dev->max_in6_daddr.s6_addr); | 1345 | in6_pton(buf, -1, pkt_dev->max_in6_daddr.s6_addr, -1, NULL); |
1348 | snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->max_in6_daddr); | 1346 | snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->max_in6_daddr); |
1349 | 1347 | ||
1350 | if (debug) | 1348 | if (debug) |
@@ -1365,7 +1363,7 @@ static ssize_t pktgen_if_write(struct file *file, | |||
1365 | return -EFAULT; | 1363 | return -EFAULT; |
1366 | buf[len] = 0; | 1364 | buf[len] = 0; |
1367 | 1365 | ||
1368 | scan_ip6(buf, pkt_dev->in6_saddr.s6_addr); | 1366 | in6_pton(buf, -1, pkt_dev->in6_saddr.s6_addr, -1, NULL); |
1369 | snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->in6_saddr); | 1367 | snprintf(buf, sizeof(buf), "%pI6c", &pkt_dev->in6_saddr); |
1370 | 1368 | ||
1371 | pkt_dev->cur_in6_saddr = pkt_dev->in6_saddr; | 1369 | pkt_dev->cur_in6_saddr = pkt_dev->in6_saddr; |
@@ -2765,97 +2763,6 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev, | |||
2765 | return skb; | 2763 | return skb; |
2766 | } | 2764 | } |
2767 | 2765 | ||
2768 | /* | ||
2769 | * scan_ip6, fmt_ip taken from dietlibc-0.21 | ||
2770 | * Author Felix von Leitner <felix-dietlibc@fefe.de> | ||
2771 | * | ||
2772 | * Slightly modified for kernel. | ||
2773 | * Should be candidate for net/ipv4/utils.c | ||
2774 | * --ro | ||
2775 | */ | ||
2776 | |||
2777 | static unsigned int scan_ip6(const char *s, char ip[16]) | ||
2778 | { | ||
2779 | unsigned int i; | ||
2780 | unsigned int len = 0; | ||
2781 | unsigned long u; | ||
2782 | char suffix[16]; | ||
2783 | unsigned int prefixlen = 0; | ||
2784 | unsigned int suffixlen = 0; | ||
2785 | __be32 tmp; | ||
2786 | char *pos; | ||
2787 | |||
2788 | for (i = 0; i < 16; i++) | ||
2789 | ip[i] = 0; | ||
2790 | |||
2791 | for (;;) { | ||
2792 | if (*s == ':') { | ||
2793 | len++; | ||
2794 | if (s[1] == ':') { /* Found "::", skip to part 2 */ | ||
2795 | s += 2; | ||
2796 | len++; | ||
2797 | break; | ||
2798 | } | ||
2799 | s++; | ||
2800 | } | ||
2801 | |||
2802 | u = simple_strtoul(s, &pos, 16); | ||
2803 | i = pos - s; | ||
2804 | if (!i) | ||
2805 | return 0; | ||
2806 | if (prefixlen == 12 && s[i] == '.') { | ||
2807 | |||
2808 | /* the last 4 bytes may be written as IPv4 address */ | ||
2809 | |||
2810 | tmp = in_aton(s); | ||
2811 | memcpy((struct in_addr *)(ip + 12), &tmp, sizeof(tmp)); | ||
2812 | return i + len; | ||
2813 | } | ||
2814 | ip[prefixlen++] = (u >> 8); | ||
2815 | ip[prefixlen++] = (u & 255); | ||
2816 | s += i; | ||
2817 | len += i; | ||
2818 | if (prefixlen == 16) | ||
2819 | return len; | ||
2820 | } | ||
2821 | |||
2822 | /* part 2, after "::" */ | ||
2823 | for (;;) { | ||
2824 | if (*s == ':') { | ||
2825 | if (suffixlen == 0) | ||
2826 | break; | ||
2827 | s++; | ||
2828 | len++; | ||
2829 | } else if (suffixlen != 0) | ||
2830 | break; | ||
2831 | |||
2832 | u = simple_strtol(s, &pos, 16); | ||
2833 | i = pos - s; | ||
2834 | if (!i) { | ||
2835 | if (*s) | ||
2836 | len--; | ||
2837 | break; | ||
2838 | } | ||
2839 | if (suffixlen + prefixlen <= 12 && s[i] == '.') { | ||
2840 | tmp = in_aton(s); | ||
2841 | memcpy((struct in_addr *)(suffix + suffixlen), &tmp, | ||
2842 | sizeof(tmp)); | ||
2843 | suffixlen += 4; | ||
2844 | len += strlen(s); | ||
2845 | break; | ||
2846 | } | ||
2847 | suffix[suffixlen++] = (u >> 8); | ||
2848 | suffix[suffixlen++] = (u & 255); | ||
2849 | s += i; | ||
2850 | len += i; | ||
2851 | if (prefixlen + suffixlen == 16) | ||
2852 | break; | ||
2853 | } | ||
2854 | for (i = 0; i < suffixlen; i++) | ||
2855 | ip[16 - suffixlen + i] = suffix[i]; | ||
2856 | return len; | ||
2857 | } | ||
2858 | |||
2859 | static struct sk_buff *fill_packet_ipv6(struct net_device *odev, | 2766 | static struct sk_buff *fill_packet_ipv6(struct net_device *odev, |
2860 | struct pktgen_dev *pkt_dev) | 2767 | struct pktgen_dev *pkt_dev) |
2861 | { | 2768 | { |