Package: mysql-server-5.0 I have a major bug with mysql-server-5.0 (both etch, 5.0.13rc-1 and sid, 5.0.15) on em64t (Quad Xeons) that either kills my app with a various strange mysql errors, seg faults mysqld or mysqld simple exits with no error logged at all =/
None of these problems happen with the Debian packages on a 32bit systems or with MySQL's own community edition 64bit binaries on em64t. So I am lead to believe the problem is just with Debians 64bit packages. This includes source builds (apt-get source ..;cd ...; dpkg-buildpackage -rfakeroot) So maybe its to do with Debian build environment, options, patches, etc I have written a version of flow-export that uses the prepared statement API with bulk inserts to greatly improve its speed. It runs fine except on my em64t box with debians mysql packages. The data that is sent to the server is not what appears in the tables, which appear to be junk memory values. It dies with various error messages, most times after running a few iterations it gives: mysql_stmt_execute(): Incorrect arguments to mysql_stmt_execute even thought the MYSQL_STMT passed to is the same one last iteration. mysqld itself sometimes seg faults I have stripped down my app to just the mysql prep stmt code path to make it stand alone so that it can be used as a test case. the test app does not stop with an error or kill mysqld (if you want that increase the number of iterations done and/or the size of the bulk insert) but the values that appear in the table are not the ones sent. I did originally posted this bug to MySQL, until I found that their binaries work fine: http://bugs.mysql.com/bug.php?id=14988 Also I have a db with a number (~300+) large (~5-10GB) tables which I merge using MyISAM_MERGE tables. When ever I change the UNION of these merge tables using ALTER TABLE it tends to kill mysqld with no error logged mysqld just disappears. This again is true just for debians 64bit packages, others are fine. My installation: Debian Linux amd64 etch (with bits from sid, eg mysql-server-5.0 5.0.15) Quad 64bit Xeon em64t, 16GB RAM Please ask if you need any more information. Thank you Thorben Jändling
/* This is a version of the app I am working on that has been stripped down to just the mysql prep stmt code path. Hence the code looks bizare, since function calls and (if) branches have been removed or hard coded. This app works fine on 32bit systems but for 64bit random numbers turn up in the table. To try, compile: gcc -lmysqlclient -I/usr/include/mysql mysql-64bit-test.c -o mysql-64bit-test and run: ./mysql-64bit-test Here is the table schema, please also edit the DB_DEFAULT_* defines below. CREATE TABLE IF NOT EXISTS !TABLENAME! ( ID int(10) unsigned NOT NULL auto_increment, 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', 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','MARY','WHO','STEVE','TOM') NOT NULL default 'UNKNOWN', PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdarg.h> #include <mysql.h> #define DB_DEFAULT_DBHOST "localhost" #define DB_DEFAULT_DBNAME "fillme" #define DB_DEFAULT_DBPORT "" #define DB_DEFAULT_DBTABLE "editme" #define DB_DEFAULT_DBUSER "tellme" #define DB_DEFAULT_DBPWD "setme" /*the following was folded in from flow-tools */ /* possible fields in export */ #define FT_XFIELD_UNIX_SECS 0x0000000000000001LL #define FT_XFIELD_UNIX_NSECS 0x0000000000000002LL #define FT_XFIELD_SYSUPTIME 0x0000000000000004LL #define FT_XFIELD_EXADDR 0x0000000000000008LL #define FT_XFIELD_DFLOWS 0x0000000000000010LL #define FT_XFIELD_DPKTS 0x0000000000000020LL #define FT_XFIELD_DOCTETS 0x0000000000000040LL #define FT_XFIELD_FIRST 0x0000000000000080LL #define FT_XFIELD_LAST 0x0000000000000100LL #define FT_XFIELD_ENGINE_TYPE 0x0000000000000200LL #define FT_XFIELD_ENGINE_ID 0x0000000000000400LL #define FT_XFIELD_SRCADDR 0x0000000000001000LL #define FT_XFIELD_DSTADDR 0x0000000000002000LL #define FT_XFIELD_NEXTHOP 0x0000000000010000LL #define FT_XFIELD_INPUT 0x0000000000020000LL #define FT_XFIELD_OUTPUT 0x0000000000040000LL #define FT_XFIELD_SRCPORT 0x0000000000080000LL #define FT_XFIELD_DSTPORT 0x0000000000100000LL #define FT_XFIELD_PROT 0x0000000000200000LL #define FT_XFIELD_TOS 0x0000000000400000LL #define FT_XFIELD_TCP_FLAGS 0x0000000000800000LL #define FT_XFIELD_SRC_MASK 0x0000000001000000LL #define FT_XFIELD_DST_MASK 0x0000000002000000LL #define FT_XFIELD_SRC_AS 0x0000000004000000LL #define FT_XFIELD_DST_AS 0x0000000008000000LL #define FT_XFIELD_IN_ENCAPS 0x0000000010000000LL #define FT_XFIELD_OUT_ENCAPS 0x0000000020000000LL #define FT_XFIELD_PEER_NEXTHOP 0x0000000040000000LL #define FT_XFIELD_ROUTER_SC 0x0000000080000000LL #define FT_XFIELD_EXTRA_PKTS 0x0000000100000000LL #define FT_XFIELD_MARKED_TOS 0x0000000200000000LL #define FT_XFIELD_SRC_TAG 0x0000000400000000LL #define FT_XFIELD_DST_TAG 0x0000000800000000LL #define FT_XFIELD_V1_MASK 0x0000000000FF31EFLL #define FT_XFIELD_V5_MASK 0x000000000FFF37EFLL #define FT_XFIELD_V6_MASK 0x000000007FFF37EFLL #define FT_XFIELD_V7_MASK 0x000000008FFF37EFLL #define FT_XFIELD_V8_1_MASK 0x000000000C0607FFLL #define FT_XFIELD_V8_2_MASK 0x00000000003807FFLL #define FT_XFIELD_V8_3_MASK 0x00000000050217FFLL #define FT_XFIELD_V8_4_MASK 0x000000000A0427FFLL #define FT_XFIELD_V8_5_MASK 0x000000000F0637FFLL #define FT_XFIELD_V8_6_MASK 0x00000003804427EFLL #define FT_XFIELD_V8_7_MASK 0x00000003804637EFLL #define FT_XFIELD_V8_8_MASK 0x00000003807E37EFLL #define FT_XFIELD_V8_9_MASK 0x000000000C4607FFLL #define FT_XFIELD_V8_10_MASK 0x00000000007807FFLL #define FT_XFIELD_V8_11_MASK 0x00000000054217FFLL #define FT_XFIELD_V8_12_MASK 0x000000000A4427FFLL #define FT_XFIELD_V8_13_MASK 0x000000000F4637FFLL #define FT_XFIELD_V8_14_MASK 0x00000000037E37FFLL #define FT_XFIELD_V1005_MASK 0x0000000C0FFF37EFLL #define FT_XFIELD_TAGGING_MASK 0x000000000FFF37EFLL #define FT_XFIELD_ASC_UNIX_SECS "unix_secs" #define FT_XFIELD_ASC_UNIX_NSECS "unix_nsecs" #define FT_XFIELD_ASC_SYSUPTIME "sysuptime" #define FT_XFIELD_ASC_EXADDR "exaddr" #define FT_XFIELD_ASC_DFLOWS "dflows" #define FT_XFIELD_ASC_DPKTS "dpkts" #define FT_XFIELD_ASC_DOCTETS "doctets" #define FT_XFIELD_ASC_FIRST "first" #define FT_XFIELD_ASC_LAST "last" #define FT_XFIELD_ASC_ENGINE_TYPE "engine_type" #define FT_XFIELD_ASC_ENGINE_ID "engine_id" #define FT_XFIELD_ASC_SRCADDR "srcaddr" #define FT_XFIELD_ASC_DSTADDR "dstaddr" #define FT_XFIELD_ASC_NEXTHOP "nexthop" #define FT_XFIELD_ASC_INPUT "input" #define FT_XFIELD_ASC_OUTPUT "output" #define FT_XFIELD_ASC_SRCPORT "srcport" #define FT_XFIELD_ASC_DSTPORT "dstport" #define FT_XFIELD_ASC_PROT "prot" #define FT_XFIELD_ASC_TOS "tos" #define FT_XFIELD_ASC_TCP_FLAGS "tcp_flags" #define FT_XFIELD_ASC_SRC_MASK "src_mask" #define FT_XFIELD_ASC_DST_MASK "dst_mask" #define FT_XFIELD_ASC_SRC_AS "src_as" #define FT_XFIELD_ASC_DST_AS "dst_as" #define FT_XFIELD_ASC_IN_ENCAPS "in_encaps" #define FT_XFIELD_ASC_OUT_ENCAPS "out_encaps" #define FT_XFIELD_ASC_PEER_NEXTHOP "peer_nexthop" #define FT_XFIELD_ASC_ROUTER_SC "router_sc" #define FT_XFIELD_ASC_MARKED_TOS "marked_tos" #define FT_XFIELD_ASC_EXTRA_PKTS "extra_pkts" #define FT_XFIELD_ASC_SRC_TAG "src_tag" #define FT_XFIELD_ASC_DST_TAG "dst_tag" #define MAX_FIELD_COUNT 33 #define u_int64 unsigned long long #define u_int32 unsigned int #define u_int16 unsigned short #define u_int8 unsigned char struct fts3rec_all2 { u_int64 dFlows64; u_int64 dPkts64; u_int64 dOctets64; u_int32 unix_secs; u_int32 unix_nsecs; u_int32 sysUpTime; u_int32 exaddr; u_int32 srcaddr; u_int32 dstaddr; u_int32 nexthop; u_int16 input; u_int16 output; u_int32 dFlows; u_int32 dPkts; u_int32 dOctets; u_int32 First; u_int32 Last; u_int16 srcport; u_int16 dstport; u_int8 prot; u_int8 tos; u_int8 tcp_flags; u_int8 engine_type; u_int8 engine_id; u_int8 src_mask; u_int8 dst_mask; u_int16 src_as; u_int16 dst_as; u_int8 in_encaps; u_int8 out_encaps; u_int32 peer_nexthop; u_int32 router_sc; u_int32 src_tag; u_int32 dst_tag; u_int32 extra_pkts; u_int8 marked_tos; }; /* the used in the real app to set number of inserts per prep stmt Obviously more then 2 in real app Note: in the real app different values did affect what error message would result and if mysqld would segfault */ #define BULK_INSERT_COUNT 2 /*this data would normaly by read in from file by the flow-tools lib I am happy that flowrec is correct in the real app when we're 64bit */ struct fts3rec_all2 flowrec[BULK_INSERT_COUNT] = { { 0,0,0, /* dFlows64,dPkts64,dOctets64 */ 1131134400, 925000992, 0, /* unix_secs,unix_nsecs,sysUpTime */ 0, 1019214221, 3259118127, 2455839625, /* exaddr,srcaddr,dstaddr,nexthop*/ 0,0,0, 1, 404, /*input,output,dFlows,dPkts,dOctets */ 643284148, 643284148, /* First,Last */ 1261, 1434, 17, /*srcport,dstport,prot */ 0, 16, 0,0, /* tos,tcp_flags,engine_type,engine_id */ 13, 19, 4134, 29212, /* src_mask,dst_mask,src_as,dst_as */ 0,0,0,0, /* in_encaps,out_encaps,peer_nexthop,router_sc */ 0,0,0,0 /* src_tag,dst_tag,extra_pkts, marked_tos */ },{ 0,0,0, /* dFlows64,dPkts64,dOctets64 */ 1131134400, 937009038, 0, /* unix_secs,unix_nsecs,sysUpTime */ 0, 3631331193, 2331764910, 2455839625, /* exaddr,srcaddr,dstaddr,nexthop*/ 0,0,0, 1, 1417, /*input,output,dFlows,dPkts,dOctets */ 643284160, 643284160, /* First,Last */ 80, 2910, 6, /*srcport,dstport,prot */ 0, 16, 0,0, /* tos,tcp_flags,engine_type,engine_id */ 19, 16, 11643, 64515, /* src_mask,dst_mask,src_as,dst_as */ 0,0,0,0, /* in_encaps,out_encaps,peer_nexthop,router_sc */ 0,0,0,0 /* src_tag,dst_tag,extra_pkts, marked_tos */ } }; /*more hardcoding/folding*/ u_int64 ft_mask = 263795171; /*bits and pieces needed*/ int fmt_xfields_type(char *buf, u_int64 xfield); int fmt_xfields_bind(u_int64 xfield, MYSQL_BIND bind[], struct fts3rec_all2 *cur); int format6(); void fterr_errx(int, char*, ...); void fterr_warnx(char *s, ...); /*no arg parsing in this version*/ int main (int argc, char *argv[]) { return format6(); } /* The main bulk of the code heavily edited for this example */ int format6() { char fields[1024], query[BULK_INSERT_COUNT*MAX_FIELD_COUNT*2+1024], query_v[128]; void *rec; char *db_host, *db_name, *db_table, *db_user, *db_pwd, *db_tmp, *tmp; int db_port; int len,count,i,j; MYSQL *mysql; MYSQL_BIND bind[BULK_INSERT_COUNT*(MAX_FIELD_COUNT+1)]; char *tag_field, *tag_value; unsigned long tag_length; MYSQL_STMT *stmt; db_host = DB_DEFAULT_DBHOST; db_name = DB_DEFAULT_DBNAME; db_port = 0; db_user = DB_DEFAULT_DBUSER; db_table = DB_DEFAULT_DBTABLE; db_pwd = DB_DEFAULT_DBPWD; /*all this top bit has been chopped up for this example */ /* generate the field names once */ len = fmt_xfields_type(fields, ft_mask); /* parse tag string*/ tag_field = "Collector"; tag_value = "UNKOWN"; if (!tag_field || !tag_value) fterr_errx(1,"DB Tag format error, expecting Field=Value."); if ((len + strlen(tag_field)+1) >= sizeof(fields)) fterr_errx(1,"Buffer too small for tag field."); strcat(fields, ","); strcat(fields, tag_field); tag_length = strlen(tag_value); /*bind flowrec fields to mysql */ i = 0; memset(bind, 0, sizeof(bind)); for (j=0; j<BULK_INSERT_COUNT; j++) { i += fmt_xfields_bind(ft_mask, &bind[i], &flowrec[j]); if (NULL != tag_field) { bind[i].buffer_type = MYSQL_TYPE_STRING; bind[i].buffer = tag_value; bind[i].buffer_length = tag_length; bind[i].is_null= 0; i++; } if (0==j) count = i; } /* open MySQL database */ mysql = NULL; if (!(mysql = mysql_init(mysql))) fterr_errx(1, "mysql_init(): failed"); 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)); stmt = NULL; if (!(stmt = mysql_stmt_init(mysql))) fterr_errx(1, "mysql_stmt_init(): %s\n", mysql_error(mysql)); i=0; query_v[i++]='('; for (j=0; j<count && i+2<sizeof(query_v); j++) { query_v[i++] = '?'; if (j+1<count) query_v[i++] = ','; } query_v[i++] = ')'; query_v[i++] = 0; /* x BULK_INSERT_COUNT insert query */ snprintf(query, sizeof(query), "INSERT INTO %s (%s) VALUES ", db_table, fields); for (i=0; i<BULK_INSERT_COUNT; i++) { strncat(query, query_v, sizeof(query) - strlen(query)); if (i+1<BULK_INSERT_COUNT) strncat(query, ",", sizeof(query) - strlen(query)); } printf("query: %s\n", 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)); /*Get a write lock. speed up MyISAM inserts, not best for InnoDB*/ snprintf(query, sizeof(query), "LOCK TABLE %s WRITE;", db_table); if (mysql_real_query(mysql, query, strlen(query)) != 0) fterr_warnx("mysql_real_query(): %s", mysql_error(mysql)); /* foreach flow */ count = 0; for (i=0; i<34235; i++) { /* the for() above was a while(read from file) and here flowrec would be filled */ if (BULK_INSERT_COUNT-1 == count) { /* print flowrec (what bind points in to) for reference/comparason */ printf("fr[0].prot(%p) = %d\n", &flowrec[0].prot, flowrec[0].prot); printf("fr[0].unix_secs(%p) = %d\n", &flowrec[0].unix_secs, flowrec[0].unix_secs); printf("fr[0].srcport(%p) = %d\n", &flowrec[0].srcport, (unsigned short int)flowrec[0].srcport); printf("fr[0].dPkts(%p) = %d\n", &flowrec[0].dPkts, flowrec[0].dPkts); /* print what bind has before calling execute <Type Long, Short, Tiny, $tring>:<value at that location>(<pointer address>) */ for (j=0; j<mysql_stmt_param_count(stmt); j++) { printf("%d:", j); switch (bind[j].buffer_type) { case MYSQL_TYPE_LONG: printf("L:%u(%p), ", *(unsigned long int*)stmt->params[j].buffer, stmt->params[j].buffer); break; case MYSQL_TYPE_SHORT: printf("S:%u(%p), ", *(unsigned short*)stmt->params[j].buffer, stmt->params[j].buffer); break; case MYSQL_TYPE_TINY: printf("T:%u(%p), ", *(unsigned char*)stmt->params[j].buffer, stmt->params[j].buffer); break; case MYSQL_TYPE_STRING: printf("$:%s\n\n", (char*)stmt->params[j].buffer); break; } } if (mysql_stmt_execute(stmt)) fterr_errx(1,"mysql_stmt_execute(): %s", mysql_stmt_error(stmt)); count = 0; } else count++; } /* while */ /* insert remainder */ if (0 < count) { snprintf(query, sizeof(query), "INSERT INTO %s (%s) VALUES ", db_table, fields); for (i=0; i<count; i++) { strncat(query, query_v, sizeof(query) - strlen(query)); if (i+1<count) strncat(query, ",", sizeof(query) - strlen(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)); if (mysql_stmt_execute(stmt)) fterr_errx(1,"mysql_stmt_execute(): %s", mysql_stmt_error(stmt)); } /*Release our locks*/ snprintf(query, sizeof(query), "UNLOCK TABLES;"); if (mysql_real_query(mysql, query, strlen(query)) != 0) fterr_warnx("mysql_real_query(): %s", mysql_error(mysql)); /* close database */ mysql_stmt_close(stmt); mysql_close(mysql); return 0; } /* format6 */ /*func replacement*/ void fterr_errx(int e, char *s, ...) { va_list ap; va_start(ap, s); vfprintf(stderr, s, ap); fprintf(stderr, "\n"); va_end(ap); exit(e); } /*func replacement*/ void fterr_warnx(char *s, ...) { va_list ap; va_start(ap, s); vfprintf(stderr, s, ap); fprintf(stderr, "\n"); va_end(ap); } /* The following are from (my version of) flow-tools unedited, except extra printf */ /* Must be ordered the same as in fmt_xfields_type !! */ int fmt_xfields_bind(u_int64 xfield, MYSQL_BIND bind[], struct fts3rec_all2 *cur) { int count; count = 0; if (xfield & FT_XFIELD_UNIX_SECS) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->unix_secs); bind[count].buffer_length = sizeof(cur->unix_secs); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p unix_secs\n", count, &(cur->unix_secs)); count++; } if (xfield & FT_XFIELD_UNIX_NSECS) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->unix_nsecs); bind[count].buffer_length = sizeof(cur->unix_nsecs); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p unix_nsecs\n", count, &(cur->unix_nsecs)); count++; } if (xfield & FT_XFIELD_SYSUPTIME) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->sysUpTime); bind[count].buffer_length = sizeof(cur->sysUpTime); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_EXADDR) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->exaddr); bind[count].buffer_length = sizeof(cur->exaddr); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_DFLOWS) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->dFlows); bind[count].buffer_length = sizeof(cur->dFlows); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_DPKTS) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->dPkts); bind[count].buffer_length = sizeof(cur->dPkts); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p dPkts\n", count, &(cur->dPkts)); count++; } if (xfield & FT_XFIELD_DOCTETS) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->dOctets); bind[count].buffer_length = sizeof(cur->dOctets); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p dOctets\n", count, &(cur->dOctets)); count++; } if (xfield & FT_XFIELD_FIRST) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->First); bind[count].is_null= 0; bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p First\n", count, &(cur->First)); count++; } if (xfield & FT_XFIELD_LAST) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->Last); bind[count].buffer_length = sizeof(cur->Last); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p Last\n", count, &(cur->Last)); count++; } if (xfield & FT_XFIELD_ENGINE_TYPE) { bind[count].buffer_type= MYSQL_TYPE_TINY; bind[count].buffer= (void *)&(cur->engine_type); bind[count].buffer_length = sizeof(cur->engine_type); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_ENGINE_ID) { bind[count].buffer_type= MYSQL_TYPE_TINY; bind[count].buffer= (void *)&(cur->engine_id); bind[count].buffer_length = sizeof(cur->engine_id); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_SRCADDR) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->srcaddr); bind[count].buffer_length = sizeof(cur->srcaddr); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p srcaddr\n", count, &(cur->srcaddr)); count++; } if (xfield & FT_XFIELD_DSTADDR) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->dstaddr); bind[count].buffer_length = sizeof(cur->dstaddr); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p dstaddr\n", count, &(cur->dstaddr)); count++; } if (xfield & FT_XFIELD_NEXTHOP) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->nexthop); bind[count].buffer_length = sizeof(cur->nexthop); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p nexthop\n", count, &(cur->nexthop)); count++; } if (xfield & FT_XFIELD_INPUT) { bind[count].buffer_type= MYSQL_TYPE_SHORT; bind[count].buffer= (void *)&(cur->input); bind[count].buffer_length = sizeof(cur->input); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_OUTPUT) { bind[count].buffer_type= MYSQL_TYPE_SHORT; bind[count].buffer= (void *)&(cur->output); bind[count].buffer_length = sizeof(cur->output); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_SRCPORT) { bind[count].buffer_type= MYSQL_TYPE_SHORT; bind[count].buffer= (void *)&(cur->srcport); bind[count].buffer_length = sizeof(cur->srcport); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p srcport\n", count, &(cur->srcport)); count++; } if (xfield & FT_XFIELD_DSTPORT) { bind[count].buffer_type= MYSQL_TYPE_SHORT; bind[count].buffer= (void *)&(cur->dstport); bind[count].buffer_length = sizeof(cur->dstport); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p dstport\n", count, &(cur->dstport)); count++; } if (xfield & FT_XFIELD_PROT) { bind[count].buffer_type= MYSQL_TYPE_TINY; bind[count].buffer= (void *)&(cur->prot); bind[count].buffer_length = sizeof(cur->prot); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p prot\n", count, &(cur->prot)); count++; } if (xfield & FT_XFIELD_TOS) { bind[count].buffer_type= MYSQL_TYPE_TINY; bind[count].buffer= (void *)&(cur->tos); bind[count].buffer_length = sizeof(cur->tos); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_TCP_FLAGS) { bind[count].buffer_type= MYSQL_TYPE_TINY; bind[count].buffer= (void *)&(cur->tcp_flags); bind[count].buffer_length = sizeof(cur->tcp_flags); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p tcp_flags\n", count, &(cur->tcp_flags)); count++; } if (xfield & FT_XFIELD_SRC_MASK) { bind[count].buffer_type= MYSQL_TYPE_TINY; bind[count].buffer= (void *)&(cur->src_mask); bind[count].buffer_length = sizeof(cur->src_mask); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p src_mask\n", count, &(cur->src_mask)); count++; } if (xfield & FT_XFIELD_DST_MASK) { bind[count].buffer_type= MYSQL_TYPE_TINY; bind[count].buffer= (void *)&(cur->dst_mask); bind[count].buffer_length = sizeof(cur->dst_mask); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p dst_mask\n", count, &(cur->dst_mask)); count++; } if (xfield & FT_XFIELD_SRC_AS) { bind[count].buffer_type= MYSQL_TYPE_SHORT; bind[count].buffer= (void *)&(cur->src_as); bind[count].buffer_length = sizeof(cur->src_as); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p src_as\n", count, &(cur->src_as)); count++; } if (xfield & FT_XFIELD_DST_AS) { bind[count].buffer_type= MYSQL_TYPE_SHORT; bind[count].buffer= (void *)&(cur->dst_as); bind[count].buffer_length = sizeof(cur->dst_as); bind[count].is_unsigned = 1; printf("bind[%d].buffer to %p dst_as\n", count, &(cur->dst_as)); count++; } if (xfield & FT_XFIELD_IN_ENCAPS) { bind[count].buffer_type= MYSQL_TYPE_TINY; bind[count].buffer= (void *)&(cur->in_encaps); bind[count].buffer_length = sizeof(cur->in_encaps); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_OUT_ENCAPS) { bind[count].buffer_type= MYSQL_TYPE_TINY; bind[count].buffer= (void *)&(cur->out_encaps); bind[count].buffer_length = sizeof(cur->out_encaps); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_PEER_NEXTHOP) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->peer_nexthop); bind[count].buffer_length = sizeof(cur->peer_nexthop); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_ROUTER_SC) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->router_sc); bind[count].buffer_length = sizeof(cur->router_sc); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_EXTRA_PKTS) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->extra_pkts); bind[count].buffer_length = sizeof(cur->extra_pkts); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_MARKED_TOS) { bind[count].buffer_type= MYSQL_TYPE_TINY; bind[count].buffer= (void *)&(cur->marked_tos); bind[count].buffer_length = sizeof(cur->marked_tos); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_SRC_TAG) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->src_tag); bind[count].buffer_length = sizeof(cur->src_tag); bind[count].is_unsigned = 1; count++; } if (xfield & FT_XFIELD_DST_TAG) { bind[count].buffer_type= MYSQL_TYPE_LONG; bind[count].buffer= (void *)&(cur->dst_tag); bind[count].buffer_length = sizeof(cur->dst_tag); bind[count].is_unsigned = 1; count++; } return count; } /* fmt_xfields_bind */ int fmt_xfields_type(char *buf, u_int64 xfield) { int comma; buf[0] = 0; if (xfield & FT_XFIELD_UNIX_SECS) { strcat(buf, FT_XFIELD_ASC_UNIX_SECS); comma = 1; } if (xfield & FT_XFIELD_UNIX_NSECS) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_UNIX_NSECS); comma = 1; } if (xfield & FT_XFIELD_SYSUPTIME) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_SYSUPTIME); comma = 1; } if (xfield & FT_XFIELD_EXADDR) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_EXADDR); comma = 1; } if (xfield & FT_XFIELD_DFLOWS) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_DFLOWS); comma = 1; } if (xfield & FT_XFIELD_DPKTS) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_DPKTS); comma = 1; } if (xfield & FT_XFIELD_DOCTETS) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_DOCTETS); comma = 1; } if (xfield & FT_XFIELD_FIRST) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_FIRST); comma = 1; } if (xfield & FT_XFIELD_LAST) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_LAST); comma = 1; } if (xfield & FT_XFIELD_ENGINE_TYPE) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_ENGINE_TYPE); comma = 1; } if (xfield & FT_XFIELD_ENGINE_ID) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_ENGINE_ID); comma = 1; } if (xfield & FT_XFIELD_SRCADDR) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_SRCADDR); comma = 1; } if (xfield & FT_XFIELD_DSTADDR) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_DSTADDR); comma = 1; } if (xfield & FT_XFIELD_NEXTHOP) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_NEXTHOP); comma = 1; } if (xfield & FT_XFIELD_INPUT) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_INPUT); comma = 1; } if (xfield & FT_XFIELD_OUTPUT) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_OUTPUT); comma = 1; } if (xfield & FT_XFIELD_SRCPORT) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_SRCPORT); comma = 1; } if (xfield & FT_XFIELD_DSTPORT) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_DSTPORT); comma = 1; } if (xfield & FT_XFIELD_PROT) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_PROT); comma = 1; } if (xfield & FT_XFIELD_TOS) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_TOS); comma = 1; } if (xfield & FT_XFIELD_TCP_FLAGS) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_TCP_FLAGS); comma = 1; } if (xfield & FT_XFIELD_SRC_MASK) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_SRC_MASK); comma = 1; } if (xfield & FT_XFIELD_DST_MASK) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_DST_MASK); comma = 1; } if (xfield & FT_XFIELD_SRC_AS) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_SRC_AS); comma = 1; } if (xfield & FT_XFIELD_DST_AS) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_DST_AS); comma = 1; } if (xfield & FT_XFIELD_IN_ENCAPS) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_IN_ENCAPS); comma = 1; } if (xfield & FT_XFIELD_OUT_ENCAPS) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_OUT_ENCAPS); comma = 1; } if (xfield & FT_XFIELD_PEER_NEXTHOP) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_NEXTHOP); comma = 1; } if (xfield & FT_XFIELD_ROUTER_SC) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_ROUTER_SC); comma = 1; } if (xfield & FT_XFIELD_EXTRA_PKTS) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_EXTRA_PKTS); comma = 1; } if (xfield & FT_XFIELD_MARKED_TOS) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_MARKED_TOS); comma = 1; } if (xfield & FT_XFIELD_SRC_TAG) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_SRC_TAG); comma = 1; } if (xfield & FT_XFIELD_DST_TAG) { if (comma) strcat(buf, ","); strcat(buf, FT_XFIELD_ASC_DST_TAG); comma = 1; } return strlen(buf); } /* fmt_xfields_type */