Skip to content

Commit

Permalink
fix: linux ifconfig parsing on Fedora 17
Browse files Browse the repository at this point in the history
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<UP,BROADCAST,RUNNING,MULTICAST> 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<global>
    inet6 fe80::22cf:30ff:feec:c889 prefixlen 64 scopeid 0x20<link>
    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<UP,LOOPBACK,RUNNING> mtu 16436
    inet 127.0.0.1 netmask 255.0.0.0
    inet6 ::1 prefixlen 128 scopeid 0x10<host>
    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<UP,BROADCAST,MULTICAST> 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 <Remi@FamilleCollet.com>
  • Loading branch information
Gonéri Le Bouder authored and guillomovitch committed Sep 4, 2012
1 parent 28253a0 commit 97ce3a1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
33 changes: 31 additions & 2 deletions lib/FusionInventory/Agent/Tools/Linux.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
$ifname =~ s/:$//;

my $status = 'Down';
if ($line =~ /<UP[>,]/) {
$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;
}
Expand Down
10 changes: 10 additions & 0 deletions resources/generic/ifconfig/linux-fc17
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> 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<link>
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

11 changes: 11 additions & 0 deletions t/tools/linux.t
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
]
);

Expand Down

0 comments on commit 97ce3a1

Please sign in to comment.