summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Larson <mike@vyatta.com>2011-03-10 10:48:50 -0800
committerMichael Larson <mike@vyatta.com>2011-03-10 10:50:43 -0800
commit9dc6a9694c68e9ae149248e58365b492468f97c2 (patch)
treee7d57e0ce52ec91fa77117fade9c214ef7906b0a /lib
parent58c315edfe60e1ff64e97b7f7fadeabe30f11bbd (diff)
downloadvyatta-cfg-9dc6a9694c68e9ae149248e58365b492468f97c2.tar.gz
vyatta-cfg-9dc6a9694c68e9ae149248e58365b492468f97c2.zip
support for fix to bug 6081. return hash of ipv4net, ipv6net networks assigned to interfaces
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Vyatta/Misc.pm33
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/Vyatta/Misc.pm b/lib/Vyatta/Misc.pm
index c6a51c8..e184523 100755
--- a/lib/Vyatta/Misc.pm
+++ b/lib/Vyatta/Misc.pm
@@ -27,7 +27,7 @@ our @ISA = qw(Exporter);
our @EXPORT = qw(getInterfaces getIP getNetAddIP get_sysfs_value
is_address_enabled is_dhcp_enabled get_ipaddr_intf_hash
isIpAddress is_ip_v4_or_v6 interface_description
- is_local_address is_primary_address);
+ is_local_address is_primary_address get_ipnet_intf_hash);
our @EXPORT_OK = qw(generate_dhclient_intf_files
getInterfacesIPadresses
getPortRuleString);
@@ -41,6 +41,8 @@ use Socket6;
#
# returns a hash of ipaddrs => interface
#
+# only works for ipv4
+#
sub get_ipaddr_intf_hash {
my %config_ipaddrs = ();
my @lines = `ip addr show | grep 'inet '`;
@@ -53,6 +55,35 @@ sub get_ipaddr_intf_hash {
return \%config_ipaddrs;
}
+#
+# returns a hash of ipnet => interface
+#
+# works for both ipv4 and ipv6
+#
+sub get_ipnet_intf_hash {
+ my @args = qw(ip addr show);
+ my @addresses;
+ my %config_ipaddrs = ();
+
+ open my $ipcmd, '-|'
+ or exec @args
+ or die "ip addr command failed: $!";
+
+ my $iface = "";
+ while (<$ipcmd>) {
+ my ( $proto, $addr ) = split;
+ if ( $proto =~ /.*:$/ && $addr =~ /.*:$/) {
+ $iface = $addr;
+ chop($iface);
+ }
+ next unless ( $proto =~ /inet/ );
+ $config_ipaddrs{$addr} = $iface;
+ }
+ close $ipcmd;
+ return \%config_ipaddrs;
+}
+
+
# Check whether an address is the primary address on some interface
sub is_primary_address {
my $ip_address = shift;