Skip to content

net: Add timeout to various send functions #86127

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

Merged
merged 5 commits into from
Mar 7, 2025

Conversation

clamattia
Copy link
Collaborator

@clamattia clamattia commented Feb 21, 2025

Add timeout to various send function. To keep stable API, functions are renamed with _try-prefix. Original functions just call the _try-variant with timeout K_FOREVER.

Fixes: #85981

Timeout can be used to early drop some request for arp and icmp to avoid being slowed when in a flood situation.

Looking forward to your thoughts.

Copy link
Collaborator

@rlubos rlubos left a comment

Choose a reason for hiding this comment

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

I think we could go this way if we retain stable APIs compability.

@clamattia clamattia changed the title net: RFC: Add timeout to various send functions net: Add timeout to various send functions Feb 21, 2025
@clamattia
Copy link
Collaborator Author

  • Created separate commits for introducing timeout and using it

  • made original functions static inline as suggested by @pdgendt

  • For now I added timeout for net_context, arp, icmp, lldp

@@ -2609,7 +2609,7 @@ static int context_sendto(struct net_context *context,
net_pkt_set_ll_proto_type(pkt,
ntohs(ll_dst_addr->sll_protocol));

net_if_queue_tx(net_pkt_iface(pkt), pkt);
net_if_try_queue_tx(net_pkt_iface(pkt), pkt, timeout);
Copy link
Collaborator

Choose a reason for hiding this comment

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

context_sendto() has actually more places where data is passed to the lower layer (net_send_data() calls above and below).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, will take a look.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added

@clamattia
Copy link
Collaborator Author

Added timeouts to more send functions in context_sendto.

@clamattia
Copy link
Collaborator Author

Fix compliance issues.

@clamattia
Copy link
Collaborator Author

  • Fix silly mistake
  • Document timeout parameter

@clamattia
Copy link
Collaborator Author

Rebased

@clamattia
Copy link
Collaborator Author

Reorder declarations in header files, so they are known for static inline functions.

pdgendt
pdgendt previously approved these changes Feb 26, 2025
Copy link
Collaborator

@pdgendt pdgendt left a comment

Choose a reason for hiding this comment

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

This looks like a good addition to me.

@clamattia
Copy link
Collaborator Author

clamattia commented Feb 26, 2025

  • Fix some CI by using correct k_timeout_t type
  • Remove no longer needed timeout to K_NO_WAIT in ISR context, because arp and icmp set to K_NO_WAIT in calling context. @rlubos do you agree?

@rlubos
Copy link
Collaborator

rlubos commented Feb 26, 2025

Remove no longer needed timeout to K_NO_WAIT in ISR context, because arp and icmp set to K_NO_WAIT in calling context. @rlubos do you agree?

I'd personally keep it just in case. Just realized, IPv6 ND has probably a similar scenario not handled here (NA reply for NS, in ipv6_nbr.c), maybe there are more cases.

@clamattia
Copy link
Collaborator Author

Remove no longer needed timeout to K_NO_WAIT in ISR context, because arp and icmp set to K_NO_WAIT in calling context. @rlubos do you agree?

I'd personally keep it just in case. Just realized, IPv6 ND has probably a similar scenario not handled here (NA reply for NS, in ipv6_nbr.c), maybe there are more cases.

Will add it to the variatn without try.
Makes sense. I just implemented for the ones I was familiar with.

@clamattia
Copy link
Collaborator Author

  • Tried to fix more ci-/compliance-problems
  • Added @rlubos ISR fix back

@clamattia
Copy link
Collaborator Author

More compliance/ci fixes

@clamattia
Copy link
Collaborator Author

Rebased

@clamattia
Copy link
Collaborator Author

Fixed silly mistake.

@clamattia
Copy link
Collaborator Author

ci failure likely unrelated. Will try rebasing soon (hopefully fixed in main?).

Allows to send with different timeouts to not block caller in some
situations. Stable API is kept and just calls `try`-variant with a timeout
of `K_FOREVER`.

Signed-off-by: Cla Mattia Galliard <[email protected]>
Use the newly added timeout in various send functions from within
net_context_sendto.

Signed-off-by: Cla Mattia Galliard <[email protected]>
This ensures system stays operational in arp-flood situation.

Signed-off-by: Cla Mattia Galliard <[email protected]>
This ensures system stays operation in lldp-flood situation.

Signed-off-by: Cla Mattia Galliard <[email protected]>
This ensure system stays operational in icmp flood situation.

Signed-off-by: Cla Mattia Galliard <[email protected]>
@clamattia
Copy link
Collaborator Author

Rebased

@clamattia clamattia requested review from rlubos and pdgendt February 28, 2025 12:59
@jukkar jukkar added this to the v4.2.0 milestone Feb 28, 2025
@clamattia
Copy link
Collaborator Author

Is there anything left to do from my side or is this waiting for the feature defrost :) ?

@rlubos
Copy link
Collaborator

rlubos commented Mar 6, 2025

Is there anything left to do from my side or is this waiting for the feature defrost :) ?

AFAICT it's just waiting for the merge window to open.

@carlescufi carlescufi merged commit 7d721ce into zephyrproject-rtos:main Mar 7, 2025
23 checks passed
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.

net: arp/icmp: throttle amount of request handled
6 participants