예제 #1
0
파일: CNAME.cs 프로젝트: IMULMUL/DnsServer
        private IReadOnlyList <DnsResourceRecord> GetAnswers(string domain, DnsQuestionRecord question, string zoneName, uint appRecordTtl, string healthCheck)
        {
            HealthCheckStatus status = _healthMonitor.QueryStatus(domain, question.Type, healthCheck, true);

            if (status is null)
            {
                if (question.Name.Equals(zoneName, StringComparison.OrdinalIgnoreCase)) //check for zone apex
                {
                    return new DnsResourceRecord[] { new DnsResourceRecord(question.Name, DnsResourceRecordType.ANAME, DnsClass.IN, 30, new DnsANAMERecord(domain)) }
                }
                ;                                                                                                                                                      //use ANAME
                else
                {
                    return new DnsResourceRecord[] { new DnsResourceRecord(question.Name, DnsResourceRecordType.CNAME, DnsClass.IN, 30, new DnsCNAMERecord(domain)) }
                };
            }
            else if (status.IsHealthy)
            {
                if (question.Name.Equals(zoneName, StringComparison.OrdinalIgnoreCase)) //check for zone apex
                {
                    return new DnsResourceRecord[] { new DnsResourceRecord(question.Name, DnsResourceRecordType.ANAME, DnsClass.IN, appRecordTtl, new DnsANAMERecord(domain)) }
                }
                ;                                                                                                                                                                //use ANAME
                else
                {
                    return new DnsResourceRecord[] { new DnsResourceRecord(question.Name, DnsResourceRecordType.CNAME, DnsClass.IN, appRecordTtl, new DnsCNAMERecord(domain)) }
                };
            }

            return(null);
        }
예제 #2
0
        private void GetAnswers(dynamic jsonAddresses, DnsQuestionRecord question, uint appRecordTtl, string healthCheck, List <DnsResourceRecord> answers)
        {
            if (jsonAddresses == null)
            {
                return;
            }

            switch (question.Type)
            {
            case DnsResourceRecordType.A:
                foreach (dynamic jsonAddress in jsonAddresses)
                {
                    IPAddress address = IPAddress.Parse(jsonAddress.Value);

                    if (address.AddressFamily == AddressFamily.InterNetwork)
                    {
                        HealthCheckStatus status = _healthMonitor.QueryStatus(address, healthCheck, true);
                        if (status is null)
                        {
                            answers.Add(new DnsResourceRecord(question.Name, DnsResourceRecordType.A, question.Class, 30, new DnsARecord(address)));
                        }
                        else if (status.IsHealthy)
                        {
                            answers.Add(new DnsResourceRecord(question.Name, DnsResourceRecordType.A, question.Class, appRecordTtl, new DnsARecord(address)));
                        }
                    }
                }
                break;

            case DnsResourceRecordType.AAAA:
                foreach (dynamic jsonAddress in jsonAddresses)
                {
                    IPAddress address = IPAddress.Parse(jsonAddress.Value);

                    if (address.AddressFamily == AddressFamily.InterNetworkV6)
                    {
                        HealthCheckStatus status = _healthMonitor.QueryStatus(address, healthCheck, true);
                        if (status is null)
                        {
                            answers.Add(new DnsResourceRecord(question.Name, DnsResourceRecordType.AAAA, question.Class, 30, new DnsAAAARecord(address)));
                        }
                        else if (status.IsHealthy)
                        {
                            answers.Add(new DnsResourceRecord(question.Name, DnsResourceRecordType.AAAA, question.Class, appRecordTtl, new DnsAAAARecord(address)));
                        }
                    }
                }
                break;
            }
        }