Пример #1
0
        /// <summary>
        /// 租期結束時間
        /// </summary>
        public DateTime GetValidEndTime()
        {
            long             validLifetime = 0;
            DhcpV6IaNaOption iaOption      = (DhcpV6IaNaOption)GetIaNaOptions().FirstOrDefault();

            if (iaOption != null && iaOption.GetIaAddrOptions() != null)
            {
                var iaAddress = iaOption.GetIaAddrOptions().FirstOrDefault();
                validLifetime = iaAddress.GetValidLifetime();
            }

            return(DateTime.Now.AddSeconds(validLifetime));
        }
Пример #2
0
        /// <summary>
        /// 取得派出的 IP
        /// </summary>
        /// <returns></returns>
        public IPAddress GetIaAddress()
        {
            if (GetIaNaOptions() == null || GetIaNaOptions().Count == 0)
            {
                return(IPAddress.IPv6Any);
            }
            DhcpV6IaNaOption iaOption = (DhcpV6IaNaOption)GetIaNaOptions().FirstOrDefault();

            if (iaOption.GetIaAddrOptions() == null || iaOption.GetIaAddrOptions().Count == 0)
            {
                return(IPAddress.IPv6Any);
            }
            var iaAddress = iaOption.GetIaAddrOptions().FirstOrDefault();

            return(iaAddress.GetInetAddress());
        }
Пример #3
0
        /**
         * Extract the list of IP addresses from within the given IA_NA option.
         *
         * @param iaNaOption the IA_NA option
         *
         * @return the list of InetAddresses for the IPs in the IA_NA option
         */
        private List <IPAddress> GetInetAddrs(DhcpV6IaNaOption iaNaOption)
        {
            List <IPAddress>          inetAddrs = null;
            List <DhcpV6IaAddrOption> iaAddrs   = iaNaOption.GetIaAddrOptions();

            if ((iaAddrs != null) && iaAddrs.Count > 0)
            {
                inetAddrs = new List <IPAddress>();
                foreach (DhcpV6IaAddrOption iaAddr in iaAddrs)
                {
                    IPAddress inetAddr = iaAddr.GetInetAddress();
                    inetAddrs.Add(inetAddr);
                }
            }
            return(inetAddrs);
        }
Пример #4
0
        protected bool AllIaAddrsOnLink(DhcpV6IaNaOption dhcpIaNaOption, DhcpLink clientLink)
        {
            bool onLink = true;

            //  assume all IPs are on link
            if ((dhcpIaNaOption != null))
            {
                List <DhcpV6IaAddrOption> iaAddrOpts = dhcpIaNaOption.GetIaAddrOptions();
                if ((iaAddrOpts != null))
                {
                    foreach (DhcpV6IaAddrOption iaAddrOpt in iaAddrOpts)
                    {
                        if (this.clientLink.GetSubnet().GetSubnetAddress().IsIPv6LinkLocal)
                        {
                            //  if the Link address is link-local, then check if the
                            //  address is within one of the pools configured for this
                            //  local Link, which automatically makes this server
                            //  "authoritative" (in ISC parlance) for this local net
                            v6AddressPool p = DhcpServerConfiguration.FindNaAddrPool(this.clientLink.GetLink(), iaAddrOpt.GetInetAddress());
                            if ((p == null))
                            {
                                log.Info(("No local address pool found for requested IA_NA: " + (iaAddrOpt.ToString() + " - considered to be off link")));
                                iaAddrOpt.SetPreferredLifetime(0);
                                iaAddrOpt.SetValidLifetime(0);
                                onLink = false;
                            }
                        }
                        else
                        {
                            //  it the Link address is remote, then check
                            //  if the address is valid for that link
                            if (!this.clientLink.GetSubnet().Contains(iaAddrOpt.GetInetAddress()))
                            {
                                log.Info("Setting zero(0) lifetimes for off link address: " + iaAddrOpt.GetIpAddress());
                                iaAddrOpt.SetPreferredLifetime(0);
                                iaAddrOpt.SetValidLifetime(0);
                                onLink = false;
                            }
                        }
                    }
                }
            }

            return(onLink);
        }