Ignore:
Timestamp:
2011-10-08T13:08:53Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bf08ff0
Parents:
8367d1d (diff), 80099c19 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/generic/net_checksum.c

    r8367d1d rd7ff048  
    4040
    4141/** Big-endian encoding CRC divider. */
    42 #define CRC_DIVIDER_BE  0x04c11db7
     42#define CRC_DIVIDER_BE  0x04c11db7
    4343
    4444/** Little-endian encoding CRC divider. */
    45 #define CRC_DIVIDER_LE  0xedb88320
     45#define CRC_DIVIDER_LE  0xedb88320
     46
     47/** Polynomial used in multicast address hashing */
     48#define CRC_MCAST_POLYNOMIAL  0x04c11db6
    4649
    4750/** Compacts the computed checksum to the 16 bit number adding the carries.
     
    203206}
    204207
    205 /** Computes the ip header checksum.
     208/** Compute the IP header checksum.
    206209 *
    207210 * To compute the checksum of a new packet, the checksum header field must be
     
    221224}
    222225
     226/** Compute the standard hash from MAC
     227 *
     228 * Hashing MAC into 64 possible values and using the value as index to
     229 * 64bit number.
     230 *
     231 * The code is copied from qemu-0.13's implementation of ne2000 and rt8139
     232 * drivers, but according to documentation there it originates in FreeBSD.
     233 *
     234 * @param[in] addr The 6-byte MAC address to be hashed
     235 *
     236 * @return 64-bit number with only single bit set to 1
     237 *
     238 */
     239uint64_t multicast_hash(const uint8_t addr[6])
     240{
     241        uint32_t crc;
     242    int carry, i, j;
     243    uint8_t b;
     244
     245    crc = 0xffffffff;
     246    for (i = 0; i < 6; i++) {
     247        b = addr[i];
     248        for (j = 0; j < 8; j++) {
     249            carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01);
     250            crc <<= 1;
     251            b >>= 1;
     252            if (carry)
     253                crc = ((crc ^ CRC_MCAST_POLYNOMIAL) | carry);
     254        }
     255    }
     256       
     257    uint64_t one64 = 1;
     258    return one64 << (crc >> 26);
     259}
     260
    223261/** @}
    224262 */
Note: See TracChangeset for help on using the changeset viewer.