summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@vyatta.com>2010-10-29 11:32:44 -0700
committerStephen Hemminger <shemminger@vyatta.com>2010-10-29 11:32:44 -0700
commiteb4be593c3b5a5b0863fb0afd00d1392026cb2fa (patch)
tree9b19667db9b07aa14b3b2e668857ea8850cdd554
parent34e617ae8bbaf88cdc3b83d11236df62a0fdde58 (diff)
parentaa669cec4147e760ac417078e6a452ab0ad12762 (diff)
downloadvyatta-cfg-system-eb4be593c3b5a5b0863fb0afd00d1392026cb2fa.tar.gz
vyatta-cfg-system-eb4be593c3b5a5b0863fb0afd00d1392026cb2fa.zip
Merge branch 'mendocino' of 172.16.122.2:vyatta/mendocino/vyatta-cfg-system into mendocino
-rw-r--r--Makefile.am1
-rwxr-xr-xscripts/snmp/if-mib-alias120
-rw-r--r--scripts/snmp/vyatta-snmp.pl3
3 files changed, 124 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index cd42522f..d9c35d8a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,6 +36,7 @@ sbin_SCRIPTS += scripts/system/vyatta-auto-irqaffin.pl
sbin_SCRIPTS += scripts/system/vyatta-irqaffin
sbin_SCRIPTS += scripts/snmp/vyatta-snmp.pl
sbin_SCRIPTS += scripts/snmp/snmpd.init
+sbin_SCRIPTS += scripts/snmp/if-mib-alias
sbin_SCRIPTS += scripts/keepalived/vyatta-keepalived.pl
sbin_SCRIPTS += scripts/keepalived/vyatta-vrrp-state.pl
sbin_SCRIPTS += scripts/telnetd.init
diff --git a/scripts/snmp/if-mib-alias b/scripts/snmp/if-mib-alias
new file mode 100755
index 00000000..c713bfe8
--- /dev/null
+++ b/scripts/snmp/if-mib-alias
@@ -0,0 +1,120 @@
+#! /usr/bin/perl
+
+# **** 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: Stig Thormodsrud
+# Date: October 2010
+# Description: script is run as net-snmp extension to read interface alias
+#
+# **** End License ****
+
+use strict;
+use warnings;
+use feature "switch";
+
+# Collect interface alias values
+sub get_alias {
+ my @interfaces;
+
+ open (my $ip, '-|', 'ip li')
+ or die "Can't run ip command\n";
+ my $index;
+ while(<$ip>) {
+ if (/^(\d+): ([^:]*): /) {
+ $index = $1;
+ $interfaces[$index] = $2;
+ } elsif (/^ +alias (.*)$/) {
+ $interfaces[$index] = $1;
+ }
+ }
+ close $ip;
+ return @interfaces;
+}
+
+sub get_oid {
+ my $oid = shift;
+ die "Not a valid Object ID: $oid"
+ unless ($oid =~ /^[0-9.]*\.(\d)$/);
+ my $ifindex = $1;
+ my @interfaces = get_alias();
+
+ my $ifalias = $interfaces[$ifindex];
+ print "$oid\nstring\n$ifalias\n" if $ifalias;
+}
+
+sub get_next {
+ my $oid = shift;
+ die "Not a valid Object ID: $oid"
+ unless ($oid =~ /^([0-9.]*)\.(\d)$/);
+ my $base = $1;
+ my $ifindex = $2;
+ my @interfaces = get_alias();
+
+ while (++$ifindex <= $#interfaces) {
+ my $ifalias = $interfaces[$ifindex];
+ if ($ifalias) {
+ print "$base.$ifindex\nstring\n$ifalias\n";
+ last;
+ }
+ }
+}
+
+sub ifindextoname {
+ my $ifindex = shift;
+
+ open (my $ip, '-|', 'ip li')
+ or die "Can't run ip command\n";
+ my $index;
+ while(<$ip>) {
+ next unless (/^(\d+): ([^:]*): /);
+ return $2 if ($1 == $ifindex);
+ }
+ return;
+}
+
+sub set_oid {
+ my ($oid, $target, $value) = @_;
+ die "Not a valid Object ID: $oid"
+ unless ($oid =~ /^[0-9.]*\.(\d)$/);
+ my $ifindex = $1;
+ unless ($target eq 'string') {
+ print "wrong-type\n";
+ return;
+ }
+
+ my $ifname = ifindextoname($ifindex);
+ if ($ifname) {
+ system("ip li set $ifname alias '$value' >/dev/null 2>&1");
+ print "not-writeable\n" if ($? != 0);
+ }
+}
+
+sub usage {
+ warn "Usage: $0 {-g|-n} OID\n";
+ warn " $0 -s OID TARGET VALUE\n";
+ exit 1;
+}
+
+usage unless $#ARGV >= 1;
+
+given ($ARGV[0]) {
+ when ('-g') { get_oid ($ARGV[1]); }
+ when ('-n') { get_next ($ARGV[1]); }
+ when ('-s') { set_oid ($ARGV[1], $ARGV[2], $ARGV[3]); }
+ default {
+ warn "$ARGV[0] unknown flag\n";
+ usage;
+ }
+}
diff --git a/scripts/snmp/vyatta-snmp.pl b/scripts/snmp/vyatta-snmp.pl
index e977d619..a812eb32 100644
--- a/scripts/snmp/vyatta-snmp.pl
+++ b/scripts/snmp/vyatta-snmp.pl
@@ -154,6 +154,9 @@ sub snmp_get_constants {
print "sysServices 14\n";
print "agentaddress ", join(',',@addr), "\n";
+ # add hook to read IF-MIB::ifAlias from sysfs
+ print "pass .1.3.6.1.2.1.31.1.1.1.18 /opt/vyatta/sbin/if-mib-alias\n";
+
print "smuxpeer .1.3.6.1.4.1.3317.1.2.2\n"; # ospfd
print "smuxpeer .1.3.6.1.4.1.3317.1.2.5\n"; # bgpd
print "smuxpeer .1.3.6.1.4.1.3317.1.2.3\n"; # ripd