| 159 | |
| 160 | |
| 161 | def flush_systemd_dns_cache(): |
| 162 | # If the user is using systemd-resolve for DNS resolution, it is |
| 163 | # possible for the request to go through systemd-resolve before we |
| 164 | # see it...and it may use a cached result instead of sending a |
| 165 | # request that we can intercept. When sshuttle starts and stops, |
| 166 | # this means that we should clear the cache! |
| 167 | # |
| 168 | # The command to do this was named systemd-resolve, but changed to |
| 169 | # resolvectl in systemd 239. |
| 170 | # https://github.com/systemd/systemd/blob/f8eb41003df1a4eab59ff9bec67b2787c9368dbd/NEWS#L3816 |
| 171 | |
| 172 | p = None |
| 173 | if helpers.which("resolvectl"): |
| 174 | debug2("Flushing systemd's DNS resolver cache: " |
| 175 | "resolvectl flush-caches") |
| 176 | p = ssubprocess.Popen(["resolvectl", "flush-caches"], |
| 177 | stdout=ssubprocess.PIPE, env=helpers.get_env()) |
| 178 | elif helpers.which("systemd-resolve"): |
| 179 | debug2("Flushing systemd's DNS resolver cache: " |
| 180 | "systemd-resolve --flush-caches") |
| 181 | p = ssubprocess.Popen(["systemd-resolve", "--flush-caches"], |
| 182 | stdout=ssubprocess.PIPE, env=helpers.get_env()) |
| 183 | |
| 184 | if p: |
| 185 | # Wait so flush is finished and process doesn't show up as defunct. |
| 186 | rv = p.wait() |
| 187 | if rv != 0: |
| 188 | log("Received non-zero return code %d when flushing DNS resolver " |
| 189 | "cache." % rv) |
| 190 | |
| 191 | |
| 192 | # This is some voodoo for setting up the kernel's transparent |