Patch to Postfix.pm to fix IPv6 address parsing

Patrick Vande Walle patrick at vande-walle.eu
Mon Apr 20 06:42:17 IST 2009


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;
           $read1strcvd = 1;


More information about the MailScanner mailing list