From 9ba0d3a860aefc250bca9c8fb53b2c2ca9543dc3 Mon Sep 17 00:00:00 2001
From: mshlyn <linlongzhou@163.com>
Date: Wed, 11 Mar 2015 00:51:43 +0800
Subject: [PATCH] Fix and enable ipv4 multicast
---
src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp | 16 +++++++++++++---
src/add-ons/kernel/network/stack/interfaces.cpp | 14 ++++++++++++++
2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp b/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp
index 15011da..607b3aa 100644
a
|
b
|
deliver_multicast(net_protocol_module_info* module, net_buffer* buffer,
|
689 | 689 | if (module->deliver_data == NULL) |
690 | 690 | return false; |
691 | 691 | |
692 | | // TODO: fix multicast! |
693 | | return false; |
694 | 692 | MutexLocker _(sMulticastGroupsLock); |
695 | 693 | |
| 694 | if (buffer->interface_address == NULL) { |
| 695 | dprintf("%s: buffer->interface_address is NULL\n", __FUNCTION__); |
| 696 | return false; |
| 697 | } |
| 698 | |
696 | 699 | sockaddr_in* multicastAddr = (sockaddr_in*)buffer->destination; |
697 | 700 | |
698 | 701 | MulticastState::ValueIterator it = sMulticastState->Lookup(std::make_pair( |
… |
… |
deliver_multicast(net_protocol_module_info* module, net_buffer* buffer,
|
714 | 717 | // as multicast filters are installed with an IPv4 protocol |
715 | 718 | // reference, we need to go and find the appropriate instance |
716 | 719 | // related to the 'receiving protocol' with module 'module'. |
717 | | net_protocol* protocol = ipProtocol->socket->first_protocol; |
| 720 | protocol = ipProtocol->socket->first_protocol; |
718 | 721 | |
719 | 722 | while (protocol != NULL && protocol->module != module) |
720 | 723 | protocol = protocol->next; |
… |
… |
ipv4_receive_data(net_buffer* buffer)
|
1612 | 1615 | notForUs = !wasMulticast; |
1613 | 1616 | } else if (IN_MULTICAST(ntohl(header.destination))) { |
1614 | 1617 | buffer->flags |= MSG_MCAST; |
| 1618 | |
| 1619 | // Multicast MAC address is different from normal MAC |
| 1620 | // Use sdl_index of Link level sockaddr structure to accquire |
| 1621 | // reference |
| 1622 | if (!sDatalinkModule->is_local_link_address(sDomain, false, |
| 1623 | buffer->destination, &buffer->interface_address)) |
| 1624 | notForUs = true; |
1615 | 1625 | } else { |
1616 | 1626 | uint32 matchedAddressType = 0; |
1617 | 1627 | |
diff --git a/src/add-ons/kernel/network/stack/interfaces.cpp b/src/add-ons/kernel/network/stack/interfaces.cpp
index 20b4110..28bf173 100644
a
|
b
|
get_interface_address_for_link(net_domain* domain, const sockaddr* address,
|
1555 | 1555 | |
1556 | 1556 | return interface->FirstForFamily(domain->family); |
1557 | 1557 | } |
| 1558 | |
| 1559 | // Multicast frame has different MAC address |
| 1560 | // Just compare the index and name |
| 1561 | if (linkAddress.sdl_index == interface->device->index |
| 1562 | && memcmp(linkAddress.sdl_data, interface->device->name, |
| 1563 | IF_NAMESIZE > linkAddress.sdl_nlen |
| 1564 | ? linkAddress.sdl_nlen : IF_NAMESIZE) == 0) { |
| 1565 | TRACE(" %s matches\n", interface->device->name); |
| 1566 | // link address matches |
| 1567 | if (unconfiguredOnly) |
| 1568 | return interface->FirstUnconfiguredForFamily(domain->family); |
| 1569 | |
| 1570 | return interface->FirstForFamily(domain->family); |
| 1571 | } |
1558 | 1572 | } |
1559 | 1573 | |
1560 | 1574 | return NULL; |