From f9a1d72ce7a002463df1fa28f2fd146b77abd923 Mon Sep 17 00:00:00 2001 From: sl077 Date: Sun, 9 May 2021 13:55:31 +0200 Subject: [PATCH] Fix IPv6 Neighbor Discovery for PPP based protocols --- src/Cedar/Hub.c | 2 +- src/Cedar/IPC.c | 18 +++++------------- src/Mayaqua/TcpIp.c | 22 +++++++++++++++++++--- src/Mayaqua/TcpIp.h | 2 +- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/Cedar/Hub.c b/src/Cedar/Hub.c index 605405b4..38c6350f 100644 --- a/src/Cedar/Hub.c +++ b/src/Cedar/Hub.c @@ -1633,7 +1633,7 @@ void HubWatchDogThread(THREAD *t, void *param) { buf = BuildICMPv6NeighborSoliciation(&hub->HubIpV6, &ip6addr, - hub->HubMacAddr, ++hub->HubIP6Id); + hub->HubMacAddr, ++hub->HubIP6Id, false); if (buf != NULL) { diff --git a/src/Cedar/IPC.c b/src/Cedar/IPC.c index ec3e7cc1..ecf76603 100644 --- a/src/Cedar/IPC.c +++ b/src/Cedar/IPC.c @@ -2109,13 +2109,12 @@ void IPCIPv6AssociateOnNDTEx(IPC *ipc, IP *ip, UCHAR *mac_address, bool isNeighb addrType = GetIPAddrType6(ip); - if (addrType != IPV6_ADDR_LOCAL_UNICAST && - addrType != IPV6_ADDR_GLOBAL_UNICAST) + if (!(addrType & IPV6_ADDR_UNICAST)) { return; } - if (addrType == IPV6_ADDR_GLOBAL_UNICAST) + if (addrType & IPV6_ADDR_GLOBAL_UNICAST) { if (!IPCIPv6CheckUnicastFromRouterPrefix(ipc, ip, NULL)) { @@ -2617,23 +2616,16 @@ void IPCIPv6SendUnicast(IPC *ipc, void *data, UINT size, IP *next_ip) // Generate the MAC address from the multicast address BUF *neighborSolicit; UCHAR destMacAddress[6]; - IPV6_ADDR solicitAddress; char tmp[MAX_SIZE]; UCHAR *copy; BLOCK *blk; - Zero(&solicitAddress, sizeof(IPV6_ADDR)); - Copy(&solicitAddress.Value[13], &header->DestAddress.Value[13], 3); - solicitAddress.Value[0] = 0xFF; - solicitAddress.Value[1] = 0x02; - solicitAddress.Value[11] = 0x01; - solicitAddress.Value[12] = 0xFF; - - neighborSolicit = BuildICMPv6NeighborSoliciation(&header->SrcAddress, &solicitAddress, ipc->MacAddress, 0); + neighborSolicit = BuildICMPv6NeighborSoliciation(&header->SrcAddress, &header->DestAddress, ipc->MacAddress, 0, true); destMacAddress[0] = 0x33; destMacAddress[1] = 0x33; - Copy(&destMacAddress[2], &solicitAddress.Value[12], sizeof(UINT)); + destMacAddress[2] = 0xFF; + Copy(&destMacAddress[3], &header->DestAddress.Value[13], 3); IPCIPv6SendWithDestMacAddr(ipc, neighborSolicit->Buf, neighborSolicit->Size, destMacAddress); FreeBuf(neighborSolicit); diff --git a/src/Mayaqua/TcpIp.c b/src/Mayaqua/TcpIp.c index 82173803..c98f3f69 100644 --- a/src/Mayaqua/TcpIp.c +++ b/src/Mayaqua/TcpIp.c @@ -845,7 +845,7 @@ BUF *BuildICMPv6(IPV6_ADDR *src_ip, IPV6_ADDR *dest_ip, UCHAR hop_limit, UCHAR t } // Build an ICMPv6 Neighbor Solicitation packet -BUF *BuildICMPv6NeighborSoliciation(IPV6_ADDR *src_ip, IPV6_ADDR *target_ip, UCHAR *my_mac_address, UINT id) +BUF *BuildICMPv6NeighborSoliciation(IPV6_ADDR *src_ip, IPV6_ADDR *target_ip, UCHAR *my_mac_address, UINT id, bool use_multicast) { ICMPV6_OPTION_LIST opt; ICMPV6_OPTION_LINK_LAYER link; @@ -875,8 +875,24 @@ BUF *BuildICMPv6NeighborSoliciation(IPV6_ADDR *src_ip, IPV6_ADDR *target_ip, UCH WriteBuf(b2, &header, sizeof(header)); WriteBufBuf(b2, b); - ret = BuildICMPv6(src_ip, target_ip, 255, - ICMPV6_TYPE_NEIGHBOR_SOLICIATION, 0, b2->Buf, b2->Size, id); + if (use_multicast) + { + IPV6_ADDR solicitAddress; + Zero(&solicitAddress, sizeof(IPV6_ADDR)); + solicitAddress.Value[0] = 0xFF; + solicitAddress.Value[1] = 0x02; + solicitAddress.Value[11] = 0x01; + solicitAddress.Value[12] = 0xFF; + Copy(&solicitAddress.Value[13], &target_ip->Value[13], 3); + + ret = BuildICMPv6(src_ip, &solicitAddress, 255, + ICMPV6_TYPE_NEIGHBOR_SOLICIATION, 0, b2->Buf, b2->Size, id); + } + else + { + ret = BuildICMPv6(src_ip, target_ip, 255, + ICMPV6_TYPE_NEIGHBOR_SOLICIATION, 0, b2->Buf, b2->Size, id); + } FreeBuf(b); FreeBuf(b2); diff --git a/src/Mayaqua/TcpIp.h b/src/Mayaqua/TcpIp.h index 4d35c5ef..aa5c42a8 100644 --- a/src/Mayaqua/TcpIp.h +++ b/src/Mayaqua/TcpIp.h @@ -792,7 +792,7 @@ BUF *BuildIPv6(IPV6_ADDR *dest_ip, IPV6_ADDR *src_ip, UINT id, UCHAR protocol, U BUF *BuildIPv6PacketHeader(IPV6_HEADER_PACKET_INFO *info, UINT *bytes_before_payload); UCHAR IPv6GetNextHeaderFromQueue(QUEUE *q); void BuildAndAddIPv6PacketOptionHeader(BUF *b, IPV6_OPTION_HEADER *opt, UCHAR next_header, UINT size); -BUF *BuildICMPv6NeighborSoliciation(IPV6_ADDR *src_ip, IPV6_ADDR *target_ip, UCHAR *my_mac_address, UINT id); +BUF *BuildICMPv6NeighborSoliciation(IPV6_ADDR *src_ip, IPV6_ADDR *target_ip, UCHAR *my_mac_address, UINT id, bool use_multicast); BUF *BuildICMPv6RouterSoliciation(IPV6_ADDR *src_ip, IPV6_ADDR *target_ip, UCHAR *my_mac_address, UINT id); BUF *BuildICMPv6(IPV6_ADDR *src_ip, IPV6_ADDR *dest_ip, UCHAR hop_limit, UCHAR type, UCHAR code, void *data, UINT size, UINT id);