From 5da52b67dc78ef08e7c8a0e1c5502a67be59cd27 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 8 Mar 2011 09:47:13 -0800 Subject: Test for ipv6 blacklist when configuring SNMP Bug 6432 Since IPv6 can be disabled several ways and the config may not match the system, use socket to test if IPv6 is disabled. --- scripts/snmp/vyatta-snmp.pl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'scripts/snmp/vyatta-snmp.pl') diff --git a/scripts/snmp/vyatta-snmp.pl b/scripts/snmp/vyatta-snmp.pl index 01283870..28d3d036 100755 --- a/scripts/snmp/vyatta-snmp.pl +++ b/scripts/snmp/vyatta-snmp.pl @@ -23,15 +23,17 @@ # **** End License **** # +use strict; +use warnings; + use lib "/opt/vyatta/share/perl5/"; use Vyatta::Config; use Vyatta::Misc; use NetAddr::IP; use Getopt::Long; use File::Copy; - -use strict; -use warnings; +use Socket; +use Socket6; my $mibdir = '/opt/vyatta/share/snmp/mibs'; my $snmp_init = 'invoke-rc.d snmpd'; @@ -112,9 +114,12 @@ sub transport_syntax { die "$addr: unknown IP version $version"; } +# Test if IPv6 is possible by opening a socket sub ipv6_disabled { - my $config = new Vyatta::Config; - return $config->exists("system ipv6 disable"); + socket ( my $s, PF_INET6, SOCK_DGRAM, 0) + or return 1; + close($s); + return; } # Find SNMP agent listening addresses -- cgit v1.2.3