1
0
mirror of https://github.com/fwbuilder/fwbuilder synced 2026-03-22 11:17:31 +01:00

removing failed attempt to parse ifconfig output

This commit is contained in:
Vadim Kurland 2011-06-02 10:33:40 -07:00
parent 58eb1a865e
commit d825133481
10 changed files with 0 additions and 1556 deletions

View File

@ -1,158 +0,0 @@
/*
Firewall Builder
Copyright (C) 2011 NetCitadel, LLC
Author: Vadim Kurland vadim@fwbuilder.org
This program is free software which we release under the GNU General Public
License. You may redistribute and/or modify this program under the terms
of that license as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To get a copy of the GNU General Public License, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "../../config.h"
#include "IfconfigImporter.h"
#include "../parsers/IfconfigLinuxCfgLexer.hpp"
#include "../parsers/IfconfigLinuxCfgParser.hpp"
#include "../parsers/IfconfigBSDCfgLexer.hpp"
#include "../parsers/IfconfigBSDCfgParser.hpp"
#include <ios>
#include <iostream>
#include <algorithm>
#include <memory>
#include <QtDebug>
extern int fwbdebug;
using namespace std;
using namespace libfwbuilder;
IfconfigImporter::IfconfigImporter(FWObject *lib,
std::istringstream &input,
Logger *log,
const std::string &host_os,
const std::string &fwname) :
Importer(lib, host_os, input, log, fwname)
{
}
IfconfigImporter::~IfconfigImporter()
{
}
void IfconfigImporter::newInterface(InterfaceSpec &is)
{
interfaces.push_back(is);
}
void IfconfigImporter::HwAddressForCurrentInterface(const std::string &str)
{
list<InterfaceSpec>::reverse_iterator last = interfaces.rbegin();
last->hwaddr = str;
}
void IfconfigImporter::inetConfigurationForCurrentInterface(AddressSpec &as)
{
list<InterfaceSpec>::reverse_iterator last = interfaces.rbegin();
last->as.push_back(as);
}
void IfconfigImporter::inet6ConfigurationForCurrentInterface(AddressSpec &as)
{
list<InterfaceSpec>::reverse_iterator last = interfaces.rbegin();
last->as.push_back(as);
}
void IfconfigImporter::addGroupToCurrentInterface(const std::string &group_name)
{
list<InterfaceSpec>::reverse_iterator last = interfaces.rbegin();
last->groups.push_back(group_name);
}
Firewall* IfconfigImporter::finalize()
{
return NULL;
}
void IfconfigImporter::run()
{
QStringList err;
QString parser_err = QObject::tr("Parser error:");
QString gen_err = QObject::tr("Error:");
std::ostringstream parser_debug;
ANTLR_USE_NAMESPACE(antlr)CharScanner *lexer = NULL;
ANTLR_USE_NAMESPACE(antlr)LLkParser *parser = NULL;
// IfconfigCfgLexer *lexer = NULL;
// IfconfigCfgParser *parser = NULL;
if (platform == "linux24")
{
lexer = new IfconfigLinuxCfgLexer(input);
IfconfigLinuxCfgParser* p = new IfconfigLinuxCfgParser(*lexer);
parser = p;
p->importer = this;
if (fwbdebug) p->dbg = &std::cerr;
else p->dbg = &parser_debug;
}
if (platform == "openbsd" || platform == "freebsd")
{
lexer = new IfconfigBSDCfgLexer(input);
IfconfigBSDCfgParser *p = new IfconfigBSDCfgParser(*lexer);
parser = p;
p->importer = this;
if (fwbdebug) p->dbg = &std::cerr;
else p->dbg = &parser_debug;
}
if (lexer == NULL)
{
*logger << "Have no importer for ifconfig output for " << platform;
return;
}
try
{
parser->cfgfile();
} catch(ANTLR_USE_NAMESPACE(antlr)ANTLRException &e)
{
err << parser_err + " " + e.toString().c_str();
} catch(ObjectMakerException &e)
{
err << gen_err + " " + e.toString();
} catch(ImporterException &e)
{
err << gen_err + " " + e.toString();
} catch(std::exception& e)
{
err << parser_err + " " + e.what();
}
if (!err.isEmpty())
*logger << err.join("\n").toUtf8().constData();
delete parser;
delete lexer;
}

View File

@ -1,67 +0,0 @@
/*
Firewall Builder
Copyright (C) 2011 NetCitadel, LLC
Author: Vadim Kurland vadim@fwbuilder.org
This program is free software which we release under the GNU General Public
License. You may redistribute and/or modify this program under the terms
of that license as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To get a copy of the GNU General Public License, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _FWB_POLICY_IMPORTER_IFCONFIG_H_
#define _FWB_POLICY_IMPORTER_IFCONFIG_H_
#include <map>
#include <list>
#include <string>
#include <functional>
#include <sstream>
#include "Importer.h"
#include "AddressSpec.h"
#include "InterfaceSpec.h"
class IfconfigImporter : public Importer
{
public:
std::list< InterfaceSpec > interfaces;
IfconfigImporter(libfwbuilder::FWObject *lib,
std::istringstream &input,
libfwbuilder::Logger *log,
const std::string &host_os,
const std::string &fwname);
~IfconfigImporter();
virtual void run();
virtual libfwbuilder::Firewall* finalize();
void newInterface(InterfaceSpec &is);
void HwAddressForCurrentInterface(const std::string &str);
void inetConfigurationForCurrentInterface(AddressSpec &as);
void inet6ConfigurationForCurrentInterface(AddressSpec &as);
void addGroupToCurrentInterface(const std::string &group_name);
};
#endif

View File

@ -1,428 +0,0 @@
/*
Firewall Builder
Copyright (C) 2011 NetCitadel, LLC
Author: Vadim Kurland vadim@fwbuilder.org
This program is free software which we release under the GNU General Public
License. You may redistribute and/or modify this program under the terms
of that license as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To get a copy of the GNU General Public License, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
header "pre_include_hpp"
{
// gets inserted before antlr generated includes in the header
// file
#include "IfconfigImporter.h"
}
header "post_include_hpp"
{
// gets inserted after antlr generated includes in the header file
// outside any generated namespace specifications
#include <iostream>
#include <sstream>
class IfconfigImporter;
}
header "pre_include_cpp"
{
// gets inserted before the antlr generated includes in the cpp
// file
}
header "post_include_cpp"
{
// gets inserted after the antlr generated includes in the cpp
// file
#include <antlr/Token.hpp>
#include <antlr/TokenBuffer.hpp>
}
header
{
// gets inserted after generated namespace specifications in the
// header file. But outside the generated class.
}
options
{
language="Cpp";
}
class IfconfigBSDCfgParser extends Parser;
options
{
k = 2;
// when default error handler is disabled, parser errors cause
// exception and terminate parsing process. We can catch the exception
// and make the error appear in importer log, but import process
// terminates which is not always optimal
//
// defaultErrorHandler = false;
// see http://www.antlr2.org/doc/options.html
}
{
// additional methods and members
public:
std::ostream *dbg;
IfconfigImporter *importer;
/// Parser error-reporting function can be overridden in subclass
virtual void reportError(const ANTLR_USE_NAMESPACE(antlr)RecognitionException& ex)
{
importer->addMessageToLog("Parser error: " + ex.toString());
std::cerr << ex.toString() << std::endl;
}
/// Parser error-reporting function can be overridden in subclass
virtual void reportError(const ANTLR_USE_NAMESPACE(std)string& s)
{
importer->addMessageToLog("Parser error: " + s);
std::cerr << s << std::endl;
}
/// Parser warning-reporting function can be overridden in subclass
virtual void reportWarning(const ANTLR_USE_NAMESPACE(std)string& s)
{
importer->addMessageToLog("Parser warning: " + s);
std::cerr << s << std::endl;
}
}
cfgfile
:
(
comment
|
interface_line
|
hwaddr_line
|
inet_address
|
inet6_address
|
groups
|
unknown_line
|
NEWLINE
|
DOUBLE_NEWLINE
)*
;
//****************************************************************
comment
: LINE_COMMENT ;
//****************************************************************
unknown_line
:
(
PRIORITY
|
MEDIA
|
STATUS
|
WORD
)
{
consumeUntil(NEWLINE);
}
;
//****************************************************************
//
// lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33200
// vic0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
// enc0: flags=0<> mtu 1536
//
interface_line { InterfaceSpec is; }
:
in:WORD COLON FLAGS EQUAL INT_CONST
{
// interface name and status
is.name = in->getText();
importer->newInterface(is);
consumeUntil(NEWLINE);
}
;
//****************************************************************
hwaddr_line
:
LLADDR addr:MAC_ADDRESS
{
importer->HwAddressForCurrentInterface(addr->getText());
}
;
//****************************************************************
//
// BSD: inet 10.3.14.81 netmask 0xffffff00 broadcast 10.3.14.255
inet_address { AddressSpec as; }
:
INET addr:IPV4 NETMASK netm:HEX_CONST BROADCAST bcast:IPV4
{
as.at = AddressSpec::INTERFACE_CONFIGURATION;
as.address = addr->getText();
as.netmask = netm->getText();
as.broadcast = bcast->getText();
importer->inetConfigurationForCurrentInterface(as);
}
;
//****************************************************************
// BSD: inet6 fe80::20c:29ff:fe3f:ac3c%vic0 prefixlen 64 scopeid 0x1
inet6_address { AddressSpec as; }
:
INET6 addr:IPV6 PERCENT WORD PREFIXLEN netm:INT_CONST SCOPEID HEX_CONST
{
as.at = AddressSpec::INTERFACE_CONFIGURATION;
as.address = addr->getText();
as.netmask = netm->getText();
importer->inet6ConfigurationForCurrentInterface(as);
}
;
//****************************************************************
groups
:
GROUPS COLON groups_list NEWLINE
;
groups_list
:
WORD { importer->addGroupToCurrentInterface(LT(0)->getText()); }
(
WORD { importer->addGroupToCurrentInterface(LT(0)->getText()); }
)*
;
//****************************************************************
class IfconfigBSDCfgLexer extends Lexer;
options
{
k = 3;
// ASCII only
charVocabulary = '\3'..'\377';
}
tokens
{
INET = "inet";
INET6 = "inet6";
FLAGS = "flags";
LINK = "Link";
GLOBAL = "Global";
HOST = "Host";
ADDR = "addr";
BCAST = "Bcast";
P_T_P = "P-t-P";
MASK = "Mask";
BROADCAST = "broadcast";
NETMASK = "netmask";
PREFIXLEN = "prefixlen";
SCOPEID = "scopeid";
SCOPE = "Scope";
GROUPS = "groups";
MTU = "mtu";
ENCAP = "encap";
LOOPBACK = "Loopback";
UP = "UP";
UPPER_BROADCAST = "BROADCAST";
UPPER_POINTOPOINT = "POINTOPOINT";
UPPER_LOOPBACK = "LOOPBACK";
UPPER_NOARP = "NOARP";
UPPER_RUNNING = "RUNNING";
RX = "RX";
TX = "TX";
COLLISIONS = "collisions";
INTERRUPT = "Interrupt";
PRIORITY = "priority";
MEDIA = "media";
STATUS = "status";
HWADDR = "HWaddr";
LLADR = "lladdr";
}
LINE_COMMENT : "#" (~('\r' | '\n'))* NEWLINE ;
Whitespace : ( '\003'..'\010' | '\t' | '\013' | '\f' | '\016'.. '\037' | '\177'..'\377' | ' ' )
{ $setType(ANTLR_USE_NAMESPACE(antlr)Token::SKIP); } ;
protected
INT_CONST:;
protected
HEX_CONST:;
protected
NUMBER:;
protected
NEG_INT_CONST:;
protected
COLON : ;
protected
HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
protected
DIGIT : '0'..'9' ;
protected
NUM_3DIGIT: ('0'..'9') (('0'..'9') ('0'..'9')?)? ;
protected
NUM_HEX_4DIGIT: HEX_DIGIT ((HEX_DIGIT) ((HEX_DIGIT) (HEX_DIGIT)?)?)? ;
protected
MAC_ADDRESS : ;
NUMBER_ADDRESS_OR_WORD
options {
testLiterals = true;
}
:
( NUM_3DIGIT '.' NUM_3DIGIT '.' ) =>
(NUM_3DIGIT '.' NUM_3DIGIT '.' NUM_3DIGIT '.' NUM_3DIGIT)
{ $setType(IPV4); }
//
// MAC adress rule - exactly 6 COLON separated ints
//
| (NUM_HEX_4DIGIT ':' NUM_HEX_4DIGIT ':'
NUM_HEX_4DIGIT ':' NUM_HEX_4DIGIT ':'
NUM_HEX_4DIGIT ':' NUM_HEX_4DIGIT ~(':') )=>
(
NUM_HEX_4DIGIT ':' NUM_HEX_4DIGIT ':'
NUM_HEX_4DIGIT ':' NUM_HEX_4DIGIT ':'
NUM_HEX_4DIGIT ':' NUM_HEX_4DIGIT
) { $setType(MAC_ADDRESS); }
// IPv6 RULE
| (NUM_HEX_4DIGIT ':')=>
(
((NUM_HEX_4DIGIT ':')+ ':')=>
(
(NUM_HEX_4DIGIT ':')+ ':'
(NUM_HEX_4DIGIT (':' NUM_HEX_4DIGIT)*)?
) { $setType(IPV6); }
| NUM_HEX_4DIGIT (':' NUM_HEX_4DIGIT)+
{ $setType(IPV6); }
) { $setType(IPV6); }
| (':' ':' NUM_HEX_4DIGIT)=>
':' ':' NUM_HEX_4DIGIT (':' NUM_HEX_4DIGIT)* { $setType(IPV6); }
| ':' ':' { $setType(IPV6); }
| ':' { $setType(COLON); }
| ( (DIGIT)+ '.' (DIGIT)+ )=> ( (DIGIT)+ '.' (DIGIT)+ )
{ $setType(NUMBER); }
| ( DIGIT )+ { $setType(INT_CONST); }
| '0' ('x' | 'X') HEX_DIGIT ( HEX_DIGIT )* { $setType(HEX_CONST); }
// making sure ',' '(' ')' '=' '<' '>' '+' are not part of WORD
// double quote " should be included, without it STRING does not match
| ( 'a'..'z' | 'A'..'Z' )
( '"' | '$' | '%' | '&' | '-' | '0'..'9' | ';' |
'?' | '@' | 'A'..'Z' | '\\' | '^' | '_' | '`' | 'a'..'z' )*
{ $setType(WORD); }
;
NEWLINE : ( "\r\n" | '\r' | '\n' ) { newline(); } ;
// DOUBLE_NEWLINE : NEWLINE NEWLINE ;
// protected
// NEWLINE :;
// protected
// DOUBLE_NEWLINE : ;
// NEWLINES
// :
// ( ( "\r\n" | '\r' | '\n' ) ~('\r' | '\n') ) =>
// ( "\r\n" | '\r' | '\n' ) { $setType(NEWLINE); }
// |
// ( "\r\n\r\n" | "\r\r" | "\n\n" ) { $setType(DOUBLE_NEWLINE); }
// ;
PERCENT : '%' ;
AMPERSAND : '&' ;
STAR : '*' ;
MINUS : '-' ;
DOT : '.' ;
SLASH : '/' ;
EQUAL : '=';
QUESTION : '?' ;
OPENING_PAREN : '(' ;
CLOSING_PAREN : ')' ;
OPENING_SQUARE : '[' ;
CLOSING_SQUARE : ']' ;
OPENING_BRACE : '{' ;
CLOSING_BRACE : '}' ;
LESS_THAN : '<' ;
GREATER_THAN : '>' ;

View File

@ -1,488 +0,0 @@
/*
Firewall Builder
Copyright (C) 2011 NetCitadel, LLC
Author: Vadim Kurland vadim@fwbuilder.org
This program is free software which we release under the GNU General Public
License. You may redistribute and/or modify this program under the terms
of that license as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To get a copy of the GNU General Public License, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
header "pre_include_hpp"
{
// gets inserted before antlr generated includes in the header
// file
#include "IfconfigImporter.h"
}
header "post_include_hpp"
{
// gets inserted after antlr generated includes in the header file
// outside any generated namespace specifications
#include <iostream>
#include <sstream>
class IfconfigImporter;
}
header "pre_include_cpp"
{
// gets inserted before the antlr generated includes in the cpp
// file
}
header "post_include_cpp"
{
// gets inserted after the antlr generated includes in the cpp
// file
#include <antlr/Token.hpp>
#include <antlr/TokenBuffer.hpp>
}
header
{
// gets inserted after generated namespace specifications in the
// header file. But outside the generated class.
}
options
{
language="Cpp";
}
class IfconfigLinuxCfgParser extends Parser;
options
{
k = 2;
// when default error handler is disabled, parser errors cause
// exception and terminate parsing process. We can catch the exception
// and make the error appear in importer log, but import process
// terminates which is not always optimal
//
// defaultErrorHandler = false;
// see http://www.antlr2.org/doc/options.html
}
{
// additional methods and members
public:
std::ostream *dbg;
IfconfigImporter *importer;
/// Parser error-reporting function can be overridden in subclass
virtual void reportError(const ANTLR_USE_NAMESPACE(antlr)RecognitionException& ex)
{
importer->addMessageToLog("Parser error: " + ex.toString());
std::cerr << ex.toString() << std::endl;
}
/// Parser error-reporting function can be overridden in subclass
virtual void reportError(const ANTLR_USE_NAMESPACE(std)string& s)
{
importer->addMessageToLog("Parser error: " + s);
std::cerr << s << std::endl;
}
/// Parser warning-reporting function can be overridden in subclass
virtual void reportWarning(const ANTLR_USE_NAMESPACE(std)string& s)
{
importer->addMessageToLog("Parser warning: " + s);
std::cerr << s << std::endl;
}
}
cfgfile
:
(
comment
|
interface_line
|
hwaddr_line
|
inet_address
|
inet6_address
|
groups
|
interface_flags
|
interface_statistics
|
unknown_line
|
NEWLINE
|
DOUBLE_NEWLINE
)*
;
//****************************************************************
comment
: LINE_COMMENT ;
//****************************************************************
unknown_line
:
(
PRIORITY
|
MEDIA
|
STATUS
|
WORD
)
{
consumeUntil(NEWLINE);
}
;
interface_flags
:
(
UP
|
UPPER_BROADCAST
|
UPPER_POINTOPOINT
|
UPPER_LOOPBACK
|
UPPER_NOARP
|
UPPER_RUNNING
|
LOOPBACK
)
{
consumeUntil(NEWLINE);
}
;
interface_statistics
:
(
( ( INTERRUPT | COLLISIONS ) COLON )
|
RX
|
TX
)
{
consumeUntil(NEWLINE);
}
;
//****************************************************************
//
// lo Link encap:Local Loopback
// eth0 Link encap:Ethernet HWaddr 00:0c:29:5f:12:cb
// he-ipv6 Link encap:IPv6-in-IPv4
// sit0 Link encap:IPv6-in-IPv4
//
interface_line { InterfaceSpec is; }
:
in1:WORD
( DOT in2:INT_CONST )?
( COLON ( lbl1:WORD | lbl2:INT_CONST ) )?
LINK ENCAP COLON WORD
{
// interface name and status
if (in2) is.name = in1->getText() + "." + in2->getText();
else is.name = in1->getText();
if (lbl1) is.label = lbl1->getText();
if (lbl2) is.label = lbl2->getText();
importer->newInterface(is);
}
;
//****************************************************************
hwaddr_line
:
HWADDR addr:MAC_ADDRESS
{
importer->HwAddressForCurrentInterface(addr->getText());
}
;
//****************************************************************
//
// Linux: inet addr:10.10.11.11 Bcast:10.10.11.255 Mask:255.255.255.0
inet_address { AddressSpec as; }
:
INET ADDR COLON
addr:IPV4
{
as.at = AddressSpec::INTERFACE_CONFIGURATION;
as.address = addr->getText();
}
(
( ( BCAST COLON bcast:IPV4 )? MASK COLON netm:IPV4 )
{
as.netmask = netm->getText();
if (bcast) as.broadcast = bcast->getText();
}
|
( P_T_P COLON IPV4 MASK COLON IPV4 )
{
// we do not support p2p interfaces at this time
}
)
{
importer->inetConfigurationForCurrentInterface(as);
}
;
//****************************************************************
// Linux: inet6 addr: fe80::20c:29ff:fe5f:12cb/64 Scope:Link
inet6_address { AddressSpec as; }
:
INET6 ADDR COLON addr:IPV6 SLASH netm:INT_CONST SCOPE COLON (HOST | LINK | GLOBAL | INT_CONST)
{
as.at = AddressSpec::INTERFACE_CONFIGURATION;
as.address = addr->getText();
as.netmask = netm->getText();
importer->inet6ConfigurationForCurrentInterface(as);
}
;
//****************************************************************
groups
:
GROUPS COLON groups_list NEWLINE
;
groups_list
:
WORD { importer->addGroupToCurrentInterface(LT(0)->getText()); }
(
WORD { importer->addGroupToCurrentInterface(LT(0)->getText()); }
)*
;
//****************************************************************
class IfconfigLinuxCfgLexer extends Lexer;
options
{
k = 3;
// ASCII only
charVocabulary = '\3'..'\377';
}
tokens
{
INET = "inet";
INET6 = "inet6";
FLAGS = "flags";
LINK = "Link";
GLOBAL = "Global";
HOST = "Host";
ADDR = "addr";
BCAST = "Bcast";
P_T_P = "P-t-P";
MASK = "Mask";
BROADCAST = "broadcast";
NETMASK = "netmask";
PREFIXLEN = "prefixlen";
SCOPEID = "scopeid";
SCOPE = "Scope";
GROUPS = "groups";
MTU = "mtu";
ENCAP = "encap";
LOOPBACK = "Loopback";
UP = "UP";
UPPER_BROADCAST = "BROADCAST";
UPPER_POINTOPOINT = "POINTOPOINT";
UPPER_LOOPBACK = "LOOPBACK";
UPPER_NOARP = "NOARP";
UPPER_RUNNING = "RUNNING";
RX = "RX";
TX = "TX";
COLLISIONS = "collisions";
INTERRUPT = "Interrupt";
PRIORITY = "priority";
MEDIA = "media";
STATUS = "status";
HWADDR = "HWaddr";
LLADR = "lladdr";
}
LINE_COMMENT : "#" (~('\r' | '\n'))* NEWLINE ;
Whitespace : ( '\003'..'\010' | '\t' | '\013' | '\f' | '\016'.. '\037' | '\177'..'\377' | ' ' )
{ $setType(ANTLR_USE_NAMESPACE(antlr)Token::SKIP); } ;
protected
INT_CONST:;
protected
HEX_CONST:;
protected
NUMBER:;
protected
NEG_INT_CONST:;
protected
COLON : ;
protected
HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
protected
DIGIT : '0'..'9' ;
protected
NUM_3DIGIT: ('0'..'9') (('0'..'9') ('0'..'9')?)? ;
protected
NUM_HEX_4DIGIT: HEX_DIGIT ((HEX_DIGIT) ((HEX_DIGIT) (HEX_DIGIT)?)?)? ;
protected
MAC_ADDRESS : ;
NUMBER_ADDRESS_OR_WORD
options {
testLiterals = true;
}
:
( NUM_3DIGIT '.' NUM_3DIGIT '.' ) =>
(NUM_3DIGIT '.' NUM_3DIGIT '.' NUM_3DIGIT '.' NUM_3DIGIT)
{ $setType(IPV4); }
//
// MAC adress rule - exactly 6 COLON separated ints
//
| (NUM_HEX_4DIGIT ':' NUM_HEX_4DIGIT ':'
NUM_HEX_4DIGIT ':' NUM_HEX_4DIGIT ':'
NUM_HEX_4DIGIT ':' NUM_HEX_4DIGIT ~(':') )=>
(
NUM_HEX_4DIGIT ':' NUM_HEX_4DIGIT ':'
NUM_HEX_4DIGIT ':' NUM_HEX_4DIGIT ':'
NUM_HEX_4DIGIT ':' NUM_HEX_4DIGIT
) { $setType(MAC_ADDRESS); }
// IPv6 RULE
| (NUM_HEX_4DIGIT ':')=>
(
((NUM_HEX_4DIGIT ':')+ ':')=>
(
(NUM_HEX_4DIGIT ':')+ ':'
(NUM_HEX_4DIGIT (':' NUM_HEX_4DIGIT)*)?
) { $setType(IPV6); }
| NUM_HEX_4DIGIT (':' NUM_HEX_4DIGIT)+
{ $setType(IPV6); }
) { $setType(IPV6); }
| (':' ':' NUM_HEX_4DIGIT)=>
':' ':' NUM_HEX_4DIGIT (':' NUM_HEX_4DIGIT)* { $setType(IPV6); }
| ':' ':' { $setType(IPV6); }
| ':' { $setType(COLON); }
| ( (DIGIT)+ '.' (DIGIT)+ )=> ( (DIGIT)+ '.' (DIGIT)+ )
{ $setType(NUMBER); }
| ( DIGIT )+ { $setType(INT_CONST); }
| '0' ('x' | 'X') HEX_DIGIT ( HEX_DIGIT )* { $setType(HEX_CONST); }
// making sure ',' '(' ')' '=' '<' '>' '+' are not part of WORD
// double quote " should be included, without it STRING does not match
| ( 'a'..'z' | 'A'..'Z' )
( '"' | '$' | '%' | '&' | '-' | '0'..'9' | ';' |
'?' | '@' | 'A'..'Z' | '\\' | '^' | '_' | '`' | 'a'..'z' )*
{ $setType(WORD); }
;
NEWLINE : ( "\r\n" | '\r' | '\n' ) { newline(); } ;
// DOUBLE_NEWLINE : NEWLINE NEWLINE ;
// protected
// NEWLINE :;
// protected
// DOUBLE_NEWLINE : ;
// NEWLINES
// :
// ( ( "\r\n" | '\r' | '\n' ) ~('\r' | '\n') ) =>
// ( "\r\n" | '\r' | '\n' ) { $setType(NEWLINE); }
// |
// ( "\r\n\r\n" | "\r\r" | "\n\n" ) { $setType(DOUBLE_NEWLINE); }
// ;
PERCENT : '%' ;
AMPERSAND : '&' ;
STAR : '*' ;
MINUS : '-' ;
DOT : '.' ;
SLASH : '/' ;
EQUAL : '=';
QUESTION : '?' ;
OPENING_PAREN : '(' ;
CLOSING_PAREN : ')' ;
OPENING_SQUARE : '[' ;
CLOSING_SQUARE : ']' ;
OPENING_BRACE : '{' ;
CLOSING_BRACE : '}' ;
LESS_THAN : '<' ;
GREATER_THAN : '>' ;

View File

@ -1,158 +0,0 @@
/*
Firewall Builder
Copyright (C) 2011 NetCitadel, LLC
Author: Vadim Kurland vadim@fwbuilder.org
This program is free software which we release under the GNU General Public
License. You may redistribute and/or modify this program under the terms
of that license as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To get a copy of the GNU General Public License, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "IfconfigImporterTest.h"
#include "config.h"
#include "global.h"
#include <fstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <stdexcept>
#include <assert.h>
#include "Importer.h"
#include "IfconfigImporter.h"
#include "FWBTree.h"
#include "fwbuilder/Policy.h"
#include "fwbuilder/Rule.h"
#include "fwbuilder/TagService.h"
#include "fwbuilder/Constants.h"
#include <QDebug>
#include <QFile>
#include <QStringList>
#include <QString>
#include <QRegExp>
using namespace std;
using namespace libfwbuilder;
extern string platform;
extern QString findBestVersionMatch(const QString &platform,
const QString &discovered_version);
class UpgradePredicate: public XMLTools::UpgradePredicate
{
public:
virtual bool operator()(const string &) const
{
return false;
}
};
void IfconfigImporterTest::setUp()
{
FWBTree *tree = new FWBTree();
/* create database */
db = new FWObjectDatabase();
/* load the data file */
UpgradePredicate upgrade_predicate;
db->setReadOnly( false );
db->load( Constants::getStandardObjectsFilePath(),
&upgrade_predicate, Constants::getDTDDirectory());
db->setFileName("");
lib = Library::cast(tree->createNewLibrary(db));
lib->setName("User");
logger = new QueueLogger();
// this makes the test compile and link. There is a problem with
// dependencies, the test depends on libimport.a and additionally,
// PFImporter.cpp depends on this function that is implemented in
// platforms.cpp in libgui.a; however since libgui.a comes before
// libimport.a in linker command line, this function does not get
// pulled since it is not used anywhere except by this test module
// and so linking fails. Making this call creates dependency and
// pulls this function at linking time before libimport.a and its
// dependencies are considered
QString version = findBestVersionMatch("pf", "4.0");
}
std::string IfconfigImporterTest::openTestFile(const QString &file_name)
{
QFile f(file_name);
f.open(QFile::ReadOnly);
string buffer = QString(f.readAll()).toStdString();
f.close();
return buffer;
}
void IfconfigImporterTest::linuxIfconfigTest()
{
platform = "pf";
std::istringstream instream(
openTestFile("test_data/linux_ifconfig.test"));
IfconfigImporter* imp = new IfconfigImporter(
lib, instream, logger, "linux24", "test_fw");
CPPUNIT_ASSERT_NO_THROW( imp->run() );
imp->finalize();
while (logger->ready())
qDebug() << logger->getLine().c_str();
for (list<InterfaceSpec>::iterator it=imp->interfaces.begin();
it!=imp->interfaces.end(); ++it)
{
qDebug() << it->toString();
}
}
void IfconfigImporterTest::bsdIfconfigTest()
{
platform = "pf";
std::istringstream instream(
openTestFile("test_data/bsd_ifconfig.test"));
IfconfigImporter* imp = new IfconfigImporter(
lib, instream, logger, "openbsd", "test_fw");
CPPUNIT_ASSERT_NO_THROW( imp->run() );
imp->finalize();
while (logger->ready())
qDebug() << logger->getLine().c_str();
for (list<InterfaceSpec>::iterator it=imp->interfaces.begin();
it!=imp->interfaces.end(); ++it)
{
qDebug() << it->toString();
}
}

View File

@ -1,65 +0,0 @@
/*
Firewall Builder
Copyright (C) 2011 NetCitadel, LLC
Author: Vadim Kurland vadim@fwbuilder.org
This program is free software which we release under the GNU General Public
License. You may redistribute and/or modify this program under the terms
of that license as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To get a copy of the GNU General Public License, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef IFCONFIGIMPORTERTEST_H
#define IFCONFIGIMPORTERTEST_H
#include "fwbuilder/Resources.h"
#include "fwbuilder/FWObjectDatabase.h"
#include "fwbuilder/Library.h"
#include "fwbuilder/FWException.h"
#include "fwbuilder/Logger.h"
#include <cppunit/extensions/HelperMacros.h>
#include <map>
#include <fstream>
#include <iostream>
#include <QString>
class IfconfigImporterTest : public CppUnit::TestFixture
{
libfwbuilder::FWObjectDatabase *db;
libfwbuilder::Library *lib;
libfwbuilder::QueueLogger *logger;
std::string openTestFile(const QString &file_name);
public:
void setUp();
void linuxIfconfigTest();
void bsdIfconfigTest();
CPPUNIT_TEST_SUITE(IfconfigImporterTest);
CPPUNIT_TEST(linuxIfconfigTest);
CPPUNIT_TEST(bsdIfconfigTest);
CPPUNIT_TEST_SUITE_END();
};
#endif // IFCONFIGIMPORTERTEST_H

View File

@ -1,7 +0,0 @@
include(../tests_common.pri)
TARGET = IfconfigImporterTest
HEADERS += IfconfigImporterTest.h
SOURCES += main_IfconfigImporterTest.cpp \
IfconfigImporterTest.cpp

View File

@ -1,62 +0,0 @@
/*
Firewall Builder
Copyright (C) 2011 NetCitadel, LLC
Author: Vadim Kurland vadim@fwbuilder.org
This program is free software which we release under the GNU General Public
License. You may redistribute and/or modify this program under the terms
of that license as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To get a copy of the GNU General Public License, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/CompilerOutputter.h>
#include "IfconfigImporterTest.h"
#include "fwbuilder/Resources.h"
#include "FWWindow.h"
#include "FWBSettings.h"
#include "FWBApplication.h"
#include "UserWorkflow.h"
#include <QApplication>
#include <QString>
#include <string>
#include "../../../common/init.cpp"
int fwbdebug = 0;
//QString user_name;
FWWindow *mw = NULL;
FWBSettings *st = NULL;
FWBApplication *app = NULL;
UserWorkflow *wfl;
int sig = FWB_SIG;
std::string platform;
int main(int argc, char** argv)
{
QApplication app(argc, argv, false);
init(argv);
Resources res(Constants::getResourcesFilePath());
CppUnit::TextUi::TestRunner runner;
runner.addTest( IfconfigImporterTest::suite() );
runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
std::cerr ) );
runner.run();
return 0;
}

View File

@ -1,24 +0,0 @@
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33200
priority: 0
groups: lo
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
vic0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
lladdr 00:0c:29:3f:ac:3c
priority: 0
groups: egress test
media: Ethernet autoselect
status: active
inet 10.1.1.81 netmask 0xffffff00 broadcast 10.1.1.255
inet6 fe80::20c:29ff:fe3f:ac3c%vic0 prefixlen 64 scopeid 0x1
vic1: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
lladdr 00:0c:29:3f:ac:46
priority: 0
media: Ethernet autoselect
status: no carrier
enc0: flags=0<> mtu 1536
priority: 0
pflog0: flags=141<UP,RUNNING,PROMISC> mtu 33200
priority: 0
groups: pflog

View File

@ -1,99 +0,0 @@
eth0 Link encap:Ethernet HWaddr 00:0d:61:42:3e:87
inet addr:192.168.1.170 Bcast:192.168.1.175 Mask:255.255.255.248
inet6 addr: 2001:db8:1f0f:162::2/64 Scope:Global
inet6 addr: fe80::20d:61ff:fe42:3e87/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:289714859 errors:0 dropped:0 overruns:0 frame:0
TX packets:364926248 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1900107617 (1.9 GB) TX bytes:3300213065 (3.3 GB)
eth1 Link encap:Ethernet HWaddr 00:0c:29:1e:dc:b4
inet addr:10.1.1.1 Bcast:10.1.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe1e:dcb4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:23 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1380 (1.3 KB) TX bytes:468 (468.0 B)
Interrupt:19 Base address:0x2080
eth1:1 Link encap:Ethernet HWaddr 00:0c:29:1e:dc:b4
inet addr:192.168.123.123 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:19 Base address:0x2080
eth1:foo Link encap:Ethernet HWaddr 00:0c:29:1e:dc:b4
inet addr:192.168.123.124 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:19 Base address:0x2080
he-ipv6 Link encap:IPv6-in-IPv4
inet6 addr: 2001:db8:1f0e:162::2/64 Scope:Global
inet6 addr: fe80::4655:afaa/128 Scope:Link
UP POINTOPOINT RUNNING NOARP MTU:1480 Metric:1
RX packets:121699 errors:0 dropped:0 overruns:0 frame:0
TX packets:153317 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:10257741 (10.2 MB) TX bytes:186526967 (186.5 MB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8149 errors:0 dropped:0 overruns:0 frame:0
TX packets:8149 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:713074 (713.0 KB) TX bytes:713074 (713.0 KB)
sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.11.11.11 P-t-P:10.12.12.12 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:416 errors:0 dropped:0 overruns:0 frame:0
TX packets:397 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:253765 (247.8 Kb) TX bytes:62621 (61.1 Kb)
eth1.100 Link encap:Ethernet HWaddr 00:0c:29:1e:dc:b4
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
eth1.100:1 Link encap:Ethernet HWaddr 00:0c:29:1e:dc:b4
inet addr:192.168.222.1 Bcast:0.0.0.0 Mask:255.255.255.0
BROADCAST MULTICAST MTU:1500 Metric:1
eth1.100:foo Link encap:Ethernet HWaddr 00:0c:29:1e:dc:b4
inet addr:192.168.222.2 Bcast:0.0.0.0 Mask:255.255.255.0
BROADCAST MULTICAST MTU:1500 Metric:1
eth1.0100 Link encap:Ethernet HWaddr 00:0c:29:1e:dc:b4
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
vlan100 Link encap:Ethernet HWaddr 00:0c:29:1e:dc:b4
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
vlan0100 Link encap:Ethernet HWaddr 00:0c:29:1e:dc:b4
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)