public void Write(IPEndPoint ep, DnsTransportProtocol protocol, string message) { string ipInfo; if (ep == null) { ipInfo = ""; } else if (ep.Address.IsIPv4MappedToIPv6) { ipInfo = "[" + ep.Address.MapToIPv4().ToString() + ":" + ep.Port + "] "; } else { ipInfo = "[" + ep.ToString() + "] "; } Write(ipInfo + "[" + protocol.ToString().ToUpper() + "] " + message); }
public override string ToString() { return(_protocol.ToString() + " " + _forwarder); }
public void Write(IPEndPoint ep, DnsTransportProtocol protocol, string message) { Write(ep, protocol.ToString(), message); }
private void ValidateProtocol() { switch (_protocol) { case DnsTransportProtocol.Udp: case DnsTransportProtocol.Tcp: if (_dohEndPoint != null) { throw new ArgumentException("Invalid DNS transport protocol was specified for current operation: " + _protocol.ToString()); } if (Port == 853) { throw new ArgumentException("Invalid DNS transport protocol was specified for current operation: " + _protocol.ToString()); } break; case DnsTransportProtocol.Tls: if (_dohEndPoint != null) { throw new ArgumentException("Invalid DNS transport protocol was specified for current operation: " + _protocol.ToString()); } if (Port == 53) { throw new ArgumentException("Invalid DNS transport protocol was specified for current operation: " + _protocol.ToString()); } break; case DnsTransportProtocol.Https: case DnsTransportProtocol.HttpsJson: if (_dohEndPoint == null) { throw new ArgumentException("Invalid DNS transport protocol was specified for current operation: " + _protocol.ToString()); } switch (Port) { case 53: case 853: throw new ArgumentException("Invalid DNS transport protocol was specified for current operation: " + _protocol.ToString()); } break; } }
public static DnsClientConnection GetConnection(DnsTransportProtocol protocol, NameServerAddress server, NetProxy proxy) { switch (protocol) { case DnsTransportProtocol.Udp: return(new UdpClientConnection(server, proxy)); case DnsTransportProtocol.Https: return(new HttpsClientConnection(server, proxy)); case DnsTransportProtocol.HttpsJson: return(new HttpsJsonClientConnection(server, proxy)); case DnsTransportProtocol.Tcp: { ConcurrentDictionary <NetProxy, DnsClientConnection> existingTcpConnection = _existingTcpConnections.GetOrAdd(server, delegate(NameServerAddress nameServer) { return(new ConcurrentDictionary <NetProxy, DnsClientConnection>()); }); NetProxy proxyKey = proxy; if (proxyKey == null) { proxyKey = NetProxy.None; } return(existingTcpConnection.GetOrAdd(proxyKey, delegate(NetProxy netProxyKey) { return new TcpClientConnection(server, proxy); })); } case DnsTransportProtocol.Tls: { ConcurrentDictionary <NetProxy, DnsClientConnection> existingTlsConnection = _existingTlsConnections.GetOrAdd(server, delegate(NameServerAddress nameServer) { return(new ConcurrentDictionary <NetProxy, DnsClientConnection>()); }); NetProxy proxyKey = proxy; if (proxyKey == null) { proxyKey = NetProxy.None; } return(existingTlsConnection.GetOrAdd(proxyKey, delegate(NetProxy netProxyKey) { return new TlsClientConnection(server, proxy); })); } default: throw new NotSupportedException("DnsClient protocol not supported: " + protocol.ToString()); } }
public static async Task <SecondaryZone> CreateAsync(DnsServer dnsServer, string name, string primaryNameServerAddresses = null, DnsTransportProtocol zoneTransferProtocol = DnsTransportProtocol.Tcp, string tsigKeyName = null) { switch (zoneTransferProtocol) { case DnsTransportProtocol.Tcp: case DnsTransportProtocol.Tls: break; default: throw new NotSupportedException("Zone transfer protocol is not supported: XFR-over-" + zoneTransferProtocol.ToString().ToUpper()); } SecondaryZone secondaryZone = new SecondaryZone(dnsServer, name); DnsQuestionRecord soaQuestion = new DnsQuestionRecord(name, DnsResourceRecordType.SOA, DnsClass.IN); DnsDatagram soaResponse; if (primaryNameServerAddresses == null) { soaResponse = await secondaryZone._dnsServer.DirectQueryAsync(soaQuestion).WithTimeout(2000); } else { DnsClient dnsClient = new DnsClient(primaryNameServerAddresses); dnsClient.Proxy = secondaryZone._dnsServer.Proxy; dnsClient.PreferIPv6 = secondaryZone._dnsServer.PreferIPv6; if (string.IsNullOrEmpty(tsigKeyName)) { soaResponse = await dnsClient.ResolveAsync(soaQuestion); } else if ((dnsServer.TsigKeys is not null) && dnsServer.TsigKeys.TryGetValue(tsigKeyName, out TsigKey key)) { soaResponse = await dnsClient.ResolveAsync(soaQuestion, key, REFRESH_TSIG_FUDGE); }
public static async Task <SecondaryZone> CreateAsync(DnsServer dnsServer, string name, string primaryNameServerAddresses = null, DnsTransportProtocol zoneTransferProtocol = DnsTransportProtocol.Tcp, string tsigKeyName = null) { switch (zoneTransferProtocol) { case DnsTransportProtocol.Tcp: case DnsTransportProtocol.Tls: break; default: throw new NotSupportedException("Zone transfer protocol is not supported: XFR-over-" + zoneTransferProtocol.ToString().ToUpper()); } SecondaryZone secondaryZone = new SecondaryZone(dnsServer, name); DnsQuestionRecord soaQuestion = new DnsQuestionRecord(name, DnsResourceRecordType.SOA, DnsClass.IN); DnsDatagram soaResponse; if (primaryNameServerAddresses == null) { soaResponse = await secondaryZone._dnsServer.DirectQueryAsync(soaQuestion); } else { DnsClient dnsClient = new DnsClient(primaryNameServerAddresses); foreach (NameServerAddress nameServerAddress in dnsClient.Servers) { if (nameServerAddress.IsIPEndPointStale) { await nameServerAddress.ResolveIPAddressAsync(secondaryZone._dnsServer, secondaryZone._dnsServer.PreferIPv6); } } dnsClient.Proxy = secondaryZone._dnsServer.Proxy; dnsClient.PreferIPv6 = secondaryZone._dnsServer.PreferIPv6; DnsDatagram soaRequest = new DnsDatagram(0, false, DnsOpcode.StandardQuery, false, false, false, false, false, false, DnsResponseCode.NoError, new DnsQuestionRecord[] { soaQuestion }, null, null, null, DnsDatagram.EDNS_DEFAULT_UDP_PAYLOAD_SIZE); if (string.IsNullOrEmpty(tsigKeyName)) { soaResponse = await dnsClient.ResolveAsync(soaRequest); } else if ((dnsServer.TsigKeys is not null) && dnsServer.TsigKeys.TryGetValue(tsigKeyName, out TsigKey key)) { soaResponse = await dnsClient.ResolveAsync(soaRequest, key, REFRESH_TSIG_FUDGE); }