Hi,
I am working on a system that will be insert something between
200MB (~12million records) and 1GB of netflow into our DB.
I look at the flow-export source and decided to rewrite it, to
improve performance and features. I left the old old format
function and add a new that does:-
-Uses prepared statements
-Data binding, so everything is sent in binary (int) form
-Tag feature (for to record which collector/router the
flow came from)
-Slightly different table structure
the table structure matches struct fts3rec_all, this includes IPs
being stored as 32 bit integers. This allows for some more maths
to be done. MySQL has INET_NTOA so you can still display the IP
in dot notation. (and INET_ATON if you want to enter IP already
in dot notation)
The tag command line argument is -t Column_name=Value
I don't think its perfect, its a first attempt. I just thought that
some here maybe interested. I use gmane and this is the only flow-tools
list it carries, so I hope this is the correct one.
Each fraction of a second it takes to insert the flows does multiply
out to minutes, and I am sure there is more that can be done to speed
this up.
For those of you always looking for schemas here's mine (as I said based
on struct fts3rec_all, but with not all the fields)
CREATE TABLE `flowtable` (
`UNIX_SECS` int(32) unsigned NOT NULL default '0',
`UNIX_NSECS` int(32) unsigned NOT NULL default '0',
`DPKTS` int(32) unsigned NOT NULL default '0',
`DOCTETS` int(32) unsigned NOT NULL default '0',
`FIRST` int(32) unsigned NOT NULL default '0',
`LAST` int(32) unsigned NOT NULL default '0',
`SRCADDR` int(32) unsigned NOT NULL default '0',
`DSTADDR` int(32) unsigned NOT NULL default '0',
`NEXTHOP` int(32) unsigned NOT NULL default '0',
`INPUT` int(16) unsigned NOT NULL default '0',
`OUTPUT` int(16) unsigned NOT NULL default '0',
`SRCPORT` int(16) unsigned NOT NULL default '0',
`DSTPORT` int(16) unsigned NOT NULL default '0',
`PROT` int(8) unsigned NOT NULL default '0',
`TCP_FLAGS` int(8) unsigned NOT NULL default '0',
`SRC_MASK` int(8) unsigned NOT NULL default '0',
`DST_MASK` int(8) unsigned NOT NULL default '0',
`SRC_AS` int(16) unsigned NOT NULL default '0',
`DST_AS` int(16) unsigned NOT NULL default '0',
`COLLECTOR` enum('UNKNOWN','JIM','BOB','JANE','JOHN') NOT NULL default
'UNKNOWN'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
The diffs are against 0.68 at
ftp://ftp.eng.oar.net/pub/flow-tools/flow-tools-0.68.tar.gz
Regards
Thorben
--- a/src/flow-export.c 2004-03-31 04:11:14.000000000 +0100
+++ b/src/flow-export.c 2005-09-22 15:50:00.000000000 +0100
@@ -58,6 +58,10 @@
#define DB_DEFAULT_DBUSER "netflow"
#define DB_DEFAULT_DBPWD "netflow"
+#define MAX_FIELD_COUNT 33
+
+int fmt_xfields_bind(u_int64 xfield, MYSQL_BIND *bind, struct fts3rec_all
*cur);
+
#endif /* MYSQL */
#ifdef HAVE_PGSQL
@@ -87,6 +91,7 @@
struct options {
char dbaseURI[256];
+ char dbtag[128];
u_int32 cflowd_mask;
u_int64 ft_mask;
u_long records;
@@ -102,6 +107,7 @@
int format3(struct ftio *ftio, struct options *opt);
int format4(struct ftio *ftio, struct options *opt);
int format5(struct ftio *ftio, struct options *opt);
+int format6(struct ftio *ftio, struct options *opt);
int ftxfield_tocflow(u_int64 xfields, u_int32 *cfmask);
@@ -109,11 +115,13 @@
u_int64 xfields, int quote);
int fmt_xfields_type(char *buf, u_int64 xfield);
+void fill_rec_all(u_int64 xfield, struct fts3rec_all *cur, void *rec, struct
fts3rec_offsets *fo);
+
void usage(void);
-#define NFORMATS 6 /* nformats - 1 */
+#define NFORMATS 7 /* nformats - 1 */
struct jump format[] = {{format0}, {format1}, {format2}, {format3},
- {format4}, {format5}};
+ {format4}, {format5}, {format6}};
int debug;
@@ -138,7 +146,7 @@
/* profile */
ftprof_start (&ftp);
- while ((i = getopt(argc, argv, "h?d:f:m:u:")) != -1)
+ while ((i = getopt(argc, argv, "h?d:f:m:t:u:")) != -1)
switch (i) {
@@ -167,6 +175,12 @@
}
break;
+ case 't': /*db Tag*/
+ if (strlen(optarg) >= sizeof(opt.dbtag))
+ fterr_errx(1, "dbTag string too long.");
+ strcpy(opt.dbtag, optarg);
+ break;
+
case 'u': /* db URI */
if (strlen(optarg) >= sizeof (opt.dbaseURI))
fterr_errx(1, "dbaseURI string too long.");
@@ -959,6 +973,619 @@
} /* format5 */
+/*
+ * function: format6
+ *
+ * improved export flows into MySQL Database
+ */
+int format6(struct ftio *ftio, struct options *opt)
+{
+#ifdef HAVE_MYSQL
+ struct fts3rec_offsets fo;
+ struct ftver ftv;
+ struct fts3rec_all cur;
+ char fields[1024], query[3*1024];
+ char *rec;
+ char *db_host, *db_name, *db_table, *db_user, *db_pwd, *db_tmp, *tmp;
+ int db_port;
+ int len,count,i;
+
+ MYSQL *mysql;
+
+ MYSQL_STMT *stmt;
+ MYSQL_BIND bind[MAX_FIELD_COUNT+1];
+ char *tag_field, *tag_value;
+ int tag_length;
+
+ db_host = DB_DEFAULT_DBHOST;
+ db_name = DB_DEFAULT_DBNAME;
+ db_port = DB_DEFAULT_DBPORT;
+ db_user = DB_DEFAULT_DBUSER;
+ db_table = DB_DEFAULT_DBTABLE;
+ db_pwd = DB_DEFAULT_DBPWD;
+
+ /* parse URI string */
+
+ if (strlen(opt->dbaseURI)) {
+
+ tmp = opt->dbaseURI;
+
+ db_user = strsep(&tmp, ":");
+ db_pwd = strsep(&tmp, ":");
+ db_host = strsep(&tmp, ":");
+ db_tmp = strsep(&tmp, ":");
+ db_name = strsep(&tmp, ":");
+ db_table = strsep(&tmp, ":");
+ db_port = atoi(db_tmp);
+
+ if (!db_user || !db_pwd || !db_host || !db_tmp || !db_name ||
!db_table) {
+ fterr_warnx("Missing field in dbaseURI, expecting
user:pwd:host:port:name:table.");
+ return -1;
+ }
+
+ } /* dbaseURI */
+
+ ftio_get_ver(ftio, &ftv);
+
+ fts3rec_compute_offsets(&fo, &ftv);
+
+ /* remove invalid fields */
+ opt->ft_mask &= ftrec_xfield(&ftv);
+
+ /* generate the field names once */
+ len = fmt_xfields_type(fields, opt->ft_mask);
+
+ memset(bind, 0, sizeof(bind));
+ count = fmt_xfields_bind(opt->ft_mask, bind, &cur);
+
+ /* parse tag string*/
+ if (strlen(opt->dbtag)) {
+ tmp = opt->dbtag;
+
+ tag_field = strsep(&tmp, "=");
+ tag_value = tmp;
+
+ if (!tag_field || !tag_value) {
+ fterr_warnx("DB Tag format error, expecting
Field=Value.");
+ return -1;
+ }
+
+ if ((len + strlen(tag_field)+1) >= sizeof(fields)) {
+ fterr_warnx("Buffer too small for tag field.");
+ return -1;
+ }
+
+ strcat(fields, ",");
+ strcat(fields, tag_field);
+
+ tag_length = strlen(tag_value);
+ bind[count].buffer_type= MYSQL_TYPE_STRING;
+ bind[count].buffer = tag_value;
+ bind[count].buffer_length = tag_length;
+ bind[count].is_null= 0;
+ bind[count].length = &tag_length;
+ count++;
+ }
+
+
+ /* open MySQL database */
+ mysql = NULL;
+ if (!(mysql = mysql_init(mysql)))
+ fterr_errx(1, "mysql_init(): failed");
+
+ if (mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "simple"))
+ fterr_errx(1, "mysql_options(): %s", mysql_error(mysql));
+
+ if (mysql_real_connect(mysql, db_host, db_user, db_pwd,
+ db_name, db_port, NULL, 0) == NULL)
+ fterr_errx(1,"mysql_real_connect(): %s\n", mysql_error(mysql));
+
+ if (!(stmt = mysql_stmt_init(mysql)))
+ fterr_errx(1, "mysql_stmt_init(): failed");
+
+ query[0] = 0;
+ strcat(query, "INSERT INTO ");
+ strcat(query, db_table);
+ strcat (query, "(");
+ strcat (query, fields);
+ strcat (query, ") VALUES (");
+ for (i=0; i<count; i++) {
+ strcat(query, "?");
+ if (i+1<count) strcat(query, ", ");
+ }
+ strcat (query, ")");
+
+ if (mysql_stmt_prepare(stmt, query, strlen(query)))
+ fterr_errx(1,"mysql_stmt_prepare(): %s\n",
mysql_stmt_error(stmt));
+
+ if (mysql_stmt_bind_param(stmt, bind))
+ fterr_errx(1,"mysql_stmt_bind_param(): %s\n",
mysql_stmt_error(stmt));
+
+ /* foreach flow */
+ while ((rec = ftio_read(ftio))) {
+
+ fill_rec_all(opt->ft_mask, &cur, rec, &fo);
+
+ if (mysql_stmt_execute(stmt))
+ fterr_warnx("mysql_stmt_execute(): %s",
mysql_stmt_error(stmt));
+
+
+ ++opt->records;
+
+ } /* while */
+
+ /* close database */
+ mysql_stmt_close(stmt);
+ mysql_close(mysql);
+
+#else /* MYSQL */
+
+ fterr_warnx("Format not supported");
+
+#endif /* MYSQL */
+
+ return 0;
+
+} /* format5 */
+
+/*
+ I can't find any similar func in lib.
+ fills a fts3rec_all from a ftio rec for fields determined by xfields
+*/
+void fill_rec_all(u_int64 xfield, struct fts3rec_all *cur, void *rec, struct
fts3rec_offsets *fo)
+{
+
+ if (xfield & FT_XFIELD_UNIX_SECS) {
+ FT_RECGET_UNIX_SECS(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_UNIX_NSECS) {
+ FT_RECGET_UNIX_NSECS(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_SYSUPTIME) {
+ FT_RECGET_SYSUPTIME(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_EXADDR) {
+ FT_RECGET_EXADDR(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_DFLOWS) {
+ FT_RECGET_DFLOWS(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_DPKTS) {
+ FT_RECGET_DPKTS(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_DOCTETS) {
+ FT_RECGET_DOCTETS(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_FIRST) {
+ FT_RECGET_FIRST(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_LAST) {
+ FT_RECGET_LAST(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_ENGINE_TYPE) {
+ FT_RECGET_ENGINE_TYPE(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_ENGINE_ID) {
+ FT_RECGET_ENGINE_ID(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_SRCADDR) {
+ FT_RECGET_SRCADDR(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_DSTADDR) {
+ FT_RECGET_DSTADDR(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_NEXTHOP) {
+ FT_RECGET_NEXTHOP(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_INPUT) {
+ FT_RECGET_INPUT(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_OUTPUT) {
+ FT_RECGET_OUTPUT(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_SRCPORT) {
+ FT_RECGET_SRCPORT(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_DSTPORT) {
+ FT_RECGET_DSTPORT(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_PROT) {
+ FT_RECGET_PROT(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_TOS) {
+ FT_RECGET_TOS(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_TCP_FLAGS) {
+ FT_RECGET_TCP_FLAGS(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_SRC_MASK) {
+ FT_RECGET_SRC_MASK(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_DST_MASK) {
+ FT_RECGET_DST_MASK(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_SRC_AS) {
+ FT_RECGET_SRC_AS(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_DST_AS) {
+ FT_RECGET_DST_AS(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_IN_ENCAPS) {
+ FT_RECGET_IN_ENCAPS(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_OUT_ENCAPS) {
+ FT_RECGET_OUT_ENCAPS(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_PEER_NEXTHOP) {
+ FT_RECGET_PEER_NEXTHOP(*cur,rec,*fo)
+ }
+
+/*hmm missing?*/
+#define FT_RECGET_ROUTER_SC(A,B,C) (A).router_sc =\
+ *((u_int32*)(B+(C).router_sc));
+
+ if (xfield & FT_XFIELD_ROUTER_SC) {
+ FT_RECGET_ROUTER_SC(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_EXTRA_PKTS) {
+ FT_RECGET_EXTRA_PKTS(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_MARKED_TOS) {
+ FT_RECGET_MARKED_TOS(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_SRC_TAG) {
+ FT_RECGET_SRC_TAG(*cur,rec,*fo)
+ }
+
+ if (xfield & FT_XFIELD_DST_TAG) {
+ FT_RECGET_DST_TAG(*cur,rec,*fo)
+ }
+
+} /* fill_rec_all */
+
+#ifdef HAVE_MYSQL
+/*
+ Must be ordered the same as in fmt_xfields_type !!
+*/
+int fmt_xfields_bind(u_int64 xfield, MYSQL_BIND *bind, struct fts3rec_all *cur)
+{
+ int count;
+
+ count = 0;
+
+ if (xfield & FT_XFIELD_UNIX_SECS) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->unix_secs);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+
+ if (xfield & FT_XFIELD_UNIX_NSECS) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->unix_nsecs);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_SYSUPTIME) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->sysUpTime);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_EXADDR) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->exaddr);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_DFLOWS) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->dFlows);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_DPKTS) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->dPkts);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_DOCTETS) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->dOctets);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_FIRST) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->First);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_LAST) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->Last);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_ENGINE_TYPE) {
+ bind[count].buffer_type= MYSQL_TYPE_SHORT;
+ bind[count].buffer= (char *)&(cur->engine_type);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_ENGINE_ID) {
+ bind[count].buffer_type= MYSQL_TYPE_SHORT;
+ bind[count].buffer= (char *)&(cur->engine_id);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_SRCADDR) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->srcaddr);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_DSTADDR) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->dstaddr);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_NEXTHOP) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->nexthop);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_INPUT) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->input);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_OUTPUT) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->output);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_SRCPORT) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->srcport);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_DSTPORT) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->dstport);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_PROT) {
+ bind[count].buffer_type= MYSQL_TYPE_SHORT;
+ bind[count].buffer= (char *)&(cur->prot);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_TOS) {
+ bind[count].buffer_type= MYSQL_TYPE_SHORT;
+ bind[count].buffer= (char *)&(cur->tos);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_TCP_FLAGS) {
+ bind[count].buffer_type= MYSQL_TYPE_SHORT;
+ bind[count].buffer= (char *)&(cur->tcp_flags);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_SRC_MASK) {
+ bind[count].buffer_type= MYSQL_TYPE_SHORT;
+ bind[count].buffer= (char *)&(cur->src_mask);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_DST_MASK) {
+ bind[count].buffer_type= MYSQL_TYPE_SHORT;
+ bind[count].buffer= (char *)&(cur->dst_mask);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_SRC_AS) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->src_as);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_DST_AS) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->dst_as);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_IN_ENCAPS) {
+ bind[count].buffer_type= MYSQL_TYPE_SHORT;
+ bind[count].buffer= (char *)&(cur->in_encaps);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_OUT_ENCAPS) {
+ bind[count].buffer_type= MYSQL_TYPE_SHORT;
+ bind[count].buffer= (char *)&(cur->out_encaps);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_PEER_NEXTHOP) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->peer_nexthop);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_ROUTER_SC) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->router_sc);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_EXTRA_PKTS) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->extra_pkts);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_MARKED_TOS) {
+ bind[count].buffer_type= MYSQL_TYPE_SHORT;
+ bind[count].buffer= (char *)&(cur->marked_tos);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_SRC_TAG) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->src_tag);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ if (xfield & FT_XFIELD_DST_TAG) {
+ bind[count].buffer_type= MYSQL_TYPE_LONG;
+ bind[count].buffer= (char *)&(cur->dst_tag);
+ bind[count].is_null= 0;
+ bind[count].is_unsigned = 1;
+ bind[count].length= 0;
+ count++;
+ }
+
+ return count;
+
+} /* fmt_xfields_bind */
+#endif /*MySQL*/
+
int fmt_xfields_type(char *buf, u_int64 xfield)
{
int comma;
--- a/lib/ftlib.h 2005-05-10 16:51:33.000000000 +0100
+++ b/lib/ftlib.h 2005-09-22 13:11:36.000000000 +0100
@@ -806,75 +806,75 @@
u_int8 marked_tos;
};
-#define FT_RECGET_UNIX_SECS(A,B,C) A.unix_secs =\
+#define FT_RECGET_UNIX_SECS(A,B,C) (A).unix_secs =\
*((u_int32*)(B+(C).unix_secs));
-#define FT_RECGET_UNIX_NSECS(A,B,C) A.unix_nsecs =\
+#define FT_RECGET_UNIX_NSECS(A,B,C) (A).unix_nsecs =\
*((u_int32*)(B+(C).unix_nsecs));
-#define FT_RECGET_SYSUPTIME(A,B,C) A.sysUpTime =\
+#define FT_RECGET_SYSUPTIME(A,B,C) (A).sysUpTime =\
*((u_int32*)(B+(C).sysUpTime));
-#define FT_RECGET_EXADDR(A,B,C) A.exaddr =\
+#define FT_RECGET_EXADDR(A,B,C) (A).exaddr =\
*((u_int32*)(B+(C).exaddr));
-#define FT_RECGET_DFLOWS(A,B,C) A.dFlows =\
+#define FT_RECGET_DFLOWS(A,B,C) (A).dFlows =\
*((u_int32*)(B+(C).dFlows));
-#define FT_RECGET64_DFLOWS(A,B,C) A.dFlows64 =\
+#define FT_RECGET64_DFLOWS(A,B,C) (A).dFlows64 =\
*((u_int32*)(B+(C).dFlows));
-#define FT_RECGET_DPKTS(A,B,C) A.dPkts =\
+#define FT_RECGET_DPKTS(A,B,C) (A).dPkts =\
*((u_int32*)(B+(C).dPkts));
-#define FT_RECGET64_DPKTS(A,B,C) A.dPkts64 =\
+#define FT_RECGET64_DPKTS(A,B,C) (A).dPkts64 =\
*((u_int32*)(B+(C).dPkts));
-#define FT_RECGET_DOCTETS(A,B,C) A.dOctets =\
+#define FT_RECGET_DOCTETS(A,B,C) (A).dOctets =\
*((u_int32*)(B+(C).dOctets));
-#define FT_RECGET64_DOCTETS(A,B,C) A.dOctets64 =\
+#define FT_RECGET64_DOCTETS(A,B,C) (A).dOctets64 =\
*((u_int32*)(B+(C).dOctets));
-#define FT_RECGET_FIRST(A,B,C) A.First =\
+#define FT_RECGET_FIRST(A,B,C) (A).First =\
*((u_int32*)(B+(C).First));
-#define FT_RECGET_LAST(A,B,C) A.Last =\
+#define FT_RECGET_LAST(A,B,C) (A).Last =\
*((u_int32*)(B+(C).Last));
-#define FT_RECGET_ENGINE_TYPE(A,B,C) A.engine_type =\
+#define FT_RECGET_ENGINE_TYPE(A,B,C) (A).engine_type =\
*((u_int8*)(B+(C).engine_type));
-#define FT_RECGET_ENGINE_ID(A,B,C) A.engine_id =\
+#define FT_RECGET_ENGINE_ID(A,B,C) (A).engine_id =\
*((u_int8*)(B+(C).engine_id));
-#define FT_RECGET_SRCADDR(A,B,C) A.srcaddr =\
+#define FT_RECGET_SRCADDR(A,B,C) (A).srcaddr =\
*((u_int32*)(B+(C).srcaddr));
-#define FT_RECGET_DSTADDR(A,B,C) A.dstaddr =\
+#define FT_RECGET_DSTADDR(A,B,C) (A).dstaddr =\
*((u_int32*)(B+(C).dstaddr));
-#define FT_RECGET_NEXTHOP(A,B,C) A.nexthop =\
+#define FT_RECGET_NEXTHOP(A,B,C) (A).nexthop =\
*((u_int32*)(B+(C).nexthop));
-#define FT_RECGET_INPUT(A,B,C) A.input =\
+#define FT_RECGET_INPUT(A,B,C) (A).input =\
*((u_int16*)(B+(C).input));
-#define FT_RECGET_OUTPUT(A,B,C) A.output =\
+#define FT_RECGET_OUTPUT(A,B,C) (A).output =\
*((u_int16*)(B+(C).output));
-#define FT_RECGET_SRCPORT(A,B,C) A.srcport =\
+#define FT_RECGET_SRCPORT(A,B,C) (A).srcport =\
*((u_int16*)(B+(C).srcport));
-#define FT_RECGET_DSTPORT(A,B,C) A.dstport =\
+#define FT_RECGET_DSTPORT(A,B,C) (A).dstport =\
*((u_int16*)(B+(C).dstport));
-#define FT_RECGET_PROT(A,B,C) A.prot =\
+#define FT_RECGET_PROT(A,B,C) (A).prot =\
*((u_int8*)(B+(C).prot));
-#define FT_RECGET_TOS(A,B,C) A.tos =\
+#define FT_RECGET_TOS(A,B,C) (A).tos =\
*((u_int8*)(B+(C).tos));
-#define FT_RECGET_TCP_FLAGS(A,B,C) A.tcp_flags =\
+#define FT_RECGET_TCP_FLAGS(A,B,C) (A).tcp_flags =\
*((u_int8*)(B+(C).tcp_flags));
-#define FT_RECGET_SRC_MASK(A,B,C) A.src_mask =\
+#define FT_RECGET_SRC_MASK(A,B,C) (A).src_mask =\
*((u_int8*)(B+(C).src_mask));
-#define FT_RECGET_DST_MASK(A,B,C) A.dst_mask =\
+#define FT_RECGET_DST_MASK(A,B,C) (A).dst_mask =\
*((u_int8*)(B+(C).dst_mask));
-#define FT_RECGET_SRC_AS(A,B,C) A.src_as =\
+#define FT_RECGET_SRC_AS(A,B,C) (A).src_as =\
*((u_int16*)(B+(C).src_as));
-#define FT_RECGET_DST_AS(A,B,C) A.dst_as =\
+#define FT_RECGET_DST_AS(A,B,C) (A).dst_as =\
*((u_int16*)(B+(C).dst_as));
-#define FT_RECGET_IN_ENCAPS(A,B,C) A.in_encaps =\
+#define FT_RECGET_IN_ENCAPS(A,B,C) (A).in_encaps =\
*((u_int8*)(B+(C).in_encaps));
-#define FT_RECGET_OUT_ENCAPS(A,B,C) A.out_encaps =\
+#define FT_RECGET_OUT_ENCAPS(A,B,C) (A).out_encaps =\
*((u_int8*)(B+(C).out_encaps));
-#define FT_RECGET_PEER_NEXTHOP(A,B,C) A.peer_nexthop =\
+#define FT_RECGET_PEER_NEXTHOP(A,B,C) (A).peer_nexthop =\
*((u_int32*)(B+(C).peer_nexthop));
-#define FT_RECGET_EXTRA_PKTS(A,B,C) A.extra_pkts =\
+#define FT_RECGET_EXTRA_PKTS(A,B,C) (A).extra_pkts =\
*((u_int32*)(B+(C).extra_pkts));
-#define FT_RECGET_MARKED_TOS(A,B,C) A.marked_tos =\
+#define FT_RECGET_MARKED_TOS(A,B,C) (A).marked_tos =\
*((u_int8*)(B+(C).marked_tos));
-#define FT_RECGET_SRC_TAG(A,B,C) A.src_tag =\
+#define FT_RECGET_SRC_TAG(A,B,C) (A).src_tag =\
*((u_int32*)(B+(C).src_tag));
-#define FT_RECGET_DST_TAG(A,B,C) A.dst_tag =\
+#define FT_RECGET_DST_TAG(A,B,C) (A).dst_tag =\
*((u_int32*)(B+(C).dst_tag));
struct fts3rec_gen {
_______________________________________________
Flow-tools mailing list
[EMAIL PROTECTED]
http://mailman.splintered.net/mailman/listinfo/flow-tools