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: ethernet: Only try ARP for IP packets #84158

Merged
merged 7 commits into from
Jan 21, 2025

Conversation

jukkar
Copy link
Member

@jukkar jukkar commented Jan 17, 2025

The work in Ethernet send in commit 2f10d7d ("net: ethernet: Set the ptype by the caller in send") introduced a bug because we could try to do ARP resolving for ARP packets too. This is clearly a wrong thing to do. So before trying to do ARP resolving, make sure the the packet type is IP packet.

pdgendt
pdgendt previously approved these changes Jan 17, 2025
rlubos
rlubos previously approved these changes Jan 17, 2025
The work in Ethernet send in commit 2f10d7d
("net: ethernet: Set the ptype by the caller in send")
introduced a bug because we could try to do ARP resolving
for ARP packets too. This is clearly a wrong thing to do.
So before trying to do ARP resolving, make sure the the
packet type is IP packet.

Signed-off-by: Jukka Rissanen <[email protected]>
Print more data / debug information for ARP messages.
Also remove unnecessary "&" when printing IPv4 address.

Signed-off-by: Jukka Rissanen <[email protected]>
It was incorrectly introduced earlier and not really needed
because the test will pass without it.

Signed-off-by: Jukka Rissanen <[email protected]>
The ARP code has set the protocol type of the packet to
0x806, so do not change it when preparing to send to 0x800
which is the IP protocol type. Lets trust the previously
called functions to set the ptype correctly and do not set
it here.

Signed-off-by: Jukka Rissanen <[email protected]>
@jukkar jukkar dismissed stale reviews from rlubos and pdgendt via 86048ad January 20, 2025 15:36
@jukkar jukkar force-pushed the fix/ethenet-ptype branch from cbb4209 to 86048ad Compare January 20, 2025 15:36
@jukkar
Copy link
Member Author

jukkar commented Jan 20, 2025

  • Found an issue which prevented VLAN from working. We blindly forced the ptype to be IP even if we were sending ARP message.

pdgendt
pdgendt previously approved these changes Jan 20, 2025
@jukkar jukkar requested a review from rlubos January 20, 2025 15:41
rlubos
rlubos previously approved these changes Jan 20, 2025
Trust that the protocol type is set correctly by functions
called before this one. We should not set the protocol type
blindly in this generic function.

Signed-off-by: Jukka Rissanen <[email protected]>
The fragmented packet should inherit the protocol type of the
original packet.

Signed-off-by: Jukka Rissanen <[email protected]>
Remove the build assert from NET_L3_REGISTER() macro as that
is causing an issue with llvm. Add runtime check of the handler
pointer value.

subsys/net/l2/ethernet/arp.c:1044:1: error: static_assert expression
is not an integral constant expression

ETH_NET_L3_REGISTER(ARP, NET_ETH_PTYPE_ARP, arp_recv);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/zephyr/net/ethernet.h:1272:2: note: expanded from
macro 'ETH_NET_L3_REGISTER'
        NET_L3_REGISTER(&NET_L2_GET_NAME(ETHERNET), name, ptype, handler)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/zephyr/net/net_core.h:190:2: note: expanded from
macro 'NET_L3_REGISTER'
        BUILD_ASSERT((_handler) != NULL, "Handler is not defined")
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/zephyr/toolchain/gcc.h:87:51: note: expanded from
macro 'BUILD_ASSERT'
define BUILD_ASSERT(EXPR, MSG...) _Static_assert((EXPR), "" MSG)
                                                  ^~~~~~
subsys/net/l2/ethernet/arp.c:1044:1: note: cast from 'void *' is not
allowed in a constant expression
include/zephyr/net/ethernet.h:1272:2: note: expanded from
macro 'ETH_NET_L3_REGISTER'
        NET_L3_REGISTER(&NET_L2_GET_NAME(ETHERNET), name, ptype, handler)
        ^
include/zephyr/net/net_core.h:190:29: note: expanded from
macro 'NET_L3_REGISTER'
        BUILD_ASSERT((_handler) != NULL, "Handler is not defined")
                                   ^
/usr/lib/llvm-14/lib/clang/14.0.0/include/stddef.h:89:16: note: expanded
from macro 'NULL'
  define NULL ((void*)0)

Signed-off-by: Jukka Rissanen <[email protected]>
@jukkar jukkar dismissed stale reviews from rlubos and pdgendt via 9980af2 January 21, 2025 08:59
@jukkar
Copy link
Member Author

jukkar commented Jan 21, 2025

  • Fix CI issues
  • Fix fragmented packet ptype setting (was missing)
  • Removed IPv6 ptype unconditional setting

@jukkar jukkar requested review from rlubos and pdgendt January 21, 2025 09:00
@@ -186,8 +186,7 @@ struct net_l3_register {
.handler = _handler, \
.name = STRINGIFY(_name), \
.l2 = _l2_type, \
}; \
BUILD_ASSERT((_handler) != NULL, "Handler is not defined")
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you intentionally remove this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, there was a compile error with llvm. I replaced it with runtime check.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Kind of surprised this isn't an issue for other instances of BUILD_ASSERT?

@jukkar
Copy link
Member Author

jukkar commented Jan 21, 2025

ping @pdgendt, please take a look if you have time, there should be no more changes to this one.

@@ -186,8 +186,7 @@ struct net_l3_register {
.handler = _handler, \
.name = STRINGIFY(_name), \
.l2 = _l2_type, \
}; \
BUILD_ASSERT((_handler) != NULL, "Handler is not defined")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Kind of surprised this isn't an issue for other instances of BUILD_ASSERT?

@jukkar
Copy link
Member Author

jukkar commented Jan 21, 2025

Kind of surprised this isn't an issue for other instances of BUILD_ASSERT?

Yes, the errors reported by llvm were weird (the output is in the commit msg). Also why this was not reported in the PR that introduced the build assert.

@kartben kartben merged commit ab9b85b into zephyrproject-rtos:main Jan 21, 2025
25 checks passed
@jukkar jukkar deleted the fix/ethenet-ptype branch January 22, 2025 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants