Commit ee5d8c60 authored by Cedric Roux's avatar Cedric Roux

prepare forwarder

parent 2bd870af
...@@ -115,11 +115,24 @@ extern T_cache_t *T_cache; ...@@ -115,11 +115,24 @@ extern T_cache_t *T_cache;
#define T_ACTIVE(x) T_active[(intptr_t)x] #define T_ACTIVE(x) T_active[(intptr_t)x]
#ifdef T_USE_SHARED_MEMORY
#define T_SEND() \ #define T_SEND() \
T_cache[T_LOCAL_slot].busy = 1; \ T_cache[T_LOCAL_slot].busy = 1; \
T_cache[T_LOCAL_slot].length = T_LOCAL_size; \ T_cache[T_LOCAL_slot].length = T_LOCAL_size; \
T_send(T_LOCAL_buf, T_LOCAL_size) T_send(T_LOCAL_buf, T_LOCAL_size)
#else /* T_USE_SHARED_MEMORY */
/* when not using shared memory, wait for send to finish */
#define T_SEND() \
T_cache[T_LOCAL_slot].busy = 1; \
T_cache[T_LOCAL_slot].length = T_LOCAL_size; \
T_send(T_LOCAL_buf, T_LOCAL_size); \
while (T_cache[T_LOCAL_slot].busy) usleep(1*1000)
#endif /* T_USE_SHARED_MEMORY */
#define T_CHECK_SIZE(len, argnum) \ #define T_CHECK_SIZE(len, argnum) \
if (T_LOCAL_size + (len) > T_BUFFER_MAX) { \ if (T_LOCAL_size + (len) > T_BUFFER_MAX) { \
printf("%s:%d:%s: cannot put argument %d in T macro, not enough space" \ printf("%s:%d:%s: cannot put argument %d in T macro, not enough space" \
......
...@@ -10,7 +10,7 @@ CFLAGS += -DT_USE_SHARED_MEMORY ...@@ -10,7 +10,7 @@ CFLAGS += -DT_USE_SHARED_MEMORY
LIBS += -lrt LIBS += -lrt
PROG=tracer PROG=tracer
OBJS=main.o plot.o database.o OBJS=main.o plot.o database.o forward.o
$(PROG): $(OBJS) $(PROG): $(OBJS)
$(CC) $(CFLAGS) -o $(PROG) $(OBJS) $(LIBS) $(CC) $(CFLAGS) -o $(PROG) $(OBJS) $(LIBS)
......
...@@ -21,4 +21,7 @@ void list_ids(void *database); ...@@ -21,4 +21,7 @@ void list_ids(void *database);
void list_groups(void *database); void list_groups(void *database);
void on_off(void *d, char *item, int *a, int onoff); void on_off(void *d, char *item, int *a, int onoff);
void *forwarder(char *ip, int port);
void forward(void *forwarder, char *buf, int size);
#endif /* _TRACER_DEFS_H_ */ #endif /* _TRACER_DEFS_H_ */
#include "defs.h"
void *forwarder(char *ip, int port)
{
return 0;
}
void forward(void *_fowarder, char *buf, int size)
{
}
...@@ -371,7 +371,7 @@ void init_shm(void) ...@@ -371,7 +371,7 @@ void init_shm(void)
void usage(void) void usage(void)
{ {
printf( printf(
"options:\n" "common options:\n"
" -d <database file> this option is mandatory\n" " -d <database file> this option is mandatory\n"
" -li print IDs in the database\n" " -li print IDs in the database\n"
" -lg print GROUPs in the database\n" " -lg print GROUPs in the database\n"
...@@ -383,6 +383,10 @@ void usage(void) ...@@ -383,6 +383,10 @@ void usage(void)
" -OFF turn all logs OFF\n" " -OFF turn all logs OFF\n"
"note: you may pass several -on/-off/-ON/-OFF, they will be processed in order\n" "note: you may pass several -on/-off/-ON/-OFF, they will be processed in order\n"
" by default, all is off\n" " by default, all is off\n"
"\n"
"remote mode options: in this mode you run a local tracer and a remote one\n"
" -r remote side\n"
" -l <IP address> <port> local side (forwards packets to remote IP:port)\n"
); );
exit(1); exit(1);
} }
...@@ -403,6 +407,13 @@ int main(int n, char **v) ...@@ -403,6 +407,13 @@ int main(int n, char **v)
int *on_off_action; int *on_off_action;
int on_off_n = 0; int on_off_n = 0;
int is_on[T_NUMBER_OF_IDS]; int is_on[T_NUMBER_OF_IDS];
int remote_local = 0;
int remote_remote = 0;
char *remote_ip = NULL;
int remote_port = -1;
#ifdef T_USE_SHARED_MEMORY
void *f;
#endif
memset(is_on, 0, sizeof(is_on)); memset(is_on, 0, sizeof(is_on));
...@@ -425,10 +436,43 @@ int main(int n, char **v) ...@@ -425,10 +436,43 @@ int main(int n, char **v)
{ on_off_name[on_off_n]=NULL; on_off_action[on_off_n++]=1; continue; } { on_off_name[on_off_n]=NULL; on_off_action[on_off_n++]=1; continue; }
if (!strcmp(v[i], "-OFF")) if (!strcmp(v[i], "-OFF"))
{ on_off_name[on_off_n]=NULL; on_off_action[on_off_n++]=0; continue; } { on_off_name[on_off_n]=NULL; on_off_action[on_off_n++]=0; continue; }
if (!strcmp(v[i], "-r")) { remote_remote = 1; continue; }
if (!strcmp(v[i], "-l")) { if (i > n-3) usage(); remote_local = 1;
remote_ip = v[++i]; remote_port = atoi(v[++i]); continue; }
printf("ERROR: unknown option %s\n", v[i]); printf("ERROR: unknown option %s\n", v[i]);
usage(); usage();
} }
#ifndef T_USE_SHARED_MEMORY
/* gcc shut up */
(void)remote_port;
(void)remote_ip;
#endif
#ifdef T_USE_SHARED_MEMORY
if (remote_remote) {
printf("ERROR: remote 'remote side' does not run with shared memory\n");
printf("recompile without T_USE_SHARED_MEMORY (edit Makefile)\n");
exit(1);
}
#endif
if (remote_remote) {
/* TODO: setup 'secure' connection with remote part */
}
#ifndef T_USE_SHARED_MEMORY
if (remote_local) {
printf("ERROR: remote 'local side' does not run without shared memory\n");
printf("recompile with T_USE_SHARED_MEMORY (edit Makefile)\n");
exit(1);
}
#endif
#ifdef T_USE_SHARED_MEMORY
if (remote_local) f = forwarder(remote_ip, remote_port);
#endif
if (database_filename == NULL) { if (database_filename == NULL) {
printf("ERROR: provide a database file (-d)\n"); printf("ERROR: provide a database file (-d)\n");
exit(1); exit(1);
...@@ -479,6 +523,18 @@ int main(int n, char **v) ...@@ -479,6 +523,18 @@ int main(int n, char **v)
#ifdef T_USE_SHARED_MEMORY #ifdef T_USE_SHARED_MEMORY
wait_message(); wait_message();
#endif #endif
#ifdef T_USE_SHARED_MEMORY
if (remote_local) {
forward(f, T_cache[T_busylist_head].buffer,
T_cache[T_busylist_head].length);
T_cache[T_busylist_head].busy = 0;
T_busylist_head++;
T_busylist_head &= T_CACHE_SIZE - 1;
continue;
}
#endif
get_message(s); get_message(s);
} }
return 0; return 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