summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmīls <emils@mullvad.net>2020-11-06 00:20:55 +0000
committerEmīls <emils@mullvad.net>2020-11-11 10:16:23 +0000
commite21e8e98cd82c0ba005754a71182867b317a8f6a (patch)
tree1ae7510ba24cc4b0ae88386ea589c35eab115469
parentd0f9058d62308bd3213e02f00040808fb9f2d920 (diff)
downloadmullvadvpn-e21e8e98cd82c0ba005754a71182867b317a8f6a.tar.xz
mullvadvpn-e21e8e98cd82c0ba005754a71182867b317a8f6a.zip
Parse routes more permissively
-rw-r--r--talpid-core/src/routing/linux.rs41
1 files changed, 23 insertions, 18 deletions
diff --git a/talpid-core/src/routing/linux.rs b/talpid-core/src/routing/linux.rs
index cf9c621d84..8667026294 100644
--- a/talpid-core/src/routing/linux.rs
+++ b/talpid-core/src/routing/linux.rs
@@ -782,16 +782,8 @@ impl RouteManagerImpl {
// Tries to coax a Route out of a RouteMessage
fn parse_route_message_inner(&self, msg: RouteMessage) -> Result<Option<Route>> {
- let mut prefix = None;
- let mut node_addr = None;
- let mut device = None;
- let mut metric = None;
- let mut gateway: Option<IpAddr> = None;
-
- let destination_length = msg.header.destination_prefix_length;
let af_spec = msg.header.address_family;
- let mut table_id = u32::from(msg.header.table);
-
+ let destination_length = msg.header.destination_prefix_length;
let is_ipv4 = match af_spec as i32 {
AF_INET => true,
AF_INET6 => false,
@@ -801,7 +793,23 @@ impl RouteManagerImpl {
}
};
- let mut is_loopback = false;
+
+ // By default, the prefix is unspecified.
+ let mut prefix = IpNetwork::new(
+ if is_ipv4 {
+ Ipv4Addr::UNSPECIFIED.into()
+ } else {
+ Ipv6Addr::UNSPECIFIED.into()
+ },
+ destination_length,
+ )
+ .map_err(Error::InvalidNetworkPrefix)?;
+ let mut node_addr = None;
+ let mut device = None;
+ let mut metric = None;
+ let mut gateway: Option<IpAddr> = None;
+
+ let mut table_id = u32::from(msg.header.table);
for nla in msg.nlas.iter() {
match nla {
@@ -811,7 +819,6 @@ impl RouteManagerImpl {
if !route_device.is_loopback() {
device = Some(route_device);
} else {
- is_loopback = true;
gateway = if is_ipv4 {
Some(Ipv4Addr::LOCALHOST.into())
} else {
@@ -830,12 +837,10 @@ impl RouteManagerImpl {
}
RouteNla::Destination(addr) => {
- prefix = Self::parse_ip(&addr)
- .and_then(|ip| {
- ipnetwork::IpNetwork::new(ip, destination_length)
- .map_err(Error::InvalidNetworkPrefix)
- })
- .map(Some)?;
+ prefix = Self::parse_ip(&addr).and_then(|ip| {
+ ipnetwork::IpNetwork::new(ip, destination_length)
+ .map_err(Error::InvalidNetworkPrefix)
+ })?;
}
// gateway NLAs indicate that this is actually a default route
@@ -866,7 +871,7 @@ impl RouteManagerImpl {
Ok(Some(Route {
node,
- prefix: prefix.unwrap(),
+ prefix,
metric,
table_id,
}))