From d33c2f84a8fb2cbcb24814ea702b2d73c62307f2 Mon Sep 17 00:00:00 2001 From: Yang Bo Date: Tue, 5 Nov 2019 10:43:37 +0800 Subject: [PATCH] netlink: Fix invalid route crashes agent Invalid routes in update_routes request crash agent, fix it Fixes: #73 Signed-off-by: Yang Bo --- src/agent/src/netlink.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/agent/src/netlink.rs b/src/agent/src/netlink.rs index 101a20d6c..9749645c0 100644 --- a/src/agent/src/netlink.rs +++ b/src/agent/src/netlink.rs @@ -2437,6 +2437,9 @@ impl RtnlHandle { for grpcroute in rt { if grpcroute.gateway.as_str() == "" { let r = RtRoute::from(grpcroute.clone()); + if r.index == -1 { + continue; + } self.add_one_route(&r)?; } } @@ -2444,6 +2447,9 @@ impl RtnlHandle { for grpcroute in rt { if grpcroute.gateway.as_str() != "" { let r = RtRoute::from(grpcroute.clone()); + if r.index == -1 { + continue; + } self.add_one_route(&r)?; } } @@ -2754,7 +2760,10 @@ impl From for RtRoute { let index = { let mut rh = RtnlHandle::new(NETLINK_ROUTE, 0).unwrap(); - rh.find_link_by_name(r.device.as_str()).unwrap().ifi_index + match rh.find_link_by_name(r.device.as_str()) { + Ok(ifi) => ifi.ifi_index, + Err(_) => -1, + } }; let (dest, dst_len) = if r.dest.is_empty() {