Commit ce011ac2 authored by 's avatar
Browse files

Bug fixes


git-svn-id: file:///home/svn/mapi/trunk@345 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 50c40e8a
......@@ -134,6 +134,7 @@ int main(int argc, char *argv[])
j=0;
while (j<MAX_PROTOCOLS && p->protocols_array[j]) {
printf("protocol: |%s|\n", p->protocols_array[j]);
if ((p->flow_run[j]=new_flow_run())==NULL) {
fprintf(stderr, "%s: new_flow_run() failed\n", __func__);
return -1;
......@@ -162,6 +163,7 @@ int main(int argc, char *argv[])
}
else
q->header_filter=p->header_filter;
printf("p->header_filter: %s, q->protocol: %s, q->header_filter: %s\n", p->header_filter, q->protocol, q->header_filter);
if ((q->fd=mapi_create_flow(p->device))<0) {
fprintf(stderr, "%s: mapi_create_flow(%s) failed\n", __func__,
......@@ -313,7 +315,7 @@ int main(int argc, char *argv[])
the flow whose checkpoint is earliest */
abw_next_timestamp(&(flow_spec[0]->interval), &next, &wait);
printf("next.tv_sec: %d, next.tv_usec: %d, wait.tv_sec: %d, wait.tv_usec: %d\n", (int)(next.tv_sec), (int)(next.tv_usec), (int)(wait.tv_sec), (int)(wait.tv_usec));
/* printf("next.tv_sec: %d, next.tv_usec: %d, wait.tv_sec: %d, wait.tv_usec: %d\n", (int)(next.tv_sec), (int)(next.tv_usec), (int)(wait.tv_sec), (int)(wait.tv_usec)); */
usleep(wait.tv_sec * 1000000 + wait.tv_usec);
......
......@@ -11,7 +11,9 @@ passwd=lab10
[node]
id=1
hostname=jra1-1.cesnet.cz
device=/dev/dag0
device=eth0
# link_mbps is used by abw_print, but not by abw_measure
link_mbps=1000
[node]
id=2
......@@ -39,6 +41,6 @@ interval_sec=1
start_time_string=01.01.2005-00:00:00
end_time_string=31.12.2037-23:59:59
[parameters]
id=2
node_id=2
#[parameters]
#id=2
#node_id=2
......@@ -48,7 +48,7 @@ typedef struct {
*/
typedef struct {
/* Local device for MAPI or hostname and device for DiMAPI */
char *hostname;
char *device;
/* Header filtering */
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "abw.h"
#include "abw_conf.h"
flow_spec_t *new_flow_spec(void) {
flow_spec_t *p;
if ((p=malloc(sizeof(flow_spec_t)))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return NULL;
}
memset(p, 0, sizeof(flow_spec_t));
p->device=DEFAULT_DEVICE;
p->header_filter=NULL;
p->sau_mode='d';
p->sau_packet_threshold=1;
p->sau_byte_threshold=3000;
p->sau_pass_probability=0.5;
p->protocols=NULL;
p->interval.tv_sec=1;
p->interval.tv_usec=0;
p->start_time_string=DEFAULT_START_TIME_STRING;
p->end_time_string=DEFAULT_END_TIME_STRING;
p->link_mbps=DEFAULT_LINK_MBPS;
return p;
} /* new_flow_spec() */
flow_run_t *new_flow_run(void) {
flow_run_t *p;
if ((p=malloc(sizeof(flow_run_t)))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return NULL;
}
memset(p, 0, sizeof(flow_run_t));
return p;
} /* new_flow_run() */
int split_protocols(char *protocols, char *protocols_array[]) {
int j, k;
char *chr;
char protocol[MAX_PROTOCOLS+1];
char *protocol_start, *protocol_stop;
if (protocols==NULL || !protocols[0])
return 0;
if (strlen(protocols)>MAX_PROTOCOLS_STRING) {
fprintf(stderr, "%s: protocols string is longer than %d characters\n",
__func__, MAX_PROTOCOLS_STRING);
return -1;
}
j=0;
chr=protocols;
/* go over the whole protocols string */
while (*chr && j<MAX_PROTOCOLS) {
/* copy one protocol, that is until comma ',' or end of string */
k=0;
while (*chr && *chr!=',') {
protocol[k]=*chr;
k++; chr++;
}
protocol[k]='\0';
if (k==0) {
fprintf(stderr, "%s: empty protocol\n", __func__);
return -1;
}
/* remove leading and trailing spaces and tabs */
protocol_start=protocol;
while (*protocol_start==' ' || *protocol_start=='\t')
protocol_start++;
protocol_stop=(protocol+k-1);
while (*protocol_stop==' ' || *protocol_stop=='\t')
protocol_stop--;
if (protocol_stop==protocol_start) {
fprintf(stderr, "%s: empty protocol\n", __func__);
return -1;
}
if ((protocols_array[j]=
malloc(protocol_stop-protocol_start+2))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return -1;
}
strncpy(protocols_array[j], protocol_start,
protocol_stop-protocol_start+1);
protocols_array[j][protocol_stop-protocol_start+1]='\0';
if (*chr)
chr++; /* skip ',' */
j++;
} /* while (*chr && j<MAX_PROTOCOLS) */
if (*chr) {
fprintf(stderr, "%s: more than %d protocols\n", __func__,
MAX_PROTOCOLS);
return -1;
}
return 0;
} /* split_protocols() */
int protocol_filter(char *header_filter, char *protocol,
char **new_header_filter) {
int new_header_filter_length;
char *new_protocol;
new_header_filter_length=0;
new_protocol=NULL;
if (protocol && protocol[0] && strcmp(protocol, "all")) {
if (!strcmp(protocol, "tcp"))
new_protocol="tcp";
else if (!strcmp(protocol, "udp"))
new_protocol="udp";
else if (!strcmp(protocol, "ipv6") || !strcmp(protocol, "ip6"))
new_protocol="ip6";
else if (!strcmp(protocol, "multicast") ||
!strcmp(protocol, "ip and multicast"))
new_protocol="ip and multicast";
else if (!strcmp(protocol, "ipv6 and multicast") ||
!strcmp(protocol, "ip6 and multicast"))
new_protocol="ip6 and multicast";
else {
fprintf(stderr, "%s: unknown protocol %s\n", __func__, protocol);
return -1;
}
new_header_filter_length+=strlen(new_protocol);
}
if (header_filter) {
if (new_protocol)
new_header_filter_length+=strlen(" and ");
new_header_filter_length+=strlen(header_filter);
}
if (header_filter || new_protocol) {
if ((*new_header_filter=malloc(new_header_filter_length+1))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return -1;
}
if (new_protocol)
strcpy(*new_header_filter, new_protocol);
if (header_filter) {
if (new_protocol)
strcat(*new_header_filter, " and ");
strcat(*new_header_filter, header_filter);
}
}
else
*new_header_filter=NULL;
return 0;
} /* protocol_filter() */
......@@ -181,14 +181,28 @@ int read_conf_file(global_spec_t *global_spec, flow_spec_t **flow_spec)
return -1;
}
/* Go over all categories and for each [parameters] category create
one flow specification */
/* Go over all categories, read global configuration in [global] category
and for each [parameters] category create one flow specification */
cat=conf;
pp=flow_spec;
p=*pp; i=0;
while (cat) {
if (!strcmp(cat->category, "parameters")) {
if (!strcmp(cat->category, "global")) {
param=cat->params;
while (param) {
if (!strcmp(param->name, "db"))
global_spec->db=param->value;
else if (!strcmp(param->name, "user"))
global_spec->user=param->value;
else if (!strcmp(param->name, "passwd"))
global_spec->passwd=param->value;
param=param->next;
}
}
else if (!strcmp(cat->category, "parameters")) {
if (i>=MAX_FLOWS) {
fprintf(stderr, "%s: maximum number of %d flows exceeded\n",
......@@ -209,7 +223,7 @@ int read_conf_file(global_spec_t *global_spec, flow_spec_t **flow_spec)
/* Retrieve items of the [parameters] section and copy them into the
flow specification. If something is missing or incorrect, it will
detected later by check_conf() function */
be detected later by check_conf() function */
node_id=-1;
payload_strings_no=0;
param=cat->params;
......@@ -223,6 +237,10 @@ int read_conf_file(global_spec_t *global_spec, flow_spec_t **flow_spec)
fprintf(stderr, "%s: header filter string must not be longer than %d characters\n", __func__, MAX_HEADER_FILTER);
return -1;
}
if ((p->header_filter=malloc(strlen(param->value)+1))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return -1;
}
strcpy(p->header_filter, param->value);
}
......@@ -297,15 +315,12 @@ int read_conf_file(global_spec_t *global_spec, flow_spec_t **flow_spec)
strcpy(p->end_time_string, param->value);
}
else if (!strcmp(param->name, "link_mbps"))
p->link_mbps=atoi(param->value);
param=param->next;
}
/* Each [parameter] section should refer to one [node] section,
which we have to find, so go over all sections and if it is
a [node] section, check whether it is the one we are lokking for */
a [node] section, check whether it is the one we are looking for */
if (node_id<0) {
fprintf(stderr, "%s: missing node_id\n", __func__);
......@@ -329,14 +344,24 @@ int read_conf_file(global_spec_t *global_spec, flow_spec_t **flow_spec)
if (searched_node) {
param2=searched_node->params;
while (param2) {
if (!strcmp(param2->name, "device")) {
printf("param2->name: %s\n", param2->name);
if (!strcmp(param2->name, "hostname")) {
if ((p->hostname=malloc(strlen(param2->value)+1))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return -1;
}
strcpy(p->hostname, param2->value);
}
else if (!strcmp(param2->name, "device")) {
if ((p->device=malloc(strlen(param2->value)+1))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return -1;
}
strcpy(p->device, param2->value);
break;
}
else if (!strcmp(param2->name, "link_mbps"))
p->link_mbps=atoi(param2->value);
param2=param2->next;
}
break;
......@@ -490,7 +515,7 @@ void print_conf(global_spec_t *global_spec, flow_spec_t **flow_spec) {
else
printf("global_spec->passwd: unspecified\n");
printf("global_spec->hostname %s\n", global_spec->hostname);
printf("global_spec->hostname: %s\n", global_spec->hostname);
/* Print specified flows */
......@@ -499,14 +524,25 @@ void print_conf(global_spec_t *global_spec, flow_spec_t **flow_spec) {
while (p) {
printf("flow[%d]:\n", i);
printf("header_filter: %s\n", p->header_filter);
printf("device: %s\n", p->device);
if (p->header_filter)
printf("header_filter: %s\n", p->header_filter);
else
printf("header_filter: unspecified\n");
if (p->hostname)
printf("hostname: %s\n", p->hostname);
else
printf("hostname: unspecified (global_spec->hostname will be used)\n");
if (p->device)
printf("device: %s\n", p->device);
else
printf("device: unspecified\n");
printf("sau_mode: %c, sau_threshold: %u\n", p->sau_mode, p->sau_threshold);
rr=p->payload_strings;
r=*rr; j=0;
if (r) {
j=0;
if (*rr) {
printf("payload_strings:");
while (r) {
while (j<MAX_PAYLOAD_STRINGS && *rr) {
r=*rr;
if (j>0)
printf(",");
printf(" |%s|", r);
......@@ -514,9 +550,13 @@ void print_conf(global_spec_t *global_spec, flow_spec_t **flow_spec) {
}
printf("\n");
}
else
printf("payload_strings: unspecified\n");
if (p->protocols)
printf("protocols: %s\n", p->protocols);
else
printf("protocols: unspecified\n");
printf("interval.tv_sec: %d, interval.tv_usec: %d\n",
(int)(p->interval.tv_sec), (int)(p->interval.tv_usec));
printf("start_time_string: %s, start_time_timestamp: %u\n",
......
#include <stdio.h>
int main()
{ return 0;
}
......@@ -40,7 +40,8 @@ int abw_mysql_get_subject_id(global_spec_t *global_spec, flow_spec_t *p) {
int subject_id;
int num;
if (global_spec==NULL || p==NULL || global_spec->hostname==NULL ||
if (global_spec==NULL || p==NULL ||
(p->hostname==NULL && global_spec->hostname==NULL) ||
p->device==NULL) {
fprintf(stderr, "%s: some required arguments were not supplied\n",
__func__);
......@@ -50,11 +51,14 @@ int abw_mysql_get_subject_id(global_spec_t *global_spec, flow_spec_t *p) {
/* We should search hostname if specified, otherwise IP address,
then interface and direction. We currently run this application
on the host with a monitoring card (no DiMAPI), so we always
search local hostname (including domain name) and device of monitoring
card, direction is included in the chosen monitoring card (but in
future more ports on the card can be used) */
search hostname and device of monitoring card, direction is included
in the chosen monitoring card (but in future more ports on the card
can be used) */
strcpy(query, "SELECT * FROM tSubject WHERE hostname='");
strcat(query, global_spec->hostname);
if (p->hostname)
strcat(query, p->hostname);
else
strcat(query, global_spec->hostname);
strcat(query, "' AND interface='");
strcat(query, p->device);
strcat(query, "';");
......@@ -100,7 +104,10 @@ int abw_mysql_get_subject_id(global_spec_t *global_spec, flow_spec_t *p) {
else { /* subject is not in tSubject */
printf("%s: subject is not in tSubject\n", __func__);
strcpy(query, "INSERT INTO tSubject (hostname, interface) VALUES ('");
strcat(query, global_spec->hostname);
if (p->hostname)
strcat(query, p->hostname);
else
strcat(query, global_spec->hostname);
strcat(query, "', '");
strcat(query, p->device);
strcat(query, "');");
......@@ -193,10 +200,10 @@ int abw_mysql_get_parameters_id(global_spec_t *global_spec,
}
else { /* parameters are not in tParameters */
printf("%s: parameters are not in tParameters\n", __func__);
sprintf(query, "INSERT INTO tParameters (sau_mode, sau_threshold, interval_sec, interval_usec, link_mbps, header_filter, payload_string) VALUES ('%c', '%d', '%d', '%d', '%d'",
sprintf(query, "INSERT INTO tParameters (sau_mode, sau_threshold, interval_sec, interval_usec, header_filter, payload_string) VALUES ('%c', '%d', '%d', '%d'",
p->sau_mode, p->sau_threshold, (int)(p->interval.tv_sec),
(int)(p->interval.tv_usec), p->link_mbps);
if (strlen(p->header_filter))
(int)(p->interval.tv_usec));
if (p->header_filter)
sprintf(query+strlen(query), ", '%s'", p->header_filter);
else
sprintf(query+strlen(query), ", ''");
......
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