mirror of
				https://github.com/nadoo/glider.git
				synced 2025-11-04 15:52:38 +08:00 
			
		
		
		
	dns: parse answers only when query type is A or AAAA
This commit is contained in:
		
							parent
							
								
									8e8361bc42
								
							
						
					
					
						commit
						52a1c35b01
					
				
							
								
								
									
										9
									
								
								dns.go
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								dns.go
									
									
									
									
									
								
							@ -139,7 +139,8 @@ func (s *DNS) ListenAndServe() {
 | 
				
			|||||||
			// SEE RFC1035, section 4.2.2 TCP: The message is prefixed with a two byte length field which gives the message length, excluding the two byte length field.
 | 
								// SEE RFC1035, section 4.2.2 TCP: The message is prefixed with a two byte length field which gives the message length, excluding the two byte length field.
 | 
				
			||||||
			if respLen > 0 {
 | 
								if respLen > 0 {
 | 
				
			||||||
				query := parseQuery(respMsg)
 | 
									query := parseQuery(respMsg)
 | 
				
			||||||
				if len(respMsg) > query.Offset {
 | 
									if (query.QueryType == DNSQueryTypeA || query.QueryType == DNSQueryTypeAAAA) &&
 | 
				
			||||||
 | 
										len(respMsg) > query.Offset {
 | 
				
			||||||
					answers := parseAnswers(respMsg[query.Offset:])
 | 
										answers := parseAnswers(respMsg[query.Offset:])
 | 
				
			||||||
					for _, answer := range answers {
 | 
										for _, answer := range answers {
 | 
				
			||||||
						if answer.IP != "" {
 | 
											if answer.IP != "" {
 | 
				
			||||||
@ -160,7 +161,7 @@ func (s *DNS) ListenAndServe() {
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			logf("proxy-dns %s <-> %s, %s: %s", clientAddr.String(), dnsServer, domain, ip)
 | 
								logf("proxy-dns %s <-> %s, type: %d, %s: %s", clientAddr.String(), dnsServer, query.QueryType, domain, ip)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}()
 | 
							}()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -231,6 +232,10 @@ func parseAnswers(p []byte) []*dnsAnswer {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		answer := &dnsAnswer{}
 | 
							answer := &dnsAnswer{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// https://tools.ietf.org/html/rfc1035#section-4.1.4
 | 
				
			||||||
 | 
							// i+2 assumes the ANSWER always using "Message compression", start with 2 bytes offset of the query domain.
 | 
				
			||||||
 | 
							// TODO: check here
 | 
				
			||||||
		answer.QueryType = binary.BigEndian.Uint16(p[i+2:])
 | 
							answer.QueryType = binary.BigEndian.Uint16(p[i+2:])
 | 
				
			||||||
		answer.QueryClass = binary.BigEndian.Uint16(p[i+4:])
 | 
							answer.QueryClass = binary.BigEndian.Uint16(p[i+4:])
 | 
				
			||||||
		answer.TTL = binary.BigEndian.Uint32(p[i+6:])
 | 
							answer.TTL = binary.BigEndian.Uint32(p[i+6:])
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user