Skip to content
Snippets Groups Projects
Commit 4ebf4b0f authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Cleaned up some more radius code

parent 8ee91033
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,7 @@ use POE; ...@@ -29,7 +29,7 @@ use POE;
use IO::Socket::INET; use IO::Socket::INET;
use opentrafficshaper::logger; use opentrafficshaper::logger;
use opentrafficshaper::utils;
# Exporter stuff # Exporter stuff
...@@ -59,6 +59,9 @@ our $pluginInfo = { ...@@ -59,6 +59,9 @@ our $pluginInfo = {
# Copy of system globals # Copy of system globals
my $globals; my $globals;
my $logger; my $logger;
# Our own data storage
my $config;
my $dictionary;
# Initialize plugin # Initialize plugin
...@@ -80,23 +83,20 @@ sub init ...@@ -80,23 +83,20 @@ sub init
$logger->log(LOG_NOTICE,"[RADIUS] OpenTrafficShaper Radius Module v".VERSION." - Copyright (c) 2013, AllWorldIT"); $logger->log(LOG_NOTICE,"[RADIUS] OpenTrafficShaper Radius Module v".VERSION." - Copyright (c) 2013, AllWorldIT");
#
# Dictionary configuration
#
# Split off dictionaries to load # Split off dictionaries to load
if (ref($globals->{'file.config'}->{'plugin.radius'}->{'dictionary'}) eq "ARRAY") { my @dicts = ref($globals->{'file.config'}->{'plugin.radius'}->{'dictionary'}) eq "ARRAY" ?
foreach my $dict (@{$globals->{'file.config'}->{'plugin.radius'}->{'dictionary'}}) { @{$globals->{'file.config'}->{'plugin.radius'}->{'dictionary'}} : ( $globals->{'file.config'}->{'plugin.radius'}->{'dictionary'} );
$dict =~ s/\s+//g; foreach my $dict (@dicts) {
# Skip comments $dict =~ s/\s+//g;
next if ($dict =~ /^#/); # Skip comments
push(@{$globals->{'plugin.radius'}->{'config'}->{'dictionaries'}},$dict); next if ($dict =~ /^#/);
} push(@{$config->{'config.dictionaries'}},$dict);
} }
# Load dictionaries # Load dictionaries
$logger->log(LOG_DEBUG,"[RADIUS] Loading dictionaries..."); $logger->log(LOG_DEBUG,"[RADIUS] Loading dictionaries...");
my $dict = new opentrafficshaper::plugins::radius::Radius::Dictionary; my $dict = new opentrafficshaper::plugins::radius::Radius::Dictionary;
foreach my $df (@{$globals->{'plugin.radius'}->{'config'}->{'dictionaries'}}) { foreach my $df (@{$config->{'config.dictionaries'}}) {
# Load dictionary # Load dictionary
if (!$dict->readfile($df)) { if (!$dict->readfile($df)) {
$logger->log(LOG_WARN,"[RADIUS] Failed to load dictionary '$df': $!"); $logger->log(LOG_WARN,"[RADIUS] Failed to load dictionary '$df': $!");
...@@ -105,7 +105,7 @@ sub init ...@@ -105,7 +105,7 @@ sub init
} }
$logger->log(LOG_DEBUG,"[RADIUS] Loading dictionaries completed."); $logger->log(LOG_DEBUG,"[RADIUS] Loading dictionaries completed.");
# Store the dictionary # Store the dictionary
$globals->{'plugin.radius'}->{'dictionary'} = $dict; $dictionary = $dict;
} }
...@@ -141,7 +141,7 @@ sub server_read { ...@@ -141,7 +141,7 @@ sub server_read {
my $peer_addr_h = inet_ntoa($peer_addr); my $peer_addr_h = inet_ntoa($peer_addr);
# Parse packet # Parse packet
my $pkt = new Radius::Packet($globals->{'plugin.radius'}->{'dictionary'},$udp_packet); my $pkt = new opentrafficshaper::plugins::radius::Radius::Packet($dictionary,$udp_packet);
# Build log line # Build log line
my $logLine = sprintf("Remote: $peer_addr_h, Code: %s, Identifier: %s => ",$pkt->code,$pkt->identifier); my $logLine = sprintf("Remote: $peer_addr_h, Code: %s, Identifier: %s => ",$pkt->code,$pkt->identifier);
...@@ -191,8 +191,8 @@ sub server_read { ...@@ -191,8 +191,8 @@ sub server_read {
} }
# Grab rate limits from the string we got # Grab rate limits from the string we got
my $trafficLimitRx = 0; my $trafficLimitTx = 0; my $trafficLimitRx; my $trafficLimitTx;
my $trafficLimitRxBurst = 0; my $trafficLimitTxBurst = 0; my $trafficLimitRxBurst; my $trafficLimitTxBurst;
if (defined($trafficLimit)) { if (defined($trafficLimit)) {
my ($trafficLimitRxQuantifier,$trafficLimitTxQuantifier); my ($trafficLimitRxQuantifier,$trafficLimitTxQuantifier);
my ($trafficLimitRxBurstQuantifier,$trafficLimitTxBurstQuantifier); my ($trafficLimitRxBurstQuantifier,$trafficLimitTxBurstQuantifier);
...@@ -207,10 +207,18 @@ sub server_read { ...@@ -207,10 +207,18 @@ sub server_read {
# Set default if they undefined # Set default if they undefined
if (!defined($trafficGroup)) { if (!defined($trafficGroup)) {
$trafficGroup = 0; $trafficGroup = 1;
} }
if (!defined($trafficClass)) { if (!defined($trafficClass)) {
$trafficClass = 0; $trafficClass = 1;
}
# NK: FIXME for testing
if (!defined($trafficLimitTx)) {
$trafficLimitTx = 1024*1024;
}
if (!defined($trafficLimitRx)) {
$trafficLimitRx = 256*1024;
} }
my $user = { my $user = {
...@@ -228,7 +236,8 @@ sub server_read { ...@@ -228,7 +236,8 @@ sub server_read {
# Throw the change at the config manager # Throw the change at the config manager
$kernel->post("configmanager" => "process_change" => $user); $kernel->post("configmanager" => "process_change" => $user);
$logger->log(LOG_DEBUG,"=> Code: $user->{'Status'}, User: $user->{'Username'}, IP: $user->{'IP'}, Group: $user->{'Group'}, Class: $user->{'Class'}, Limits: $user->{'Limits'}, Burst: $user->{'BurstLimits'}"); $logger->log(LOG_DEBUG,"=> Code: $user->{'Status'}, User: $user->{'Username'}, IP: $user->{'IP'}, Group: $user->{'GroupID'}, Class: $user->{'ClassID'}, ".
"Limits: ".prettyUndef($trafficLimitTx)."/".prettyUndef($trafficLimitRx).", Burst: ".prettyUndef($trafficLimitTxBurst)."/".prettyUndef($trafficLimitRxBurst));
} }
...@@ -256,8 +265,8 @@ sub getKbit ...@@ -256,8 +265,8 @@ sub getKbit
{ {
my ($counter,$quantifier) = @_; my ($counter,$quantifier) = @_;
# If there is no counter, return 0 # If there is no counter
return 0 if (!defined($counter)); return undef if (!defined($counter));
# We need a quantifier # We need a quantifier
return undef if (!defined($quantifier)); return undef if (!defined($quantifier));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment