php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42918 IPv6 addresses not supported in SNMP extension
Submitted: 2007-10-10 14:39 UTC Modified: 2011-08-25 21:41 UTC
Votes:12
Avg. Score:4.6 ± 0.8
Reproduced:11 of 11 (100.0%)
Same Version:3 (27.3%)
Same OS:8 (72.7%)
From: estesp at fastmail dot us Assigned: lytboris (profile)
Status: Closed Package: SNMP related
PHP Version: 5CVS-2007-10-10 (snap) OS: *
Private report: No CVE-ID: None
 [2007-10-10 14:39 UTC] estesp at fastmail dot us
Description:
------------
The snmp interface code in php5 does not properly support IPv6 addresses for the hostname.  Since net-snmp 5.x the SNMP daemon can be listening on udp6 port and therefore, the hostname passed could be a valid IPv6 address.

However, the code in the snmp extension has:

     if ((pptr = strchr (hostname, ':'))) {
                remote_port = strtol (pptr + 1, NULL, 0);
        }

So, instead of defaulting to the usual (default) snmp port, given an IPv6 address, it is taking everything past the first colon as the port number.. which, I believe is going to give a very interesting port number for most IPv6 addresses :)

Reproduce code:
---------------
Just call snmpget() with an IPv6 IP address.. you will get a host not found, or similar:

$host = '0000:0000:0000:0000:0000:0000:0000:0001';
$community = 'public';
$sysName = snmpget($host, $community, "system.sysName.0");
print "$sysName

Expected result:
----------------
snmpget() should work for IPv6 addresses given you have a net-snmp version with IPv6 support and have snmpd listening on an IPv6 transport.

Actual result:
--------------
PHP Warning:  snmpget(): Could not open snmp connection: Unknown host
(0000:0000:0000:0000:0000:0000:0000:0001) in /my_ipv6_php on line 4

There may be other issues here as "unknown host" sounds like a getaddrinfo problem, but since doing an snmpget on the server in Ipv6 mode outside of php5 works, I have to bet that something in the snmp interface in php5 is broken with respect to IPv6.

Patches

php_bug42918.diff (last revision 2011-08-21 23:35 UTC by ch@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-14 14:39 UTC] j dot ek at gmx dot net
Actually the code mentioned above occurs two times. First time in function "php_snmpv3" (for SNMPv3) and second in "php_snmp" (for v1 and v2c).

It also seems that some other things should be updated to support IPv6 addresses, e.g. not only support IpAddress SMIv2 Base Type but also the more generic address schema described in RFC3291. On the other hand I cannot say whether the net-snmp library already does support this, but as they claim to be fully IPv6 compatible, it's worth a try.
 [2011-04-08 21:12 UTC] jani@php.net
-Package: Feature/Change Request +Package: SNMP related
 [2011-07-29 01:17 UTC] ch@php.net
Ping! This is 2011 and IPv6 spreading!

Fixing this issue shouldn't be very hard as the underlying Net_SNMP library already supports IPv6:

  $ snmpwalk -v 2c -c public 'udp6:[::1]' sysname
  SNMPv2-MIB::sysName.0 = STRING: james
 
  $ snmpwalk -v 2c -c public 'udp6:::1' sysname
  SNMPv2-MIB::sysName.0 = STRING: james

For testing the following hast to be put into /etc/snmp/snmpd.conf:

   agentAddress  udp:127.0.0.1:161,udp6:[::1]:161
   rwcommunity6 private ::1
   rocommunity6 public ::1

Currently PHP still gives the following error:
   $ ~/workspace/php-src-5.4/sapi/cli/php -r 'echo snmpget("::1", "private", "IF-MIB::ifAlias.1");'

   Warning: snmpget(): Could not open snmp connection: Unknown host (::1) (Illegal seek) in Command line code on line 1

Different formats like "[::1]:161" or "::1:161" make no difference.
 [2011-08-14 19:40 UTC] lytboris@php.net
-Assigned To: +Assigned To: lytboris
 [2011-08-20 15:53 UTC] lytboris@php.net
Automatic comment from SVN on behalf of lytboris
Revision: http://svn.php.net/viewvc/?view=revision&revision=315236
Log: Adding IPv6 support (FR #42918)
 [2011-08-20 16:10 UTC] lytboris@php.net
Automatic comment from SVN on behalf of lytboris
Revision: http://svn.php.net/viewvc/?view=revision&revision=315237
Log: merge from trunk two commits:
Adding IPv6 support (FR #42918)
more code coverage
 [2011-08-20 16:24 UTC] lytboris@php.net
Automatic comment from SVN on behalf of lytboris
Revision: http://svn.php.net/viewvc/?view=revision&revision=315238
Log: document FR #55312, #42918
 [2011-08-20 16:24 UTC] lytboris@php.net
-Status: Assigned +Status: Feedback
 [2011-08-20 16:24 UTC] lytboris@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.4-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2011-08-20 20:55 UTC] lytboris@php.net
Automatic comment from SVN on behalf of lytboris
Revision: http://svn.php.net/viewvc/?view=revision&revision=315245
Log: IPv6 Support for SNMP. (FR #42918)
 [2011-08-21 23:34 UTC] ch@php.net
Now it works, thanks!

Attached you find a diff that adds two basic tests for "udp6[::1]" as hostname.
 [2011-08-21 23:35 UTC] ch@php.net
The following patch has been added/updated:

Patch Name: php_bug42918.diff
Revision:   1313969737
URL:        https://bugs.php.net/patch-display.php?bug=42918&patch=php_bug42918.diff&revision=1313969737
 [2011-08-22 05:52 UTC] lytboris@php.net
There is IPv6 test both in trunk and PHP_5_4, revs 315236, 315237 already.
 [2011-08-25 21:41 UTC] lytboris@php.net
-Status: Feedback +Status: Closed -Operating System: Linux +Operating System: *
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC