From 771f8bc910debf5565c1dbe7e31430fb382bb8e3 Mon Sep 17 00:00:00 2001 From: Seth Hall Date: Fri, 2 Sep 2011 10:43:32 -0400 Subject: [PATCH] Added pf_ring load balancing support to the scripting layer. - If the misc/pf-ring-load-balancing script is loaded, the correct environment variables will be set to enable automatic flow based load balancing used pf_ring if Bro is built against the pf_ring libpcap wrapper. Loading the script on non-Linux OSs or when Bro isn't linked against the correct libpcap has no known side effects since the script just sets environment variables. - Added a BiF named setenv for setting environment variables. --- .../policy/misc/pf-ring-load-balancing.bro | 22 +++++++++++++++++++ src/bro.bif | 10 +++++++++ 2 files changed, 32 insertions(+) create mode 100644 scripts/policy/misc/pf-ring-load-balancing.bro diff --git a/scripts/policy/misc/pf-ring-load-balancing.bro b/scripts/policy/misc/pf-ring-load-balancing.bro new file mode 100644 index 0000000000..871958f4d1 --- /dev/null +++ b/scripts/policy/misc/pf-ring-load-balancing.bro @@ -0,0 +1,22 @@ +##! This script adds the necessary environment variables for Bro to make use +##! of PF_RING's clustering (and load balancing) support through the libpcap +##! wrapper. + +module PF_Ring; + +export { + ## Define the pf_ring cluster ID that you would like this instance + ## of Bro to use. Please set a value from 0 to 255 + const cluster_id = 150 &redef; +} + + +event bro_init() &priority=10 + { + if ( cluster_id > 255 || cluster_id < 0 ) + Reporter::fatal(fmt("%d is an invalid value for PF_Ring::cluster_id", cluster_id)); + + if ( ! setenv("PCAP_PF_RING_USE_CLUSTER_PER_FLOW", "1") || + ! setenv("PCAP_PF_RING_CLUSTER_ID", fmt("%d", cluster_id)) ) + Reporter::fatal("Unable to set the PF_RING environment variable."); + } \ No newline at end of file diff --git a/src/bro.bif b/src/bro.bif index bf7763522f..f5d9536cd2 100644 --- a/src/bro.bif +++ b/src/bro.bif @@ -791,6 +791,16 @@ function getenv%(var: string%): string return new StringVal(env_val); %} +function setenv%(var: string, val: string%): bool + %{ + int result = setenv(var->AsString()->CheckString(), + val->AsString()->CheckString(), 1); + + if ( result < 0 ) + return new Val(0, TYPE_BOOL); + return new Val(1, TYPE_BOOL); + %} + function sqrt%(x: double%): double %{ if ( x < 0 )