Skip to content

Commit 748df0d

Browse files
committed
bgp: add guardrail for policy check
Whenever the prefix-set has no prefix-list, a crash is experienced at the codition lookup: ``` thread 'tokio-runtime-worker' (42) panicked at holo-bgp/src/policy.rs:184:69: called `Option::unwrap()` on a `None` value stack backtrace: note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ``` Fixed in this PR. Signed-off-by: Paul Wekesa <paul1tw1@gmail.com>
1 parent 7ac2713 commit 748df0d

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

holo-bgp/src/policy.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,14 @@ fn process_stmt_condition(
181181
// "match-prefix-set"
182182
PolicyCondition::MatchPrefixSet(value) => {
183183
let af = prefix.address_family();
184-
let set = match_sets.prefixes.get(&(value.clone(), af)).unwrap();
185-
set.prefixes.iter().any(|range| {
186-
prefix.ip() == range.prefix.ip()
187-
&& prefix.prefix() >= range.masklen_lower
188-
&& prefix.prefix() <= range.masklen_upper
189-
})
184+
match match_sets.prefixes.get(&(value.clone(), af)) {
185+
Some(set) => set.prefixes.iter().any(|range| {
186+
prefix.ip() == range.prefix.ip()
187+
&& prefix.prefix() >= range.masklen_lower
188+
&& prefix.prefix() <= range.masklen_upper
189+
}),
190+
None => false,
191+
}
190192
}
191193
// "match-neighbor-set"
192194
PolicyCondition::MatchNeighborSet(value) => {
@@ -195,13 +197,16 @@ fn process_stmt_condition(
195197
return true;
196198
};
197199

198-
let set = match_sets.neighbors.get(value).unwrap();
199-
set.addrs.contains(remote_addr)
200+
match match_sets.neighbors.get(value) {
201+
Some(set) => set.addrs.contains(remote_addr),
202+
None => false,
203+
}
200204
}
201205
// "match-tag-set"
202206
PolicyCondition::MatchTagSet(value) => {
203-
if let Some(tag) = &rpinfo.tag {
204-
let set = match_sets.tags.get(value).unwrap();
207+
if let Some(tag) = &rpinfo.tag
208+
&& let Some(set) = match_sets.tags.get(value)
209+
{
205210
set.tags.contains(tag)
206211
} else {
207212
false

0 commit comments

Comments
 (0)