summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2008-12-01 23:10:46 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2008-12-01 23:10:46 -0800
commit0437fd20433ec46843f6415323dd73e5167111db (patch)
tree5ddd810f72471b78c79c86ec609271f3152d120f
parentdb4770b72d8e8cb51d7777e28df27207f470ae2e (diff)
parent43be74e8740be9ea7d85ac76210884db53bac172 (diff)
downloadvyatta-wanloadbalance-0437fd20433ec46843f6415323dd73e5167111db.tar.gz
vyatta-wanloadbalance-0437fd20433ec46843f6415323dd73e5167111db.zip
Merge branch 'jenner' of suva.vyatta.com:/git/vyatta-wanloadbalance into jenner
-rw-r--r--Makefile.am2
-rw-r--r--scripts/vyatta-wlb-connection4
-rw-r--r--scripts/vyatta-wlb-connection.pl84
-rw-r--r--templates/show/wan-load-balance/connection/node.def2
4 files changed, 86 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am
index f0d9b3b..81b5f97 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,7 +13,7 @@ sbin_SCRIPTS = scripts/vyatta-wanloadbalance.pl
sbin_SCRIPTS += scripts/vyatta-wanloadbalance.init
bin_sudo_users_SCRIPTS = scripts/vyatta-wlb-status
-bin_sudo_users_SCRIPTS += scripts/vyatta-wlb-connection
+bin_sudo_users_SCRIPTS += scripts/vyatta-wlb-connection.pl
curver_DATA = cfg-version/wanloadbalance@1
diff --git a/scripts/vyatta-wlb-connection b/scripts/vyatta-wlb-connection
deleted file mode 100644
index 40060ae..0000000
--- a/scripts/vyatta-wlb-connection
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-
-cat /proc/net/ip_conntrack | grep ' mark=[1-9]'
-
diff --git a/scripts/vyatta-wlb-connection.pl b/scripts/vyatta-wlb-connection.pl
new file mode 100644
index 0000000..902e0aa
--- /dev/null
+++ b/scripts/vyatta-wlb-connection.pl
@@ -0,0 +1,84 @@
+#!/usr/bin/perl
+#
+# Module: vyatta-show-wlb-connection.pl
+#
+# **** License ****
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# This code was originally developed by Vyatta, Inc.
+# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc.
+# All Rights Reserved.
+#
+# Author: Michael Larson
+# Date: December 2008
+# Description: Script to display wlb connection information
+#
+# **** End License ****
+#
+
+use lib "/opt/vyatta/share/perl5/";
+
+#examine /var/load-balance/wlb.conf for disable-source-nat
+if (!open($CONFFILE, "<", "/var/load-balance/wlb.conf")) {
+ return;
+}
+$_ = <$CONFFILE>;
+if (/disable-source-nat/) {
+ if (!open($FILE, "<", "/proc/net/ip_conntrack")) {
+ return;
+ }
+}
+else {
+ if (!open($FILE, "/usr/sbin/conntrack -L -n|")) {
+ return;
+ }
+}
+
+print "Type\tState\t\tSrc\t\t\tDst\t\t\tPackets\tBytes\n";
+
+@line = <$FILE>;
+foreach (@line) {
+ $_ =~ s/\[\S+\]\s//;
+
+
+ my $proto,$tmp,$state,$src,$dst,$sport,$dport,$pkts,$bytes;
+
+
+ if (/tcp/) {
+ ($proto,$tmp,$tmp,$state,$src,$dst,$sport,$dport,$pkts,$bytes) = split(' ',$_);
+ }
+ elsif (/udp/) {
+ $state = "";
+ ($proto,$tmp,$tmp,$src,$dst,$sport,$dport,$pkts,$bytes) = split(' ',$_);
+ }
+ ($tmp,$src) = split('=',$src);
+ ($tmp,$dst) = split('=',$dst);
+ ($tmp,$dport) = split('=',$dport);
+ ($tmp,$sport) = split('=',$sport);
+ ($tmp,$pkts) = split('=',$pkts);
+ ($tmp,$bytes) = split('=',$bytes);
+
+ my $snet = sprintf("%s:%s%-10s",$src,$sport);
+ $snet = substr($snet,0,18);
+
+ my $dnet = sprintf("%s:%s%-10s",$dst,$dport);
+ $dnet = substr($dnet,0,18);
+
+ $state = sprintf("%s%-12s",$state);
+ $state = substr($state,0,12);
+
+ #mark=[1-9]
+ if (/ mark=[1-9]/) {
+ print "$proto\t$state\t$snet\t$dnet\t$pkts\t$bytes\n";
+ }
+}
+
+#now dump out results
+
diff --git a/templates/show/wan-load-balance/connection/node.def b/templates/show/wan-load-balance/connection/node.def
index d76fb51..d5ec64e 100644
--- a/templates/show/wan-load-balance/connection/node.def
+++ b/templates/show/wan-load-balance/connection/node.def
@@ -1,6 +1,6 @@
help: Show Wide Area Network (WAN) load-balancing flow
run: if [ -f /var/load-balance/wlb.out ] ; then
- sudo ${vyatta_bindir}/sudo-users/vyatta-wlb-connection
+ sudo ${vyatta_bindir}/sudo-users/vyatta-wlb-connection.pl
else
echo WAN load balancing is not configured
fi