From patchwork Wed Aug 1 13:36:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Morey-Chaisemartin X-Patchwork-Id: 10552309 X-Patchwork-Delegate: leon@leon.nu Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C62113BF for ; Wed, 1 Aug 2018 13:36:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CDA32B4BF for ; Wed, 1 Aug 2018 13:36:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30BB32B513; Wed, 1 Aug 2018 13:36:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,T_TVD_MIME_EPI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05FE62B528 for ; Wed, 1 Aug 2018 13:36:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389278AbeHAPWo (ORCPT ); Wed, 1 Aug 2018 11:22:44 -0400 Received: from mx2.suse.de ([195.135.220.15]:46146 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389108AbeHAPWo (ORCPT ); Wed, 1 Aug 2018 11:22:44 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 71618ACB0 for ; Wed, 1 Aug 2018 13:36:53 +0000 (UTC) From: Nicolas Morey-Chaisemartin Subject: [PATCH rdma-core 1/3] rxe: support iproute2 in rxe_cfg To: linux-rdma@vger.kernel.org References: <2fb5bb71-8b9c-3164-a89d-526c73a06fbb@suse.de> Openpgp: preference=signencrypt Message-ID: Date: Wed, 1 Aug 2018 15:36:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <2fb5bb71-8b9c-3164-a89d-526c73a06fbb@suse.de> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ifconfig is now deprecated in most distro in favour on iproute2. Use the ip command when ifconfig is missing. Signed-off-by: Nicolas Morey-Chaisemartin --- providers/rxe/rxe_cfg.in | 64 +++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/providers/rxe/rxe_cfg.in b/providers/rxe/rxe_cfg.in index 555a5cde983a..cf9e04ca6818 100755 --- a/providers/rxe/rxe_cfg.in +++ b/providers/rxe/rxe_cfg.in @@ -130,6 +130,7 @@ sub get_dev_info { my $np; my $i = 0; my $j = 0; + my $ifconfig; get_mlx4_list(); @@ -191,22 +192,43 @@ sub get_dev_info { $ipv4_addr{$eth} = " "; $eth_mtu{$eth} = ""; - @lines = `ifconfig $eth`; - foreach $line (@lines) { - # get IP address - if ($line =~ /inet addr/) { - $line =~ s/^\s+inet addr://g; - @fields = split(/\s+/, $line); - $ipv4_addr{$eth} = $fields[0]; - } - - # get ethernet mtu - if ($line =~ /MTU:/) { - $line =~ s/^.*MTU://g; - @fields = split(/\s+/, $line); - $eth_mtu{$eth} = $fields[0]; - } - } + $ifconfig=`which ifconfig 2> /dev/null`; + if ($ifconfig =~ /ifconfig/) { + @lines = `ifconfig $eth`; + foreach $line (@lines) { + # get IP address + if ($line =~ /inet addr/) { + $line =~ s/^\s+inet addr://g; + @fields = split(/\s+/, $line); + $ipv4_addr{$eth} = $fields[0]; + } + + # get ethernet mtu + if ($line =~ /MTU:/) { + $line =~ s/^.*MTU://g; + @fields = split(/\s+/, $line); + $eth_mtu{$eth} = $fields[0]; + } + } + } else { + @lines = `ip addr show $eth`; + foreach $line (@lines) { + # get IP address + if ($line =~ /inet /) { + $line =~ s/^\s+inet ([0-9.]+)\//$1 /g; + print($line); + @fields = split(/\s+/, $line); + $ipv4_addr{$eth} = $fields[0]; + } + + # get ethernet mtu + if ($line =~ /mtu /) { + $line =~ s/^.*mtu //g; + @fields = split(/\s+/, $line); + $eth_mtu{$eth} = $fields[0]; + } + } + } } # get rxe mtu @@ -527,8 +549,14 @@ sub do_start { foreach my $rxe (@rxe_array) { my $stat = get_devinfo($rxe); if ($stat =~ "PORT_DOWN") { - my $cmd = "ifconfig $eth_names{$rxe} up"; - system($cmd); + my $ifconfig=`which ifconfig 2> /dev/null`; + my $cmd; + if ($ifconfig =~ /ifconfig/) { + $cmd = "ifconfig $eth_names{$rxe} up"; + } else { + $cmd = "ip link set $eth_names{$rxe} up"; + } + system($cmd); } }