Commit 16901714 authored by 's avatar

Added support for current combo6x card (replaced old combo6 driver).

Regular make support instead of extra_dist.



git-svn-id: file:///home/svn/mapi/trunk@1495 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 4ad519a8
......@@ -8,6 +8,7 @@ ACLOCAL_AMFLAGS = -I .
EXTRA_DIST = COPYING INSTALL applications tests \
config/mapi.conf.dag.entry \
config/mapi.conf.napatech.entry \
config/mapi.conf.combo6.entry \
config/mapi.conf.ipfixflib.entry
dist-hook:
......
[driver]
device=/dev/szedataIIO
driver=mapicombo6drv.so
description=Combo6x capture card
......@@ -323,6 +323,30 @@ else
fi
AC_SUBST_FILE(MAPI_CONF_NAPATECH_ENTRY)
# COMBO6 support
AC_MSG_CHECKING(if COMBO6 cards support is enabled)
AC_ARG_ENABLE(combo6,
AS_HELP_STRING([--enable-combo6], [Enable support for COMBO6 cards]),
[case "${enableval}" in
yes) combo6=true ;;
no) combo6=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-combo6) ;;
esac], [combo6=false])
AM_CONDITIONAL(DRIVER_COMBO6, test x$combo6 = xtrue)
AM_CONDITIONAL(BINARY_COMBO6FLIB, test x$combo6 = xtrue)
# AM_CONDITIONAL(PRECLASSIFICATION, test x$combo = xtrue)
if test x$combo6 = xtrue; then
MAPI_CONF_COMBO6_ENTRY=$srcdir/config/mapi.conf.combo6.entry
MAPI_FUNC_LIBS="${MAPI_FUNC_LIBS}:combo6flib.so"
# AC_DEFINE(PRECLASSIFICATION, 1, [hardware preliminary packet classification])
AC_DEFINE(WITH_COMBO6, 1, [if COMBO6 cards are supported])
AC_MSG_RESULT(yes)
else
MAPI_CONF_COMBO6_ENTRY=/dev/null
AC_MSG_RESULT(no)
fi
AC_SUBST_FILE(MAPI_CONF_COMBO6_ENTRY)
# optional MAPI function libraries
......@@ -644,6 +668,72 @@ AC_SUBST(NAPATECHINC)
AC_SUBST(NAPATECHLIB)
#
# libcombo6 (only for --enable-combo6)
#
AC_MSG_CHECKING([for libcombo6])
AC_ARG_WITH(libcombo6,
AS_HELP_STRING([--with-libcombo6=DIR], [Manual libcombo6 path configuration, in case the configuration script can't find it. Search for libcombo6 in DIR/lib, and for the header file in DIR/include and DIR/include/combo6. Effective only if --enable-combo6 has been previously specified]),
[ case "$withval" in
yes|no)
AC_MSG_RESULT(no)
;;
*)
if test x$combo6 = xfalse; then
AC_MSG_ERROR(Please use --with-libcombo6 only in conjunction with --enable-combo6. You don't need to configure libcombo6 if you are not going to use a Combo6 card.)
else
AC_MSG_RESULT($withval)
incdir=""
if test -f $withval/include/szedata2.h; then
incdir=$withval/include
elif test -f $withval/include/combo6/szedata2.h; then
incdir=$withval/include/combo6
fi
if test "x$incdir" != "x" -a -f $withval/lib/libsze2.so; then
owd=`pwd`
if cd $withval; then withval=`pwd`; cd $owd; fi
COMBO6INC="-I$incdir"
COMBO6LIB="-L$withval/lib -lsze2 -ldbus-1"
else
AC_MSG_ERROR(szedata2.h or libsze2.so not found in $withval/include and $withval/lib)
fi
fi
;;
esac ],
[ if test x$combo6 = xtrue; then
if test -f ${prefix}/include/szedata2.h -a -f ${prefix}/lib/libsze2.so; then
COMBO6INC="-I${prefix}/include"
COMBO6LIB="-L${prefix}/lib -lsze2 -ldbus-1"
elif test -f /opt/combo6/include/szedata2.h -a -f /opt/combo6/lib/libsze2.so; then
COMBO6INC="-I/opt/combo6/include"
COMBO6LIB="-L/opt/combo6/lib -lsze2 -ldbus-1"
elif test -f /opt/combo6/include/combo6/szedata2.h -a -f /opt/combo6/lib/libsze2.so; then
COMBO6INC="-I/opt/combo6/include/combo6"
COMBO6LIB="-L/opt/combo6/lib -lsze2 -ldbus-1"
elif test -f /usr/local/include/szedata2.h -a -f /usr/local/lib/libsze2.so; then
COMBO6INC="-I/usr/local/include"
COMBO6LIB="-L/usr/local/lib -lsze2 -ldbus-1"
elif test -f /usr/local/include/combo6/szedata2.h -a -f /usr/local/lib/libsze2.so; then
COMBO6INC="-I/usr/local/include/combo6"
COMBO6LIB="-L/usr/local/lib -lsze2 -ldbus-1"
elif test -f /usr/include/combo6/szedata2.h; then
COMBO6INC="-I/usr/include/combo6"
COMBO6LIB="-lsze2"
elif test -f /usr/include/szedata2.h; then
COMBO6LIB="szedata2.h"
else
AC_MSG_RESULT(no)
AC_MSG_ERROR([libcombo6 not found])
fi
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi ]
)
AC_SUBST(COMBO6INC)
AC_SUBST(COMBO6LIB)
#
# libnids >= 1.21 (only for --enable-extraflib)
......@@ -916,6 +1006,7 @@ AC_CONFIG_FILES([
src/bpfcompiler/pcap/Makefile
src/dagflib/Makefile
src/napatechflib/Makefile
src/combo6flib/Makefile
src/extraflib/Makefile
applications/Makefile
applications/appmon/Makefile
......@@ -948,6 +1039,9 @@ fi
if test x$napatech = xtrue; then
echo "option: support for Napatech cards"
fi
if test x$combo6 = xtrue; then
echo "option: support for Combo6 cards"
fi
if test x$authentication = xtrue; then
echo "option: authentication on"
fi
......
......@@ -19,6 +19,9 @@ endif
if BINARY_NAPATECHFLIB
BUILD_napatechflib = napatechflib
endif
if BINARY_COMBO6FLIB
BUILD_combo6flib = combo6flib
endif
if BINARY_EXTRAFLIB
BUILD_extraflib = extraflib
endif
......@@ -31,6 +34,7 @@ $(BUILD_ipfixflib) \
$(BUILD_anonflib) \
$(BUILD_dagflib) \
$(BUILD_napatechflib) \
$(BUILD_combo6flib) \
$(BUILD_extraflib)
#DIST_SUBDIRS =
......@@ -66,7 +70,7 @@ mapicommd_SOURCES = mapicommd.c
endif
EXTRA_DIST = errors.mapi combo6flib vod
EXTRA_DIST = errors.mapi vod
dist-hook:
rm -rf `find $(distdir)/combo6flib -name .svn`
......
AM_CPPFLAGS = -I$(srcdir)/.. -I$(srcdir)/../lib -I$(srcdir)/../common -I$(srcdir)/../bpfcompiler @PCAPINC@ @DAGINC@ @NAPATECHINC@ -D_NT_OS_TYPE=_NT_OS_TYPE_LINUX -D_GNU_SOURCE -D_THREAD_SAFE
AM_CPPFLAGS = -I$(srcdir)/.. -I$(srcdir)/../lib -I$(srcdir)/../common -I$(srcdir)/../bpfcompiler @PCAPINC@ @DAGINC@ @NAPATECHINC@ @COMBO6INC@ -D_NT_OS_TYPE=_NT_OS_TYPE_LINUX -D_GNU_SOURCE -D_THREAD_SAFE
libdir = $(pkgdatadir)
if DRIVER_DAG
......@@ -13,7 +13,11 @@ if DRIVER_NAPATECH
BUILD_napatechdrv = mapinapatechdrv.la
endif
lib_LTLIBRARIES = mapinicdrv.la mapivindrv.la $(BUILD_dagdrv) $(BUILD_enp2611drv) $(BUILD_napatechdrv)
if DRIVER_COMBO6
BUILD_combo6drv = mapicombo6drv.la
endif
lib_LTLIBRARIES = mapinicdrv.la mapivindrv.la $(BUILD_dagdrv) $(BUILD_enp2611drv) $(BUILD_napatechdrv) $(BUILD_combo6drv)
# mapi device drivers are dynamically loadable modules (but not standalone
# libraries for users)
......@@ -76,4 +80,17 @@ mapinapatechdrv_la_LIBADD = \
mapinapatechdrv_la_SOURCES = mapinapatechdrv.c mapidlib.c mapidlib.h mapidrv.h
endif
EXTRA_DIST = mapicombo6drv.c
if DRIVER_COMBO6
mapicombo6drv_la_LDFLAGS = -module
mapicombo6drv_la_LIBADD = \
../common/libflist.la \
../common/libmapiipc.la \
../common/libparseconf.la \
../common/libprintfstring.la \
../common/libmapilibhandler.la \
../common/libdebug.la \
-lrt @COMBO6LIB@
mapicombo6drv_la_SOURCES = mapicombo6drv.c mapidlib.c mapidlib.h mapidrv.h
endif
#EXTRA_DIST =
......@@ -6,13 +6,14 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <fcntl.h>
#include <time.h>
#include <errno.h>
#include <pthread.h>
#include <pcap.h>
#include <sys/mman.h>
#include <sys/shm.h>
#include <net/bpf.h>
#include <sys/time.h>
#include "mapi.h"
#include "mapidrv.h"
......@@ -20,36 +21,30 @@
#include "mapid.h"
#include "mapidevices.h"
#include "flist.h"
#include "debug.h"
#include "mapi_errors.h"
#include "libscampi.h"
#include "libfilter.h" /* scampi_reset_classification() */
/* Suppress inclusion of types.h, because <linux/types.h> was already included */
#define _TYPES_H 1
#include "libscampi.h"
#include "scampi_kernel.h" // for packet descriptor
#define COMBO6STR "scampi"
__attribute__ ((constructor)) void init ();
__attribute__ ((destructor)) void fini ();
function_manipulation_t* manipulation;
#include "libsze2.h"
typedef struct combo6_instance {
char *name; //name of device
int id; //Device ID
int offline; //1 if this is an offline device
int file;
char *name;
int id;
pthread_attr_t th_attr;
pthread_t th_proc;
int combo6fd;
struct szedata *sze;
mapi_offline_device_status_t *offline_status;
mapid_hw_info_t hwinfo;
mapidlib_instance_t mapidlib;
} combo6_instance_t;
flist_t *devlist;
__attribute__ ((constructor)) void init ();
__attribute__ ((destructor)) void fini ();
int debug=0;
static flist_t *devlist;
/* for mapidlib errorcode */
int
......@@ -62,8 +57,8 @@ mapidrv_get_errno(int devid, int fd)
#ifdef WITH_AUTHENTICATION
int mapidrv_authenticate(int devid, int fd, char *vo)
{
combo6_instance_t *i = flist_get(devlist, devid);
return mapid_authenticate(&i->mapidlib, fd, vo);
combo6_instance_t *i = flist_get(devlist, devid);
return mapid_authenticate(&i->mapidlib, fd, vo);
}
#endif
......@@ -75,34 +70,37 @@ mapidrv_connect (int devid, int fd)
}
int
mapidrv_apply_function (int devid,int fd,int pid, char* function, mapiFunctArg *fargs)
mapidrv_apply_function (int devid, int fd, int flags, char* function, mapiFunctArg *fargs)
{
DEBUG_CMD(Debug_Message("combo6drv: mapidrv_apply_function; devid = %d; fd = %d; function = %s", devid, fd, function));
combo6_instance_t *i=flist_get(devlist,devid);
return mapid_apply_function(&i->mapidlib,fd,pid, function, fargs, manipulation);
}
/*
//Deprecated.
int
mapidrv_apply_function (int devid, int fd, char* function, mapiFunctArg *fargs)
{
combo6_instance_t *i=flist_get(devlist,devid);
// Sven
// printf("mapicombo6drv:mapidrv_apply_function(): calling mapid_apply_function()\n");
return mapid_apply_function(&i->mapidlib, fd, function, fargs);
int _flags = flags;
return mapid_apply_function(&i->mapidlib, fd, function, fargs, _flags);
}
*/
int mapidrv_add_device(mapi_offline_device_status_t *olstatus,char *devname, int file, int devid, function_manipulation_t* manip)
int mapidrv_add_device(const char *devname, int file,int devid, global_function_list_t *gflist,void *olstatus)
{
manipulation = manip;
DEBUG_CMD(Debug_Message("combo6drv: mapidrv_add_device"));
combo6_instance_t *i=malloc(sizeof(combo6_instance_t));
DEBUG_CMD(Debug_Message("combo6drv: mapidrv_add_device; devname: %s", devname));
i->name=strdup(devname);
i->id=devid;
i->combo6fd=0;
i->offline=0;
i->hwinfo.ff_list=malloc(sizeof(flist_t));
flist_init(i->hwinfo.ff_list);
i->file=file;
i->hwinfo.offline=0;
i->combo6fd = -1;
i->hwinfo.devfd=i->combo6fd;
i->hwinfo.gflist=gflist;
i->hwinfo.pkt_drop=0;
i->offline_status = olstatus;
if(devid<0)
i->hwinfo.offline = 1;
#ifdef DEBUG
printf("Added device %d: %s\n",devid,devname);
#endif
......@@ -115,81 +113,168 @@ int mapidrv_add_device(mapi_offline_device_status_t *olstatus,char *devname, int
return 0;
}
int mapidrv_delete_device(int devid)
{
DEBUG_CMD(Debug_Message("combo6drv: mapidrv_delete_device"));
combo6_instance_t *i=flist_remove(devlist,devid);
if (i!=NULL) {
int err=0;
if (i->th_proc && pthread_equal(i->th_proc, pthread_self())==0) {
DEBUG_CMD(Debug_Message("Calling thread != th_proc (%lu != %lu), cancelling", i->th_proc, pthread_self()));
fflush(stdout);
if ((err=pthread_cancel(i->th_proc))!=0) {
if (!(i->hwinfo.offline==1 && err==ESRCH)) {
DEBUG_CMD(Debug_Message("WARNING: Could not cancel thread for devid %d (%s)", devid, strerror(err)));
fflush(stdout);
}
}
}
if (i->hwinfo.offline==0) {
// TODO
szedata_close(i->sze);
} else {
if (i->file) {
close(i->file);
DEBUG_CMD(Debug_Message("Closed file"));
}
}
mapid_destroy(&i->mapidlib);
free(i->name);
if(i->offline_status != NULL)
*(i->offline_status) = DEVICE_DELETED;
free(i);
}
return 0;
}
static void
mapidrv_proc_loop (void *arg)
{
int devid = *(int *)arg;
unsigned char *dev_pkt;
unsigned char *link_pkt;
mapid_pkthdr_t mhdr;
struct scampi_mmap_packet_descriptor *descriptor;
combo6_instance_t *i=flist_get(devlist,devid);
char *fce="mapidrv_proc_loop()";
DEBUG_CMD(Debug_Message("combo6drv: mapidrv_proc_loop"));
int devid = *(int *)arg;
combo6_instance_t *i=flist_get(devlist,devid);
int err;
unsigned int rx = 0xff, tx = 0x00;
unsigned char *packet;
unsigned char *dev_pkt;
unsigned char *link_pkt;
unsigned int data_len;
mapid_pkthdr_t mhdr;
DEBUG_CMD(Debug_Message("combo6drv: subscribing: rx-0x%02hx tx-0x%02hx", rx, tx));
err = szedata_subscribe(i->sze, &rx, &tx, SZE2_RX_POLL_CNT, SZE2_TX_POLL_CNT);
if (err) {
DEBUG_CMD(Debug_Message("combo6drv: ERROR subscring."));
}
else {
DEBUG_CMD(Debug_Message("combo6drv: subscribed: rx-0x%02hx tx-0x%02hx", rx, tx));
}
err = szedata_start(i->sze);
if (err) {
DEBUG_CMD(Debug_Message("combo6drv: ERROR szedata_start()."));
}
else {
DEBUG_CMD(Debug_Message("combo6drv: szedata_start()."));
}
struct timeval ts; // FIXME
while (1)
{
if (debug)
printf("Debug: combo6fd: %d\n", i->combo6fd);
dev_pkt=scampi_get_next_packet(i->combo6fd, &descriptor);
if (dev_pkt==NULL) {
fprintf(stderr, "%s: scampi_get_next_packet() failed\n", fce);
exit(-1);
}
link_pkt=(unsigned char*)dev_pkt+(descriptor->hh_size);
mhdr.caplen=(descriptor->size)-(descriptor->hh_size);
mhdr.wlen=(descriptor->size)-(descriptor->hh_size);
mhdr.ts=descriptor->timestamp;
mhdr.ifindex=descriptor->if_index;
#ifdef PRECLASSIFICATION
mhdr.preclassification = 0; /* process all packets */
#endif
if (debug) {
unsigned char *p;
int j;
p=(unsigned char*)link_pkt;
printf("%s: Ethernet and IP headers: ", fce);
for (j=0; j<34; j++) {
printf("%02x", *p++);
if (((j-3)%4)==0)
printf(" ");
}
printf("\n");
}
packet = szedata_read_next(i->sze, &data_len);
//unsigned int data_len;
unsigned int hw_data_len;
unsigned char *data;
unsigned char *hw_data;
if(packet) {
//DEBUG_CMD(Debug_Message("combo6drv: packet..."));
szedata_decode_packet(packet, &data, &hw_data, &data_len, &hw_data_len);
dev_pkt = hw_data;
link_pkt = data;
mhdr.caplen=hw_data_len;
mhdr.wlen=data_len;
gettimeofday(&ts, NULL);
mhdr.ts = (((unsigned long long)ts.tv_sec)<<32)+(((ts.tv_usec << 12) + (ts.tv_usec<<8) - ((ts.tv_usec*1825)>>5)) & 0xffffffff);
mapid_process_pkt(&i->mapidlib,dev_pkt,link_pkt,&mhdr);
i->hwinfo.pkts++;
}
}
}
int
mapidrv_read_results (int devid, int fd, int fid,int pid, mapid_result_t** result)
mapidrv_read_results (int devid, int fd, int fid, mapid_result_t** result)
{
DEBUG_CMD(Debug_Message("combo6drv: mapidrv_read_results"));
combo6_instance_t *i=flist_get(devlist,devid);
return mapid_read_results(&i->mapidlib,fd,fid,result);
}
mapid_funct_info_t* mapidrv_get_flow_functions(int devid,int fd)
{
combo6_instance_t *i=flist_get(devlist,devid);
return mapid_read_results(&i->mapidlib,fd,fid,pid,result);
DEBUG_CMD(Debug_Message("combo6drv: mapidrv_get_flow_functions"));
combo6_instance_t *i=flist_get(devlist,devid);
return mapid_get_flow_functions(&i->mapidlib,fd);
}
int mapidrv_get_flow_info(int devid,int fd,mapi_flow_info_t *info) {
DEBUG_CMD(Debug_Message("combo6drv: mapidrv_get_flow_info"));
combo6_instance_t *i=flist_get(devlist,devid);
return mapid_get_flow_info(&i->mapidlib,fd,info);
}
int
mapidrv_create_flow (int devid, int fd, char **devtype)
{
DEBUG_CMD(Debug_Message("combo6drv: mapidrv_create_flow"));
combo6_instance_t *i=flist_get(devlist,devid);
int ret;
int pid;
char c6all[256]="COMBO6_ALL";
if(devid < 0)
{
*devtype=MAPI_DEVICE_SCAMPI;
i->hwinfo.offline=1;
i->hwinfo.cap_length=1500;
i->hwinfo.link_type=DLT_EN10MB;
i->hwinfo.devtype=MAPI_DEVICE_SCAMPI;
i->hwinfo.devid=i->id;
i->hwinfo.pkts=0;
DEBUG_CMD(Debug_Message("Reading from trace file: %s", i->name));
return mapid_add_flow(&i->mapidlib,fd,&i->hwinfo,NULL);
}
i=flist_get(devlist,devid);
i->hwinfo.offline=0;
*devtype=MAPI_DEVICE_SCAMPI;
//Open device if it is not already open
if (!i->combo6fd)
if (i->combo6fd < 0)
{
if ((i->combo6fd = scampi_open (i->name)) < 0) {
fprintf (stderr, "scampi_open(%s): %s\n", i->name, strerror (errno));
if ((i->sze = szedata_open (i->name)) == NULL) {
fprintf (stderr, "szedata_open(%s): %s\n", i->name, strerror (errno));
return COMBO6_OPEN_ERR;
}
if (debug)
printf("Debug: combo6fd: %d\n", i->combo6fd);
fprintf (stderr, "szedata_open(%s): %p\n", i->name, i->sze);
//This should be read from the hardware
i->hwinfo.link_type=DLT_EN10MB;
......@@ -199,85 +284,36 @@ mapidrv_create_flow (int devid, int fd, char **devtype)
i->hwinfo.devid=i->id;
i->hwinfo.pkts=0;
if (debug) {
struct timeval tv;
struct timezone tz;
if (gettimeofday(&tv, &tz)<0)
fprintf(stderr, "gettimeofday() failed\n");
else
printf("after scampi_open(): time: %d.%d\n", (int)(tv.tv_sec),
(int)(tv.tv_usec));
}
//Start processing thread
if (pthread_attr_init (&i->th_attr) != 0)
{
fprintf (stderr, "pthread_attr_init failed");
DEBUG_CMD(Debug_Message("ERROR: pthread_attr_init failed"));
return COMBO6_PTHR_ERR;
}
if (pthread_create(&i->th_proc, &i->th_attr, (void *) mapidrv_proc_loop, (void *) &(i->id)) != 0)
{
fprintf (stderr, "pthread_create failed");
DEBUG_CMD(Debug_Message("ERROR: pthread_create failed"));
return COMBO6_PTHR_ERR;
}
}
ret=mapid_add_flow(&i->mapidlib, fd,&i->hwinfo,NULL);
mapidrv_apply_function(i->hwinfo.devid,fd,pid,c6all,"");
/* Reset mechanism of processing filters to be downloaded to Combo6 card */
scampi_reset_classification(DIRECT);
return ret;
return mapid_add_flow(&i->mapidlib, fd,&i->hwinfo,NULL);
}
int mapidrv_load_library(int devid, char* lib)
{
DEBUG_CMD(Debug_Message("combo6drv: mapidrv_load_library"));
return mapid_load_library(lib);
}
int
mapidrv_close_flow (int devid, int fd)
{
DEBUG_CMD(Debug_Message("combo6drv: mapidrv_close_flow"));
combo6_instance_t *i=flist_get(devlist,devid);
return mapid_close_flow (&i->mapidlib, fd);
}
mapid_funct_info_t* mapidrv_get_flow_functions(int devid, int fd)
{
// return NULL;
combo6_instance_t *i=flist_get(devlist,devid);
return mapid_get_flow_functions(&i->mapidlib,fd);
}
int mapidrv_get_flow_info(int devid,int fd,mapi_flow_info_t *info) {
combo6_instance_t *i=flist_get(devlist,devid);
return mapid_get_flow_info(&i->mapidlib,fd,info);
}
mapi_function_def_mini_t*
mapidrv_get_function_info(int libnumber,int functionnumber)
{
return mapid_get_function_info(libnumber, functionnumber);
}
char*
mapidrv_get_lib_name(int libnumber)
{
return mapid_get_lib_name(libnumber);
}
__attribute__ ((constructor))
void init ()
......@@ -293,3 +329,5 @@ __attribute__ ((destructor))
{
printf ("Combo6 driver unloaded\n");
}
/* vim: set shiftwidth=2 tabstop=2 smarttab expandtab : */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment