Merge pull request #104 from dave-tucker/fix_skskb_load

obj: fix name parsing for sk_skb sections
pull/105/head
Alessandro Decina 3 years ago committed by GitHub
commit daf8630133
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -146,6 +146,15 @@ impl FromStr for ProgramSection {
} }
"socket_filter" => SocketFilter { name }, "socket_filter" => SocketFilter { name },
"sk_msg" => SkMsg { name }, "sk_msg" => SkMsg { name },
"sk_skb" => match &*name {
"stream_parser" => SkSkbStreamParser { name },
"stream_verdict" => SkSkbStreamVerdict { name },
_ => {
return Err(ParseError::InvalidProgramSection {
section: section.to_owned(),
})
}
},
"sk_skb/stream_parser" => SkSkbStreamParser { name }, "sk_skb/stream_parser" => SkSkbStreamParser { name },
"sk_skb/stream_verdict" => SkSkbStreamVerdict { name }, "sk_skb/stream_verdict" => SkSkbStreamVerdict { name },
"sockops" => SockOps { name }, "sockops" => SockOps { name },
@ -1072,4 +1081,41 @@ mod tests {
}) })
); );
} }
#[test]
fn test_parse_section_skskb_unnamed() {
let mut obj = fake_obj();
assert_matches!(
obj.parse_section(fake_section("sk_skb/stream_parser", bytes_of(&fake_ins()))),
Ok(())
);
assert_matches!(
obj.programs.get("stream_parser"),
Some(Program {
section: ProgramSection::SkSkbStreamParser { .. },
..
})
);
}
#[test]
fn test_parse_section_skskb_named() {
let mut obj = fake_obj();
assert_matches!(
obj.parse_section(fake_section(
"sk_skb/stream_parser/my_parser",
bytes_of(&fake_ins())
)),
Ok(())
);
assert_matches!(
obj.programs.get("my_parser"),
Some(Program {
section: ProgramSection::SkSkbStreamParser { .. },
..
})
);
}
} }

Loading…
Cancel
Save