obj: fix name parsing for sk_skb sections

This commit fixes name parsing of sk_skb sections such that both named
and unnamed variants will work correctly.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
pull/104/head
Dave Tucker 3 years ago
parent 2206fb6456
commit 352e54b724

@ -146,6 +146,15 @@ impl FromStr for ProgramSection {
}
"socket_filter" => SocketFilter { 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_verdict" => SkSkbStreamVerdict { 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