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

net: l2: ieee802154: set the src addr before deciphering the frame #78525

Conversation

lorc-dev
Copy link
Contributor

ieee802154_decipher_data_frame() called from ieee802154_recv() always failed when checking the length of the src address, as it was not yet set.

This sets the src and dst address of the packet before calling the decipher function, and converts the addresses to big endian afterward.

Fixes #78490

The call to ieee802154_decipher_data_frame() from ieee802154_recv()
always failed when checking the length of the src address,
as it was not yet set. This sets the src and dst address of the packet
before calling the decipher function, and converts the addresses
to big endian afterward.

Fixes zephyrproject-rtos#78490

Signed-off-by: Lorenz Clijnen <[email protected]>
@lorc-dev lorc-dev force-pushed the issues/set-src-addr-before-decipher branch from 25d8f0c to 47b28eb Compare September 17, 2024 11:47
Copy link
Contributor

@fgrandel fgrandel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR. Nothing wrong with it from a functionality pov but I'd like to propose that we also improve decoupling of abstraction layers - see the inline review comment.

I started a PR before you pushed yours. If you don't mind I'd like to propose it as an alternative solution for you to review...

Do you agree with this?

@@ -431,19 +421,20 @@ static enum net_verdict ieee802154_recv(struct net_if *iface, struct net_pkt *pk
return NET_OK;
}

set_pkt_ll_addr(net_pkt_lladdr_src(pkt), !fs->fc.pan_id_comp, fs->fc.src_addr_mode,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this definitely works, I think we should rather fix the L2/L3 encapsulation issue that caused this bug to slip through in the first place: IMO it would be better if we removed access to net_pkt_lladdr_src(pkt) (upper layers access to the LL addr) in ieee802154_decipher_data_frame() (L2) as it doesn't make sense to let an L2 function depend on mangled upper layer fields. I'd also prefer if fields being documented as "big endian" would not contain "little endian" data even temporarily. This has bitten us so many times already.

This means that setting and mangling the address fields for the upper layer packet should continue to be done last, i.e. just before we pass the packet on to L3.

(That being said: We'll still need access to the packet in ieee802154_decipher_data_frame() for the moment being to calculate L2 header length. But that can be removed in the future as well.)

@fgrandel fgrandel added the bug The issue is a bug, or the PR is fixing a bug label Sep 17, 2024
@lorc-dev
Copy link
Contributor Author

I started a PR before you pushed yours. If you don't mind I'd like to propose it as an alternative solution for you to review...

Do you agree with this?

Sounds good, I will close this PR

@lorc-dev lorc-dev closed this Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: IEEE 802.15.4 bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

net: l2: ieee802154: IEEE-802.15.4 packets dropped when CONFIG_NET_L2_IEEE802154_SECURITY is enabled
3 participants