bug 1646 - ICMPv6 Redirect are sent from global address instead of link-local
authorGuowang Shi <shiguowang2007@gmail.com>
Sat, 15 Jun 2013 10:56:55 +0200
changeset 9833 a12922454a0c
parent 9832 02642e139f19
child 9834 0d35086abaaa
bug 1646 - ICMPv6 Redirect are sent from global address instead of link-local
src/internet/model/icmpv6-l4-protocol.cc
src/internet/model/icmpv6-l4-protocol.h
src/internet/model/ipv6-l3-protocol.cc
--- a/src/internet/model/icmpv6-l4-protocol.cc	Fri Jun 14 16:31:10 2013 -0700
+++ b/src/internet/model/icmpv6-l4-protocol.cc	Sat Jun 15 10:56:55 2013 +0200
@@ -1083,7 +1083,7 @@
   SendMessage (p, dst, header, 255);
 }
 
-void Icmpv6L4Protocol::SendRedirection (Ptr<Packet> redirectedPacket, Ipv6Address dst, Ipv6Address redirTarget, Ipv6Address redirDestination, Address redirHardwareTarget)
+void Icmpv6L4Protocol::SendRedirection (Ptr<Packet> redirectedPacket, Ipv6Address src, Ipv6Address dst, Ipv6Address redirTarget, Ipv6Address redirDestination, Address redirHardwareTarget)
 {
   NS_LOG_FUNCTION (this << redirectedPacket << dst << redirTarget << redirDestination << redirHardwareTarget);
   uint32_t llaSize = 0;
@@ -1128,7 +1128,10 @@
   Icmpv6Redirection redirectionHeader;
   redirectionHeader.SetTarget (redirTarget);
   redirectionHeader.SetDestination (redirDestination);
-  SendMessage (p, dst, redirectionHeader, 64);
+  redirectionHeader.CalculatePseudoHeaderChecksum (src, dst, p->GetSize () + redirectionHeader.GetSerializedSize (), PROT_NUMBER);
+  p->AddHeader (redirectionHeader);
+
+  SendMessage (p, src, dst, 64);
 }
 
 Ptr<Packet> Icmpv6L4Protocol::ForgeNA (Ipv6Address src, Ipv6Address dst, Address* hardwareAddress, uint8_t flags)
--- a/src/internet/model/icmpv6-l4-protocol.h	Fri Jun 14 16:31:10 2013 -0700
+++ b/src/internet/model/icmpv6-l4-protocol.h	Sat Jun 15 10:56:55 2013 +0200
@@ -274,12 +274,13 @@
   /**
    * \brief Send an ICMPv6 Redirection.
    * \param redirectedPacket the redirected packet
-   * \param dst destination IPv6 address
+   * \param src IPv6 address to send the redirect from
+   * \param dst IPv6 address to send the redirect to
    * \param redirTarget IPv6 target address for Icmpv6Redirection
    * \param redirDestination IPv6 destination address for Icmpv6Redirection
    * \param redirHardwareTarget L2 target address for Icmpv6OptionRdirected
    */
-  void SendRedirection (Ptr<Packet> redirectedPacket, Ipv6Address dst, Ipv6Address redirTarget, Ipv6Address redirDestination, Address redirHardwareTarget);
+  void SendRedirection (Ptr<Packet> redirectedPacket, Ipv6Address src, Ipv6Address dst, Ipv6Address redirTarget, Ipv6Address redirDestination, Address redirHardwareTarget);
 
   /**
    * \brief Forge a Neighbor Solicitation.
--- a/src/internet/model/ipv6-l3-protocol.cc	Fri Jun 14 16:31:10 2013 -0700
+++ b/src/internet/model/ipv6-l3-protocol.cc	Sat Jun 15 10:56:55 2013 +0200
@@ -938,14 +938,15 @@
         }
 
       copy->AddHeader (header);
+      Ipv6Address linkLocal = GetInterface (GetInterfaceForDevice (rtentry->GetOutputDevice ()))->GetLinkLocalAddress ().GetAddress ();
 
       if (icmpv6->Lookup (target, rtentry->GetOutputDevice (), 0, &hardwareTarget))
         {
-          icmpv6->SendRedirection (copy, src, target, dst, hardwareTarget);
+          icmpv6->SendRedirection (copy, linkLocal, src, target, dst, hardwareTarget);
         }
       else
         {
-          icmpv6->SendRedirection (copy, src, target, dst, Address ());
+          icmpv6->SendRedirection (copy, linkLocal, src, target, dst, Address ());
         }
     }