-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make PacketBuilder and Layer::encode_bytes #65
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added several comments, and then I realized it's better to start a review for that.
Concretely -
- Think of
PacketBuilder
as something that builds thePacket
. - Look at my suggestions for implementing
stack
method (this would also simplify the logic you are implementing during thebuild
). - We may need to add a couple of methods in the
Layer
trait (eg.demux
(takesmut self
and&str
and returns Self) (updating internal fields (originalself
may be generated usingdefault
). (Also may beparse
API, something that willparse
scapy
strings (we may visit this later.)
The |
I initially decided to return a let builder = scalpel::builder::PacketBuilder::new()
.stack(eth_layer)?
.stack(ip_layer)?
.stack_bytes(bytes);
let packet: Packet = builder.build().unwrap();
let bytes: Vec<Vec<u8>> = packet.to_bytes(); We would expect
|
It's possible to implement Surely this is a bit tricky to handle but possible. Thus when everything is
Does it make sense? |
I incorporated this and what I said above and ended up with this approach, where fn stack_and_encode(&mut self, next_layer: &[u8], info: &str) -> Result<Vec<u8>, Error>; This takes care of the demuxing, encoding, setting checksums all in one function. |
31b7a85
to
d99cc3e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like coming into a decent shape. Only a few nit-picks at the moment, Will need more time to review. What we may do is - this basic code we can merge into master (maybe gate sculpting
with a feature flag?) so that we don't break others?
I am looking at what's minimum that can be merged into master, so that it's easier to build subsequently on the work.
checksum
part - for the IP header is fine, but UDP
and TCP
checksums are a bit involved (because they need some fields from the IP
header.) Hence I believe - a final fixup_checksums
would be a good idea!
Oh right. I wasn't aware that the TCP and UDP checksums also used fields from the previous headers. I've a few ideas in mind for the |
This link has got code for UDP checksum. My high level idea was as follows - keep certain fields in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, let's do a squash push only towards the end when all conversations are resolved.
Currently I am a bit confused which conversations are resolved. Can you explicitly mark those? and some minor changes that I have suggested in the review?
Sorry, I missed those earlier!
I believe it's ready to be merged as a first step, but the PR is so big, it's difficult to say with confidence. So let's just minimize the changes using the suggestions I have given and take a look.
a4dd875
to
c068ee0
Compare
- Implement `PacketBuilder` to sculpt packets. - Implement `Layer::stack_and_encode` for Ethernet and IPv4. - Implement `as_slice` and `as_mut_slice` for MACAddress, IPv4Address and IPv6Address. - Create example `packet_sculpting.rs`. - Add new `crate::Error` variant SculptingError. Signed-off-by: Mohammad Aadil Shabier <[email protected]>
I've marked all the relevant commits as resolved. Apologies for not doing it earlier.
I've minimized most of the changes and made them as slim as possible, there's only one other change I want to make right now (inverse Hashmaps for sculpting), but I think those too can be implemented later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good as a first cut implementation. Let's merge it and then identify issues and try to resolve those.
I am going to open a PR to wrap sculpting inside a feature. Once ready we will not require that or make |
Refer to #56 for discussion
This aims to bring packet sculpting to scalpel. This is done by extending
Layer
withLayer::encode_bytes()
. It's usage can be seen inexamples/packet_sculpting.rs
result
is aVec<Vec<u8>>
, where each innerVec<u8>
contains the bytes of that layer in thePacket
, i.e.result[0]
contains the Ethernet packet.Only Ethernet and IPV4 sculpting are currently implemented.