- Initialize ifp->if_baudrate to a sensible value when the interface is
attached. - Add ether_crc32_be() and ether_crc_le(), common functions for computing the Ethernet CRC on arbitrary length buffers. Nothing uses them yet, and these should be double-checked and probably re-implemented as table-driven functions.
This commit is contained in:
parent
c2c2f491bc
commit
b99cf790df
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: if_ether.h,v 1.13 1999/11/19 20:41:19 thorpej Exp $ */
|
||||
/* $NetBSD: if_ether.h,v 1.14 2000/03/06 20:54:41 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
@ -72,6 +72,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
|
||||
|
||||
#ifndef _STANDALONE
|
||||
|
||||
/*
|
||||
@ -198,10 +204,13 @@ struct ether_multistep {
|
||||
ETHER_NEXT_MULTI((step), (enm)); \
|
||||
}
|
||||
|
||||
#ifdef _KERNEL
|
||||
u_int32_t ether_crc32_le __P((const u_int8_t *, size_t));
|
||||
u_int32_t ether_crc32_be __P((const u_int8_t *, size_t));
|
||||
#else
|
||||
/*
|
||||
* Prototype ethers(3) functions.
|
||||
*/
|
||||
#ifndef _KERNEL
|
||||
#include <sys/cdefs.h>
|
||||
__BEGIN_DECLS
|
||||
char * ether_ntoa __P((struct ether_addr *));
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: if_ethersubr.c,v 1.52 2000/02/01 22:52:05 thorpej Exp $ */
|
||||
/* $NetBSD: if_ethersubr.c,v 1.53 2000/03/06 20:54:41 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
@ -770,6 +770,7 @@ ether_ifattach(ifp, lla)
|
||||
ifp->if_mtu = ETHERMTU;
|
||||
ifp->if_output = ether_output;
|
||||
ifp->if_input = ether_input;
|
||||
ifp->if_baudrate = IF_Mbps(10); /* just a default */
|
||||
if ((sdl = ifp->if_sadl) &&
|
||||
sdl->sdl_family == AF_LINK) {
|
||||
sdl->sdl_type = IFT_ETHER;
|
||||
@ -791,6 +792,54 @@ ether_ifdetach(ifp)
|
||||
/* Nothing. */
|
||||
}
|
||||
|
||||
u_int32_t
|
||||
ether_crc32_le(buf, len)
|
||||
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) | carry;
|
||||
}
|
||||
}
|
||||
|
||||
return (crc);
|
||||
}
|
||||
|
||||
u_int32_t
|
||||
ether_crc32_be(buf, len)
|
||||
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);
|
||||
}
|
||||
|
||||
#ifdef INET
|
||||
u_char ether_ipmulticast_min[6] = { 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 };
|
||||
u_char ether_ipmulticast_max[6] = { 0x01, 0x00, 0x5e, 0x7f, 0xff, 0xff };
|
||||
|
Loading…
Reference in New Issue
Block a user