Patch to Postfix.pm to fix IPv6 address parsing

Julian Field MailScanner at ecs.soton.ac.uk
Mon Apr 20 09:26:48 IST 2009



On 20/04/2009 06:42, Patrick Vande Walle wrote:
> Hi Julian,
>
> This is with MS 4.75-11 on Linux CentOS 5 with Postfix.
>
> The Postfix.pm routine that extracts  $message->{clientip} will not
> correctly handle IPv6 addresses on Linux, because the latter adds "IPv6:"
> in front of the address. An example header is:
>
> Received: from mail.ietf.org (mail.ietf.org [IPv6:2001:1890:1112:1::20])
> 	by whatever.host.name (Postfix) with ESMTP id 1FE959C07A
> 	for<patrick at vande-walle.eu>; Mon, 20 Apr 2009 05:16:42 +0200 (CEST)
>
> I searched quit some a bit to find the right regexp. Actually, the simplest
> way is to use the regexp from the same routine in Sendmail.pm. It handles
> both IPv4 and IPv6 addresses, thus ultimately simplifying the code. Diff
> below.
>
> It has been running fine for 3 days here, with no side effects as far as I
> can see. It now returns the right clientip value to MailWatch.  As an
> aside, MailWatch has its own issues with IPv6, for which I have submitted a
> patch on Sourceforge.
>
> I do not post often to this list, I think I actually never did. So let me
> take this opportunity to thank you all for your dedication and
> helpfulness.
>
> All the best,
>
> Patrick Vande Walle
>
>
>
> --- Postfix.pm.orig    2009-04-18 16:16:07.000000000 +0200
> +++ Postfix.pm    2009-04-18 16:16:48.000000000 +0200
> @@ -544,16 +544,8 @@
>             $InSubject = 0;
>           }
>         }
> -      if ($recdata =~ /^Received: .+\[(\d+\.\d+\.\d+\.\d+)\]/i) {
> -        unless ($read1strcvd) {
> -          $ipfromheader = $1;
> -          $read1strcvd = 1;
> -        }
> -        unless ($IPFound) {
> -          $message->{clientip} = $1;
> -          $IPFound = 1;
> -        }
> -      } elsif ($recdata =~ /^Received: .+\[([\dabcdef.:]+)\]/i) {
> +# Linux adds "IPv6:" on the front of the IPv6 address, so remove it
> +    if ($recdata =~ /^Received: .+\[(?:IPv6:)?([\dabcdef.:]+)\]/i) {
>           unless ($read1strcvd) {
>             $ipfromheader = $1;
>    
Are you sure you meant $1 and not $2 here?
>             $read1strcvd = 1;
>    

Jules

-- 
Julian Field MEng CITP CEng
www.MailScanner.info
Buy the MailScanner book at www.MailScanner.info/store

Need help customising MailScanner?
Contact me!
Need help fixing or optimising your systems?
Contact me!
Need help getting you started solving new requirements from your boss?
Contact me!

PGP footprint: EE81 D763 3DB0 0BFD E1DC 7222 11F6 5947 1415 B654


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.



More information about the MailScanner mailing list