Skip to content

Commit

Permalink
- Updated the filter brick
Browse files Browse the repository at this point in the history
	--> Only this type of brick should accept communication requests
	--> Currently any general-purpose brick can accept filter requests.
	--> Still in development
- Code cleanup will come next.
  • Loading branch information
ajamshed committed Dec 16, 2015
1 parent 2cb8da4 commit f6aaf3e
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 26 deletions.
25 changes: 25 additions & 0 deletions include/bricks_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
/*---------------------------------------------------------------------*/
/* for polling */
#include <sys/poll.h>
/* for flist */
#include "netmap_module.h"
/*---------------------------------------------------------------------*/
#define INET_MASK 32
#ifdef ENABLE_BROKER
Expand All @@ -40,18 +42,41 @@
#define BROKER_PORT 9999
#endif
/*---------------------------------------------------------------------*/
struct FilterContext {
/* name of output node */
char name[IFNAMSIZ];
/*
* the linked list ptr that will chain together
* all filter bricks (for bricks_filter.c). this
* will be used for network communication module
*/
TAILQ_ENTRY(FilterContext) entry;

/* Filter list */
flist filter_list;

} __attribute__((aligned(__WORDSIZE)));
/*---------------------------------------------------------------------*/
/**
* Analyze the packet across the filter. And pass it along
* the communication node, if the filter allows...
*/
int
#if 1
analyze_packet(unsigned char *buf, CommNode *cn, time_t t);
#else
analyze_packet(unsigned char *buf, FilterContext *cn, time_t t);
#endif

/**
* Add the filter to the selected CommNode
*/
int
#if 1
apply_filter(CommNode *cn, Filter *f);
#else
apply_filter(FilterContext *cn, Filter *f);
#endif

/**
* Initialize the filter communication backend
Expand Down
3 changes: 3 additions & 0 deletions include/bricks_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ typedef struct Filter {
/* target */
Target tgt;

/* comm node name */
char node_name[IFNAMSIZ];

TAILQ_ENTRY(Filter) entry;
} Filter __attribute__((aligned(__WORDSIZE)));
/*---------------------------------------------------------------------*/
Expand Down
8 changes: 8 additions & 0 deletions include/pkt_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ struct engine_src;
typedef struct CommNode CommNode;
/* CommNode list declaration */
typedef TAILQ_HEAD(clist, CommNode) clist;

/* Declaring FilterContext struct */
typedef struct FilterContext FilterContext;
/* FilterContext list declaration */
typedef TAILQ_HEAD(fclist, FilterContext) fclist;
/*---------------------------------------------------------------------*/
/**
*
Expand Down Expand Up @@ -90,6 +95,9 @@ typedef struct engine {

/* the commnode list that shall be referred to by netmodule */
clist commnode_list;
/* the filter brick list that shalle be referred to by netmodule */
fclist filter_list;

#ifdef ENABLE_BROKER
/* filter communication handle */
void *pq_ptr;
Expand Down
4 changes: 0 additions & 4 deletions src/bricks/dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
#include "brick.h"
/* for bricks logging */
#include "bricks_log.h"
/* for engine declaration */
#include "pkt_engine.h"
/* for strcmp */
#include <string.h>
/*---------------------------------------------------------------------*/
int32_t
dummy_init(Brick *brick, Linker_Intf *li)
Expand Down
66 changes: 48 additions & 18 deletions src/bricks/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,54 @@
#include "brick.h"
/* for bricks logging */
#include "bricks_log.h"
#include "pkt_hash.h"
/* for pkt engine */
#include "pkt_engine.h"
/* for strcpy */
#include <string.h>
/* for linked list queue */
#include "queue.h"
/* for filter context */
#include "bricks_filter.h"
/*---------------------------------------------------------------------*/
typedef struct FilterContext {
/* nothing here so far... */
} FilterContext __attribute__((aligned(__WORDSIZE)));
#if 0
struct FilterContext {
/* name of output node */
char name[IFNAMSIZ];
/*
* the linked list ptr that will chain together
* all filter bricks (for bricks_filter.c). this
* will be used for network communication module
*/
TAILQ_ENTRY(FilterContext) entry;

/* Filter list */
flist filter_list;

} __attribute__((aligned(__WORDSIZE)));
#endif
/*---------------------------------------------------------------------*/
int32_t
filter_init(Brick *brick, Linker_Intf *li)
{
TRACE_BRICK_FUNC_START();
brick->private_data = calloc(1, sizeof(FilterContext));
if (brick->private_data == NULL) {
TRACE_LOG("Can't create private context "
"for filter\n");
FilterContext *fc = calloc(1, sizeof(FilterContext));
if (fc == NULL) {
TRACE_LOG("Can't allocate memory for private FilterContext!\n");
TRACE_BRICK_FUNC_END();
return -1;
}
brick->private_data = fc;
li->type = SHARE;
#if 1
#else
strcpy(fc->name, li->output_link[0]);
TRACE_LOG("Adding brick with output link named: %s for engine %s\n",
li->output_link[0], brick->eng->name);
/* Adding filter brick to the engine's filter list */
TAILQ_INSERT_TAIL(&brick->eng->filter_list, fc, entry);
#endif
TRACE_BRICK_FUNC_END();

return 1;
}
/*---------------------------------------------------------------------*/
Expand All @@ -61,27 +90,28 @@ static BITMAP
filter_dummy(Brick *brick, unsigned char *buf)
{
TRACE_BRICK_FUNC_START();
linkdata *lnd = (linkdata *)(&brick->lnd);
BITMAP b;

INIT_BITMAP(b);
uint key = pkt_hdr_hash(buf, 4, lnd->level)
% lnd->count;
SET_BIT(b, key);

TRACE_BRICK_FUNC_END();
SET_BIT(b, 0);
#if 1
UNUSED(brick);
UNUSED(buf);
#else
FilterContext *fc;

fc = (FilterContext *)brick->private_data;
if (analyze_packet(buf, fc, time(NULL)))
#endif
TRACE_BRICK_FUNC_END();
return b;
}
/*---------------------------------------------------------------------*/
void
filter_deinit(Brick *brick)
{
TRACE_BRICK_FUNC_START();
if (brick->private_data != NULL) {
free(brick->private_data);
brick->private_data = NULL;
}
free(brick->private_data);
free(brick);
TRACE_BRICK_FUNC_END();
}
Expand Down
1 change: 1 addition & 0 deletions src/bricks/lb.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ lb_init(Brick *brick, Linker_Intf *li)
else
lbc->hash_split = li->hash_split;
li->type = SHARE;
TRACE_LOG("Adding brick %s to the engine\n", li->output_link[0]);
TRACE_BRICK_FUNC_END();

return 1;
Expand Down
61 changes: 57 additions & 4 deletions src/bricks_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ HandleMACFilter(Filter *f, struct ether_header *ethh)
/*---------------------------------------------------------------------*/
/* Under construction.. */
int
#if 1
analyze_packet(unsigned char *buf, CommNode *cn, time_t current_time)
#else
analyze_packet(unsigned char *buf, FilterContext *cn, time_t current_time)
#endif
{
TRACE_FILTER_FUNC_START();
struct ether_header *ethh = NULL;
Expand Down Expand Up @@ -431,7 +435,11 @@ adjustMasks(Filter *f)
}
/*---------------------------------------------------------------------*/
int
#if 1
apply_filter(CommNode *cn, Filter *fin)
#else
apply_filter(FilterContext *cn, Filter *fin)
#endif
{
TRACE_FILTER_FUNC_START();
Filter *f = (Filter *)calloc(1, sizeof(Filter));
Expand All @@ -453,7 +461,8 @@ apply_filter(CommNode *cn, Filter *fin)
TRACE_FILTER_FUNC_END();
}
/*---------------------------------------------------------------------*/
#ifdef DEBUG
//#ifdef DEBUG
#if 1
void
printFilter(Filter *f)
{
Expand Down Expand Up @@ -511,6 +520,17 @@ printFilter(Filter *f)
#endif /* !DEBUG */
/*---------------------------------------------------------------------*/
#ifdef ENABLE_BROKER
void
accept_node_name(Filter *f, char *name)
{
TRACE_FILTER_FUNC_START();

if (strstr(name, "}") != NULL)
strcpy(f->node_name, name);

TRACE_FILTER_FUNC_END();
}
/*---------------------------------------------------------------------*/
#define parse_request(x, f) parse_record(x, f)
void
parse_record(broker_data *v, Filter *f)
Expand Down Expand Up @@ -554,6 +574,7 @@ parse_record(broker_data *v, Filter *f)
case broker_data_type_string:
TRACE_DEBUG_LOG( "Got a string: %s\n",
broker_string_data(broker_data_as_string(inner_d)));
accept_node_name(f, (char *)broker_string_data(broker_data_as_string(inner_d)));
break;
case broker_data_type_address:
baddr = broker_data_as_address(inner_d);
Expand Down Expand Up @@ -731,6 +752,11 @@ brokerize_request(engine *eng, broker_message_queue *q)
int n = broker_deque_of_message_size(msgs);
int i;
Filter f;
#if 1
CommNode *cn = NULL;
#else
FilterContext *cn = NULL;
#endif

memset(&f, 0, sizeof(f));

Expand Down Expand Up @@ -772,9 +798,36 @@ brokerize_request(engine *eng, broker_message_queue *q)
broker_deque_of_message_delete(msgs);

/* TODO: XXX - This needs to be set with respect to interface name */
apply_filter(TAILQ_FIRST(&eng->commnode_list), &f);

#ifdef DEBUG
//apply_filter(TAILQ_FIRST(&eng->commnode_list), &f);
#if 1
if (f.node_name != NULL) {
/* first locate the right commnode entry */
TAILQ_FOREACH(cn, &eng->commnode_list, entry) {
if (!strcmp((char *)cn->nm_ifname, (char *)f.node_name)) {
/* apply the filter */
apply_filter(cn, &f);
break;
} else {
TRACE_LOG("ifname: %s does not match\n", cn->nm_ifname);
}
}
}
#else
if (f.node_name != NULL) {
/* first locate the right commnode entry */
TAILQ_FOREACH(cn, &eng->filter_list, entry) {
if (!strcmp((char *)cn->name, (char *)f.node_name)) {
/* apply the filter */
apply_filter(cn, &f);
break;
} else {
TRACE_LOG("ifname: %s does not match\n", cn->name);
}
}
}
#endif
//#ifdef DEBUG
#if 1
printFilter(&f);
#endif
TRACE_FILTER_FUNC_END();
Expand Down
6 changes: 6 additions & 0 deletions src/netmap_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,11 @@ dispatch_pkt(struct netmap_ring *rxring,
lnd->level,
current_time);
} else {
#if 1
cn->mark = analyze_packet(buf, cn, current_time);
#else
cn->mark = 1;
#endif
}
}
CLR_BIT(b, j);
Expand Down Expand Up @@ -830,7 +834,9 @@ install_filter(req_block *rb, engine *eng)
TAILQ_FOREACH(cn, &eng->commnode_list, entry) {
if (!strcmp((char *)cn->nm_ifname, (char *)rb->ifname)) {
/* apply the filter */
#if 0
apply_filter(cn, &rb->f);
#endif
TRACE_NETMAP_FUNC_END();
return 1;
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/pkt_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ pktengine_new(const unsigned char *name,
/* creating the commnode list */
TAILQ_INIT(&eng->commnode_list);

/* creating the filter list */
TAILQ_INIT(&eng->filter_list);

TRACE_PKTENGINE_FUNC_END();
}
/*---------------------------------------------------------------------*/
Expand Down

0 comments on commit f6aaf3e

Please sign in to comment.