Commit ff29e943 authored by 's avatar
Browse files

fixed some argument parsing


git-svn-id: file:///home/svn/mapi/trunk@926 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 4144b89b
......@@ -37,7 +37,7 @@ void *commthread(void *threadid);
void create_flows(char *scope);
void *process();
char local_net[MAXLINE]; //XXX
char *local_net;
char user_net[MAXLINE]; //XXX
int user_net_defined = 0;
......@@ -61,7 +61,7 @@ char *MonitorName = "University of Crete Monitor";
int main(int argc, char **argv) {
int i, scope_strlen=0;
char *scope;
char *scope = "eth0";
int opt;
......@@ -71,6 +71,7 @@ int main(int argc, char **argv) {
anonymize = 1;
refresh_time = 10;
private = 1;
local_net = NULL;
signal(SIGINT, terminate);
signal(SIGQUIT, terminate);
......@@ -84,7 +85,7 @@ int main(int argc, char **argv) {
}
while((opt = getopt(argc, argv, "hvpal:i:n:")) != EOF)
while((opt = getopt(argc, argv, "hvpal:i:n:u:")) != EOF)
{
switch(opt)
{
......@@ -105,8 +106,13 @@ int main(int argc, char **argv) {
anonymize = 1;
private = 1;
break;
case 'f':
case 's':
free(scope);
scope = strdup(optarg);
break;
case 'u':
user_net = strdup(optarg);
break;
case 'v':
verbose = 1;
break;
......@@ -115,18 +121,14 @@ int main(int argc, char **argv) {
}
}
if(optind + 2 != argc) {
usage();
/* look for subnet filters */
if(optind < argc) {
local_net = strdup(argv[optind]);
printf("local_net: %s\n",local_net);
}
strncpy(local_net, argv[optind], MAXLINE);
printf("local net: %s\n", local_net);
/* concatenate args to build the scope argument for create_flow() */
scope = strdup(argv[optind + 1]);
printf("scope: %s\n",scope);
/* start processing */
create_flows(scope);
if((fp = fopen(RRD_FILENAME, "r")) == NULL) {
my_rrd_create(RRD_FILENAME, NUMFILTERS);
......@@ -152,14 +154,16 @@ void create_flows(char *scope) {
char tmpstr_out[2048];
char tmpstr[100];
if (user_net_defined)
if (user_net_defined) {
remote_net = user_net;
else {
printf("remote net: %s\n", remote_net);
}
else if (local_net) {
remote_net = malloc(MAXLINE);
snprintf(remote_net, MAXLINE, "not %s", local_net);
printf("remote net: %s\n", remote_net);
}
printf("remote net: %s\n", remote_net);
for (i=0; i<NUMFILTERS; i++) {
......@@ -190,32 +194,46 @@ void create_flows(char *scope) {
err_quit("apply in tracker %s", filter[i].name);
if (mapi_apply_function(filter[i].fd_out, filter[i].f) < 0)
err_quit("apply out tracker %s", filter[i].name);
}
if ((filter[i].type == F_BPF) &&(filter[i].f != NULL)) { // second check needed for "other"
/* incoming traffic: remote -> local */
snprintf(tmpstr_in, 2048, "(ip and src net %s and dst net %s and %s) or (vlan and src net %s and dst net %s and %s)",
remote_net, local_net, filter[i].f, remote_net, local_net, filter[i].f);
/* outgoing traffic: local -> remote */
snprintf(tmpstr_out, 2048, "(ip and src net %s and dst net %s and %s) or (vlan and src net %s and dst net %s and %s)",
local_net, remote_net, filter[i].f, local_net, remote_net, filter[i].f);
if(local_net) {
snprintf(tmpstr_in, 2048, "(ip and src net %s and dst net %s and %s) or (vlan and src net %s and dst net %s and %s)",
remote_net, local_net, filter[i].f, remote_net, local_net, filter[i].f);
/* outgoing traffic: local -> remote */
snprintf(tmpstr_out, 2048, "(ip and src net %s and dst net %s and %s) or (vlan and src net %s and dst net %s and %s)",
local_net, remote_net, filter[i].f, local_net, remote_net, filter[i].f);
}
else {
snprintf(tmpstr_in, 2048, "(ip and %s) or (vlan and %s)",
filter[i].f, filter[i].f);
/* outgoing traffic: local -> remote */
snprintf(tmpstr_out, 2048, "(ip and %s) or (vlan and %s)",
filter[i].f, filter[i].f);
}
if (mapi_apply_function(filter[i].fd_in, "BPF_FILTER", tmpstr_in) < 0)
err_quit("apply BPF in");
if (mapi_apply_function(filter[i].fd_out, "BPF_FILTER", tmpstr_out) < 0)
err_quit("apply BPF out");
}
else {
/* incoming traffic: remote -> local */
snprintf(tmpstr_in, 2048, "(ip and src net %s and dst net %s) or (vlan and src net %s and dst net %s)",
remote_net, local_net, remote_net, local_net);
/* outgoing traffic: local -> remote */
snprintf(tmpstr_out, 2048, "(ip and src net %s and dst net %s) or (vlan and src net %s and dst net %s)",
local_net, remote_net, local_net, remote_net);
if(local_net) {
/* incoming traffic: remote -> local */
snprintf(tmpstr_in, 2048, "(ip and src net %s and dst net %s) or (vlan and src net %s and dst net %s)",
remote_net, local_net, remote_net, local_net);
/* outgoing traffic: local -> remote */
snprintf(tmpstr_out, 2048, "(ip and src net %s and dst net %s) or (vlan and src net %s and dst net %s)",
local_net, remote_net, local_net, remote_net);
if (mapi_apply_function(filter[i].fd_in, "BPF_FILTER", tmpstr_in) < 0)
err_quit("apply BPF in");
if (mapi_apply_function(filter[i].fd_out, "BPF_FILTER", tmpstr_out) < 0)
err_quit("apply BPF out");
}
}
if (mapi_apply_function(filter[i].fd_in, "BPF_FILTER", tmpstr_in) < 0)
err_quit("apply BPF in");
if (mapi_apply_function(filter[i].fd_out, "BPF_FILTER", tmpstr_out) < 0)
err_quit("apply BPF out");
if ((filter[i].fid_in = mapi_apply_function(filter[i].fd_in, "BYTE_COUNTER")) < 0)
err_quit("apply BYTE_COUNTER in\n");
if ((filter[i].fid_out = mapi_apply_function(filter[i].fd_out, "BYTE_COUNTER")) < 0)
......
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