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

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