diff --git a/src/pflib/NATCompiler_ipf_writers.cpp b/src/pflib/NATCompiler_ipf_writers.cpp index a9cb86017..efa998ba9 100644 --- a/src/pflib/NATCompiler_ipf_writers.cpp +++ b/src/pflib/NATCompiler_ipf_writers.cpp @@ -90,9 +90,6 @@ void NATCompiler_ipf::PrintRule::_printAddr_L(Address *o, bool print_netmask) assert(atrt==NULL); } - const InetAddr *addr = o->getAddressPtr(); - InetAddr mask = *(o->getNetmaskPtr()); - if (Interface::cast(o)!=NULL && Interface::cast(o)->isDyn()) { if (options->getBool("dynAddr")) @@ -103,50 +100,67 @@ void NATCompiler_ipf::PrintRule::_printAddr_L(Address *o, bool print_netmask) return; } - if (Interface::cast(o)!=NULL && ! Interface::cast(o)->isDyn()) - mask = InetAddr(InetAddr::getAllOnes()); - - if (o->dimension()==1) - mask = InetAddr(InetAddr::getAllOnes()); - - if (addr->isAny() && mask.isAny()) - { - compiler->output << "any "; - } else + const InetAddr *addr = o->getAddressPtr(); + if (addr) { + InetAddr mask = *(o->getNetmaskPtr()); - compiler->output << addr->toString(); + if (Interface::cast(o)!=NULL && ! Interface::cast(o)->isDyn()) + mask = InetAddr(InetAddr::getAllOnes()); - if (print_netmask) - compiler->output << "/" << mask.getLength(); - compiler->output << " "; - } + if (o->dimension()==1) + mask = InetAddr(InetAddr::getAllOnes()); + + if (addr->isAny() && mask.isAny()) + { + compiler->output << "any "; + } else + { + + compiler->output << addr->toString(); + + if (print_netmask) + compiler->output << "/" << mask.getLength(); + compiler->output << " "; + } + } } void NATCompiler_ipf::PrintRule::_printAddr_R(Address *o, bool print_netmask) { const InetAddr *addr = o->getAddressPtr(); - InetAddr mask = *(o->getNetmaskPtr)(); - if (Interface::cast(o) != NULL) - mask = InetAddr(InetAddr::getAllOnes()); - - if (o->dimension()==1) - mask = InetAddr(InetAddr::getAllOnes()); - - if (addr->isAny() && print_netmask && mask.isHostMask()) + // check for the case when dynamic interface is used in TSrc (or when + // interface in TSrc just has no IP address ) + if (Interface::cast(o) != NULL && (addr==NULL || addr->isAny())) { compiler->output << "0/32 "; - } else + return; + } + + if (addr) { - compiler->output << addr->toString(); - if (print_netmask) - compiler->output << "/" << mask.getLength(); - compiler->output << " "; + InetAddr mask = *(o->getNetmaskPtr)(); + + if (Interface::cast(o) != NULL) + mask = InetAddr(InetAddr::getAllOnes()); + + if (o->dimension()==1) + mask = InetAddr(InetAddr::getAllOnes()); + + if (addr->isAny() && print_netmask && mask.isHostMask()) + { + compiler->output << "0/32 "; + } else + { + compiler->output << addr->toString(); + if (print_netmask) + compiler->output << "/" << mask.getLength(); + compiler->output << " "; + } } } - void NATCompiler_ipf::PrintRule::_printAddr_R_LB(RuleElementTDst *tdst) { bool first=true; diff --git a/src/pflib/PolicyCompiler_ipf_writers.cpp b/src/pflib/PolicyCompiler_ipf_writers.cpp index c7e859876..20cb14961 100644 --- a/src/pflib/PolicyCompiler_ipf_writers.cpp +++ b/src/pflib/PolicyCompiler_ipf_writers.cpp @@ -267,9 +267,6 @@ void PolicyCompiler_ipf::PrintRule::_printAddr(Address *o,bool neg) assert(atrt==NULL); } - const InetAddr *addr = o->getAddressPtr(); - InetAddr mask = *(o->getNetmaskPtr()); - if (options->getBool("dynAddr") && Interface::cast(o)!=NULL && Interface::cast(o)->isDyn()) { @@ -278,26 +275,36 @@ void PolicyCompiler_ipf::PrintRule::_printAddr(Address *o,bool neg) return; } - if (Interface::cast(o)!=NULL) { - mask = InetAddr(InetAddr::getAllOnes()); - } - - if (o->dimension()==1) + const InetAddr *addr = o->getAddressPtr(); + if (Interface::cast(o)!=NULL && addr==NULL) { - mask = InetAddr(InetAddr::getAllOnes()); + compiler->output << " "; } - - if (addr->isAny() && mask.isAny()) + if (addr) { - compiler->output << "any "; - } else { - if (neg) compiler->output << "! "; - compiler->output << addr->toString(); - if (!mask.isHostMask()) + InetAddr mask = *(o->getNetmaskPtr()); + + if (Interface::cast(o)!=NULL) { + mask = InetAddr(InetAddr::getAllOnes()); + } + + if (o->dimension()==1) { - compiler->output << "/" << mask.getLength(); - } - compiler->output << " "; + mask = InetAddr(InetAddr::getAllOnes()); + } + + if (addr->isAny() && mask.isAny()) + { + compiler->output << "any "; + } else { + if (neg) compiler->output << "! "; + compiler->output << addr->toString(); + if (!mask.isHostMask()) + { + compiler->output << "/" << mask.getLength(); + } + compiler->output << " "; + } } } diff --git a/test/ipf/objects-for-regression-tests.fwb b/test/ipf/objects-for-regression-tests.fwb index ec8fb4d2a..411cf5f5d 100644 --- a/test/ipf/objects-for-regression-tests.fwb +++ b/test/ipf/objects-for-regression-tests.fwb @@ -1,6 +1,6 @@ - + @@ -20,13 +20,8 @@ - - - - - - - + + @@ -47,13 +42,8 @@ - - - - - - - + + @@ -587,8 +577,7 @@ - - + @@ -641,31 +630,27 @@ - - + - - + - - + - - + - - + -m ip_conntrack_talk -m ip_nat_talk + @@ -5842,13 +5827,8 @@ - - - - - - - + + @@ -5867,13 +5847,8 @@ - - - - - - - + + @@ -5885,8 +5860,7 @@ - - + @@ -5924,27 +5898,25 @@ - - + - - + - - + + diff --git a/test/ipf/run.all b/test/ipf/run.all index d6077e92b..7266526a3 100755 --- a/test/ipf/run.all +++ b/test/ipf/run.all @@ -8,6 +8,8 @@ while (<>) { while ( $str=~ /]+name="([^"]*).*$"/; $fw=$1; + printf "\n"; + printf "echo '******* $fw'\n"; printf "fwb_ipf -v -f $XMLFILE $fw\n"; $str=~ s/^.*]+name="$fw"[^>]+>//; }