Blame SOURCES/0079-bz1374141-fix-incorrect-mask-for-ppc64.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Masahiro Matsuya <mmatsuya@redhat.com>
d9d99f
Date: Sat, 29 Oct 2016 08:35:26 +0900
d9d99f
Subject: [PATCH] bz1374141 fix incorrect mask for ppc64
d9d99f
d9d99f
The netmask configured in firmware is not respected on ppc64 (big endian).
d9d99f
When 255.255.252.0 is set as netmask in firmware, the following is the value of bootpath string in grub_ieee1275_parse_bootpath().
d9d99f
d9d99f
 /vdevice/l-lan@30000002:speed=auto,duplex=auto,192.168.88.10,,192.168.89.113,192.168.88.1,5,5,255.255.252.0,512
d9d99f
d9d99f
The netmask in this bootpath is no problem, since it's a value specified in firmware. But,
d9d99f
The value of 'subnet_mask.ipv4' was set with 0xfffffc00, and __builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4)) returned 16 (not 22).
d9d99f
As a result, 16 was used for netmask wrongly.
d9d99f
d9d99f
1111 1111 1111 1111 1111 1100 0000 0000 # subnet_mask.ipv4 (=0xfffffc00)
d9d99f
0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32 (subnet_mask.ipv4)
d9d99f
1111 1111 0000 0011 0000 0000 0000 0000 # ~grub_le_to_cpu32 (subnet_mask.ipv4)
d9d99f
d9d99f
And, the count of zero with __builtin_ctz can be 16.
d9d99f
This patch changes it as below.
d9d99f
d9d99f
1111 1111 1111 1111 1111 1100 0000 0000 # subnet_mask.ipv4 (=0xfffffc00)
d9d99f
0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32 (subnet_mask.ipv4)
d9d99f
1111 1111 1111 1111 1111 1100 0000 0000 # grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4))
d9d99f
0000 0000 0000 0000 0000 0011 1111 1111 # ~grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4))
d9d99f
d9d99f
The count of zero with __builtin_clz can be 22. (clz counts the number of one bits preceding the most significant zero bit)
d9d99f
---
d9d99f
 grub-core/net/drivers/ieee1275/ofnet.c | 3 +--
d9d99f
 1 file changed, 1 insertion(+), 2 deletions(-)
d9d99f
d9d99f
diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c
d9d99f
index 002446be1c3..3df75357a70 100644
d9d99f
--- a/grub-core/net/drivers/ieee1275/ofnet.c
d9d99f
+++ b/grub-core/net/drivers/ieee1275/ofnet.c
d9d99f
@@ -220,8 +220,7 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath,
d9d99f
                                  flags);
d9d99f
       inter->vlantag = vlantag;
d9d99f
       grub_net_add_ipv4_local (inter,
d9d99f
-                          __builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4)));
d9d99f
-
d9d99f
+                          __builtin_clz (~grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4))));
d9d99f
     }
d9d99f
 
d9d99f
   if (gateway_addr.ipv4 != 0)