Blame SOURCES/0002-Allow-pifconfig-script-to-show-multiple-IPv4-address.patch

c75343
From 7279bdb8a281de67be61f745f24344d0574e32cf Mon Sep 17 00:00:00 2001
c75343
From: Lumir Balhar <lbalhar@redhat.com>
c75343
Date: Tue, 4 Dec 2018 11:58:48 +0100
c75343
Subject: [PATCH 1/2] Allow pifconfig script to show multiple IPv4 addresses
c75343
c75343
---
c75343
 scripts/pifconfig     | 34 ++++++++++++++++++----------------
c75343
 tests/test_ethtool.py | 15 +++++++++------
c75343
 2 files changed, 27 insertions(+), 22 deletions(-)
c75343
 mode change 100644 => 100755 scripts/pifconfig
c75343
c75343
diff --git a/scripts/pifconfig b/scripts/pifconfig
c75343
old mode 100644
c75343
new mode 100755
c75343
index f2b0707..c4e726d
c75343
--- a/scripts/pifconfig
c75343
+++ b/scripts/pifconfig
c75343
@@ -17,10 +17,17 @@
c75343
 from __future__ import unicode_literals, print_function
c75343
 
c75343
 import ethtool
c75343
+import socket
c75343
+import struct
c75343
 import sys
c75343
 from optparse import OptionParser
c75343
 
c75343
 
c75343
+def bits2netmask(bits):
c75343
+    mask = (1 << 32) - (1 << 32 >> bits)
c75343
+    return socket.inet_ntoa(struct.pack(">L", mask))
c75343
+
c75343
+
c75343
 def flags2str(flags):
c75343
     string = ''
c75343
     if flags & ethtool.IFF_UP:
c75343
@@ -60,24 +67,19 @@ def flags2str(flags):
c75343
 
c75343
 
c75343
 def show_config(device):
c75343
-    try:
c75343
-        ipaddr = ethtool.get_ipaddr(device)
c75343
-        netmask = ethtool.get_netmask(device)
c75343
-        broadcast = ethtool.get_broadcast(device)
c75343
-    except (IOError, OSError):
c75343
-        ipaddr, netmask, broadcast = None, None, None
c75343
     flags = ethtool.get_flags(device)
c75343
-    print('%s' % device)
c75343
-    if not (flags & ethtool.IFF_LOOPBACK):
c75343
-        print('\tHWaddr %s' % ethtool.get_hwaddr(device))
c75343
-    if ipaddr is not None:
c75343
-        print('\tinet addr:%s' % ipaddr)
c75343
-    if broadcast is not None and \
c75343
-       not (flags & (ethtool.IFF_LOOPBACK | ethtool.IFF_POINTOPOINT)):
c75343
-        print('\tBcast:%s' % broadcast)
c75343
-    if netmask is not None:
c75343
-        print('\tMask:%s' % netmask)
c75343
+
c75343
     for info in ethtool.get_interfaces_info(device):
c75343
+        print(device)
c75343
+        if not (flags & ethtool.IFF_LOOPBACK):
c75343
+                print('\tHWaddr %s' % ethtool.get_hwaddr(device))
c75343
+
c75343
+        for addr in info.get_ipv4_addresses():
c75343
+            print('\tinet addr:%s' % addr.address, end=" ")
c75343
+            if not (flags & (ethtool.IFF_LOOPBACK | ethtool.IFF_POINTOPOINT)):
c75343
+                print('Bcast:%s' % addr.broadcast, end=" ")
c75343
+            print('Mask:%s' % bits2netmask(addr.netmask))
c75343
+
c75343
         for addr in info.get_ipv6_addresses():
c75343
             print('\tinet6 addr: %s/%s Scope: %s'
c75343
                   % (addr.address,
c75343
diff --git a/tests/test_ethtool.py b/tests/test_ethtool.py
c75343
index 2d8bc0e..6162cd3 100755
c75343
--- a/tests/test_ethtool.py
c75343
+++ b/tests/test_ethtool.py
c75343
@@ -175,17 +175,20 @@ class EthtoolTests(unittest.TestCase):
c75343
             scraped = None
c75343
 
c75343
         self.assertIsStringOrNone(ei.ipv4_address)
c75343
-        if scraped:
c75343
-            self.assertEqual(ei.ipv4_address, scraped.inet)
c75343
+        if scraped and scraped.inet:
c75343
+            addresses = [ip.address for ip in ei.get_ipv4_addresses()]
c75343
+            self.assertTrue(scraped.inet in addresses)
c75343
 
c75343
         self.assertIsStringOrNone(ei.ipv4_broadcast)
c75343
-        if scraped and scraped.broadcast:
c75343
+        if scraped and scraped.broadcast not in (None, '0.0.0.0'):
c75343
             # Broadcast is optional
c75343
-            self.assertEqual(ei.ipv4_broadcast, scraped.broadcast)
c75343
+            broadcasts = [ip.broadcast for ip in ei.get_ipv4_addresses()]
c75343
+            self.assertTrue(scraped.broadcast in broadcasts)
c75343
 
c75343
         self.assertIsInt(ei.ipv4_netmask)
c75343
-        if scraped:
c75343
-            self.assertEqual(ei.ipv4_netmask, scraped.get_netmask_bits())
c75343
+        if scraped and scraped.netmask:
c75343
+            netmasks = [ip.netmask for ip in ei.get_ipv4_addresses()]
c75343
+            self.assertTrue(scraped.get_netmask_bits(), netmasks)
c75343
 
c75343
         self.assertIsStringOrNone(ei.mac_address)
c75343
         if scraped and scraped.hwaddr and scraped.hwtitle.lower() != 'unspec':
c75343
-- 
c75343
2.19.2
c75343