-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fixing L4 offset for IP packets with Options field #54
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: evershalik <[email protected]>
__u8 l4_offset = iph->ihl * 4; // ipv4 header length | ||
|
||
/* Check if it is a valid IPV4 packet */ | ||
if (iph->ihl < 5 || ((unsigned char *)iph + l4_offset) > data_end) |
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.
Range of IHL is 5 to 15, with boundary values included. Please add check explicitly for this.
__u16 data_offset = tcph->doff * 4; // tcp header length | ||
|
||
/* Check if it is a valid TCP packet */ | ||
if (tcph->doff < 5 || ((unsigned char *)tcph + data_offset) > data_end) |
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.
Same as the range comment for IHL.
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.
Please fix this issue in Traffic Mirroring as well.
@evershalik Can you address this above comments. |
This PR fixed #30
Problem Statement:
The current implementation of the codebase does not handle IP and TCP packets with a header length greater than 20 bytes correctly. This issue is particularly problematic for packets containing options, which increase the header length beyond 20 bytes.
Approach:
To address this issue, we have taken the following approaches:
Firstly, I have modified the code to use the
l4_offset
variable(IP Header Length) instead ofsizeof(iphdr struct)
when adding to the iph pointer. This ensures that the code correctly traverses to the end of the IP header( or the start of the transport layer header), even in cases where the header length is greater than 20 bytes.Secondly, I have modified the code to use the
data_offset
variable(TCP Header Length) instead ofsizeof(tcphdr struct)
when adding to the tcph pointer. This ensures that the code correctly traverses to the end of the TCP header (or start of the payload), even in cases where the header length is greater than 20 bytes.By implementing these changes, I can ensure that IP and TCP packets with options are handled correctly, which improves the reliability and stability of the system.
Signed-off-by: SHANKAR [email protected]