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

(-)orig/tap-bridge.cc (-15 / +17 lines)
 Lines 696-709    Link Here 
696
  //
696
  //
697
697
698
  //
698
  //
699
  // First, create a packet out of the byte buffer we received and free that
700
  // buffer.
701
  //
702
  Ptr<Packet> packet = Create<Packet> (reinterpret_cast<const uint8_t *> (buf), len);
703
  std::free (buf);
704
  buf = 0;
705
706
  //
707
  // Make sure the packet we received is reasonable enough for the rest of the 
699
  // Make sure the packet we received is reasonable enough for the rest of the 
708
  // system to handle and get it ready to be injected directly into an ns-3
700
  // system to handle and get it ready to be injected directly into an ns-3
709
  // device.  What should come back is a packet with the Ethernet header 
701
  // device.  What should come back is a packet with the Ethernet header 
 Lines 714-720    Link Here 
714
706
715
  NS_LOG_LOGIC ("Received packet from tap device");
707
  NS_LOG_LOGIC ("Received packet from tap device");
716
708
717
  Ptr<Packet> p = Filter (packet, &src, &dst, &type);
709
  Ptr<Packet> p = Filter (buf, len, &src, &dst, &type);
710
  std::free (buf);
711
  buf = 0;
718
  if (p == 0)
712
  if (p == 0)
719
    {
713
    {
720
      NS_LOG_LOGIC ("TapBridge::ForwardToBridgedDevice:  Discarding packet as unfit for ns-3 consumption");
714
      NS_LOG_LOGIC ("TapBridge::ForwardToBridgedDevice:  Discarding packet as unfit for ns-3 consumption");
 Lines 795-803    Link Here 
795
}
789
}
796
790
797
Ptr<Packet>
791
Ptr<Packet>
798
TapBridge::Filter (Ptr<Packet> p, Address *src, Address *dst, uint16_t *type)
792
TapBridge::Filter (uint8_t *buf, ssize_t len, Address *src, Address *dst, uint16_t *type)
799
{
793
{
800
  NS_LOG_FUNCTION (p);
794
  NS_LOG_FUNCTION (buf << len);
801
  uint32_t pktSize;
795
  uint32_t pktSize;
802
796
803
  //
797
  //
 Lines 806-819    Link Here 
806
  // enough to hold an EthernetHeader.  If it can't, we signify the packet 
800
  // enough to hold an EthernetHeader.  If it can't, we signify the packet 
807
  // should be filtered out by returning 0.
801
  // should be filtered out by returning 0.
808
  //
802
  //
809
  pktSize = p->GetSize ();
803
  pktSize = len;
810
  EthernetHeader header (false);
804
  EthernetHeader header (false);
811
  if (pktSize < header.GetSerializedSize ())
805
  if (pktSize < header.GetSerializedSize ())
812
    {
806
    {
813
      return 0;
807
      return 0;
814
    }
808
    }
815
809
816
  p->RemoveHeader (header);
810
  Buffer buffer = Buffer ();
811
  buffer.AddAtStart (pktSize);
812
  buffer.Begin ().Write (buf, pktSize);
813
  header.Deserialize (buffer.Begin ());
814
  buffer.RemoveAtStart (header.GetSerializedSize ());
815
  pktSize -= header.GetSerializedSize ();
817
816
818
  NS_LOG_LOGIC ("Pkt source is " << header.GetSource ());
817
  NS_LOG_LOGIC ("Pkt source is " << header.GetSource ());
819
  NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ());
818
  NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ());
 Lines 830-843    Link Here 
830
      *src = header.GetSource ();
829
      *src = header.GetSource ();
831
      *dst = header.GetDestination ();
830
      *dst = header.GetDestination ();
832
831
833
      pktSize = p->GetSize ();
832
      pktSize = buffer.GetSize ();
834
      LlcSnapHeader llc;
833
      LlcSnapHeader llc;
835
      if (pktSize < llc.GetSerializedSize ())
834
      if (pktSize < llc.GetSerializedSize ())
836
        {
835
        {
837
          return 0;
836
          return 0;
838
        }
837
        }
839
838
840
      p->RemoveHeader (llc);
839
      header.Serialize (buffer.Begin ());
840
      buffer.RemoveAtStart (llc.GetSerializedSize ());
841
      pktSize -= llc.GetSerializedSize ();
841
      *type = llc.GetType ();
842
      *type = llc.GetType ();
842
    }
843
    }
843
  else
844
  else
 Lines 852-857    Link Here 
852
  // possible llc/snap header) on it.  We think it is ready to send on
853
  // possible llc/snap header) on it.  We think it is ready to send on
853
  // out the bridged net device.
854
  // out the bridged net device.
854
  //
855
  //
856
  Ptr<Packet> p = Create<Packet> (reinterpret_cast<const uint8_t *> (buffer.PeekData()), pktSize);
855
  return p;
857
  return p;
856
}
858
}
857
859

Return to bug 1787