-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
operational-state (datastore) change notifications #17796
Open
choppsv1
wants to merge
7
commits into
FRRouting:master
Choose a base branch
from
LabNConsulting:chopps/datastore-notifications
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,686
−108
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f059844
lib: northbound: add basic oper-state update functions
choppsv1 2f9f2cf
lib: vrf: track oper-state inline
choppsv1 5bf302c
lib: if: track oper-state inline
choppsv1 3e79c56
lib: notify on datastore (oper-state) changes
choppsv1 f72142b
mgmtd: add notify selectors to filter datastore notifications
choppsv1 02eb937
tests: add datastore notification test
choppsv1 26f0f0a
lib: fix new (incorrect) CLANG SA warnings
choppsv1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* December 1 2024, Christian Hopps <[email protected]> | ||
* | ||
* Copyright (c) 2024, LabN Consulting, L.L.C. | ||
* | ||
*/ | ||
#include <zebra.h> | ||
#include "debug.h" | ||
#include "typesafe.h" | ||
#include "northbound.h" | ||
|
||
#define __dbg(fmt, ...) DEBUGD(&nb_dbg_notif, "NB_OP_CHANGE: %s: " fmt, __func__, ##__VA_ARGS__) | ||
#define __log_err(fmt, ...) zlog_err("NB_OP_CHANGE: %s: ERROR: " fmt, __func__, ##__VA_ARGS__) | ||
|
||
static void nb_notif_add(const char *path) | ||
{ | ||
} | ||
|
||
|
||
static void nb_notif_delete(const char *path) | ||
{ | ||
} | ||
|
||
struct lyd_node *nb_op_update(struct lyd_node *tree, const char *path, const char *value) | ||
{ | ||
struct lyd_node *dnode; | ||
const char *abs_path = NULL; | ||
|
||
|
||
__dbg("updating path: %s with value: %s", path, value); | ||
|
||
dnode = yang_state_new(tree, path, value); | ||
|
||
if (path[0] == '/') | ||
abs_path = path; | ||
else { | ||
abs_path = lyd_path(dnode, LYD_PATH_STD, NULL, 0); | ||
} | ||
|
||
nb_notif_add(abs_path); | ||
|
||
if (abs_path != path) | ||
free((char *)abs_path); | ||
|
||
return dnode; | ||
} | ||
|
||
void nb_op_update_delete(struct lyd_node *tree, const char *path) | ||
{ | ||
char *abs_path = NULL; | ||
|
||
__dbg("deleting path: %s", path); | ||
|
||
if (path && path[0] == '/') | ||
abs_path = (char *)path; | ||
else { | ||
assert(tree); | ||
abs_path = lyd_path(tree, LYD_PATH_STD, NULL, 0); | ||
assert(abs_path); | ||
if (path) { | ||
char *tmp = darr_strdup(abs_path); | ||
free(abs_path); | ||
abs_path = tmp; | ||
if (*darr_last(abs_path) != '/') | ||
darr_in_strcat(abs_path, "/"); | ||
assert(abs_path); /* silence bad CLANG NULL warning */ | ||
darr_in_strcat(abs_path, path); | ||
} | ||
} | ||
|
||
yang_state_delete(tree, path); | ||
|
||
nb_notif_delete(abs_path); | ||
|
||
if (abs_path != path) { | ||
if (path) | ||
darr_free(abs_path); | ||
else | ||
free(abs_path); | ||
} | ||
} | ||
|
||
PRINTFRR(2, 0) | ||
struct lyd_node *nb_op_update_vpathf(struct lyd_node *tree, const char *path_fmt, const char *value, | ||
va_list ap) | ||
{ | ||
struct lyd_node *dnode; | ||
char *path; | ||
|
||
path = darr_vsprintf(path_fmt, ap); | ||
dnode = nb_op_update(tree, path, value); | ||
darr_free(path); | ||
|
||
return dnode; | ||
} | ||
|
||
struct lyd_node *nb_op_update_pathf(struct lyd_node *tree, const char *path_fmt, const char *value, | ||
...) | ||
{ | ||
struct lyd_node *dnode; | ||
va_list ap; | ||
|
||
va_start(ap, value); | ||
dnode = nb_op_update_vpathf(tree, path_fmt, value, ap); | ||
va_end(ap); | ||
|
||
return dnode; | ||
} | ||
|
||
PRINTFRR(2, 0) | ||
void nb_op_update_delete_vpathf(struct lyd_node *tree, const char *path_fmt, va_list ap) | ||
{ | ||
char *path; | ||
|
||
path = darr_vsprintf(path_fmt, ap); | ||
nb_op_update_delete(tree, path); | ||
darr_free(path); | ||
} | ||
|
||
void nb_op_update_delete_pathf(struct lyd_node *tree, const char *path_fmt, ...) | ||
{ | ||
va_list ap; | ||
|
||
va_start(ap, path_fmt); | ||
nb_op_update_delete_vpathf(tree, path_fmt, ap); | ||
va_end(ap); | ||
} | ||
|
||
|
||
PRINTFRR(3, 0) | ||
struct lyd_node *nb_op_vupdatef(struct lyd_node *tree, const char *path, const char *val_fmt, | ||
va_list ap) | ||
{ | ||
struct lyd_node *dnode; | ||
char *value; | ||
|
||
value = darr_vsprintf(val_fmt, ap); | ||
dnode = nb_op_update(tree, path, value); | ||
darr_free(value); | ||
|
||
return dnode; | ||
} | ||
|
||
|
||
struct lyd_node *nb_op_updatef(struct lyd_node *tree, const char *path, const char *val_fmt, ...) | ||
{ | ||
struct lyd_node *dnode; | ||
va_list ap; | ||
|
||
va_start(ap, val_fmt); | ||
dnode = nb_op_vupdatef(tree, path, val_fmt, ap); | ||
va_end(ap); | ||
|
||
return dnode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What is the chance that abs_path and path are equal and path was passed in?
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.
abs_path
starts out assigned asNULL
, it is then either assigned the valuepath
or it is a new allocation fromlyd_path()
.path
is not currently allowed to be NULL (notice we usepath[0]
without checking forpath == NULL
). So path can only ever equalabs_path
when we set it that way (which is what our equality check is deciding, did we set it or newly allocate it).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.
That said, I don't see a reason we couldn't also support a NULL path for updating the path/value of the tree node itself, so I'll modify the code to also handle path == NULL.
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.
actually nm, this gets tricky deeper in the implementation, i'll leave extended functionality for later if we need it.