Skip to content
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

Modifying existing ip packets #29

Open
shriphani opened this issue May 18, 2022 · 2 comments
Open

Modifying existing ip packets #29

shriphani opened this issue May 18, 2022 · 2 comments

Comments

@shriphani
Copy link

Thank you very much for your work on this awesome library.

I need to alter a packet that I am able to parse (using SlicedPacket::from_ip). Specifically, I need to be able to (i) alter the source IP, (ii) alter the source port, (iii) recompute the checksum and obtain a valid packet.

I can see some references to PacketBuilder, update_checksum_ipv4 and so on but I am curious what is the recommended (and most convenient) way to do this.

Warmest regards,
Shriphani

@JulianSchmid
Copy link
Owner

JulianSchmid commented Jun 4, 2022

Hi @shriphani ,

Currently the library does not support an efficient way of changing data and re-calculating checksums.

Probably the easiest way is to decode the headers via PacketHeaders::from_ethernet_slice or PacketHeaders::from_ip_slice modify the decoded data and then updating the checksums via update checksum methods in the ip & transport headers (e.g. Ipv4Header::calc_header_checksum, TransportHeader::update_checksum_ipv4 TransportHeader::update_checksum_ipv6. Finally you will have to write the headers one-by-one.

I will see if I can add methods to simplify the checksum updating & writing in the future. But currently other features have a higher priority (or have been waiting for a longer time).

Greets
Julian

@robs-zeynet
Copy link
Contributor

robs-zeynet commented Dec 17, 2022

@JulianSchmid - this is related to the issue I was looking at. One thing that occurred to me was adding PacketBuilder::From<SlidedPacket> and PacketBuilder::From<ParsedHeaders> methods. It's more computationally expensive than just "change the IPs and recalculate the checksums" but is probably more general as well. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants