Skip to content

Commit

Permalink
net: icmp: Send replies with timeout K_NO_WAIT
Browse files Browse the repository at this point in the history
This ensure system stays operational in icmp flood situation.

Signed-off-by: Cla Mattia Galliard <[email protected]>
  • Loading branch information
clamattia committed Feb 21, 2025
1 parent 38d6094 commit d7b8255
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions subsys/net/ip/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ static int send_icmpv4_echo_request(struct net_icmp_ctx *ctx,
ctx->user_data = user_data;
ctx->iface = iface;

if (net_send_data(pkt) >= 0) {
if (net_try_send_data(pkt, K_NO_WAIT) >= 0) {
net_stats_update_icmp_sent(iface);
return 0;
}
Expand Down Expand Up @@ -330,7 +330,7 @@ static int send_icmpv6_echo_request(struct net_icmp_ctx *ctx,
ctx->user_data = user_data;
ctx->iface = iface;

if (net_send_data(pkt) >= 0) {
if (net_try_send_data(pkt, K_NO_WAIT) >= 0) {
net_stats_update_icmp_sent(iface);
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions subsys/net/ip/icmpv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ static int icmpv4_handle_echo_request(struct net_icmp_ctx *ctx,
net_sprint_ipv4_addr(src),
net_sprint_ipv4_addr(&ip_hdr->src));

if (net_send_data(reply) < 0) {
if (net_try_send_data(reply, K_NO_WAIT) < 0) {
goto drop;
}

Expand Down Expand Up @@ -588,7 +588,7 @@ int net_icmpv4_send_error(struct net_pkt *orig, uint8_t type, uint8_t code)
net_sprint_ipv4_addr(&ip_hdr->dst),
net_sprint_ipv4_addr(&ip_hdr->src));

if (net_send_data(pkt) >= 0) {
if (net_try_send_data(pkt, K_NO_WAIT) >= 0) {
net_stats_update_icmp_sent(net_pkt_iface(orig));
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions subsys/net/ip/icmpv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static int icmpv6_handle_echo_request(struct net_icmp_ctx *ctx,
net_sprint_ipv6_addr(src),
net_sprint_ipv6_addr(&ip_hdr->src));

if (net_send_data(reply) < 0) {
if (net_try_send_data(reply, K_NO_WAIT) < 0) {
goto drop;
}

Expand Down Expand Up @@ -319,7 +319,7 @@ int net_icmpv6_send_error(struct net_pkt *orig, uint8_t type, uint8_t code,
net_sprint_ipv6_addr(src),
net_sprint_ipv6_addr(&ip_hdr->src));

if (net_send_data(pkt) >= 0) {
if (net_try_send_data(pkt, K_NO_WAIT) >= 0) {
net_stats_update_icmp_sent(net_pkt_iface(pkt));
return 0;
}
Expand Down

0 comments on commit d7b8255

Please sign in to comment.