public void Encapsulate(VpnChannel channel, VpnPacketBufferList packets, VpnPacketBufferList encapulatedPackets)
        {
            var vpnSendPacketBuffer = channel.GetVpnSendPacketBuffer();

            while (packets.Size > 0) //can't iterate over packets
            {
                var packet       = packets.RemoveAtEnd();
                var packetAppId  = packet.AppId;
                var packetBuffer = packet.Buffer;
                var fromBuffer   = DataReader.FromBuffer(packetBuffer);
                var fromBufferUnconsumedBufferLength = fromBuffer.UnconsumedBufferLength;
                var bytes = new byte[fromBufferUnconsumedBufferLength];
                fromBuffer.ReadBytes(bytes);

                var bytesRead  = 0;
                var ipv4Header = Ipv4Header.Create(bytes, ref bytesRead);

                var vpnPacketBufferStatus   = packet.Status;
                var packetTransportAffinity = packet.TransportAffinity;
                var packetTransportContext  = packet.TransportContext;

                encapulatedPackets.Append(packet);

                //parse ip datagram and inspect destination IP
                //if destIP isn't found in peer list, drop and send ICMP "no route to host"?
            }
        }
 public void Encapsulate(VpnChannel channel, VpnPacketBufferList packets, VpnPacketBufferList encapulatedPackets)
 {
     while (packets.Size > 0)
     {
         encapulatedPackets.Append(packets.RemoveAtBegin());
     }
 }
        public void Encapsulate(VpnChannel channel, VpnPacketBufferList packets, VpnPacketBufferList encapulatedPackets)
        {
            try
            {
                uint packetCount = packets.Size;
                var  tun         = context.tun;
                if (tun == null)
                {
                    return;
                }
                while (packetCount-- > 0)
                {
#if YTLOG_VERBOSE
                    LogLine("Encapsulating " + packets.Size.ToString(), channel);
#endif
                    var packet = packets.RemoveAtBegin();
                    tun.PushPacket(packet.Buffer.ToArray());
                    packets.Append(packet);
                }
            }
            catch (Exception ex)
            {
                DebugLogger.Log("Error encapsulating packets: " + ex.ToString());
            }
        }
Exemple #4
0
        public void Decapsulate(VpnChannel channel, VpnPacketBuffer encapBuffer, VpnPacketBufferList decapsulatedPackets, VpnPacketBufferList controlPacketsToSend)
        {
            var context = channel.PlugInContext as VpnContext;

            while (context.PendingPackets.TryDequeue(out byte[] originBuffer))
            {
                var buf = channel.GetVpnReceivePacketBuffer();
                if (encapBuffer.Buffer.Length > buf.Buffer.Capacity)
                {
                    LogLine("Dropped one packet", channel);
                    //Drop larger packets.
                    return;
                }
                originBuffer.CopyTo(0, buf.Buffer, 0, originBuffer.Length);
                buf.Buffer.Length = (uint)originBuffer.Length;
                LogLine("Added one packet" + buf.Buffer.Length, channel);
                decapsulatedPackets.Append(buf);
            }
            //var buf = channel.GetVpnReceivePacketBuffer();
            // LogLine("Decapsulating one packet", channel);
            //if (encapBuffer.Buffer.Length > buf.Buffer.Capacity)
            //{
            //    LogLine("Dropped one packet", channel);
            //    //Drop larger packets.
            //    return;
            //}

            //encapBuffer.Buffer.CopyTo(buf.Buffer);
            //buf.Buffer.Length = encapBuffer.Buffer.Length;
            //decapsulatedPackets.Append(buf);
            // LogLine("Decapsulated one packet", channel);
        }
Exemple #5
0
 public void Encapsulate(VpnChannel channel, VpnPacketBufferList packets, VpnPacketBufferList encapulatedPackets)
 {
     // LogLine("Encapsulating", channel);
     while (packets.Size > 0)
     {
         var packet = packets.RemoveAtBegin();
         encapulatedPackets.Append(packet);
         //LogLine("Encapsulated one packet", channel);
     }
 }
Exemple #6
0
        public void Encapsulate(VpnChannel channel, VpnPacketBufferList packets, VpnPacketBufferList encapulatedPackets)
        {
            //Debug.WriteLine("Encapsulate++");
            while (packets.Size > 0)
            {
                encapulatedPackets.Append(packets.RemoveAtBegin());
            }

            //Debug.WriteLine("Encapsulate--");
        }
Exemple #7
0
        public void Decapsulate(VpnChannel channel, VpnPacketBuffer encapBuffer, VpnPacketBufferList decapsulatedPackets, VpnPacketBufferList controlPacketsToSend)
        {
            if (encapBuffer.Buffer.Capacity > ushort.MaxValue)
            {
                return;
            }
            var packetBuffer = encapBuffer.Buffer.ToArray();

            packetBuffer.CopyTo(0, encapBuffer.Buffer, 0, packetBuffer.Length);
            decapsulatedPackets.Append(encapBuffer);
        }
Exemple #8
0
        public void Encapsulate(VpnChannel channel, VpnPacketBufferList packets, VpnPacketBufferList encapulatedPackets)
        {
            while (packets.Size > 0)
            {
#if YTLOG_VERBOSE
                LogLine("Encapsulating " + packets.Size.ToString(), channel);
#endif
                var packet = packets.RemoveAtBegin();
                encapulatedPackets.Append(packet);
                //LogLine("Encapsulated one packet", channel);
            }
        }
Exemple #9
0
 public void Encapsulate(VpnChannel channel, VpnPacketBufferList packets, VpnPacketBufferList encapulatedPackets)
 {
     while (packets.Size > 0)
     {
         var packet = packets.RemoveAtBegin();
         if (packet.Buffer.Capacity <= ushort.MaxValue)
         {
             var packetBuffer = packet.Buffer.ToArray();
             packetBuffer.CopyTo(0, packet.Buffer, 0, packetBuffer.Length);
             encapulatedPackets.Append(packet);
         }
     }
 }
        public void Decapsulate(VpnChannel channel, VpnPacketBuffer encapBuffer, VpnPacketBufferList decapsulatedPackets,
                                VpnPacketBufferList controlPacketsToSend)
        {
            var buf = channel.GetVpnReceivePacketBuffer();

            // LogLine("Decapsulating one packet", channel);
            if (encapBuffer.Buffer.Length > buf.Buffer.Capacity)
            {
                //Drop larger packets.
                return;
            }
            encapBuffer.Buffer.CopyTo(buf.Buffer);
            buf.Buffer.Length = encapBuffer.Buffer.Length;
            decapsulatedPackets.Append(buf);
        }
Exemple #11
0
        public void Decapsulate(VpnChannel channel, VpnPacketBuffer encapPacketBuffer, VpnPacketBufferList decapsulatedPackets, VpnPacketBufferList controlPacketsToSend)
        {
            try
            {
                var reader = context.outPackets?.Reader;
                if (reader == null)
                {
                    return;
                }

                while (reader.TryRead(out var bytes))
                {
                    var encapBuffer = channel.GetVpnReceivePacketBuffer();
                    var encapBuf    = encapBuffer.Buffer;
                    bytes.CopyTo(encapBuf);
                    encapBuf.Length = (uint)bytes.Length;
                    decapsulatedPackets.Append(encapBuffer);
                }
            }
            catch (Exception ex)
            {
                DebugLogger.Log("Error decapsulating packets: " + ex.ToString());
            }
        }
 public void Decapsulate(VpnChannel channel, VpnPacketBuffer encapBuffer, VpnPacketBufferList decapsulatedPackets, VpnPacketBufferList controlPacketsToSend)
 {
     decapsulatedPackets.Append(encapBuffer);
 }