-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Conversation
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]>
cbb4209
to
86048ad
Compare
|
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]>
|
@@ -186,8 +186,7 @@ struct net_l3_register { | |||
.handler = _handler, \ | |||
.name = STRINGIFY(_name), \ | |||
.l2 = _l2_type, \ | |||
}; \ | |||
BUILD_ASSERT((_handler) != NULL, "Handler is not defined") |
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.
Did you intentionally remove this?
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.
Yes, there was a compile error with llvm. I replaced it with runtime check.
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.
Kind of surprised this isn't an issue for other instances of BUILD_ASSERT
?
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") |
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.
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. |
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.