Menu

#1655 (ok 4.5) Support IPv6 browser transformation

Needs_decision
resolved
None
Low
2015-04-20
2015-04-16
No

MySQL 5.6.3 added the INET6_* functions which make it much easier to store both IPv4 and IPv6 addresses in a single VARBINARY(16) field, which will be 4 bytes long for Pv4, and 16 bytes long for IPv6. PHPMyAdmin currently has an output transform for Long2ipv4, but that won't work for IPv6. If you use the suggested VARBINARY, the output transforms don't work on IPv4 addresses either. There is a straightforward mapping between MySQL's binary format and PHP's net functions, so my request is to implement this so that both IPv4 and IPv6 addresses are supported with the input and output transforms. Here is a function to transform MySQL's binary format into a string in PHP, named after the same function in MySQL:

/**
 * Convert a MySQL binary v4 (4-byte) or v6 (16-byte) IP address to a string.
 * @param string $ip a binary string containing an IP address, as returned from MySQL's INET6_ATON function
 * @return string Empty if not valid.
 */
function inet6_ntop($ip) {
    $l = strlen($ip);
    if ($l == 16 or $l == 4) {
        return inet_ntop(pack('A' . $l, $ip));
    }
    return '';
}

The other direction does not require anything special as MySQL's INET6_ATON function understands standard strings with colon-format IPv6 and dotted-quad IPv4.

Discussion

  • Madhura Jayaratne

    • assigned_to: Madhura Jayaratne
     
  • Madhura Jayaratne

    Do you agree to our DCO (https://github.com/phpmyadmin/phpmyadmin/blob/master/DCO)?

     
  • Marcus Bointon

    Marcus Bointon - 2015-04-17

    Yes.

    Not that it makes any difference, but I realised the function name is not the same as MySQL's - that would be inet6_ntoa, though the name I have given it is more like an extension of PHP's inet_ntop. One tiny optimisation - it would be marginally faster to check for $l == 4 first if the majority of addresses are IPv4.

     
  • Madhura Jayaratne

    Thanks.
    I intend to use the code directly inside applyTransformation() method. https://github.com/phpmyadmin/phpmyadmin/pull/1650

     

    Last edit: Madhura Jayaratne 2015-04-17
  • Marcus Bointon

    Marcus Bointon - 2015-04-17

    That looks great, thanks.

     
  • Madhura Jayaratne

    • summary: Support IPv6 browser transformation --> (ok 4.5) Support IPv6 browser transformation
    • status: open --> resolved
    • Priority: Normal --> Low
     
  • Marcus Bointon

    Marcus Bointon - 2015-04-18

    The output transform is working for me on OS X, but I just installed a fresh clone on a linux server with the same database schema and it's not working on there. Instead of reformatting the binary value, it shows it in hex and it's linkable, and if I click it it downloads a .bin file - this is the same as it behaves if I remove the transforms from that field.

    A long2ip transform works ok on a different field, so transforms in general appear to be working.

    Is there some global setting relating to binary fields?

    On OS X the output transform works fine, but the input doesn't seem to - when I edit the field it turns into hex, rather than remaining as a colon-delimited or dotted quad string.

     
  • Madhura Jayaratne

    I can reproduce the issue on out demo server. I am working on it.

     
  • Madhura Jayaratne

    This should be fixed now. You might have to manually delete the corresponding rows from 'pma__column_info' table and set the transformations again.

     
  • Madhura Jayaratne

    I also added input transformation named Iptobinary.

     
  • Marcus Bointon

    Marcus Bointon - 2015-04-20

    Thanks. That fixes the output transform, but if I set the input transform too, when I double-click a field to edit it, it turns back into hex for the edit, then is reformatted on save. Isn't it supposed to remain in the formatted style when using the input transform?

     
  • Madhura Jayaratne

    Transformations are not supported for the inline edit functionality, only for the regular edit/insert functionality.

     
  • Marcus Bointon

    Marcus Bointon - 2015-04-20

    Ah, ok, thanks.