Skip to contentSkip to conversation

lan9118: fix multicast filtering

PATCH In review Aurelien Jarno 3 participants 7 messages Aug 23, 2012 – Sep 7, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lan9118: fix multicast filtering

The lan9118 emulation tries to compute the multicast index by calling directly the crc32() function from zlib, but fails to get the correct result.

Use the common compute_mcast_idx() function instead, which gives the correct result. This fixes IPv6 support.

---
 hw/lan9118.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/lan9118.c +1 -1
index ff0a50b..ceaf96f 100644
@@ -500,7 +500,7 @@ static int lan9118_filter(lan9118_state *s, const uint8_t *addr)
         }
     } else {
         /* Hash matching  */
-        hash = (crc32(~0, addr, 6) >> 26);
+        hash = compute_mcast_idx(addr);
         if (hash & 0x20) {
             return (s->mac_hashh >> (hash & 0x1f)) & 1;
         } else {
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 11 lines · Aurelien Jarno

The lan9118 emulation tries to compute the multicast index by calling directly the crc32() function from zlib, but fails to get the correct result.

Use the common compute_mcast_idx() function instead, which gives the correct result. This fixes IPv6 support.

---
 hw/lan9118.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

There is another crc32() call in hw/lan9118.c:lan9118_receive(). Can that be replaced too and then #include <zlib.h> can be dropped?

Stefan

#2 lore raw
Quoted 8 lines · Stefan Hajnoczi
Quoted 7 lines · Aurelien Jarno

The lan9118 emulation tries to compute the multicast index by calling directly the crc32() function from zlib, but fails to get the correct result.

Use the common compute_mcast_idx() function instead, which gives the correct result. This fixes IPv6 support.

Quoted 8 lines
Quoted 4 lines
---
 hw/lan9118.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

There is another crc32() call in hw/lan9118.c:lan9118_receive(). Can that be replaced too and then #include <zlib.h> can be dropped?

I don't think so, at least not easily. This is a different call (the length is variable), and most emulated NICs have a call to crc32(), but in slightly different ways.

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#3 lore raw
Quoted 14 lines · Aurelien Jarno
Quoted 13 lines · Stefan Hajnoczi
Quoted 11 lines · Aurelien Jarno

The lan9118 emulation tries to compute the multicast index by calling directly the crc32() function from zlib, but fails to get the correct result.

Use the common compute_mcast_idx() function instead, which gives the correct result. This fixes IPv6 support.

---
 hw/lan9118.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines
Quoted 3 lines

There is another crc32() call in hw/lan9118.c:lan9118_receive(). Can that be replaced too and then #include <zlib.h> can be dropped?

I don't think so, at least not easily. This is a different call (the length is variable), and most emulated NICs have a call to crc32(), but in slightly different ways.

Okay. I haven't looked at the datasheet for this NIC, so I have no more input to this patch except that it looks fine.

Stefan

#4 lore raw
In reply to Aurelien Jarno
Quoted 17 lines · Aurelien Jarno

The lan9118 emulation tries to compute the multicast index by calling directly the crc32() function from zlib, but fails to get the correct result.

Use the common compute_mcast_idx() function instead, which gives the correct result. This fixes IPv6 support.

---
 hw/lan9118.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/lan9118.c +0 -0
index ff0a50b..ceaf96f 100644

hw/lan9118.c static int lan9118_filter(lan9118_state *s, const uint8_t *addr) · line 506

Quoted 8 lines
hw/lan9118.c +1 -1
@@ -500,7 +500,7 @@ static int lan9118_filter(lan9118_state *s, const uint8_t *addr)
         }
     } else {
         /* Hash matching  */
-        hash = (crc32(~0, addr, 6) >> 26);
+        hash = compute_mcast_idx(addr);
         if (hash & 0x20) {
             return (s->mac_hashh >> (hash & 0x1f)) & 1;
         } else {

Ping?

For the record the Linux kernel uses the ether_crc() function for smsc911x.c, but also for 8139cp.c, 8139too.c and ethoc.c, which use compute_mcast_idx() on the QEMU side.

To test it, just run this machine with a Linux kernel with IPv6 support on an IPv6-enabled network with router advertisement, it should get an IPv6 address automatically. It doesn't without this patch.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
Reviewed-by
#5 lore raw
Quoted 29 lines · Aurelien Jarno
Quoted 17 lines · Aurelien Jarno

The lan9118 emulation tries to compute the multicast index by calling directly the crc32() function from zlib, but fails to get the correct result.

Use the common compute_mcast_idx() function instead, which gives the correct result. This fixes IPv6 support.

---
 hw/lan9118.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/lan9118.c +0 -0
index ff0a50b..ceaf96f 100644

hw/lan9118.c static int lan9118_filter(lan9118_state *s, const uint8_t *addr) · line 506

Quoted 8 lines
hw/lan9118.c +1 -1
@@ -500,7 +500,7 @@ static int lan9118_filter(lan9118_state *s, const uint8_t *addr)
         }
     } else {
         /* Hash matching  */
-        hash = (crc32(~0, addr, 6) >> 26);
+        hash = compute_mcast_idx(addr);
         if (hash & 0x20) {
             return (s->mac_hashh >> (hash & 0x1f)) & 1;
         } else {

Ping?

Quoted 3 lines

For the record the Linux kernel uses the ether_crc() function for smsc911x.c, but also for 8139cp.c, 8139too.c and ethoc.c, which use compute_mcast_idx() on the QEMU side.

Looks ok to me. I did check the data sheet, which helpfully doesn't say exactly what the CRC function is, and also the zlib docs (which suggest we should use something that isn't what we were doing here). So I guess

Happy for you to commit directly or I can put it in arm-devs.next if you prefer.

-- PMM

#6 lore raw
Quoted 39 lines · Peter Maydell
Quoted 29 lines · Aurelien Jarno
Quoted 17 lines · Aurelien Jarno

The lan9118 emulation tries to compute the multicast index by calling directly the crc32() function from zlib, but fails to get the correct result.

Use the common compute_mcast_idx() function instead, which gives the correct result. This fixes IPv6 support.

---
 hw/lan9118.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/lan9118.c +0 -0
index ff0a50b..ceaf96f 100644

hw/lan9118.c static int lan9118_filter(lan9118_state *s, const uint8_t *addr) · line 506

Quoted 8 lines
hw/lan9118.c +1 -1
@@ -500,7 +500,7 @@ static int lan9118_filter(lan9118_state *s, const uint8_t *addr)
         }
     } else {
         /* Hash matching  */
-        hash = (crc32(~0, addr, 6) >> 26);
+        hash = compute_mcast_idx(addr);
         if (hash & 0x20) {
             return (s->mac_hashh >> (hash & 0x1f)) & 1;
         } else {

Ping?

Quoted 3 lines

For the record the Linux kernel uses the ether_crc() function for smsc911x.c, but also for 8139cp.c, 8139too.c and ethoc.c, which use compute_mcast_idx() on the QEMU side.

Looks ok to me. I did check the data sheet, which helpfully doesn't say exactly what the CRC function is, and also the zlib docs (which suggest we should use something that isn't what we were doing here). So I guess

Quoted 5 lines

Happy for you to commit directly or I can put it in arm-devs.next if you prefer.

Thanks for the review, I have applied it.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net