summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/arch/macppc/dev/if_gm.c28
-rw-r--r--sys/dev/ic/lemac.c29
-rw-r--r--sys/net/if_ethersubr.c76
-rw-r--r--sys/netinet/if_ether.h11
4 files changed, 87 insertions, 57 deletions
diff --git a/sys/arch/macppc/dev/if_gm.c b/sys/arch/macppc/dev/if_gm.c
index 437a558e1d1..4a0854f2b2e 100644
--- a/sys/arch/macppc/dev/if_gm.c
+++ b/sys/arch/macppc/dev/if_gm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_gm.c,v 1.6 2002/03/14 01:26:36 millert Exp $ */
+/* $OpenBSD: if_gm.c,v 1.7 2002/05/07 19:28:59 nate Exp $ */
/* $NetBSD: if_gm.c,v 1.14 2001/07/22 11:29:46 wiz Exp $ */
/*-
@@ -139,8 +139,6 @@ void gmac_mii_writereg(struct device *, int, int, int);
void gmac_mii_statchg(struct device *);
void gmac_mii_tick(void *);
-u_int32_t ether_crc32_le(const u_int8_t *buf, size_t len);
-
#ifdef __NetBSD__
#define letoh32 le32toh
#endif
@@ -1188,27 +1186,3 @@ gmac_enable_hack()
printf("gmac enabled\n");
}
-
-/* HACK, THIS SHOULD NOT BE IN THIS FILE */
-u_int32_t
-ether_crc32_le(const u_int8_t *buf, size_t len)
-{
- static const u_int32_t crctab[] = {
- 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
- 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
- 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
- 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
- };
- u_int32_t crc;
- int i;
-
- crc = 0xffffffffU; /* initial value */
-
- for (i = 0; i < len; i++) {
- crc ^= buf[i];
- crc = (crc >> 4) ^ crctab[crc & 0xf];
- crc = (crc >> 4) ^ crctab[crc & 0xf];
- }
-
- return (crc);
-}
diff --git a/sys/dev/ic/lemac.c b/sys/dev/ic/lemac.c
index 63452a50111..4d0a70559b3 100644
--- a/sys/dev/ic/lemac.c
+++ b/sys/dev/ic/lemac.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lemac.c,v 1.2 2002/02/25 08:48:30 niklas Exp $ */
+/* $OpenBSD: lemac.c,v 1.3 2002/05/07 19:28:59 nate Exp $ */
/* $NetBSD: lemac.c,v 1.20 2001/06/13 10:46:02 wiz Exp $ */
/*-
@@ -77,9 +77,6 @@
#include <net/bpf.h>
#endif
-/* XXX Should be in if_ethersubr.c */
-u_int32_t ether_crc32_le(const u_int8_t *, size_t);
-
int lemac_ifioctl(struct ifnet *, u_long, caddr_t);
int lemac_ifmedia_change(struct ifnet *const);
void lemac_ifmedia_status(struct ifnet *const, struct ifmediareq *);
@@ -449,30 +446,6 @@ lemac_read_macaddr(unsigned char *hwaddr, const bus_space_tag_t iot,
return (0);
}
-/* XXX Should be moved to if_ethersubr.c */
-u_int32_t
-ether_crc32_le(const u_int8_t *buf, size_t len)
-{
- static const u_int32_t crctab[] = {
- 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
- 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
- 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
- 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
- };
- u_int32_t crc;
- int i;
-
- crc = 0xffffffffU; /* initial value */
-
- for (i = 0; i < len; i++) {
- crc ^= buf[i];
- crc = (crc >> 4) ^ crctab[crc & 0xf];
- crc = (crc >> 4) ^ crctab[crc & 0xf];
- }
-
- return (crc);
-}
-
void
lemac_multicast_op(u_int16_t *mctbl, const u_char *mca, int enable)
{
diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c
index 417993e4dc3..ffffc70d106 100644
--- a/sys/net/if_ethersubr.c
+++ b/sys/net/if_ethersubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ethersubr.c,v 1.61 2002/02/07 23:20:57 art Exp $ */
+/* $OpenBSD: if_ethersubr.c,v 1.62 2002/05/07 19:28:58 nate Exp $ */
/* $NetBSD: if_ethersubr.c,v 1.19 1996/05/07 02:40:30 thorpej Exp $ */
/*
@@ -1087,6 +1087,80 @@ ether_ifdetach(ifp)
}
}
+#if 0
+/*
+ * This is for reference. We have a table-driven version
+ * of the little-endian crc32 generator, which is faster
+ * than the double-loop.
+ */
+u_int32_t
+ether_crc32_le(const u_int8_t *buf, size_t len)
+{
+ u_int32_t c, crc, carry;
+ size_t i, j;
+
+ crc = 0xffffffffU; /* initial value */
+
+ for (i = 0; i < len; i++) {
+ c = buf[i];
+ for (j = 0; j < 8; j++) {
+ carry = ((crc & 0x01) ? 1 : 0) ^ (c & 0x01);
+ crc >>= 1;
+ c >>= 1;
+ if (carry)
+ crc = (crc ^ ETHER_CRC_POLY_LE);
+ }
+ }
+
+ return (crc);
+}
+#else
+u_int32_t
+ether_crc32_le(const u_int8_t *buf, size_t len)
+{
+ static const u_int32_t crctab[] = {
+ 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
+ 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
+ 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
+ 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
+ };
+ u_int32_t crc;
+ int i;
+
+ crc = 0xffffffffU; /* initial value */
+
+ for (i = 0; i < len; i++) {
+ crc ^= buf[i];
+ crc = (crc >> 4) ^ crctab[crc & 0xf];
+ crc = (crc >> 4) ^ crctab[crc & 0xf];
+ }
+
+ return (crc);
+}
+#endif
+
+u_int32_t
+ether_crc32_be(const u_int8_t *buf, size_t len)
+{
+ u_int32_t c, crc, carry;
+ size_t i, j;
+
+ crc = 0xffffffffU; /* initial value */
+
+ for (i = 0; i < len; i++) {
+ c = buf[i];
+ for (j = 0; j < 8; j++) {
+ carry = ((crc & 0x80000000U) ? 1 : 0) ^ (c & 0x01);
+ crc <<= 1;
+ c >>= 1;
+ if (carry)
+ crc = (crc ^ ETHER_CRC_POLY_BE) | carry;
+ }
+ }
+
+ return (crc);
+}
+
u_char ether_ipmulticast_min[6] = { 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 };
u_char ether_ipmulticast_max[6] = { 0x01, 0x00, 0x5e, 0x7f, 0xff, 0xff };
diff --git a/sys/netinet/if_ether.h b/sys/netinet/if_ether.h
index 8bfd7a0af28..f1284d7be0e 100644
--- a/sys/netinet/if_ether.h
+++ b/sys/netinet/if_ether.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ether.h,v 1.19 2002/03/14 01:27:11 millert Exp $ */
+/* $OpenBSD: if_ether.h,v 1.20 2002/05/07 19:28:59 nate Exp $ */
/* $NetBSD: if_ether.h,v 1.22 1996/05/11 13:00:00 mycroft Exp $ */
/*
@@ -90,6 +90,12 @@ struct ether_header {
#define ETHERMTU (ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
+/*
+ * Ethernet CRC32 polynomials (big- and little-endian verions).
+ */
+#define ETHER_CRC_POLY_LE 0xedb88320
+#define ETHER_CRC_POLY_BE 0x04c11db6
+
#ifdef _KERNEL
/*
* Macro to map an IP multicast address to an Ethernet multicast address.
@@ -286,6 +292,9 @@ int revarpwhoarewe(struct ifnet *, struct in_addr *, struct in_addr *);
int revarpwhoami(struct in_addr *, struct ifnet *);
int db_show_arptab(void);
+u_int32_t ether_crc32_le(const u_int8_t *, size_t);
+u_int32_t ether_crc32_be(const u_int8_t *, size_t);
+
#else
char *ether_ntoa(struct ether_addr *);