percona-toolkit icon indicating copy to clipboard operation
percona-toolkit copied to clipboard

Supporting IPv6 in pt-query-digest

Open yoshinorim opened this issue 9 years ago • 1 comments

Summary: Currently pt-query-digest does not support tcpdump in IPv6 format. This diff adds support for IPv6.

yoshinorim avatar Mar 24 '15 23:03 yoshinorim

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 4 committers have signed the CLA.

:white_check_mark: tplavcic
:white_check_mark: hrvojem
:x: frank-cizmich
:x: yoshinorim
You have signed the CLA already but the status is still pending? Let us recheck it.

it-percona avatar May 15 '20 18:05 it-percona

CLA is not signed. The patch is too large to apply to the 3.x branch, does not have test case for IPv6 protocol, and looks like the actual fix is only here:

@@ -3628,10 +3552,10 @@
 # ###########################################################################
 # TcpdumpParser package
 # This package is a copy without comments from the original.  The original
-# with comments and its test file can be found in the GitHub repository at,
+# with comments and its test file can be found in the Bazaar repository at,
 #   lib/TcpdumpParser.pm
 #   t/lib/TcpdumpParser.t
-# See https://github.com/percona/percona-toolkit for more information.
+# See https://launchpad.net/percona-toolkit for more information.
 # ###########################################################################
 {
 package TcpdumpParser;
@@ -3668,7 +3592,6 @@
       $pos_in_log -= 1 if $pos_in_log;
 
       $raw_packet =~ s/\n20\Z//;
-      $raw_packet = "20$raw_packet" if $raw_packet =~ /\A20-\d\d-\d\d/; # workaround for year 2020 problem
       $raw_packet = "20$raw_packet" unless $raw_packet =~ m/\A20/;
 
       $raw_packet =~ s/0x0000:.+?(450.) /0x0000:  $1 /;
@@ -3690,18 +3613,31 @@
    my ( $self, $packet ) = @_;
    die "I need a packet" unless $packet;
 
-   my ( $ts, $source, $dest )  = $packet =~ m/\A(\S+ \S+).*? IP .*?(\S+) > (\S+):/;
-   my ( $src_host, $src_port ) = $source =~ m/((?:\d+\.){3}\d+)\.(\w+)/;
-   my ( $dst_host, $dst_port ) = $dest   =~ m/((?:\d+\.){3}\d+)\.(\w+)/;
+   my ( $ts, $ipv6, $source, $dest ) = $packet =~ m/\A(\S+ \S+).*? IP(?:(6?)) .*?(\S+) > (\S+):/;
+   my ( $src_host, $src_port );
+   my ( $dst_host, $dst_port );
+   if ( $ipv6 ) {
+      ( $src_host, $src_port ) = $source =~ m/((?:\w+\:){7}\w+)\.(\w+)/;
+      ( $dst_host, $dst_port ) = $dest   =~ m/((?:\w+\:){7}\w+)\.(\w+)/;
+   } else {
+      ( $src_host, $src_port ) = $source =~ m/((?:\d+\.){3}\d+)\.(\w+)/;
+      ( $dst_host, $dst_port ) = $dest   =~ m/((?:\d+\.){3}\d+)\.(\w+)/;
+   }
 
    $src_port = $self->port_number($src_port);
    $dst_port = $self->port_number($dst_port);
-
+   
    my $hex = qr/[0-9a-f]/;
-   (my $data = join('', $packet =~ m/\s+0x$hex+:\s((?:\s$hex{2,4})+)/go)) =~ s/\s+//g;
+   (my $data = join('', $packet =~ m/\s+0x$hex+:\s((?:\s$hex{2,4})+)/go)) =~ s/\s+//g; 
 
-   my $ip_hlen = hex(substr($data, 1, 1)); # Num of 32-bit words in header.
-   my $ip_plen = hex(substr($data, 4, 4)); # Num of BYTES in IPv4 datagram.
+   my ( $ip_hlen, $ip_plen );
+   if ( $ipv6 ) {
+      $ip_hlen = 10; # Num of 32-bit words in header.
+      $ip_plen = hex(substr($data, 8, 4)) + 40; # Num of BYTES in IPv6 datagram.
+   } else {
+      $ip_hlen = hex(substr($data, 1, 1)); # Num of 32-bit words in header.
+      $ip_plen = hex(substr($data, 4, 4)); # Num of BYTES in IPv4 datagram.
+   }
    my $complete = length($data) == 2 * $ip_plen ? 1 : 0;
 
    my $tcp_hlen = hex(substr($data, ($ip_hlen + 3) * 8, 1));

We will welcome a small patch against 3.x branch with the test case.

svetasmirnova avatar Dec 08 '23 11:12 svetasmirnova