|  |  | @ -2,6 +2,7 @@ package sgfw | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | import ( |  |  |  | import ( | 
			
		
	
		
		
			
				
					
					|  |  |  | 	"encoding/binary" |  |  |  | 	"encoding/binary" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	"fmt" | 
			
		
	
		
		
			
				
					
					|  |  |  | 	"net" |  |  |  | 	"net" | 
			
		
	
		
		
			
				
					
					|  |  |  | 	"strings" |  |  |  | 	"strings" | 
			
		
	
		
		
			
				
					
					|  |  |  | 	"sync" |  |  |  | 	"sync" | 
			
		
	
	
		
		
			
				
					|  |  | @ -71,7 +72,10 @@ func (dc *dnsCache) processDNS(pkt *nfqueue.NFQPacket) { | 
			
		
	
		
		
			
				
					
					|  |  |  | 			if pinfo == nil { |  |  |  | 			if pinfo == nil { | 
			
		
	
		
		
			
				
					
					|  |  |  | 				if !FirewallConfig.LogRedact { |  |  |  | 				if !FirewallConfig.LogRedact { | 
			
		
	
		
		
			
				
					
					|  |  |  | 					log.Warningf("Skipping attempted DNS cache entry for process that can't be found: %v -> %v\n", q.Name, dns.answer) |  |  |  | 					log.Warningf("Skipping attempted DNS cache entry for process that can't be found: %v -> %v\n", q.Name, dns.answer) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 				} else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 					dbLogger.logRedacted("default", fmt.Sprintf("Skipping attempted DNS cache entry for process that can't be found: %v -> %v\n", q.Name, dns.answer)) | 
			
		
	
		
		
			
				
					
					|  |  |  | 				} |  |  |  | 				} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 				return |  |  |  | 				return | 
			
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  | 			} | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
	
		
		
			
				
					|  |  | @ -82,7 +86,8 @@ func (dc *dnsCache) processDNS(pkt *nfqueue.NFQPacket) { | 
			
		
	
		
		
			
				
					
					|  |  |  | 	if !FirewallConfig.LogRedact { |  |  |  | 	if !FirewallConfig.LogRedact { | 
			
		
	
		
		
			
				
					
					|  |  |  | 		log.Infof("Unhandled DNS message: %v", dns) |  |  |  | 		log.Infof("Unhandled DNS message: %v", dns) | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} else { |  |  |  | 	} else { | 
			
		
	
		
		
			
				
					
					|  |  |  | 		log.Infof("Unhandled DNS message [redacted]") |  |  |  | 		log.Infof("Unhandled DNS message: %s", STR_REDACTED) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		dbLogger.logRedacted("default", fmt.Sprintf("Unhandled DNS message: %v", dns)) | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
	
		
		
			
				
					|  |  | @ -128,6 +133,7 @@ func (dc *dnsCache) processRecordAddress(name string, answers []dnsRR, pid int) | 
			
		
	
		
		
			
				
					
					|  |  |  | 				log.Warningf("Unexpected RR type in answer section of A response: %v", rec) |  |  |  | 				log.Warningf("Unexpected RR type in answer section of A response: %v", rec) | 
			
		
	
		
		
			
				
					
					|  |  |  | 			} else { |  |  |  | 			} else { | 
			
		
	
		
		
			
				
					
					|  |  |  | 				log.Warningf("Unexpected RR type in answer section of A response: [redacted]") |  |  |  | 				log.Warningf("Unexpected RR type in answer section of A response: [redacted]") | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 				dbLogger.logRedacted("default", fmt.Sprintf("Unexpected RR type in answer section of A response: %v", rec)) | 
			
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  | 			} | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -145,7 +151,7 @@ func (dc *dnsCache) processRecordAddress(name string, answers []dnsRR, pid int) | 
			
		
	
		
		
			
				
					
					|  |  |  | 			pid = 0 |  |  |  | 			pid = 0 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | //		log.Noticef("______ Adding to dns map: %s: %s -> pid %d", name, ip, pid)
 |  |  |  | 		//		log.Noticef("______ Adding to dns map: %s: %s -> pid %d", name, ip, pid)
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		_, ok := dc.ipMap[pid] |  |  |  | 		_, ok := dc.ipMap[pid] | 
			
		
	
		
		
			
				
					
					|  |  |  | 		if !ok { |  |  |  | 		if !ok { | 
			
		
	
	
		
		
			
				
					|  |  | @ -159,6 +165,8 @@ func (dc *dnsCache) processRecordAddress(name string, answers []dnsRR, pid int) | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  | 		if !FirewallConfig.LogRedact { |  |  |  | 		if !FirewallConfig.LogRedact { | 
			
		
	
		
		
			
				
					
					|  |  |  | 			log.Infof("Adding %s: %s", name, ip) |  |  |  | 			log.Infof("Adding %s: %s", name, ip) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		} else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			dbLogger.logRedacted("default", fmt.Sprintf("Adding %s: %s", name, ip)) | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
	
		
		
			
				
					|  |  | @ -183,6 +191,9 @@ func (dc *dnsCache) Lookup(ip net.IP, pid int) string { | 
			
		
	
		
		
			
				
					
					|  |  |  | 				if !FirewallConfig.LogRedact { |  |  |  | 				if !FirewallConfig.LogRedact { | 
			
		
	
		
		
			
				
					
					|  |  |  | 					log.Warningf("Skipping expired per-pid (%d) DNS cache entry: %s -> %s / exp. %v (%ds)\n", |  |  |  | 					log.Warningf("Skipping expired per-pid (%d) DNS cache entry: %s -> %s / exp. %v (%ds)\n", | 
			
		
	
		
		
			
				
					
					|  |  |  | 						pid, ip.String(), entry.name, entry.exp, entry.ttl) |  |  |  | 						pid, ip.String(), entry.name, entry.exp, entry.ttl) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 				} else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 					dbLogger.logRedacted("default", fmt.Sprintf("Skipping expired per-pid (%d) DNS cache entry: %s -> %s / exp. %v (%ds)\n", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 						pid, ip.String(), entry.name, entry.exp, entry.ttl)) | 
			
		
	
		
		
			
				
					
					|  |  |  | 				} |  |  |  | 				} | 
			
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  | 			} | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
	
		
		
			
				
					|  |  | @ -198,6 +209,9 @@ func (dc *dnsCache) Lookup(ip net.IP, pid int) string { | 
			
		
	
		
		
			
				
					
					|  |  |  | 			if !FirewallConfig.LogRedact { |  |  |  | 			if !FirewallConfig.LogRedact { | 
			
		
	
		
		
			
				
					
					|  |  |  | 				log.Warningf("Skipping expired global DNS cache entry: %s -> %s / exp. %v (%ds)\n", |  |  |  | 				log.Warningf("Skipping expired global DNS cache entry: %s -> %s / exp. %v (%ds)\n", | 
			
		
	
		
		
			
				
					
					|  |  |  | 					ip.String(), entry.name, entry.exp, entry.ttl) |  |  |  | 					ip.String(), entry.name, entry.exp, entry.ttl) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			} else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 				dbLogger.logRedacted("default", fmt.Sprintf("Skipping expired global DNS cache entry: %s -> %s / exp. %v (%ds)\n", | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 					ip.String(), entry.name, entry.exp, entry.ttl)) | 
			
		
	
		
		
			
				
					
					|  |  |  | 			} |  |  |  | 			} | 
			
		
	
		
		
			
				
					
					|  |  |  | 		} |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
	
		
		
			
				
					|  |  | 
 |