compiler for ipfilter: int IDs and member vars for tcp/udp ports

This commit is contained in:
Vadim Kurland
2008-06-09 22:11:30 +00:00
parent b0fc8dfa5f
commit efc9f2f507
2 changed files with 47 additions and 46 deletions
+46 -45
View File
@@ -139,52 +139,52 @@ bool NATCompiler_ipf::ExpandPortRange::processNext()
if (UDPService::isA(osrv) || TCPService::isA(osrv)) if (UDPService::isA(osrv) || TCPService::isA(osrv))
{ {
int rs = osrv->getInt("dst_range_start"); int rs = TCPUDPService::cast(osrv)->getDstRangeStart();
int re = osrv->getInt("dst_range_end"); int re = TCPUDPService::cast(osrv)->getDstRangeEnd();
int numPorts = re-rs+1; int numPorts = re-rs+1;
if (numPorts==1) if (numPorts==1)
{ {
tmp_queue.push_back(rule); tmp_queue.push_back(rule);
return true; return true;
} }
if (numPorts > 20) if (numPorts > 20)
{ {
ostringstream ostr; ostringstream ostr;
ostr << string("Rule ") << rule->getLabel() << " : " ostr << string("Rule ") << rule->getLabel() << " : "
<< string("Expanding port range ") << osrv->getName() << string("Expanding port range ") << osrv->getName()
<< " creates " << numPorts << " rules"; << " creates " << numPorts << " rules";
compiler->warning(ostr.str()); compiler->warning(ostr.str());
} }
string newSrvType = TCPService::TYPENAME; string newSrvType = TCPService::TYPENAME;
if (UDPService::isA(osrv)) newSrvType = UDPService::TYPENAME; if (UDPService::isA(osrv)) newSrvType = UDPService::TYPENAME;
for (int p=rs; p<=re; ++p) for (int p=rs; p<=re; ++p)
{ {
NATRule *r = NATRule::cast( NATRule *r = NATRule::cast(
compiler->dbcopy->create(NATRule::TYPENAME) ); compiler->dbcopy->create(NATRule::TYPENAME) );
r->duplicate(rule); r->duplicate(rule);
FWObject *newSrv = compiler->dbcopy->create(newSrvType); FWObject *newSrv = compiler->dbcopy->create(newSrvType);
newSrv->duplicate(osrv,true); newSrv->duplicate(osrv,true);
newSrv->setInt("dst_range_start",p); TCPUDPService::cast(newSrv)->setDstRangeStart(p);
newSrv->setInt("dst_range_end",p); TCPUDPService::cast(newSrv)->setDstRangeEnd(p);
compiler->dbcopy->add(newSrv,false); compiler->dbcopy->add(newSrv,false);
compiler->dbcopy->addToIndex(newSrv); compiler->dbcopy->addToIndex(newSrv);
compiler->cacheObj(newSrv); compiler->cacheObj(newSrv);
RuleElementOSrv *nosrv = r->getOSrv(); RuleElementOSrv *nosrv = r->getOSrv();
nosrv->clearChildren(); nosrv->clearChildren();
nosrv->addRef(newSrv); nosrv->addRef(newSrv);
compiler->temp_ruleset->add(r); compiler->temp_ruleset->add(r);
tmp_queue.push_back(r); tmp_queue.push_back(r);
} }
} else } else
{ {
tmp_queue.push_back(rule); tmp_queue.push_back(rule);
} }
return true; return true;
} }
@@ -436,7 +436,8 @@ bool NATCompiler_ipf::appProxy::processNext()
{ {
UDPService *s=UDPService::cast(osrv); UDPService *s=UDPService::cast(osrv);
if (ipsec_proxy && if (ipsec_proxy &&
s->getInt("dst_range_start")==ISAKMP_PORT && s->getInt("dst_range_end")==ISAKMP_PORT)
s->getDstRangeStart()==ISAKMP_PORT && s->getDstRangeEnd()==ISAKMP_PORT)
rule->setStr("nat_rule_proxy",ipsec_proxy_str); rule->setStr("nat_rule_proxy",ipsec_proxy_str);
} }
@@ -444,35 +445,35 @@ bool NATCompiler_ipf::appProxy::processNext()
{ {
TCPService *s=TCPService::cast(osrv); TCPService *s=TCPService::cast(osrv);
if (ftp_proxy && if (ftp_proxy &&
s->getInt("dst_range_start")==FTP_PORT && s->getInt("dst_range_end")==FTP_PORT ) s->getDstRangeStart()==FTP_PORT && s->getDstRangeEnd()==FTP_PORT )
rule->setStr("nat_rule_proxy",ftp_proxy_str); rule->setStr("nat_rule_proxy",ftp_proxy_str);
if (rcmd_proxy && if (rcmd_proxy &&
s->getInt("dst_range_start")==RCMD_PORT && s->getInt("dst_range_end")==RCMD_PORT ) s->getDstRangeStart()==RCMD_PORT && s->getDstRangeEnd()==RCMD_PORT )
rule->setStr("nat_rule_proxy",rcmd_proxy_str); rule->setStr("nat_rule_proxy",rcmd_proxy_str);
if (krcmd_proxy && if (krcmd_proxy &&
s->getInt("dst_range_start")==KRCMD_PORT && s->getInt("dst_range_end")==KRCMD_PORT ) s->getDstRangeStart()==KRCMD_PORT && s->getDstRangeEnd()==KRCMD_PORT )
rule->setStr("nat_rule_proxy",krcmd_proxy_str); rule->setStr("nat_rule_proxy",krcmd_proxy_str);
if (ekshell_proxy && if (ekshell_proxy &&
s->getInt("dst_range_start")==EKSHELL_PORT && s->getInt("dst_range_end")==EKSHELL_PORT ) s->getDstRangeStart()==EKSHELL_PORT && s->getDstRangeEnd()==EKSHELL_PORT )
rule->setStr("nat_rule_proxy",ekshell_proxy_str); rule->setStr("nat_rule_proxy",ekshell_proxy_str);
if (raudio_proxy && if (raudio_proxy &&
s->getInt("dst_range_start")==RAUDIO_PORT && s->getInt("dst_range_end")==RAUDIO_PORT ) s->getDstRangeStart()==RAUDIO_PORT && s->getDstRangeEnd()==RAUDIO_PORT )
rule->setStr("nat_rule_proxy",raudio_proxy_str); rule->setStr("nat_rule_proxy",raudio_proxy_str);
if (h323_proxy && if (h323_proxy &&
s->getInt("dst_range_start")==H323_PORT && s->getInt("dst_range_end")==H323_PORT ) s->getDstRangeStart()==H323_PORT && s->getDstRangeEnd()==H323_PORT )
rule->setStr("nat_rule_proxy",h323_proxy_str); rule->setStr("nat_rule_proxy",h323_proxy_str);
if (pptp_proxy && if (pptp_proxy &&
s->getInt("dst_range_start")==PPTP_PORT && s->getInt("dst_range_end")==PPTP_PORT ) s->getDstRangeStart()==PPTP_PORT && s->getDstRangeEnd()==PPTP_PORT )
rule->setStr("nat_rule_proxy",pptp_proxy_str); rule->setStr("nat_rule_proxy",pptp_proxy_str);
if (irc_proxy && if (irc_proxy &&
s->getInt("dst_range_start")==IRC_PORT && s->getInt("dst_range_end")==IRC_PORT ) s->getDstRangeStart()==IRC_PORT && s->getDstRangeEnd()==IRC_PORT )
rule->setStr("nat_rule_proxy",irc_proxy_str); rule->setStr("nat_rule_proxy",irc_proxy_str);
} }
} }
+1 -1
View File
@@ -199,7 +199,7 @@ void NATCompiler_ipf::PrintRule::_printPort(Service *srv,bool eq)
{ {
if (TCPService::isA(srv) || UDPService::isA(srv)) if (TCPService::isA(srv) || UDPService::isA(srv))
{ {
int drs=srv->getInt("dst_range_start"); int drs=TCPUDPService::cast(srv)->getDstRangeStart();
if (!eq || drs!=0) if (!eq || drs!=0)
{ {
compiler->output << "port "; compiler->output << "port ";