Ejemplo n.º 1
0
Archivo: Paxifax.cs Proyecto: niksu/pax
        public ForwardingDecision process_packet(int in_port, ref Packet packet)
        {
            ForwardingDecision fd = null;

            //We return the ForwardingDecision made by the last element in the chain.
            foreach (IPacketProcessor pp in chain)
            {
                fd = pp.process_packet(in_port, ref packet);
            }

            return(fd);
        }
Ejemplo n.º 2
0
Archivo: Paxifax.cs Proyecto: niksu/pax
        public void packetHandler(object sender, CaptureEventArgs e)
        {
            var packet  = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
            int in_port = PaxConfig.rdeviceMap[e.Device.Name];

            int out_port;
            ForwardingDecision des = process_packet(in_port, ref packet);

            if (des is ForwardingDecision.SinglePortForward)
            {
                out_port = ((ForwardingDecision.SinglePortForward)des).target_port;
            }
            else
            {
                throw (new Exception("Expected SinglePortForward"));
            }

#if DEBUG
            Debug.Write(PaxConfig.deviceMap[in_port].Name + " -1> ");
#endif
            if (out_port > -1)
            {
                var device = PaxConfig.deviceMap[out_port];
                if (packet is EthernetPacket)
                {
                    ((EthernetPacket)packet).SourceHwAddress = device.MacAddress;
                }
                device.SendPacket(packet);
#if DEBUG
                Debug.WriteLine(PaxConfig.deviceMap[out_port].Name);
            }
            else
            {
                Debug.WriteLine("<dropped>");
#endif
            }
        }
Ejemplo n.º 3
0
Archivo: Paxifax.cs Proyecto: niksu/pax
        public void packetHandler(object sender, CaptureEventArgs e)
        {
            var packet  = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
            int in_port = PaxConfig.rdeviceMap[e.Device.Name];

            int[] out_ports;
            ForwardingDecision des = process_packet(in_port, ref packet);

            if (des is ForwardingDecision.MultiPortForward)
            {
                out_ports = ((ForwardingDecision.MultiPortForward)des).target_ports;

                /*
                 * Since MultiPortForward works with arrays, this increases the exposure
                 * to dud values:
                 * negative values within arrays
                 * repeated values within arrays
                 * an array might be larger than intended, and contains rubbish data.
                 * These could manifest themselves as bugs or abused behaviour.
                 * FIXME determine how each of these cases will be treated.
                 */
            }
            else
            {
                throw (new Exception("Expected MultiPortForward"));
            }

#if DEBUG
            Debug.Write(PaxConfig.deviceMap[in_port].Name + " -> ");
            // It's useful to know the width of the returned array during debugging,
            // since it might be that the array was wider than intended, and contained
            // repeated or rubbish values.
            Debug.Write("[" + out_ports.Length.ToString() + "] ");
#endif

            for (int idx = 0; idx < out_ports.Length; idx++)
            {
                int out_port = out_ports[idx];
                // Check if trying to send over a non-existent port.
                if (out_port < PaxConfig_Lite.no_interfaces)
                {
                    PaxConfig.deviceMap[out_port].SendPacket(packet);
#if DEBUG
                    Debug.Write("(" + out_port.ToString() + ") "); // Show the network interface offset.
                    // And now show the network interface name that the offset resolves to.
                    if (idx < out_ports.Length - 1)
                    {
                        Debug.Write(PaxConfig.deviceMap[out_port].Name + ", ");
                    }
                    else
                    {
                        Debug.Write(PaxConfig.deviceMap[out_port].Name);
                    }
#endif
                }
                else if (!(out_port < PaxConfig_Lite.no_interfaces) &&
                         !PaxConfig_Lite.ignore_phantom_forwarding)
                {
                    throw (new Exception("Tried forward to non-existant port"));
                }
            }

#if DEBUG
            Debug.WriteLine("");
#endif
        }