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

sockets: Fix IPv6 raw packet checksum in IPv6-only configuration #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

david-cermak
Copy link
Contributor

Issue:

In an IPv6-only setup, raw IPv6 packets were being sent with an incorrect checksum, whereas they worked correctly in a dual-stack configuration (both IPv4 and IPv6).

Analysis:

  • The checksum is calculated in raw.c when the pcb->chksum_reqd flag is set.
  • This flag is enabled for all IPv6 raw pcbs in api_msg.c, but only when NETCONNTYPE_ISIPV6(msg->conn->type) evaluates to true.
  • The issue arises because the macro NETCONNTYPE_ISIPV6() checks if the NETCONN_TYPE_IPV6 flag is set in the netconn type. This flag wasn’t being set when creating the socket, as the DOMAIN_TO_NETCONN_TYPE() macro returned the original type without adding the IPv6 flag.

Fix:

  • Made enum netconn_type reflect protocol family also in IPv6-only configs, updating the macro DOMAIN_TO_NETCONN_TYPE() to set the NETCONN_TYPE_IPV6 flag.

Alternative Approach:

  • Another potential solution would be to modify the enum netconn_type to reflect both the connection type and protocol family (as of now) in a dual-stack setup, while reflect connection type only in a single-stack setup (IPv4 only or IPv6 only).
    (i.e. setting NETCONNTYPE_ISIPV6() to true in IPv6 only mode)

PS: saw that you enabled CI runs for new PRs, so maybe you'll accept something from Github, too.
PPS: the main reason for choosing this way of fixing is that the alternative would require semantic changes to the API, but open to suggestions.

Issue:
In an IPv6-only setup, raw IPv6 packets were being sent with an incorrect checksum,
whereas they worked correctly in a dual-stack configuration (both IPv4 and IPv6).

Analysis:
* The checksum is calculated in `raw.c` when the `pcb->chksum_reqd` flag is set.
* This flag is enabled for all IPv6 raw pcbs in `api_msg.c`, but only when
  `NETCONNTYPE_ISIPV6(msg->conn->type)` evaluates to true.
* The issue arises because the macro `NETCONNTYPE_ISIPV6()` checks if
  the `NETCONN_TYPE_IPV6` flag is set in the netconn type. This flag wasn’t being
  set when creating the socket, as the `DOMAIN_TO_NETCONN_TYPE()` macro returned
  the original type without adding the IPv6 flag.

Fix:
* Made enum netconn_type reflect protocol family also in IPv6-only configs,
updating the macro DOMAIN_TO_NETCONN_TYPE() to set the NETCONN_TYPE_IPV6 flag.

Alternative Approach:
* Another potential solution would be to modify the `enum netconn_type` to reflect
both the connection type and protocol family (as of now) in a dual-stack setup,
while reflect connection type only in a single-stack setup (IPv4 only or
IPv6 only)
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

Successfully merging this pull request may close these issues.

1 participant