View | Details | Raw Unified | Return to bug 1646
Collapse All | Expand All

(-)./a/examples/ipv6/icmpv6-redirect.cc (-1 / +1 lines)
 Lines 155-161   int main (int argc, char **argv) Link Here 
155
  Ipv6InterfaceContainer iic2 = ipv6.Assign (ndc2);
155
  Ipv6InterfaceContainer iic2 = ipv6.Assign (ndc2);
156
  iic2.SetRouter (0, true);
156
  iic2.SetRouter (0, true);
157
157
158
  stackHelper.AddHostRouteTo (r1, iic2.GetAddress (1, 1), iic1.GetAddress (2, 1), iic1.GetInterfaceIndex (1));
158
  stackHelper.AddHostRouteTo (r1, iic2.GetAddress (1, 1), iic1.GetAddress (2, 0), iic1.GetInterfaceIndex (1));
159
159
160
  Simulator::Schedule (Seconds (0.0), &StackHelper::PrintRoutingTable, &stackHelper, r1);
160
  Simulator::Schedule (Seconds (0.0), &StackHelper::PrintRoutingTable, &stackHelper, r1);
161
  Simulator::Schedule (Seconds (3.0), &StackHelper::PrintRoutingTable, &stackHelper, sta1);
161
  Simulator::Schedule (Seconds (3.0), &StackHelper::PrintRoutingTable, &stackHelper, sta1);
(-)./a/src/internet/model/icmpv6-l4-protocol.cc (-4 / +27 lines)
 Lines 593-602   void Icmpv6L4Protocol::HandleNA (Ptr<Pac Link Here 
593
      Ipv6InterfaceAddress ifaddr;
593
      Ipv6InterfaceAddress ifaddr;
594
      bool found = false;
594
      bool found = false;
595
      uint32_t i = 0;
595
      uint32_t i = 0;
596
      uint32_t nb = 0;
596
      uint32_t nb = interface->GetNAddresses ();
597
597
598
      for (i = 0; i < nb; i++)
598
      for (i = 0; i < nb; i++)
599
        {
599
        {
600
          ifaddr = interface->GetAddress (i);
600
          if (ifaddr.GetAddress () == target)
601
          if (ifaddr.GetAddress () == target)
601
            {
602
            {
602
              found = true;
603
              found = true;
 Lines 1072-1078   void Icmpv6L4Protocol::SendErrorParamete Link Here 
1072
  SendMessage (p, dst, header, 255);
1073
  SendMessage (p, dst, header, 255);
1073
}
1074
}
1074
1075
1075
void Icmpv6L4Protocol::SendRedirection (Ptr<Packet> redirectedPacket, Ipv6Address dst, Ipv6Address redirTarget, Ipv6Address redirDestination, Address redirHardwareTarget)
1076
void Icmpv6L4Protocol::SendRedirection (Ptr<Packet> redirectedPacket, Ipv6Address src, Ipv6Address dst, Ipv6Address redirTarget, Ipv6Address redirDestination, Address redirHardwareTarget)
1076
{
1077
{
1077
  NS_LOG_FUNCTION (this << redirectedPacket << dst << redirTarget << redirDestination << redirHardwareTarget);
1078
  NS_LOG_FUNCTION (this << redirectedPacket << dst << redirTarget << redirDestination << redirHardwareTarget);
1078
  uint32_t llaSize = 0;
1079
  uint32_t llaSize = 0;
 Lines 1117-1123   void Icmpv6L4Protocol::SendRedirection ( Link Here 
1117
  Icmpv6Redirection redirectionHeader;
1118
  Icmpv6Redirection redirectionHeader;
1118
  redirectionHeader.SetTarget (redirTarget);
1119
  redirectionHeader.SetTarget (redirTarget);
1119
  redirectionHeader.SetDestination (redirDestination);
1120
  redirectionHeader.SetDestination (redirDestination);
1120
  SendMessage (p, dst, redirectionHeader, 64);
1121
  redirectionHeader.CalculatePseudoHeaderChecksum (src, dst, p->GetSize () + redirectionHeader.GetSerializedSize (), PROT_NUMBER);
1122
  p->AddHeader (redirectionHeader);
1123
  SendMessage (p, src, dst, 64);
1121
}
1124
}
1122
1125
1123
Ptr<Packet> Icmpv6L4Protocol::ForgeNA (Ipv6Address src, Ipv6Address dst, Address* hardwareAddress, uint8_t flags)
1126
Ptr<Packet> Icmpv6L4Protocol::ForgeNA (Ipv6Address src, Ipv6Address dst, Address* hardwareAddress, uint8_t flags)
 Lines 1232-1238   bool Icmpv6L4Protocol::Lookup (Ipv6Addre Link Here 
1232
      cache = FindCache (device);
1235
      cache = FindCache (device);
1233
    }
1236
    }
1234
1237
1235
  return cache->Lookup (dst);
1238
  NdiscCache::Entry* entry = cache->Lookup (dst);
1239
  if (entry)
1240
    {
1241
      if (entry->IsReachable () || entry->IsDelay ())
1242
        {
1243
          *hardwareDestination = entry->GetMacAddress ();
1244
          return true;
1245
        }
1246
      else if (entry->IsStale ())
1247
        {
1248
          entry->StartDelayTimer ();
1249
          entry->MarkDelay ();
1250
          *hardwareDestination = entry->GetMacAddress ();
1251
          return true;
1252
        }
1253
      else
1254
        {
1255
          return false;
1256
        }
1257
    }
1258
  return false;
1236
}
1259
}
1237
1260
1238
bool Icmpv6L4Protocol::Lookup (Ptr<Packet> p, Ipv6Address dst, Ptr<NetDevice> device, Ptr<NdiscCache> cache, Address* hardwareDestination)
1261
bool Icmpv6L4Protocol::Lookup (Ptr<Packet> p, Ipv6Address dst, Ptr<NetDevice> device, Ptr<NdiscCache> cache, Address* hardwareDestination)
(-)./a/src/internet/model/icmpv6-l4-protocol.h (-1 / +2 lines)
 Lines 274-285   public: Link Here 
274
  /**
274
  /**
275
   * \brief Send an ICMPv6 Redirection.
275
   * \brief Send an ICMPv6 Redirection.
276
   * \param redirectedPacket the redirected packet
276
   * \param redirectedPacket the redirected packet
277
   * \param src source IPv6 address
277
   * \param dst destination IPv6 address
278
   * \param dst destination IPv6 address
278
   * \param redirTarget IPv6 target address for Icmpv6Redirection
279
   * \param redirTarget IPv6 target address for Icmpv6Redirection
279
   * \param redirDestination IPv6 destination address for Icmpv6Redirection
280
   * \param redirDestination IPv6 destination address for Icmpv6Redirection
280
   * \param redirHardwareTarget L2 target address for Icmpv6OptionRdirected
281
   * \param redirHardwareTarget L2 target address for Icmpv6OptionRdirected
281
   */
282
   */
282
  void SendRedirection (Ptr<Packet> redirectedPacket, Ipv6Address dst, Ipv6Address redirTarget, Ipv6Address redirDestination, Address redirHardwareTarget);
283
  void SendRedirection (Ptr<Packet> redirectedPacket, Ipv6Address src, Ipv6Address dst, Ipv6Address redirTarget, Ipv6Address redirDestination, Address redirHardwareTarget);
283
284
284
  /**
285
  /**
285
   * \brief Forge a Neighbor Solicitation.
286
   * \brief Forge a Neighbor Solicitation.
(-)./a/src/internet/model/ipv6-l3-protocol.cc (-10 / +17 lines)
 Lines 879-885   void Ipv6L3Protocol::SendRealOut (Ptr<Ip Link Here 
879
    }
879
    }
880
}
880
}
881
881
882
void Ipv6L3Protocol::IpForward (Ptr<Ipv6Route> rtentry, Ptr<const Packet> p, const Ipv6Header& header)
882
void Ipv6L3Protocol::IpForward (Ptr<const NetDevice> idev, Ptr<Ipv6Route> rtentry, Ptr<const Packet> p, const Ipv6Header& header)
883
{
883
{
884
  NS_LOG_FUNCTION (this << rtentry << p << header);
884
  NS_LOG_FUNCTION (this << rtentry << p << header);
885
  NS_LOG_LOGIC ("Forwarding logic for node: " << m_node->GetId ());
885
  NS_LOG_LOGIC ("Forwarding logic for node: " << m_node->GetId ());
 Lines 911-924   void Ipv6L3Protocol::IpForward (Ptr<Ipv6 Link Here 
911
911
912
  /* ICMPv6 Redirect */
912
  /* ICMPv6 Redirect */
913
913
914
  /* if we forward to a machine on the same network as the source,
914
  /*
915
   * we send him an ICMPv6 redirect message to notify him that a short route
915
   * incoming and outgoing devices are the same
916
   * exists.
916
   * send a redirect.
917
   */
917
   */
918
918
  if (m_sendIcmpv6Redirect && (rtentry->GetOutputDevice () == idev))
919
  if (m_sendIcmpv6Redirect &&
920
      ((!rtentry->GetGateway ().IsAny () && rtentry->GetGateway ().CombinePrefix (Ipv6Prefix (64)) == header.GetSourceAddress ().CombinePrefix (Ipv6Prefix (64)))
921
      || (rtentry->GetDestination ().CombinePrefix (Ipv6Prefix (64)) == header.GetSourceAddress ().CombinePrefix (Ipv6Prefix (64)))))
922
    {
919
    {
923
      NS_LOG_LOGIC ("ICMPv6 redirect!");
920
      NS_LOG_LOGIC ("ICMPv6 redirect!");
924
      Ptr<Icmpv6L4Protocol> icmpv6 = GetIcmpv6 ();
921
      Ptr<Icmpv6L4Protocol> icmpv6 = GetIcmpv6 ();
 Lines 932-947   void Ipv6L3Protocol::IpForward (Ptr<Ipv6 Link Here 
932
        {
929
        {
933
          target = dst;
930
          target = dst;
934
        }
931
        }
932
      if ((target != dst) && (!target.IsLinkLocal ())) /* RFC 4861 */
933
        {
934
          SendRealOut (rtentry, packet, ipHeader);
935
          return;
936
        }
935
937
936
      copy->AddHeader (header);
938
      copy->AddHeader (header);
937
939
940
      Ipv6Address linkLocal = GetInterface (GetInterfaceForDevice (rtentry->GetOutputDevice ()))->GetLinkLocalAddress ().GetAddress ();
941
      Address hardwareSrc;
942
      icmpv6->Lookup (src, rtentry->GetOutputDevice (), 0, &hardwareSrc);
943
      Ipv6Address linkLocalSrc = Ipv6Address::MakeAutoconfiguredLinkLocalAddress (Mac48Address::ConvertFrom (hardwareSrc));
944
938
      if (icmpv6->Lookup (target, rtentry->GetOutputDevice (), 0, &hardwareTarget))
945
      if (icmpv6->Lookup (target, rtentry->GetOutputDevice (), 0, &hardwareTarget))
939
        {
946
        {
940
          icmpv6->SendRedirection (copy, src, target, dst, hardwareTarget);
947
          icmpv6->SendRedirection (copy, linkLocal, linkLocalSrc, target, dst, hardwareTarget);
941
        }
948
        }
942
      else
949
      else
943
        {
950
        {
944
          icmpv6->SendRedirection (copy, src, target, dst, Address ());
951
          icmpv6->SendRedirection (copy, linkLocal, linkLocalSrc, target, dst, hardwareTarget);
945
        }
952
        }
946
    }
953
    }
947
954
(-)./a/src/internet/model/ipv6-l3-protocol.h (-1 / +2 lines)
 Lines 420-430   private: Link Here 
420
420
421
  /**
421
  /**
422
   * \brief Forward a packet.
422
   * \brief Forward a packet.
423
   * \param Ptr<const NetDevice> input device
423
   * \param rtentry route 
424
   * \param rtentry route 
424
   * \param p packet to forward
425
   * \param p packet to forward
425
   * \param header IPv6 header to add to the packet
426
   * \param header IPv6 header to add to the packet
426
   */
427
   */
427
  void IpForward (Ptr<Ipv6Route> rtentry, Ptr<const Packet> p, const Ipv6Header& header);
428
  void IpForward (Ptr<const NetDevice>, Ptr<Ipv6Route> rtentry, Ptr<const Packet> p, const Ipv6Header& header);
428
429
429
  /**
430
  /**
430
   * \brief Forward a packet in multicast.
431
   * \brief Forward a packet in multicast.
(-)./a/src/internet/model/ipv6-routing-protocol.h (-1 / +1 lines)
 Lines 56-62   class Ipv6RoutingProtocol : public Objec Link Here 
56
public:
56
public:
57
  static TypeId GetTypeId (void);
57
  static TypeId GetTypeId (void);
58
58
59
  typedef Callback<void, Ptr<Ipv6Route>, Ptr<const Packet>, const Ipv6Header &> UnicastForwardCallback;
59
  typedef Callback<void, Ptr<const NetDevice>, Ptr<Ipv6Route>, Ptr<const Packet>, const Ipv6Header &> UnicastForwardCallback;
60
  typedef Callback<void, Ptr<Ipv6MulticastRoute>, Ptr<const Packet>, const Ipv6Header &> MulticastForwardCallback;
60
  typedef Callback<void, Ptr<Ipv6MulticastRoute>, Ptr<const Packet>, const Ipv6Header &> MulticastForwardCallback;
61
  typedef Callback<void, Ptr<const Packet>, const Ipv6Header &, uint32_t > LocalDeliverCallback;
61
  typedef Callback<void, Ptr<const Packet>, const Ipv6Header &, uint32_t > LocalDeliverCallback;
62
  typedef Callback<void, Ptr<const Packet>, const Ipv6Header &, Socket::SocketErrno > ErrorCallback;
62
  typedef Callback<void, Ptr<const Packet>, const Ipv6Header &, Socket::SocketErrno > ErrorCallback;
(-)./a/src/internet/model/ipv6-static-routing.cc (-1 / +5 lines)
 Lines 304-309   Ptr<Ipv6Route> Ipv6StaticRouting::Lookup Link Here 
304
                {
304
                {
305
                  rtentry->SetSource (SourceAddressSelection (interfaceIdx, route->GetPrefixToUse ().IsAny () ? route->GetGateway () : route->GetPrefixToUse ()));
305
                  rtentry->SetSource (SourceAddressSelection (interfaceIdx, route->GetPrefixToUse ().IsAny () ? route->GetGateway () : route->GetPrefixToUse ()));
306
                }
306
                }
307
              else if (route->GetGateway ().IsLinkLocal ()) /* send message via route, the source address should be global unicast address */
308
                {
309
                  rtentry->SetSource (m_ipv6->GetAddress (interfaceIdx, 1).GetAddress ()); /* we don't have a method to find a better global unicast address */
310
                }
307
              else
311
              else
308
                {
312
                {
309
                  rtentry->SetSource (SourceAddressSelection (interfaceIdx, route->GetGateway ()));
313
                  rtentry->SetSource (SourceAddressSelection (interfaceIdx, route->GetGateway ()));
 Lines 607-613   bool Ipv6StaticRouting::RouteInput (Ptr< Link Here 
607
  if (rtentry != 0)
611
  if (rtentry != 0)
608
    {
612
    {
609
      NS_LOG_LOGIC ("Found unicast destination- calling unicast callback");
613
      NS_LOG_LOGIC ("Found unicast destination- calling unicast callback");
610
      ucb (rtentry, p, header);  // unicast forwarding callback
614
      ucb (idev, rtentry, p, header);  // unicast forwarding callback
611
      return true;
615
      return true;
612
    }
616
    }
613
  else
617
  else

Return to bug 1646