//Request Process(Direct connections part) bool __fastcall DirectRequestProcess( const char *OriginalSend, const size_t SendSize, PSTR OriginalRecv, const uint16_t Protocol, const bool DirectRequest, const SOCKET_DATA &LocalSocketData) { size_t DataLength = 0; //Direct Request mode check DataLength = SelectNetworkProtocol(); if (DirectRequest && (DataLength == AF_INET6 && Parameter.DirectRequest == DIRECT_REQUEST_MODE_IPV4 || //IPv6 DataLength == AF_INET && Parameter.DirectRequest == DIRECT_REQUEST_MODE_IPV6)) //IPv4 return false; //TCP Mode if (Parameter.RequestMode_Transport == REQUEST_MODE_TCP || Protocol == IPPROTO_TCP) { //Multi requesting. if (Parameter.AlternateMultiRequest || Parameter.MultiRequestTimes > 1U) DataLength = TCPRequestMulti(OriginalSend, SendSize, OriginalRecv, LARGE_PACKET_MAXSIZE); //Normal requesting else DataLength = TCPRequest(OriginalSend, SendSize, OriginalRecv, LARGE_PACKET_MAXSIZE, false); //Send response. if (DataLength >= DNS_PACKET_MINSIZE && DataLength < LARGE_PACKET_MAXSIZE) { SendToRequester(OriginalRecv, DataLength, Protocol, LocalSocketData); return true; } } //UDP Mode(REQUEST_MODE_UDP) if (Protocol == IPPROTO_TCP) //TCP requesting DataLength = LARGE_PACKET_MAXSIZE; else //UDP requesting DataLength = PACKET_MAXSIZE; //Multi requesting. if (Parameter.AlternateMultiRequest || Parameter.MultiRequestTimes > 1U) DataLength = UDPCompleteRequestMulti(OriginalSend, SendSize, OriginalRecv, DataLength); //Normal requesting else DataLength = UDPCompleteRequest(OriginalSend, SendSize, OriginalRecv, DataLength, false); //Send response. if (DataLength >= DNS_PACKET_MINSIZE && (DataLength < PACKET_MAXSIZE || Protocol == IPPROTO_TCP && DataLength < LARGE_PACKET_MAXSIZE)) { SendToRequester(OriginalRecv, DataLength, Protocol, LocalSocketData); return true; } return false; }
//Request Process(Direct connections part) bool __fastcall DirectRequestProcess( const DNS_PACKET_DATA &Packet, char *OriginalRecv, const size_t RecvSize, const bool DirectRequest, const SOCKET_DATA &LocalSocketData) { size_t DataLength = 0; memset(OriginalRecv, 0, RecvSize); //Direct Request mode check DataLength = SelectNetworkProtocol(); if (DirectRequest && (DataLength == AF_INET6 && Parameter.DirectRequest == DIRECT_REQUEST_MODE_IPV4 || //IPv6 DataLength == AF_INET && Parameter.DirectRequest == DIRECT_REQUEST_MODE_IPV6)) //IPv4 return false; //EDNS switching(Part 1) size_t EDNS_SwitchLength = Packet.Length; uint16_t EDNS_Packet_Flags = ((dns_hdr *)(Packet.Buffer))->Flags; if (Parameter.EDNS_Label && !Parameter.EDNS_Switch.EDNS_Direct) { //Reset EDNS flags, resource record counts and packet length. ((dns_hdr *)(Packet.Buffer))->Flags = htons(ntohs(((dns_hdr *)(Packet.Buffer))->Flags) & (~DNS_GET_BIT_AD)); ((dns_hdr *)(Packet.Buffer))->Flags = htons(ntohs(((dns_hdr *)(Packet.Buffer))->Flags) & (~DNS_GET_BIT_CD)); if (((dns_hdr *)(Packet.Buffer))->Additional > 0) ((dns_hdr *)(Packet.Buffer))->Additional = htons(ntohs(((dns_hdr *)(Packet.Buffer))->Additional) - 1U); EDNS_SwitchLength -= Packet.EDNS_Record; } //TCP request if (Parameter.RequestMode_Transport == REQUEST_MODE_TCP || Packet.Protocol == IPPROTO_TCP) { //Multi request process if (Parameter.AlternateMultiRequest || Parameter.MultiRequestTimes > 1U) DataLength = TCPRequestMulti(REQUEST_PROCESS_DIRECT, Packet.Buffer, EDNS_SwitchLength, OriginalRecv, RecvSize); //Normal request process else DataLength = TCPRequest(REQUEST_PROCESS_DIRECT, Packet.Buffer, EDNS_SwitchLength, OriginalRecv, RecvSize); //Send response. if (DataLength >= DNS_PACKET_MINSIZE && DataLength < RecvSize) { SendToRequester(OriginalRecv, DataLength, RecvSize, Packet.Protocol, LocalSocketData); return true; } } //UDP request if (Parameter.AlternateMultiRequest || Parameter.MultiRequestTimes > 1U) //Multi request process DataLength = UDPCompleteRequestMulti(REQUEST_PROCESS_DIRECT, Packet.Buffer, EDNS_SwitchLength, OriginalRecv, RecvSize); else //Normal request process DataLength = UDPCompleteRequest(REQUEST_PROCESS_DIRECT, Packet.Buffer, EDNS_SwitchLength, OriginalRecv, RecvSize); //Send response. if (DataLength >= DNS_PACKET_MINSIZE && DataLength < RecvSize) { SendToRequester(OriginalRecv, DataLength, RecvSize, Packet.Protocol, LocalSocketData); return true; } //EDNS switching(Part 2) if (Parameter.EDNS_Label && !Parameter.EDNS_Switch.EDNS_Direct) { ((dns_hdr *)(Packet.Buffer))->Flags = EDNS_Packet_Flags; ((dns_hdr *)(Packet.Buffer))->Additional = htons(ntohs(((dns_hdr *)(Packet.Buffer))->Additional) + 1U); } return false; }