2017 © Pedro Peláez
 

library ip-set

Efficiently match IP addresses against a set of CIDR specifications.

image

wikimedia/ip-set

Efficiently match IP addresses against a set of CIDR specifications.

  • Saturday, July 28, 2018
  • by mediawiki
  • Repository
  • 18 Watchers
  • 17 Stars
  • 251,381 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 6 Versions
  • 9 % Grown

The README.md

IPSet

IPSet is a PHP library for matching IP addresses against a set of CIDR specifications., (*1)

Here is how you use it:, (*2)

use Wikimedia\IPSet;
// At startup, calculate the optimized data structure for the set:
$ipset = new IPSet( [
    '208.80.154.0/26',
    '2620:0:861:1::/64',
    '10.64.0.0/22',
] );

// Runtime check against cached set (returns bool):
if ( $ipset->match( $ip ) ) {
    // ...
}

In rough benchmarking, this takes about 80% more time than in_array() checks on a short (a couple hundred at most) array of addresses. It's fast either way at those levels, though, and IPSet would scale better than in_array if the array were much larger., (*3)

For mixed-family CIDR sets, however, this code gives well over 100x speedup vs iterating Wikimedia\IPUtils::isInRange() over an array of CIDR specs., (*4)

The basic implementation is two separate binary trees (IPv4 and IPv6) as nested php arrays with keys named 0 and 1. The values false and true are terminal match-fail and match-success, otherwise the value is a deeper node in the tree., (*5)

A simple depth-compression scheme is also implemented: whole-byte tree compression at whole-byte boundaries only, where no branching occurs during that whole byte of depth. A compressed node has keys 'comp' (the byte to compare) and 'next' (the next node to recurse into if 'comp' matched successfully)., (*6)

For example, given these inputs:, (*7)

25.0.0.0/9
25.192.0.0/10

The v4 tree would look like:, (*8)

root4 => [
    'comp' => 25,
    'next' => [
        0 => true,
        1 => [
            0 => false,
            1 => true,
        ],
    ],
];

(multi-byte compression nodes were attempted as well, but were a net loss in my test scenarios due to additional match complexity), (*9)

License

Copyright 2014, 2015 Brandon Black blblack@gmail.com, (*10)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version., (*11)

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details., (*12)

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. http://www.gnu.org/copyleft/gpl.html, (*13)

The Versions

28/07 2018

dev-master

9999999-dev https://www.mediawiki.org/wiki/IPSet

Efficiently match IP addresses against a set of CIDR specifications.

  Sources   Download

GPL-2.0+ GPL-2.0-or-later

The Requires

  • php >=5.5.9

 

The Development Requires

by Brandon Black

30/12 2017

1.2.0

1.2.0.0 https://github.com/wikimedia/IPSet

Efficiently match IP addresses against a set of CIDR specifications.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.5.9

 

The Development Requires

by Brandon Black

12/02 2016

1.1.0

1.1.0.0 https://github.com/wikimedia/IPSet

Efficiently match IP addresses against a set of CIDR specifications.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.3

 

The Development Requires

by Brandon Black

10/02 2016

dev-sandbox/tgr/loop-debug

dev-sandbox/tgr/loop-debug https://github.com/wikimedia/IPSet

Efficiently match IP addresses against a set of CIDR specifications.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.3

 

The Development Requires

by Brandon Black

29/06 2015

1.0.1

1.0.1.0 https://github.com/wikimedia/IPSet

Efficiently match IP addresses against a set of CIDR specifications.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.3

 

The Development Requires

by Brandon Black

26/06 2015

1.0

1.0.0.0 https://github.com/wikimedia/IPSet

Efficiently match IP addresses against a set of CIDR specifications.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.3

 

The Development Requires

by Brandon Black