internal DHCPv4Packet HandleDecline(DHCPv4Packet packet) { DHCPv4ScopeAddressProperties addressProperties = GetAddressProperties(); if (addressProperties.AcceptDecline == false) { base.Apply(new DHCPv4DeclineHandledEvent(this.Id, packet, DHCPv4DeclineHandledEvent.DeclineErros.DeclineNotAllowed)); return(DHCPv4Packet.Empty); } IPv4Address address = packet.GetRequestedAddressFromRequestedOption(); if (address == IPv4Address.Empty) { base.Apply(new DHCPv4DeclineHandledEvent(this.Id, packet, DHCPv4DeclineHandledEvent.DeclineErros.IPAddressNotFound)); return(DHCPv4Packet.Empty); } DHCPv4Lease lease = Leases.GetLeaseByAddress(address); if (lease == DHCPv4Lease.Empty) { base.Apply(new DHCPv4DeclineHandledEvent(this.Id, packet, DHCPv4DeclineHandledEvent.DeclineErros.LeaseNotFound)); return(DHCPv4Packet.Empty); } if (lease.State == LeaseStates.Suspended) { base.Apply(new DHCPv4DeclineHandledEvent(this.Id, packet, DHCPv4DeclineHandledEvent.DeclineErros.AddressAlreadySuspended)); return(DHCPv4Packet.Empty); } if (lease.IsPending() == false && lease.IsActive() == false) { base.Apply(new DHCPv4DeclineHandledEvent(this.Id, packet, DHCPv4DeclineHandledEvent.DeclineErros.LeaseInInvalidState)); return(DHCPv4Packet.Empty); } lease.Suspend(null); base.Apply(new DHCPv4DeclineHandledEvent(this.Id, packet)); return(DHCPv4Packet.Empty); }
internal DHCPv4Packet HandleRelease(DHCPv4Packet packet) { IPv4Address address = packet.Header.Source; DHCPv4Lease lease = Leases.GetLeaseByAddress(address); if (lease == DHCPv4Lease.Empty) { base.Apply(new DHCPv4ReleaseHandledEvent(this.Id, packet, DHCPv4ReleaseHandledEvent.ReleaseError.NoLeaseFound)); return(DHCPv4Packet.Empty); } if (lease.IsActive() == false) { base.Apply(new DHCPv4ReleaseHandledEvent(this.Id, packet, DHCPv4ReleaseHandledEvent.ReleaseError.LeaseNotActive)); return(DHCPv4Packet.Empty); } Leases.Release(lease); base.Apply(new DHCPv4ReleaseHandledEvent(this.Id, packet)); return(DHCPv4Packet.Empty); }