Skip to content

Commit

Permalink
Merge pull request #18 from Ma27/workaround-link-local-zone-ids
Browse files Browse the repository at this point in the history
Strip link-local zone ids from IPv6 socket addrs
  • Loading branch information
MindFlavor authored Nov 8, 2019
2 parents 09aa62a + 9a54a8f commit 90a1585
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 deletions.
35 changes: 10 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ failure = "0.1.5"
hyper = "0.12.29"
http = "0.1.17"
prometheus_exporter_base = "0.2.0"

regex = "1.3.1"
4 changes: 3 additions & 1 deletion src/wireguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use prometheus_exporter_base::PrometheusCounter;
use std::collections::HashMap;
use std::convert::TryFrom;
use std::net::SocketAddr;
use regex::Regex;

const EMPTY: &str = "(none)";

Expand Down Expand Up @@ -77,7 +78,8 @@ impl TryFrom<&str> for WireGuard {
let public_key = v[1].to_owned();

let (remote_ip, remote_port) = if let Some(ip_and_port) = to_option_string(v[3]) {
let addr: SocketAddr = ip_and_port.parse::<SocketAddr>().unwrap();
let re = Regex::new(r"^\[(?P<ip>[A-Fa-f0-9:]+)%(.*)\]:(?P<port>[0-9]+)$").unwrap();
let addr: SocketAddr = re.replace_all(&ip_and_port, "[$ip]:$port").parse::<SocketAddr>().unwrap();

(Some(addr.ip().to_string()), Some(addr.port()))
} else {
Expand Down

0 comments on commit 90a1585

Please sign in to comment.