diff mbox series

[rdma-core,1/3] rxe: support iproute2 in rxe_cfg

Message ID b2459862-dd2b-b798-4eb7-520420a512f0@suse.de (mailing list archive)
State Not Applicable
Delegated to: Leon Romanovsky
Headers show
Series rxe_cfg fixes | expand

Commit Message

Nicolas Morey-Chaisemartin Aug. 1, 2018, 1:36 p.m. UTC
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 <nmoreychaisemartin@suse.com>
---
 providers/rxe/rxe_cfg.in | 64 +++++++++++++++++++++++++++++-----------
 1 file changed, 46 insertions(+), 18 deletions(-)

Comments

Jason Gunthorpe Aug. 1, 2018, 4:38 p.m. UTC | #1
On Wed, Aug 01, 2018 at 03:36:52PM +0200, Nicolas Morey-Chaisemartin wrote:
> 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 <nmoreychaisemartin@suse.com>
> ---
>  providers/rxe/rxe_cfg.in | 64 +++++++++++++++++++++++++++++-----------
>  1 file changed, 46 insertions(+), 18 deletions(-)

Lets just always use iproute please? ifconfig sometimes truncates and
mangles its output.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Nicolas Morey-Chaisemartin Aug. 2, 2018, 6:23 a.m. UTC | #2
I'm more than OK with that. Let's just hope no one will complain later on :)

On 08/01/2018 06:38 PM, Jason Gunthorpe wrote:
> On Wed, Aug 01, 2018 at 03:36:52PM +0200, Nicolas Morey-Chaisemartin wrote:
>> 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 <nmoreychaisemartin@suse.com>
>> ---
>>  providers/rxe/rxe_cfg.in | 64 +++++++++++++++++++++++++++++-----------
>>  1 file changed, 46 insertions(+), 18 deletions(-)
> Lets just always use iproute please? ifconfig sometimes truncates and
> mangles its output.
>
> Jason
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox series

Patch

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);
 	}
     }