IP v6 addresses ARE used

mbutcher - November 21, 2008 - 19:53
Project:Sphinx search
Version:6.x-1.x-dev
Component:Documentation
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

According to the help text on the Sphinx Search configuration page, "IPv6 addresses are not supported."

This, however, is not correct.

Whether or not ip_address() returns an IPv4 address is contingent upon the IP configuration of the local machine. Mine (Mac OS X using IPv6) returns an IPv6 address.

Conseqently, if the client is using an IPv6 address, you MUST specify the IPv6 address in the Sphinx Search configuration page, otherwise they will not match.

If the above is intended to reflect only CIDR limitations, that should be stated more clearly.

I'm guessing that the documentation is what needs changing, here.

#1

markus_petrux - November 22, 2008 - 08:05

hmm... good point.

The description now is "You can also specify IP ranges using CIDR notation. IPv6 addresses are not supported.". It could be changed to "You can also specify IPv4 ranges using CIDR notation (not supported for IPv6 addresses)." ¿?

Then, in sphinxsearch_xmlpipe() we have the following code, that we need to change somehow to parse IPv6 addresses differently. Suggestions?

<?php
 
// Check access to XMLPipe process by IP.
 
$access_xmlpipe = FALSE;
 
$sphinxsearch_indexer_ips = array_map('trim', explode(',', variable_get('sphinxsearch_indexer_ips', '')));
  if (!empty(
$sphinxsearch_indexer_ips)) {
    foreach (
$sphinxsearch_indexer_ips as $cidr) {
      if (
sphinxsearch_ip_check_cidr(ip_address(), $cidr)) {
       
$access_xmlpipe = TRUE;
        break;
      }
    }
  }
?>

<?php
/**
* Check if IP address belongs to specified CIDR range.
* Note: IPv6 addresses are not supported.
*
* @param string $ip
*   IPv4 address. ie. 192.168.0.1
* @param string $cidr
*   CIDR mask. ie. 192.168.0.0/24
* @return boolean
*   TRUE if $ip matches specified CIDR mask, FALSE otherwise.
*/
function sphinxsearch_ip_check_cidr($ip, $cidr) {
  list(
$net, $mask) = explode('/', $cidr);
 
$ip_net = ip2long($net);
 
$ip_mask = ~((1 << (32 - $mask)) - 1);
 
$ip_ip = ip2long($ip);
 
$ip_ip_net = $ip_ip & $ip_mask;
  return (
$ip_ip_net == $ip_net);
}
?>

#2

mbutcher - November 24, 2008 - 16:51

PHP doesn't have an equivalent of ip2long for IPv6, so... I guess a full IPv6 CIDR parser and replacement algorithm would be a larger project.

MediaWiki has a nice IP.php class file that might provide a useful starting point for the algorithms:

http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/IP.php?r...

The method to start with would probably be "public static function isInRange( $addr, $range )".

But if the documentation was fixed, I'd certainly suggest lowering the priority on IPv6 support. Unless it's a big need for you (or you'd like the clout of being the first Drupal component to correctly support IPv6), this is obviously less important than other issues.

#3

DerekMorr - June 25, 2009 - 21:23

There's also the Net_IPv6 module. It has a function which might work - http://pear.php.net/manual/en/package.networking.net-ipv6.isinnetmask.php

 
 

Drupal is a registered trademark of Dries Buytaert.