Is your website IPv6 ready?

Is your (CakePHP) website ready for the new protocol version?
Some time this year your provider will probably change to IPv6. Usually it will then provide both.

Why now?

Due to the IPv4 exhaustion it is now time to act. The address space is officially full (as of Feb. 2011).
The new address space can theoretically assign each and every sand corn on this planet its own IP address. So it’s quite safe to assume that we won’t face any exhaustions in the next few decades.
But the change requires some modifications in most php scripts.

The new standard will be integrated in a way that the normal user doesn’t notice it.
It will still provide IPv4 – in most cases, anyway. Some sites will be IPv6 only (right now only for testing purposes, though).
If you browse a site with both IPv6 and IPv4 support it will then auto-select IPv6. So as soon as IPV6 is available on your server you need to react. Otherwise your site might run into some issues.

Raise field length

If you store the IP somewhere (to track visitors online etc), you need to adjust the field length. Instead of varchar(15) it should now be varchar(39).

Validation

With cake, the validation will automatically switch to IPv6. So nothing to worry here.

Normalization

IPv4 addresses are easily structured: 4 blocks separated by a dot.
IPv6 addresses, though, can be structured quite wildly because some parts may be left out (if just zeros) and replaced by "::". So there could be 20 different string versions of the very same IP address.

So I think the addresses should always be stored normalized. Thats easier for comparing them later on or working with them in general.

/**
 * Normalizes an IPv6 address to long notation.
 * @link http://svn.kd2.org/svn/misc/libs/tools/ip_utils.php
 * Examples:
 *  -- ::1
 *  -> 0000:0000:0000:0000:0000:0000:0000:0001
 *  -- 2001:db8:85a3::8a2e:370:7334
 *  -> 2001:0db8:85a3:0000:0000:8a2e:0370:7334
 *
 * @param string $ip Input IPv6 address
 * @return string IPv6 address
 */
function normalizeIpv6($ip) {
    if (strpos($ip, '::') !== false) {
        $ip = str_replace('::', str_repeat(':0', 8 - substr_count($ip, ':')) . ':', $ip);
    }

    if ($ip[0] == ':') {
        $ip = '0' . $ip;
    }

    $ip = explode(':', $ip);

    foreach ($ip as & $part) {
        $part = str_pad($part, 4, '0', STR_PAD_LEFT);
    }

    return implode(':', $ip);
}

"::1" will be transformed in "0000:0000:0000:0000:0000:0000:0000:0001" "2001:db8:85a3::8a2e:370:7334" in "2001:0db8:85a3:0000:0000:8a2e:0370:7334"

Are you IPv6 ready?

Do you surf via IPv6?
You can easily find out using one of many webservices.
One Example: areyou.v6ready.info/

3 Comments

  1. Another option here:
    http://stackoverflow.com/questions/1120371/how-to-convert-ipv6-from-binary-for-storage-in-mysql#answer-1271123

    I could like your idea better — however, it has no license to use. Code from Stack Overflow is legal to use in all programming projects (see http://stackoverflow.com/legal clause 3).

    Regarding posting of code in a blog (like yours), http://www.codinghorror.com/blog/2007/04/pick-a-license-any-license.html . Pick a license. Any license.

  2. Well, as you can see, the @link states, that is not my code, either. I simply picked up the idea and posted his code with the link to the official document.
    It is probably under "GNU GPLv3 License" – since other files in the same branch are, too (but as your linke states, who knows for sure^^).

    <blockquote>"Code from Stack Overflow is legal to use"</blockquote>

    I would not be so sure about that…
    What if you paste code from copyrighted code? It cannot be legal now to use that – if posted by someone that wouldn’t have the right to do that 🙂 But thats kinda off topic already.

    Anyway – the idea of numeric records are nice, too.
    But since they are equally long, i prefer the one, that you can even "read" without transformation right away.

  3. Internet Protocols (IPv4, IPv6), needs development and a small company may not have too much time. I think that this article is very helpful bit of advice and code. The change is happening very quickly. ISP’s beta testing at broadband level.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.