Skip to content

Commit 4c45c3e

Browse files
sasatakuMaureenHelm
authored andcommitted
net: context: Fix the ICMP error on raw
This commit applies the issues detected in UDP to recv_raw() as well. Please refer to the previous commit log for details. Signed-off-by: Takuya Sasaki <[email protected]> (cherry picked from commit 7d1edd1)
1 parent 4c54123 commit 4c45c3e

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

subsys/net/ip/net_context.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,18 +2512,31 @@ static int recv_raw(struct net_context *context,
25122512

25132513
ARG_UNUSED(timeout);
25142514

2515-
context->recv_cb = cb;
2516-
2515+
/* If the context already has a connection handler, it means it's
2516+
* already registered. In that case, all we have to do is 1) update
2517+
* the callback registered in the net_context and 2) update the
2518+
* user_data using net_conn_update().
2519+
*
2520+
* The callback function passed to net_conn_update() must be the same
2521+
* function as the one passed to net_conn_register(), not the callback
2522+
* set for the net context passed by recv_raw().
2523+
*/
25172524
if (context->conn_handler) {
2518-
net_conn_unregister(context->conn_handler);
2519-
context->conn_handler = NULL;
2525+
context->recv_cb = cb;
2526+
ret = net_conn_update(context->conn_handler,
2527+
net_context_raw_packet_received,
2528+
user_data,
2529+
NULL, 0);
2530+
return ret;
25202531
}
25212532

25222533
ret = bind_default(context);
25232534
if (ret) {
25242535
return ret;
25252536
}
25262537

2538+
context->recv_cb = cb;
2539+
25272540
ret = net_conn_register(net_context_get_proto(context),
25282541
net_context_get_family(context),
25292542
NULL, local_addr, 0, 0,

0 commit comments

Comments
 (0)