Skip to content

Commit 88336e4

Browse files
authored
Merge pull request #56 from NLnetLabs/absorb-fsm
Merge long-living absorb-fsm
2 parents a90449a + 586ac67 commit 88336e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+9928
-6938
lines changed

Cargo.toml

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,25 @@ keywords = ["routing", "bgp"]
1212
license = "BSD-3-Clause"
1313

1414
[dependencies]
15-
arbitrary = { version = "1", optional = true, features = ["derive"] }
16-
bytes = { version = "1", optional = true }
15+
inetnum = { version = "0.1.0", features = ["arbitrary", "serde"] }
16+
arbitrary = { version = "1.3.1", optional = true, features = ["derive"] }
17+
bytes = { version = "1.2", optional = true }
1718
chrono = { version = "0.4.20", optional = true, default-features = false }
1819
const-str = { version = "0.5", optional = true, features = ["case"] }
1920
log = { version = "0.4.4", optional = true }
2021
octseq = { version = "0.4.0", optional = true, features = ["bytes"] }
22+
paste = { version = "1" }
2123
serde = { version = "1.0.165", optional = true, features = ["derive"] }
22-
tokio = { version = ">=1.24.2", optional = true, features = ["sync", "rt"] }
24+
tokio = { version = ">=1.24.2", optional = true, features = ["io-util", "macros", "net", "sync", "rt-multi-thread", "time"] }
2325

2426
[dev-dependencies]
2527
memmap2 = "0.9"
2628
serde_test = "1"
2729

2830
[features]
29-
default = []
31+
default = ["bgp"]
3032
bgp = ["bytes", "log", "octseq", "const-str"]
3133
bmp = ["bgp", "chrono"]
34+
fsm = ["tokio"]
35+
bgpsec = []
36+

fuzz/Cargo.lock

+45-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fuzz/Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,15 @@ name = "parse_open_message"
4545
path = "fuzz_targets/parse_open_message.rs"
4646
test = false
4747
doc = false
48+
49+
[[bin]]
50+
name = "nlri_ord"
51+
path = "fuzz_targets/nlri_ord.rs"
52+
test = false
53+
doc = false
54+
55+
[[bin]]
56+
name = "path_selection"
57+
path = "fuzz_targets/path_selection.rs"
58+
test = false
59+
doc = false

fuzz/fuzz_targets/nlri_ord.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![no_main]
2+
3+
use std::cmp::Ordering::*;
4+
use libfuzzer_sys::fuzz_target;
5+
use routecore::bgp::nlri::afisafi::Nlri;
6+
7+
fuzz_target!(|data: (Nlri<&[u8]>, Nlri<&[u8]>, Nlri<&[u8]>)| {
8+
let (a, b, c) = data;
9+
match (a.cmp(&b), b.cmp(&c)) {
10+
// a < b < c
11+
(Less, Less) => assert_eq!(a.cmp(&c), Less),
12+
// a < b == c
13+
(Less, Equal) => assert_eq!(a.cmp(&c), Less),
14+
// a < b > c
15+
(Less, Greater) => { } ,
16+
17+
// a == b == c
18+
(Equal, Equal) => assert_eq!(a.cmp(&c), Equal),
19+
// a == b < c
20+
(Equal, Less) => assert_eq!(a.cmp(&c), Less),
21+
// a == b > c
22+
(Equal, Greater) => assert_eq!(a.cmp(&c), Greater),
23+
24+
// a > b > c
25+
(Greater, Greater) => assert_eq!(a.cmp(&c), Greater),
26+
// a > b < c
27+
(Greater, Less) => { },
28+
// a > b == c
29+
(Greater, Equal) => assert_eq!(a.cmp(&c), Greater),
30+
}
31+
});
32+

fuzz/fuzz_targets/parse_update_message.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,18 @@ use routecore::bgp::message::{UpdateMessage, SessionConfig};
55
use routecore::bgp::message::update_builder::UpdateBuilder;
66

77
fuzz_target!(|data: (&[u8], SessionConfig)| {
8-
if let Ok(upd) = UpdateMessage::from_octets(data.0, data.1) {
8+
if let Ok(upd) = UpdateMessage::from_octets(data.0, &data.1) {
99
if let Ok(pas) = upd.path_attributes() {
1010
for pa in pas.into_iter() {
11-
if let Ok(pa) = pa {
12-
let _ = pa.to_owned();
13-
}
11+
let _ = pa.unwrap().to_owned();
1412
}
1513
}
16-
/*
17-
if let Ok(builder) = UpdateBuilder::from_update_message(
18-
&upd,
19-
data.1,
20-
target,
21-
) {
22-
let _ = builder.into_message(); //.unwrap();
14+
if let Ok(iter) = upd.announcements() {
15+
iter.count();
16+
}
17+
if let Ok(iter) = upd.withdrawals() {
18+
iter.count();
2319
}
24-
*/
2520
}
2621
});
2722

fuzz/fuzz_targets/path_selection.rs

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#![no_main]
2+
3+
use std::cmp::Ordering::*;
4+
use libfuzzer_sys::fuzz_target;
5+
use routecore::bgp::{path_attributes::PaMap, path_selection::{OrdRoute, Rfc4271, SkipMed, TiebreakerInfo}};
6+
7+
fn verify_ord<T>(a: &T, b: &T, c: &T)
8+
where T: Ord
9+
{
10+
match (a.cmp(b), b.cmp(c)) {
11+
// a < b < c
12+
(Less, Less) => assert_eq!(a.cmp(c), Less),
13+
// a < b == c
14+
(Less, Equal) => assert_eq!(a.cmp(c), Less),
15+
// a < b > c
16+
(Less, Greater) => { } ,
17+
18+
// a == b == c
19+
(Equal, Equal) => {
20+
assert_eq!(a.cmp(c), Equal);
21+
// Test PartialEq
22+
assert!(a == b);
23+
assert!(b == c);
24+
}
25+
// a == b < c
26+
(Equal, Less) => assert_eq!(a.cmp(c), Less),
27+
// a == b > c
28+
(Equal, Greater) => assert_eq!(a.cmp(c), Greater),
29+
30+
// a > b > c
31+
(Greater, Greater) => assert_eq!(a.cmp(c), Greater),
32+
// a > b < c
33+
(Greater, Less) => { },
34+
// a > b == c
35+
(Greater, Equal) => assert_eq!(a.cmp(c), Greater),
36+
}
37+
}
38+
39+
// XXX while doing fuzz_target!(|data: &[u8]| ... and then creating an
40+
// Unstructured from `data` can be useful, the Debug output becomes quite
41+
// useless. It'll be just a bunch of bytes without any structure.
42+
// So, something like
43+
// fuzz_target!(|data: (OrdRoute, OrdRoute, OrdRoute)| {
44+
// has benefits.
45+
//
46+
47+
fuzz_target!(|data: (
48+
PaMap, TiebreakerInfo,
49+
PaMap, TiebreakerInfo,
50+
PaMap, TiebreakerInfo
51+
)|{
52+
53+
//dbg!(&data);
54+
55+
let a = match OrdRoute::<SkipMed>::try_new(&data.0, data.1) {
56+
Ok(r) => r,
57+
Err(_) => return,
58+
};
59+
let b = match OrdRoute::<SkipMed>::try_new(&data.2, data.3) {
60+
Ok(r) => r,
61+
Err(_) => return,
62+
};
63+
let c = match OrdRoute::<SkipMed>::try_new(&data.4, data.5) {
64+
Ok(r) => r,
65+
Err(_) => return,
66+
};
67+
68+
//dbg!("skipmed");
69+
verify_ord(&a, &b, &c);
70+
71+
//dbg!("rfc4271");
72+
/*
73+
verify_ord(
74+
&a.into_strat::<Rfc4271>(),
75+
&b.into_strat::<Rfc4271>(),
76+
&c.into_strat::<Rfc4271>()
77+
);
78+
*/
79+
80+
});

rustfmt.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
max_width = 78
1+
edition = "2021"
2+
max_width = 78
3+

0 commit comments

Comments
 (0)