From 97ce3a19d0a2ab7f807505034a29819001a3c552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Mon, 3 Sep 2012 19:08:01 +0200 Subject: [PATCH] fix: linux ifconfig parsing on Fedora 17 ifconfig output on Fedora 17 is based on a net-tools git snapshot: net-tools-1.60-138.20120702git.fc17.x86_64 The ifconfig output is much more UNIX like: -->8------ em1: flags=4163 mtu 1500 inet 192.168.0.11 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 2a01:e35:2f18:2790:22cf:30ff:feec:c889 prefixlen 64 scopeid 0x0 inet6 fe80::22cf:30ff:feec:c889 prefixlen 64 scopeid 0x20 ether 20:cf:30:ec:c8:89 txqueuelen 1000 (Ethernet) RX packets 467964 bytes 438067184 (417.7 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 462167 bytes 273637311 (260.9 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 16436 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 0 (Boucle locale) RX packets 121763 bytes 59893237 (57.1 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 121763 bytes 59893237 (57.1 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099 mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:38:0d:b7 txqueuelen 0 (Ethernet) RX packets 36309 bytes 2533768 (2.4 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 78400 bytes 112637354 (107.4 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 --8<------ Unlike UNIX ifconfig, there is an empty link like the common Linux ifconfig. https://bugzilla.redhat.com/show_bug.cgi?id=853982 Reported-by: Remi Collet --- lib/FusionInventory/Agent/Tools/Linux.pm | 33 ++++++++++++++++++++++-- resources/generic/ifconfig/linux-fc17 | 10 +++++++ t/tools/linux.t | 11 ++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 resources/generic/ifconfig/linux-fc17 diff --git a/lib/FusionInventory/Agent/Tools/Linux.pm b/lib/FusionInventory/Agent/Tools/Linux.pm index 29c04600b4..41279a2ed0 100644 --- a/lib/FusionInventory/Agent/Tools/Linux.pm +++ b/lib/FusionInventory/Agent/Tools/Linux.pm @@ -299,11 +299,40 @@ sub getInterfacesFromIfconfig { if ($line =~ /^(\S+)/) { # new interface + my $ifname = $1; +# ifconfig on Fedora 17 generates line like this one +#em1: flags=4163 mtu 1500 + $ifname =~ s/:$//; + + my $status = 'Down'; + if ($line =~ /,]/) { + $status = 'Up'; + } + $interface = { - STATUS => 'Down', - DESCRIPTION => $1 + STATUS => $status, + DESCRIPTION => $ifname } } + if ($line =~ /inet\s($ip_address_pattern) + \s\snetmask\s($ip_address_pattern) + \s\sbroadcast\s$ip_address_pattern/x) { + $interface->{IPADDRESS} = $1; + $interface->{IPMASK} = $2; + + } + if ($line =~ /ether\s($mac_address_pattern) + \s\s.*\s\s\((.*?)\)/x) { + $interface->{MACADDR} = $1; + $interface->{TYPE} = $2; + + } + if ($line =~ /inet6\s(\S+) + \s\sprefixlen\s\d+\s\s/x) { + $interface->{IPADDRESS6} = $1; + + } + if ($line =~ /inet addr:($ip_address_pattern)/i) { $interface->{IPADDRESS} = $1; } diff --git a/resources/generic/ifconfig/linux-fc17 b/resources/generic/ifconfig/linux-fc17 new file mode 100644 index 0000000000..39a18dc54b --- /dev/null +++ b/resources/generic/ifconfig/linux-fc17 @@ -0,0 +1,10 @@ +em1: flags=4163 mtu 1500 + inet 10.1.65.145 netmask 255.255.0.0 broadcast 10.1.255.255 + inet6 fe80::223:aeff:fe8c:33b6 prefixlen 64 scopeid 0x20 + ether 00:23:ae:8c:33:b6 txqueuelen 1000 (Ethernet) + RX packets 4634814 bytes 4923336168 (4.5 GiB) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 1736369 bytes 1125167322 (1.0 GiB) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + device interrupt 21 memory 0xf7ae0000-f7b00000 + diff --git a/t/tools/linux.t b/t/tools/linux.t index 94276cc164..4e17c57e6f 100755 --- a/t/tools/linux.t +++ b/t/tools/linux.t @@ -685,6 +685,17 @@ my %ifconfig_tests = ( TYPE => 'Ethernet', IPADDRESS6 => 'fe80::fcff:ffff:feff:ffff/64' } + ], + 'linux-fc17' => [ + { + IPMASK => '255.255.0.0', + MACADDR => '00:23:ae:8c:33:b6', + DESCRIPTION => 'em1', + STATUS => 'Up', + TYPE => 'Ethernet', + IPADDRESS6 => 'fe80::223:aeff:fe8c:33b6', + IPADDRESS => '10.1.65.145' + } ] );