| 
									
										
										
										
											2020-09-28 16:53:00 +02:00
										 |  |  | package cache
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import "github.com/miekg/dns"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-21 09:29:04 -06:00
										 |  |  | // filterRRSlice filters out OPT RRs, and sets all RR TTLs to ttl.
 | 
					
						
							| 
									
										
										
										
											2025-07-03 04:20:47 +02:00
										 |  |  | // If dup is true the RRs in rrs are _copied_ before adjusting their
 | 
					
						
							|  |  |  | // TTL and the slice of copied RRs is returned.
 | 
					
						
							| 
									
										
										
										
											2022-10-21 09:29:04 -06:00
										 |  |  | func filterRRSlice(rrs []dns.RR, ttl uint32, dup bool) []dns.RR {
 | 
					
						
							| 
									
										
										
										
											2020-09-28 16:53:00 +02:00
										 |  |  | 	j := 0
 | 
					
						
							| 
									
										
										
										
											2021-11-20 00:15:58 +08:00
										 |  |  | 	rs := make([]dns.RR, len(rrs))
 | 
					
						
							| 
									
										
										
										
											2020-09-28 16:53:00 +02:00
										 |  |  | 	for _, r := range rrs {
 | 
					
						
							| 
									
										
										
										
											2020-10-14 04:11:22 +02:00
										 |  |  | 		if r.Header().Rrtype == dns.TypeOPT {
 | 
					
						
							|  |  |  | 			continue
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2020-09-28 16:53:00 +02:00
										 |  |  | 		if dup {
 | 
					
						
							|  |  |  | 			rs[j] = dns.Copy(r)
 | 
					
						
							|  |  |  | 		} else {
 | 
					
						
							|  |  |  | 			rs[j] = r
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2025-07-03 04:20:47 +02:00
										 |  |  | 		rs[j].Header().Ttl = ttl
 | 
					
						
							| 
									
										
										
										
											2020-09-28 16:53:00 +02:00
										 |  |  | 		j++
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	return rs[:j]
 | 
					
						
							|  |  |  | }
 |