[rancid] Rancid 3.2 RHEL6 compatibilities with Socket module.

heasley heas at shrubbery.net
Fri Jun 5 21:07:11 UTC 2015


Mon, Jun 01, 2015 at 09:50:56PM -0400, Robert Drake:
> Not speaking for anyone but myself.
> 
> FWIW, this is code from spamassassin:
> 
> my $ip6 = eval {
>       require Socket;
>       Socket->VERSION(1.95);
>       Socket->import( 'inet_pton' );
>       1;
> } || eval {
>       require Socket6;
>       Socket6->import( 'inet_pton' );
>       1;
> };
> 
> Normally I would say use NetAddr::IP or another library to avoid the 
> inet_pton call, but I found this note:
> 
> # ipaddrval(IPaddr) converts and IPv4/v6 address to a string for comparison.
> # Some may ask why not use Net::IP; performance.  We tried and it was 
> horribly
> # slow.
> 
> If performance is a major concern I would make minor changes to the 
> existing code (sorry for the formatting):
> 
>      if ($a =~ /:/) {
>      my($l);
>      ($a, $l) = split(/\//, $a);   # this split works even if the slash 
> isn't there
>      $l ||= 128;    # if !defined is faster than if (/\//)
> 
>      $norder = inet_pton(AF_INET6, $a);
>      return unpack('H128', $norder) . unpack('H', pack('C', $l));
>      }

that doesn't handle /0 properly.  this does:

        ($a, $l) = split(/\//, $a);
        if (!defined($l)) {
            $l ||= 128;
        }

the difference in speed/efficiency is tiny (on 13M of acls).  Net::IP was
utterly haneous; seemingly in perl's object handling mess.

> I don't think this sacrifices readability but it improves the 
> performance (by about 30-40k calls/s).  The regex and split string 
> operations are almost always the most expensive aspect and if there were 
> ways to get rid of them then the speed would go way up. Honestly 
> inet_pton is low level but it's the best way to get speed out of IP 
> operations (because it's just wrapping a C function).
> 
> Drawbacks:  RHEL6 (or anything older than 2009 running perl5.10.x) don't 
> have inet_pton.   Socket.pm also doesn't support MSWin32 until 2.019, 
> which hasn't been shipped yet with any version of perl (so inet_pton 
> isn't available on any windows systems without workarounds.  I have no 
> idea if anyone runs rancid on windows though, or if that would be possible)
> 
> Suggested workarounds:  It's a minor change.  I'm not sure if Redhat 
> uses a system like Debian's quilt for maintaining downstream patches, 
> but I would just put together a changeset for the 3 lines and repackage 
> it rather than forcing the change upstream.  The reason being that 
> although this is minor, changing it causes documentation headaches 
> (well.. a comment saying why it is the way it is) and doesn't give a 
> sunset clause to it.  If it's maintained in downstream then as soon as 
> RHEL6 support is dropped the packages stop being produced and that is 
> the sunset of the changes.

I agree with that; if they insist upon using ancient versions, then ....
hrm.


More information about the Rancid-discuss mailing list