| 
									
										
										
										
											2023-01-27 13:37:20 -08:00
										 |  |  | // Copyright (c) Tailscale Inc & AUTHORS | 
					
						
							|  |  |  | // SPDX-License-Identifier: BSD-3-Clause | 
					
						
							| 
									
										
										
										
											2021-03-25 17:40:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | package dns | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"fmt" | 
					
						
							|  |  |  | 	"os/exec" | 
					
						
							| 
									
										
										
										
											2024-06-05 14:57:08 -06:00
										 |  |  | 	"syscall" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"golang.org/x/sys/windows" | 
					
						
							| 
									
										
										
										
											2021-03-25 17:40:52 -07:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-18 20:33:21 -07:00
										 |  |  | func flushCaches() error { | 
					
						
							| 
									
										
										
										
											2024-06-05 14:57:08 -06:00
										 |  |  | 	cmd := exec.Command("ipconfig", "/flushdns") | 
					
						
							|  |  |  | 	cmd.SysProcAttr = &syscall.SysProcAttr{ | 
					
						
							|  |  |  | 		CreationFlags: windows.DETACHED_PROCESS, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	out, err := cmd.CombinedOutput() | 
					
						
							| 
									
										
										
										
											2021-03-25 17:40:52 -07:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return fmt.Errorf("%v (output: %s)", err, out) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-09-18 20:33:21 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Flush clears the local resolver cache. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // Only Windows has a public dns.Flush, needed in router_windows.go. Other | 
					
						
							|  |  |  | // platforms like Linux need a different flush implementation depending on | 
					
						
							|  |  |  | // the DNS manager. There is a FlushCaches method on the manager which | 
					
						
							|  |  |  | // can be used on all platforms. | 
					
						
							|  |  |  | func Flush() error { | 
					
						
							|  |  |  | 	return flushCaches() | 
					
						
							|  |  |  | } |