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

zebra: Prevent possible wedged fpm write #15025

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions zebra/dplane_fpm_nl.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
#define SOUTHBOUND_DEFAULT_ADDR INADDR_LOOPBACK
#define SOUTHBOUND_DEFAULT_PORT 2620

/*
* Time in seconds that if the other end is not responding
* something terrible has gone wrong. Let's fix that.
*/
#define DPLANE_FPM_NL_WEDGIE_TIME 15
Copy link
Contributor

Choose a reason for hiding this comment

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

excellent - has to go down as one of the best token names in all of FRR


/**
* FPM header:
* {
Expand Down Expand Up @@ -93,6 +99,7 @@ struct fpm_nl_ctx {
struct event *t_event;
struct event *t_nhg;
struct event *t_dequeue;
struct event *t_wedged;

/* zebra events. */
struct event *t_lspreset;
Expand Down Expand Up @@ -1367,6 +1374,18 @@ static void fpm_rmac_reset(struct event *t)
&fnc->t_rmacwalk);
}

static void fpm_process_wedged(struct event *t)
{
struct fpm_nl_ctx *fnc = EVENT_ARG(t);

zlog_warn("%s: Connection unable to write to peer for over %u seconds, resetting",
__func__, DPLANE_FPM_NL_WEDGIE_TIME);

atomic_fetch_add_explicit(&fnc->counters.connection_errors, 1,
memory_order_relaxed);
FPM_RECONNECT(fnc);
}

static void fpm_process_queue(struct event *t)
{
struct fpm_nl_ctx *fnc = EVENT_ARG(t);
Expand Down Expand Up @@ -1411,9 +1430,13 @@ static void fpm_process_queue(struct event *t)
processed_contexts, memory_order_relaxed);

/* Re-schedule if we ran out of buffer space */
if (no_bufs)
event_add_timer(fnc->fthread->master, fpm_process_queue, fnc, 0,
if (no_bufs) {
event_add_event(fnc->fthread->master, fpm_process_queue, fnc, 0,
&fnc->t_dequeue);
event_add_timer(fnc->fthread->master, fpm_process_wedged, fnc,
DPLANE_FPM_NL_WEDGIE_TIME, &fnc->t_wedged);
} else
EVENT_OFF(fnc->t_wedged);

/*
* Let the dataplane thread know if there are items in the
Expand Down Expand Up @@ -1617,7 +1640,7 @@ static int fpm_nl_process(struct zebra_dplane_provider *prov)
if (atomic_load_explicit(&fnc->counters.ctxqueue_len,
memory_order_relaxed)
> 0)
event_add_timer(fnc->fthread->master, fpm_process_queue, fnc, 0,
event_add_event(fnc->fthread->master, fpm_process_queue, fnc, 0,
&fnc->t_dequeue);

/* Ensure dataplane thread is rescheduled if we hit the work limit */
Expand Down
Loading