first working example: Two tun devices + nfnetlink-conntrack
This commit is contained in:
parent
8fd5e2ae6b
commit
bae934d467
|
@ -67,34 +67,34 @@ ARCHIVE_DIR = backup
|
|||
#
|
||||
|
||||
# TTCN-3 modules of this project:
|
||||
TTCN3_MODULES = IPL4asp_Functions.ttcn IPL4asp_PortType.ttcn IPL4asp_Types.ttcn Socket_API_Definitions.ttcn TCCConversion_Functions.ttcn TCCInterface_Functions.ttcn
|
||||
TTCN3_MODULES = IPL4_example.ttcn NetfilterConntrack_Functions.ttcn TunDevice_PortType.ttcn TunDevice_Types.ttcn UsefulTtcn3Types.ttcn XSD.ttcn http_www_netfilter_org_xml_libnetfilter_conntrack.ttcn
|
||||
|
||||
# ASN.1 modules of this project:
|
||||
ASN1_MODULES =
|
||||
|
||||
# C++ source & header files generated from the TTCN-3 & ASN.1 modules of
|
||||
# this project:
|
||||
GENERATED_SOURCES = IPL4asp_Functions.cc IPL4asp_PortType.cc IPL4asp_Types.cc Socket_API_Definitions.cc TCCConversion_Functions.cc TCCInterface_Functions.cc
|
||||
GENERATED_HEADERS = IPL4asp_Functions.hh IPL4asp_PortType.hh IPL4asp_Types.hh Socket_API_Definitions.hh TCCConversion_Functions.hh TCCInterface_Functions.hh
|
||||
GENERATED_SOURCES = IPL4_example.cc NetfilterConntrack_Functions.cc TunDevice_PortType.cc TunDevice_Types.cc UsefulTtcn3Types.cc XSD.cc http_www_netfilter_org_xml_libnetfilter_conntrack.cc
|
||||
GENERATED_HEADERS = IPL4_example.hh NetfilterConntrack_Functions.hh TunDevice_PortType.hh TunDevice_Types.hh UsefulTtcn3Types.hh XSD.hh http_www_netfilter_org_xml_libnetfilter_conntrack.hh
|
||||
|
||||
# C/C++ Source & header files of Test Ports, external functions and
|
||||
# other modules:
|
||||
USER_SOURCES = IPL4asp_PT.cc IPL4asp_discovery.cc TCCConversion.cc TCCInterface.cc
|
||||
USER_HEADERS = IPL4asp_PT.hh IPL4asp_protocol_L234.hh
|
||||
USER_SOURCES = NetfilterConntrack.cc Socket_API_Definitions.cc TunDevice_PT.cc
|
||||
USER_HEADERS = Socket_API_Definitions.hh TunDevice_PT.hh
|
||||
|
||||
# Object files of this project that are needed for the executable test suite:
|
||||
OBJECTS = $(GENERATED_OBJECTS) $(USER_OBJECTS)
|
||||
|
||||
GENERATED_OBJECTS = IPL4asp_Functions.o IPL4asp_PortType.o IPL4asp_Types.o Socket_API_Definitions.o TCCConversion_Functions.o TCCInterface_Functions.o
|
||||
GENERATED_OBJECTS = IPL4_example.o NetfilterConntrack_Functions.o TunDevice_PortType.o TunDevice_Types.o UsefulTtcn3Types.o XSD.o http_www_netfilter_org_xml_libnetfilter_conntrack.o
|
||||
|
||||
USER_OBJECTS = IPL4asp_PT.o IPL4asp_discovery.o TCCConversion.o TCCInterface.o
|
||||
USER_OBJECTS = NetfilterConntrack.o Socket_API_Definitions.o TunDevice_PT.o
|
||||
|
||||
# Other files of the project (Makefile, configuration files, etc.)
|
||||
# that will be added to the archived source files:
|
||||
OTHER_FILES = Makefile
|
||||
|
||||
# The name of the executable test suite:
|
||||
EXECUTABLE = IPL4asp_Functions
|
||||
EXECUTABLE = IPL4_example
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,21 @@ namespace NetfilterConntrack__Functions
|
|||
return NFCT_CB_CONTINUE;
|
||||
}
|
||||
|
||||
struct nfct_handle *_nfct_init(CHARSTRING *ret_val)
|
||||
{
|
||||
struct nfct_handle *h;
|
||||
|
||||
h = nfct_open(CONNTRACK, 0);
|
||||
if (!h) {
|
||||
perror("nfct_open");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nfct_callback_register(h, NFCT_T_ALL, cb, (void *) ret_val);
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
/* external function exposed to TTCN3 */
|
||||
CHARSTRING f__get__conntracks__xml(void)
|
||||
{
|
||||
|
@ -31,23 +46,38 @@ namespace NetfilterConntrack__Functions
|
|||
struct nfct_handle *h;
|
||||
uint32_t family = AF_INET;
|
||||
int rc;
|
||||
CHARSTRING ret_val("");
|
||||
CHARSTRING ret_val("<flows xmlns=\"http://www.netfilter.org/xml/libnetfilter_conntrack\">");
|
||||
|
||||
h = nfct_open(CONNTRACK, 0);
|
||||
if (!h) {
|
||||
perror("nfct_open");
|
||||
h = _nfct_init(&ret_val);
|
||||
|
||||
rc = nfct_query(h, NFCT_Q_DUMP, &family);
|
||||
if (rc < 0) {
|
||||
ret_val += "</flows>";
|
||||
return ret_val;
|
||||
}
|
||||
printf("ret_val=%p\n", &ret_val);
|
||||
|
||||
nfct_callback_register(h, NFCT_T_ALL, cb, (void *) &ret_val);
|
||||
rc = nfct_query(h, NFCT_Q_DUMP, &family);
|
||||
if (rc < 0)
|
||||
return ret_val;
|
||||
|
||||
nfct_close(h);
|
||||
|
||||
ret_val += "</flows>";
|
||||
return ret_val;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* get a single conntrack entry for given 5-tuple */
|
||||
CHARSTRING f_get_conntrack_xml(CHARSTRING& src_ip, CHARSTRING& dst_ip, INTEGER& proto, INTEGER& src_port, INTEGER& dst_port)
|
||||
{
|
||||
struct nfct_handle *h;
|
||||
uint32_t family = AF_INET;
|
||||
int rc;
|
||||
CHARSTRING ret_val("<flows xmlns=\"http://www.netfilter.org/xml/libnetfilter_conntrack\">");
|
||||
|
||||
h = _nfct_init(&ret_val);
|
||||
|
||||
/* FIXME: actually query */
|
||||
|
||||
nfct_close(h);
|
||||
|
||||
ret_val += "</flows>";
|
||||
return ret_val;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
module NetfilterConntrack_Functions {
|
||||
|
||||
external function f_get_conntracks_xml() return charstring;
|
||||
//external function f_get_conntrack_xml(charstring src_ip, charstring dst_ip, integer proto, integer src_port, integer dst_port) return charstring;
|
||||
|
||||
}
|
||||
|
|
|
@ -93,9 +93,6 @@ TunDevice__PT_PROVIDER::TunDevice__PT_PROVIDER(const char *par_port_name)
|
|||
tun_data.fd = -1;
|
||||
tun_data.dev = NULL;
|
||||
debugging = false;
|
||||
|
||||
tun_data.dev = strdup("foo"); /* FIXME */
|
||||
debugging = true; /* FIXME */
|
||||
}
|
||||
|
||||
TunDevice__PT_PROVIDER::~TunDevice__PT_PROVIDER()
|
||||
|
@ -109,6 +106,7 @@ TunDevice__PT_PROVIDER::~TunDevice__PT_PROVIDER()
|
|||
void TunDevice__PT_PROVIDER::set_parameter(const char *parameter_name,
|
||||
const char *parameter_value)
|
||||
{
|
||||
printf("%s(%s, %s)\n", __func__, parameter_name, parameter_value);
|
||||
if (!strcmp(parameter_name, "device_name"))
|
||||
tun_data.dev = strdup(parameter_value);
|
||||
if (!strcmp(parameter_name, "debugging"))
|
||||
|
|
|
@ -22,3 +22,5 @@ gen_links $DIR $FILES
|
|||
DIR=$BASEDIR/titan.Libraries.TCCUsefulFunctions/src
|
||||
FILES="TCCInterface_Functions.ttcn TCCConversion_Functions.ttcn TCCConversion.cc TCCInterface.cc TCCInterface_ip.h"
|
||||
gen_links $DIR $FILES
|
||||
|
||||
xsd2ttcn libnetfilter_conntrack.xsd
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
FILES="*.ttcn *.cc *.hh"
|
||||
|
||||
ttcn3_makefilegen -f $FILES
|
||||
ttcn3_makefilegen -f IPL4_example.ttcn $FILES
|
||||
sed -i -e 's/# TTCN3_DIR = /TTCN3_DIR = \/usr/' Makefile
|
||||
sed -i -e 's/LDFLAGS = /LDFLAGS = -L \/usr\/lib\/titan `pkg-config --libs libnetfilter_conntrack`/' Makefile
|
||||
sed -i -e 's/TTCN3_LIB = ttcn3-parallel/TTCN3_LIB = ttcn3/' Makefile
|
||||
|
|
Loading…
Reference in New Issue