Exemple #1
0
        internal override void ReceiveEvent(DhcpFormat dhcp)
        {
            //DebugStub.WriteLine("FSM DHCP packet SELECTING.\n");

            // Check if message is in response to our request
            if (dhcp.BootMessageType != DhcpFormat.BootType.Reply ||
                dhcp.TransactionID != client.TransactionID ||
                dhcp.GetHardwareAddress() != client.MacAddress)
            {
                DebugStub.WriteLine("FSM DHCP bad id.\n");
                return;
            }

            IPv4 serverAddress = dhcp.NextServerIPAddress;

            // Check if offered address is valid (ie not zero
            // and below class E)
            IPv4 offeredAddress = dhcp.YourIPAddress;

            if (offeredAddress == IPv4.Any || offeredAddress.IsMulticast())
            {
                DebugStub.WriteLine("FSM DHCP multicast addr.\n");
                return;
            }

            // Check if message is an offer
            SortedList     offeredOptions = dhcp.GetOptions();
            DhcpByteOption messageType
                = offeredOptions[DhcpMessageType.OptionCode] as DhcpByteOption;

            if (messageType == null ||
                messageType.Value != (byte)DhcpFormat.MessageType.Offer)
            {
                DebugStub.WriteLine("FSM DHCP not an offer.\n");
                return;
            }

            // Must have parameters
            byte [] parameters = new byte [] {
                DhcpSubnetMask.OptionCode,
                DhcpRouter.OptionCode,
                // DhcpDomainNameServer.OptionCode
            };

            foreach (byte p in parameters)
            {
                IDhcpOption ido = offeredOptions[p] as IDhcpOption;
                if (ido == null)
                {
                    DebugStub.WriteLine("FSM DHCP missing option 0x{0:x2}.\n", DebugStub.ArgList(p));
                    return;
                }
            }

            client.CancelStateTimeout();
            client.ChangeState(new DhcpClientStateRequesting(client,
                                                             serverAddress,
                                                             offeredAddress,
                                                             offeredOptions));
        }
Exemple #2
0
        internal override void ReceiveEvent(DhcpFormat dhcp)
        {
            //DebugStub.WriteLine("FSM DHCP packet REQUESTING.\n");

            // Check if message is in response to our request
            if (dhcp.BootMessageType != DhcpFormat.BootType.Reply ||
                dhcp.TransactionID != client.TransactionID ||
                dhcp.GetHardwareAddress() != client.MacAddress)
            {
                return;
            }

            IPv4 serverAddress = dhcp.NextServerIPAddress;

            // Check if offered address is valid (ie not zero
            // and below class E)
            IPv4 offeredAddress = dhcp.YourIPAddress;

            if (offeredAddress == IPv4.Any || offeredAddress.IsMulticast())
            {
                return;
            }

            // Check if message is an ack
            SortedList     offeredOptions = dhcp.GetOptions();
            DhcpByteOption messageType
                = offeredOptions[DhcpMessageType.OptionCode] as DhcpByteOption;

            if (messageType == null)
            {
                return;
            }

            switch (messageType.Value)
            {
            case (byte)DhcpFormat.MessageType.Ack:
                break;

            case (byte)DhcpFormat.MessageType.Nak:
                client.ChangeState(new DhcpClientStateInitialize(client));
                return;

            default:
                return;
            }

            // Must have parameters
            byte [] parameters = new byte [] {
                DhcpSubnetMask.OptionCode,
                DhcpRouter.OptionCode,
                // DhcpDomainNameServer.OptionCode
            };

            foreach (byte p in parameters)
            {
                IDhcpOption ido = offeredOptions[p] as IDhcpOption;
                if (ido == null)
                {
                    return;
                }
            }

            client.CancelStateTimeout();
            client.ChangeState(new DhcpClientStateBound(client,
                                                        serverAddress,
                                                        offeredAddress,
                                                        offeredOptions));
        }
Exemple #3
0
        static IDhcpOption ParseDhcpOption(
            byte optionCode,
            byte length,
            byte[] srcBuffer,
            int offset)
        {
            byte type = optionCode;

            switch (optionCode)
            {
            case DhcpSubnetMask.OptionCode:
                return(DhcpIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpTimeOffset.OptionCode:
                return(DhcpDWordOption.Parse(type, length, srcBuffer, offset));

            case DhcpRouter.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpTimeServer.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpNameServer.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpDomainNameServer.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpLogServer.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpCookieServer.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpLprServer.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpImpressServer.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpResourceLocationServer.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpHostName.OptionCode:
                return(DhcpStringOption.Parse(type, length, srcBuffer, offset));

            case DhcpBootFileSize.OptionCode:
                return(DhcpWordOption.Parse(type, length, srcBuffer, offset));

            case DhcpMeritDumpFile.OptionCode:
                return(DhcpStringOption.Parse(type, length, srcBuffer, offset));

            case DhcpDomainName.OptionCode:
                return(DhcpStringOption.Parse(type, length, srcBuffer, offset));

            case DhcpSwapServer.OptionCode:
                return(DhcpIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpRootPath.OptionCode:
                return(DhcpStringOption.Parse(type, length, srcBuffer, offset));

            case DhcpExtensionsPath.OptionCode:
                return(DhcpStringOption.Parse(type, length, srcBuffer, offset));

            case DhcpIPForwarding.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpForwardRemoteSourceRoute.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpPolicyFilter.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpMaximumDatagramReassembly.OptionCode:
                return(DhcpWordOption.Parse(type, length, srcBuffer, offset));

            case DhcpDefaultTtl.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpPathMtuAgingTimeout.OptionCode:
                return(DhcpDWordOption.Parse(type, length, srcBuffer, offset));

            case DhcpPathMtuPlateauTable.OptionCode:
                return(DhcpMultiWordOption.Parse(type, length, srcBuffer, offset));

            case DhcpInterfaceMtu.OptionCode:
                return(DhcpWordOption.Parse(type, length, srcBuffer, offset));

            case DhcpAllSubnetsLocal.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpBroadcastAddress.OptionCode:
                return(DhcpIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpMaskDiscovery.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpMaskSupplier.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpRouterDiscovery.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpRouterSolicitationAddress.OptionCode:
                return(DhcpIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpStaticRoutes.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpTrailerEncapsulate.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpArpCacheTimeout.OptionCode:
                return(DhcpDWordOption.Parse(type, length, srcBuffer, offset));

            case DhcpEthernetEncapsulation.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpTcpDefaultTtl.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpTcpKeepalive.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpTcpKeepaliveGarbage.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpNisDomain.OptionCode:
                return(DhcpStringOption.Parse(type, length, srcBuffer, offset));

            case DhcpNisServers.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpNtpServers.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpVendorSpecific.OptionCode:
                return(DhcpMultiByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpNetBiosNameServer.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpNetBiosDistributionServer.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpNetBiosType.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpNetBiosScope.OptionCode:
                return(DhcpMultiDWordOption.Parse(type, length, srcBuffer, offset));

            case DhcpXWindowsFontServer.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpXWindowsDisplayManager.OptionCode:
                return(DhcpMultiIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpRequestedIPAddress.OptionCode:
                return(DhcpIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpIPAddressLeaseTime.OptionCode:
                return(DhcpDWordOption.Parse(type, length, srcBuffer, offset));

            case DhcpOverloadIndicator.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpMessageType.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpServerID.OptionCode:
                return(DhcpIPv4Option.Parse(type, length, srcBuffer, offset));

            case DhcpParameterRequest.OptionCode:
                return(DhcpMultiByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpMessage.OptionCode:
                return(DhcpStringOption.Parse(type, length, srcBuffer, offset));

            case DhcpMaximumMessageSize.OptionCode:
                return(DhcpWordOption.Parse(type, length, srcBuffer, offset));

            case DhcpRenewalTime.OptionCode:
                return(DhcpDWordOption.Parse(type, length, srcBuffer, offset));

            case DhcpRebindingTime.OptionCode:
                return(DhcpDWordOption.Parse(type, length, srcBuffer, offset));

            case DhcpClassID.OptionCode:
                return(DhcpStringOption.Parse(type, length, srcBuffer, offset));

            case DhcpClientID.OptionCode:
                return(DhcpMultiByteOption.Parse(type, length, srcBuffer, offset));

            case DhcpAutoConfigure.OptionCode:
                return(DhcpByteOption.Parse(type, length, srcBuffer, offset));

            default: return(null);
            }
        }