示例#1
0
        /// <summary>
        /// Handles RIPv1 updates
        /// </summary>
        /// <param name="udpFrame"></param>
        /// <param name="ipFrame"></param>
        /// <returns>Bool indicating if something changed</returns>
        private bool HandleRIPV1(UDP.UDPFrame udpFrame, IP.IPFrame ipFrame)
        {
            RIPFrame fRIPFrame;
            bool     bChanged = false;

            if (ipFrame.SourceAddress.Equals(IPAddress.Broadcast)) // Check Addr
            {
                if (udpFrame.DestinationPort == iRIPPort)          // Check Port
                {
                    fRIPFrame = new RIPFrame(udpFrame.EncapsulatedFrame.FrameBytes);
                    if (fRIPFrame.Version == 1)
                    {
                        foreach (RIPUpdate ru in fRIPFrame.GetUpdates())
                        {
                            if (ru.AddressFamilyIdentifier == RIPEntryAddressFamily.IPv4)
                            {
                                bChanged |= UpdateEntry(ipFrame.SourceAddress, ru.Address, IPAddressAnalysis.GetClassfullSubnetMask(ru.Address), (int)ru.Metric);
                            }
                        }
                    }
                }
            }

            return(bChanged);
        }
示例#2
0
        /// <summary>
        /// Handles RIPv2 Frames
        /// </summary>
        /// <param name="udpFrame"></param>
        /// <param name="ipFrame"></param>
        /// <returns>Bool indicating if something changed</returns>
        private bool HandleRIPV2(UDP.UDPFrame udpFrame, IP.IPFrame ipFrame)
        {
            RIPFrame fRIPFrame;
            bool     bChanged = false;

            if (ipFrame.SourceAddress.Equals(IPAddress.Broadcast))
            {
                HandleRIPV1(udpFrame, ipFrame);                          // RIPv1? Fallback!
            }
            else if (ipFrame.DestinationAddress.Equals(ipaRIPv2Address)) // Check Addr
            {
                if (udpFrame.DestinationPort == iRIPPort)                //Check Port
                {
                    fRIPFrame = new RIPFrame(udpFrame.EncapsulatedFrame.FrameBytes);

                    if (fRIPFrame.Version == 2)
                    {
                        foreach (RIPUpdate ru in fRIPFrame.GetUpdates())
                        {
                            if (ru.AddressFamilyIdentifier == RIPEntryAddressFamily.IPv4)
                            {
                                if (!IsHoldDown(ru.Address))
                                {
                                    bChanged |= UpdateEntry(ipFrame.SourceAddress, ru.Address, ru.Ripv2SubnetMask, (int)ru.Metric);
                                }
                            }
                        }
                    }
                    else
                    {
                        bChanged |= HandleRIPV1(udpFrame, ipFrame);
                    }
                }
            }

            return(bChanged);
        }
示例#3
0
        /// <summary>
        /// Forces this instance to distribute traffic immidiately, with exluding the specified interface from forwarding operations.
        /// </summary>
        /// <param name="ipiExcludeInterface">The interface to exclude from forwarding operations or null, if no interface should be excluded.</param>
        public void DistributeUpdate(IPInterface ipiExcludeInterface)
        {
            IRouter rtRouter = this.RouterToManage;

            if (rtRouter != null)
            {
                RIPFrame rf = new RIPFrame();
                rf.Version = (uint)this.iVersion;
                rf.Command = RipCommand.RIPResponse;

                RoutingEntry[] arre = rtRouter.RoutingTable.GetRoutes();

                foreach (RoutingEntry re in arre)
                {
                    if (re.Owner == RoutingEntryOwner.RIP || re.Owner == RoutingEntryOwner.Interface)
                    {
                        if (this.iVersion == 1)
                        {
                            rf.AddUpdate(new RIPUpdate(RIPEntryAddressFamily.IPv4, new byte[2], new Subnetmask(), IPAddress.Any, re.Destination, (uint)((re.Metric + 1) > 16 ? 16 : (re.Metric + 1))));
                        }
                        else if (this.iVersion == 2)
                        {
                            rf.AddUpdate(new RIPUpdate(RIPEntryAddressFamily.IPv4, new byte[2], re.Subnetmask, IPAddress.Any, re.Destination, (uint)((re.Metric + 1) > 16 ? 16 : (re.Metric + 1))));
                        }
                    }
                    else if ((re.Owner == RoutingEntryOwner.UserStatic || re.Owner == RoutingEntryOwner.System) && this.bRedistributeStatic)
                    {
                        if (this.iVersion == 1)
                        {
                            rf.AddUpdate(new RIPUpdate(RIPEntryAddressFamily.IPv4, new byte[2], new Subnetmask(), IPAddress.Any, re.Destination, 1));
                        }
                        else if (this.iVersion == 2)
                        {
                            rf.AddUpdate(new RIPUpdate(RIPEntryAddressFamily.IPv4, new byte[2], re.Subnetmask, IPAddress.Any, re.Destination, 1));
                        }
                    }
                }

                UDP.UDPFrame uf = new UDP.UDPFrame();
                uf.DestinationPort   = iRIPPort;
                uf.SourcePort        = iRIPPort;
                uf.EncapsulatedFrame = rf;

                foreach (IPInterface ipi in lInterfaces)
                {
                    if (ipi != ipiExcludeInterface && ipi.IpAddresses.Length > 0 && !ipiPassiveInterfaces.Contains(ipi))
                    {
                        IP.IPv4Frame ipf = new IP.IPv4Frame();
                        ipf.SourceAddress = ipi.IpAddresses[0];
                        if (iVersion == 2)
                        {
                            ipf.DestinationAddress = ipaRIPv2Address;
                        }
                        else if (iVersion == 1)
                        {
                            ipf.DestinationAddress = IPAddress.Broadcast;
                        }
                        ipf.Protocol          = eExNetworkLibrary.IP.IPProtocol.UDP;
                        ipf.Version           = 4;
                        ipf.EncapsulatedFrame = uf;

                        TrafficDescriptionFrame tdf = new TrafficDescriptionFrame(null, DateTime.Now);
                        tdf.EncapsulatedFrame = ipf;

                        ipi.Send(tdf, IPAddress.Broadcast);
                    }
                }
            }
        }