ソースを参照

check if static route exists before trying to remove

master
Jonathan Cobb 4年前
コミット
3165317a30
2個のファイルの変更7行の追加3行の削除
  1. +6
    -2
      src/net.rs
  2. +1
    -1
      src/proxy.rs

+ 6
- 2
src/net.rs ファイルの表示

@@ -89,7 +89,7 @@ pub fn ip_gateway() -> String {
gateway
}

pub fn needs_static_route(ip_string: &String) -> bool {
pub fn static_route_exists(ip_string: &String) -> bool {
trace!("needs_static_route: checking ip={:?}", ip_string);
let platform: Platform = platform();
let output = match platform {
@@ -124,7 +124,7 @@ pub fn needs_static_route(ip_string: &String) -> bool {
let data = String::from_utf8(output).unwrap();
let mut parts = data.split_ascii_whitespace();
let first_part = parts.next();
first_part.is_none() || first_part.unwrap().len() == 0
first_part.is_some() && first_part.unwrap().len() > 0
}

pub fn create_static_route(gateway: &String, ip_string: &String) -> bool {
@@ -168,6 +168,10 @@ pub fn create_static_route(gateway: &String, ip_string: &String) -> bool {
}

pub fn remove_static_route(ip_string: &String) -> bool {
if !static_route_exists(ip_string) {
info!("remove_static_route: route does not exist for ip={}", ip_string);
return true;
}
info!("remove_static_route: removing ip={}", ip_string);
let platform: Platform = platform();
let output = match platform {


+ 1
- 1
src/proxy.rs ファイルの表示

@@ -147,7 +147,7 @@ async fn proxy(client: Client<HttpsConnector<HttpConnector<CacheResolver>>>,
info!("proxy: host {} resolved to: {}", host, ip_string);
trace!("proxy: request is {:?}", req);

if needs_static_route(&ip_string) {
if !static_route_exists(&ip_string) {
if !create_static_route(&gateway, &ip_string) {
// we MUST fail here, without a valid static route, the request would go back out
// through the VPN interface, creating an infinite loop


読み込み中…
キャンセル
保存