mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 07:13:54 -06:00
net: move compute_mcast_idx() to net.h
Reduce duplicated codes. Signed-off-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
afe0a59535
commit
7fc8d918b9
6 changed files with 26 additions and 98 deletions
23
net.c
23
net.c
|
@ -1475,3 +1475,26 @@ int net_client_parse(QemuOptsList *opts_list, const char *optarg)
|
|||
default_net = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* From FreeBSD */
|
||||
/* XXX: optimize */
|
||||
unsigned compute_mcast_idx(const uint8_t *ep)
|
||||
{
|
||||
uint32_t crc;
|
||||
int carry, i, j;
|
||||
uint8_t b;
|
||||
|
||||
crc = 0xffffffff;
|
||||
for (i = 0; i < 6; i++) {
|
||||
b = *ep++;
|
||||
for (j = 0; j < 8; j++) {
|
||||
carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01);
|
||||
crc <<= 1;
|
||||
b >>= 1;
|
||||
if (carry) {
|
||||
crc = ((crc ^ POLYNOMIAL) | carry);
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc >> 26;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue