forked from Mirror/frr
lib: split nb_operation into two types
Currently, nb_operation enum means two different things - edit operation type (frontend part), and callback type (backend part). These types overlap, but they are not identical. We need to add more operation types to support NETCONF/RESTCONF integration, so it's better to have separate enums to identify different entities. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
This commit is contained in:
parent
67e8ef293f
commit
5d1a314038
188
lib/northbound.c
188
lib/northbound.c
|
@ -209,12 +209,12 @@ bool nb_node_has_dependency(struct nb_node *node)
|
|||
}
|
||||
|
||||
static int nb_node_validate_cb(const struct nb_node *nb_node,
|
||||
enum nb_operation operation,
|
||||
enum nb_cb_operation operation,
|
||||
int callback_implemented, bool optional)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
valid = nb_operation_is_valid(operation, nb_node->snode);
|
||||
valid = nb_cb_operation_is_valid(operation, nb_node->snode);
|
||||
|
||||
/*
|
||||
* Add an exception for operational data callbacks. A rw list usually
|
||||
|
@ -226,15 +226,15 @@ static int nb_node_validate_cb(const struct nb_node *nb_node,
|
|||
* depends on context (e.g. some daemons might augment "frr-interface"
|
||||
* while others don't).
|
||||
*/
|
||||
if (!valid && callback_implemented && operation != NB_OP_GET_NEXT
|
||||
&& operation != NB_OP_GET_KEYS && operation != NB_OP_LOOKUP_ENTRY)
|
||||
if (!valid && callback_implemented && operation != NB_CB_GET_NEXT
|
||||
&& operation != NB_CB_GET_KEYS && operation != NB_CB_LOOKUP_ENTRY)
|
||||
flog_warn(EC_LIB_NB_CB_UNNEEDED,
|
||||
"unneeded '%s' callback for '%s'",
|
||||
nb_operation_name(operation), nb_node->xpath);
|
||||
nb_cb_operation_name(operation), nb_node->xpath);
|
||||
|
||||
if (!optional && valid && !callback_implemented) {
|
||||
flog_err(EC_LIB_NB_CB_MISSING, "missing '%s' callback for '%s'",
|
||||
nb_operation_name(operation), nb_node->xpath);
|
||||
nb_cb_operation_name(operation), nb_node->xpath);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -253,27 +253,27 @@ static unsigned int nb_node_validate_cbs(const struct nb_node *nb_node)
|
|||
if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS))
|
||||
return error;
|
||||
|
||||
error += nb_node_validate_cb(nb_node, NB_OP_CREATE,
|
||||
error += nb_node_validate_cb(nb_node, NB_CB_CREATE,
|
||||
!!nb_node->cbs.create, false);
|
||||
error += nb_node_validate_cb(nb_node, NB_OP_MODIFY,
|
||||
error += nb_node_validate_cb(nb_node, NB_CB_MODIFY,
|
||||
!!nb_node->cbs.modify, false);
|
||||
error += nb_node_validate_cb(nb_node, NB_OP_DESTROY,
|
||||
error += nb_node_validate_cb(nb_node, NB_CB_DESTROY,
|
||||
!!nb_node->cbs.destroy, false);
|
||||
error += nb_node_validate_cb(nb_node, NB_OP_MOVE, !!nb_node->cbs.move,
|
||||
error += nb_node_validate_cb(nb_node, NB_CB_MOVE, !!nb_node->cbs.move,
|
||||
false);
|
||||
error += nb_node_validate_cb(nb_node, NB_OP_PRE_VALIDATE,
|
||||
error += nb_node_validate_cb(nb_node, NB_CB_PRE_VALIDATE,
|
||||
!!nb_node->cbs.pre_validate, true);
|
||||
error += nb_node_validate_cb(nb_node, NB_OP_APPLY_FINISH,
|
||||
error += nb_node_validate_cb(nb_node, NB_CB_APPLY_FINISH,
|
||||
!!nb_node->cbs.apply_finish, true);
|
||||
error += nb_node_validate_cb(nb_node, NB_OP_GET_ELEM,
|
||||
error += nb_node_validate_cb(nb_node, NB_CB_GET_ELEM,
|
||||
!!nb_node->cbs.get_elem, false);
|
||||
error += nb_node_validate_cb(nb_node, NB_OP_GET_NEXT,
|
||||
error += nb_node_validate_cb(nb_node, NB_CB_GET_NEXT,
|
||||
!!nb_node->cbs.get_next, false);
|
||||
error += nb_node_validate_cb(nb_node, NB_OP_GET_KEYS,
|
||||
error += nb_node_validate_cb(nb_node, NB_CB_GET_KEYS,
|
||||
!!nb_node->cbs.get_keys, false);
|
||||
error += nb_node_validate_cb(nb_node, NB_OP_LOOKUP_ENTRY,
|
||||
error += nb_node_validate_cb(nb_node, NB_CB_LOOKUP_ENTRY,
|
||||
!!nb_node->cbs.lookup_entry, false);
|
||||
error += nb_node_validate_cb(nb_node, NB_OP_RPC, !!nb_node->cbs.rpc,
|
||||
error += nb_node_validate_cb(nb_node, NB_CB_RPC, !!nb_node->cbs.rpc,
|
||||
false);
|
||||
|
||||
return error;
|
||||
|
@ -409,7 +409,7 @@ static inline int nb_config_cb_compare(const struct nb_config_cb *a,
|
|||
RB_GENERATE(nb_config_cbs, nb_config_cb, entry, nb_config_cb_compare);
|
||||
|
||||
static void nb_config_diff_add_change(struct nb_config_cbs *changes,
|
||||
enum nb_operation operation,
|
||||
enum nb_cb_operation operation,
|
||||
uint32_t *seq,
|
||||
const struct lyd_node *dnode)
|
||||
{
|
||||
|
@ -449,7 +449,7 @@ void nb_config_diff_del_changes(struct nb_config_cbs *changes)
|
|||
void nb_config_diff_created(const struct lyd_node *dnode, uint32_t *seq,
|
||||
struct nb_config_cbs *changes)
|
||||
{
|
||||
enum nb_operation operation;
|
||||
enum nb_cb_operation operation;
|
||||
struct lyd_node *child;
|
||||
|
||||
/* Ignore unimplemented nodes. */
|
||||
|
@ -462,10 +462,10 @@ void nb_config_diff_created(const struct lyd_node *dnode, uint32_t *seq,
|
|||
if (lyd_is_default(dnode))
|
||||
break;
|
||||
|
||||
if (nb_operation_is_valid(NB_OP_CREATE, dnode->schema))
|
||||
operation = NB_OP_CREATE;
|
||||
else if (nb_operation_is_valid(NB_OP_MODIFY, dnode->schema))
|
||||
operation = NB_OP_MODIFY;
|
||||
if (nb_cb_operation_is_valid(NB_CB_CREATE, dnode->schema))
|
||||
operation = NB_CB_CREATE;
|
||||
else if (nb_cb_operation_is_valid(NB_CB_MODIFY, dnode->schema))
|
||||
operation = NB_CB_MODIFY;
|
||||
else
|
||||
return;
|
||||
|
||||
|
@ -473,8 +473,8 @@ void nb_config_diff_created(const struct lyd_node *dnode, uint32_t *seq,
|
|||
break;
|
||||
case LYS_CONTAINER:
|
||||
case LYS_LIST:
|
||||
if (nb_operation_is_valid(NB_OP_CREATE, dnode->schema))
|
||||
nb_config_diff_add_change(changes, NB_OP_CREATE, seq,
|
||||
if (nb_cb_operation_is_valid(NB_CB_CREATE, dnode->schema))
|
||||
nb_config_diff_add_change(changes, NB_CB_CREATE, seq,
|
||||
dnode);
|
||||
|
||||
/* Process child nodes recursively. */
|
||||
|
@ -494,8 +494,8 @@ static void nb_config_diff_deleted(const struct lyd_node *dnode, uint32_t *seq,
|
|||
if (!dnode->schema->priv)
|
||||
return;
|
||||
|
||||
if (nb_operation_is_valid(NB_OP_DESTROY, dnode->schema))
|
||||
nb_config_diff_add_change(changes, NB_OP_DESTROY, seq, dnode);
|
||||
if (nb_cb_operation_is_valid(NB_CB_DESTROY, dnode->schema))
|
||||
nb_config_diff_add_change(changes, NB_CB_DESTROY, seq, dnode);
|
||||
else if (CHECK_FLAG(dnode->schema->nodetype, LYS_CONTAINER)) {
|
||||
struct lyd_node *child;
|
||||
|
||||
|
@ -644,7 +644,7 @@ void nb_config_diff(const struct nb_config *config1,
|
|||
/* either moving an entry or changing a value */
|
||||
target = yang_dnode_get(config2->dnode, path);
|
||||
assert(target);
|
||||
nb_config_diff_add_change(changes, NB_OP_MODIFY,
|
||||
nb_config_diff_add_change(changes, NB_CB_MODIFY,
|
||||
&seq, target);
|
||||
break;
|
||||
case 'n': /* none */
|
||||
|
@ -748,27 +748,29 @@ int nb_candidate_edit(struct nb_config *candidate,
|
|||
case NB_OP_MOVE:
|
||||
/* TODO: update configuration. */
|
||||
break;
|
||||
case NB_OP_PRE_VALIDATE:
|
||||
case NB_OP_APPLY_FINISH:
|
||||
case NB_OP_GET_ELEM:
|
||||
case NB_OP_GET_NEXT:
|
||||
case NB_OP_GET_KEYS:
|
||||
case NB_OP_LOOKUP_ENTRY:
|
||||
case NB_OP_RPC:
|
||||
flog_warn(EC_LIB_DEVELOPMENT,
|
||||
"%s: unknown operation (%u) [xpath %s]", __func__,
|
||||
operation, xpath_edit);
|
||||
return NB_ERR;
|
||||
}
|
||||
|
||||
return NB_OK;
|
||||
}
|
||||
|
||||
static bool nb_is_operation_allowed(struct nb_node *nb_node,
|
||||
struct nb_cfg_change *change)
|
||||
const char *nb_operation_name(enum nb_operation operation)
|
||||
{
|
||||
enum nb_operation oper = change->operation;
|
||||
switch (operation) {
|
||||
case NB_OP_CREATE:
|
||||
return "create";
|
||||
case NB_OP_MODIFY:
|
||||
return "modify";
|
||||
case NB_OP_DESTROY:
|
||||
return "destroy";
|
||||
case NB_OP_MOVE:
|
||||
return "move";
|
||||
}
|
||||
|
||||
assert(!"Reached end of function we should never hit");
|
||||
}
|
||||
|
||||
bool nb_is_operation_allowed(struct nb_node *nb_node, enum nb_operation oper)
|
||||
{
|
||||
if (lysc_is_key(nb_node->snode)) {
|
||||
if (oper == NB_OP_MODIFY || oper == NB_OP_DESTROY)
|
||||
return false;
|
||||
|
@ -815,7 +817,7 @@ void nb_candidate_edit_config_changes(
|
|||
continue;
|
||||
}
|
||||
/* Find if the node to be edited is not a key node */
|
||||
if (!nb_is_operation_allowed(nb_node, change)) {
|
||||
if (!nb_is_operation_allowed(nb_node, change->operation)) {
|
||||
zlog_err(" Xpath %s points to key node", xpath);
|
||||
if (error)
|
||||
*error = true;
|
||||
|
@ -1140,7 +1142,7 @@ int nb_running_lock_check(enum nb_client client, const void *user)
|
|||
}
|
||||
|
||||
static void nb_log_config_callback(const enum nb_event event,
|
||||
enum nb_operation operation,
|
||||
enum nb_cb_operation operation,
|
||||
const struct lyd_node *dnode)
|
||||
{
|
||||
const char *value;
|
||||
|
@ -1157,7 +1159,7 @@ static void nb_log_config_callback(const enum nb_event event,
|
|||
|
||||
zlog_debug(
|
||||
"northbound callback: event [%s] op [%s] xpath [%s] value [%s]",
|
||||
nb_event_name(event), nb_operation_name(operation), xpath,
|
||||
nb_event_name(event), nb_cb_operation_name(operation), xpath,
|
||||
value);
|
||||
}
|
||||
|
||||
|
@ -1173,7 +1175,7 @@ static int nb_callback_create(struct nb_context *context,
|
|||
|
||||
assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS));
|
||||
|
||||
nb_log_config_callback(event, NB_OP_CREATE, dnode);
|
||||
nb_log_config_callback(event, NB_CB_CREATE, dnode);
|
||||
|
||||
args.context = context;
|
||||
args.event = event;
|
||||
|
@ -1224,7 +1226,7 @@ static int nb_callback_modify(struct nb_context *context,
|
|||
|
||||
assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS));
|
||||
|
||||
nb_log_config_callback(event, NB_OP_MODIFY, dnode);
|
||||
nb_log_config_callback(event, NB_CB_MODIFY, dnode);
|
||||
|
||||
args.context = context;
|
||||
args.event = event;
|
||||
|
@ -1275,7 +1277,7 @@ static int nb_callback_destroy(struct nb_context *context,
|
|||
|
||||
assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS));
|
||||
|
||||
nb_log_config_callback(event, NB_OP_DESTROY, dnode);
|
||||
nb_log_config_callback(event, NB_CB_DESTROY, dnode);
|
||||
|
||||
args.context = context;
|
||||
args.event = event;
|
||||
|
@ -1320,7 +1322,7 @@ static int nb_callback_move(struct nb_context *context,
|
|||
|
||||
assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS));
|
||||
|
||||
nb_log_config_callback(event, NB_OP_MOVE, dnode);
|
||||
nb_log_config_callback(event, NB_CB_MOVE, dnode);
|
||||
|
||||
args.context = context;
|
||||
args.event = event;
|
||||
|
@ -1366,7 +1368,7 @@ static int nb_callback_pre_validate(struct nb_context *context,
|
|||
if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS))
|
||||
return 0;
|
||||
|
||||
nb_log_config_callback(NB_EV_VALIDATE, NB_OP_PRE_VALIDATE, dnode);
|
||||
nb_log_config_callback(NB_EV_VALIDATE, NB_CB_PRE_VALIDATE, dnode);
|
||||
|
||||
args.dnode = dnode;
|
||||
args.errmsg = errmsg;
|
||||
|
@ -1400,7 +1402,7 @@ static void nb_callback_apply_finish(struct nb_context *context,
|
|||
if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS))
|
||||
return;
|
||||
|
||||
nb_log_config_callback(NB_EV_APPLY, NB_OP_APPLY_FINISH, dnode);
|
||||
nb_log_config_callback(NB_EV_APPLY, NB_CB_APPLY_FINISH, dnode);
|
||||
|
||||
args.context = context;
|
||||
args.dnode = dnode;
|
||||
|
@ -1552,7 +1554,7 @@ static int nb_callback_configuration(struct nb_context *context,
|
|||
struct nb_config_change *change,
|
||||
char *errmsg, size_t errmsg_len)
|
||||
{
|
||||
enum nb_operation operation = change->cb.operation;
|
||||
enum nb_cb_operation operation = change->cb.operation;
|
||||
char xpath[XPATH_MAXLEN];
|
||||
const struct nb_node *nb_node = change->cb.nb_node;
|
||||
const struct lyd_node *dnode = change->cb.dnode;
|
||||
|
@ -1568,29 +1570,29 @@ static int nb_callback_configuration(struct nb_context *context,
|
|||
resource = &change->resource;
|
||||
|
||||
switch (operation) {
|
||||
case NB_OP_CREATE:
|
||||
case NB_CB_CREATE:
|
||||
ret = nb_callback_create(context, nb_node, event, dnode,
|
||||
resource, errmsg, errmsg_len);
|
||||
break;
|
||||
case NB_OP_MODIFY:
|
||||
case NB_CB_MODIFY:
|
||||
ret = nb_callback_modify(context, nb_node, event, dnode,
|
||||
resource, errmsg, errmsg_len);
|
||||
break;
|
||||
case NB_OP_DESTROY:
|
||||
case NB_CB_DESTROY:
|
||||
ret = nb_callback_destroy(context, nb_node, event, dnode,
|
||||
errmsg, errmsg_len);
|
||||
break;
|
||||
case NB_OP_MOVE:
|
||||
case NB_CB_MOVE:
|
||||
ret = nb_callback_move(context, nb_node, event, dnode, errmsg,
|
||||
errmsg_len);
|
||||
break;
|
||||
case NB_OP_PRE_VALIDATE:
|
||||
case NB_OP_APPLY_FINISH:
|
||||
case NB_OP_GET_ELEM:
|
||||
case NB_OP_GET_NEXT:
|
||||
case NB_OP_GET_KEYS:
|
||||
case NB_OP_LOOKUP_ENTRY:
|
||||
case NB_OP_RPC:
|
||||
case NB_CB_PRE_VALIDATE:
|
||||
case NB_CB_APPLY_FINISH:
|
||||
case NB_CB_GET_ELEM:
|
||||
case NB_CB_GET_NEXT:
|
||||
case NB_CB_GET_KEYS:
|
||||
case NB_CB_LOOKUP_ENTRY:
|
||||
case NB_CB_RPC:
|
||||
yang_dnode_get_path(dnode, xpath, sizeof(xpath));
|
||||
flog_err(EC_LIB_DEVELOPMENT,
|
||||
"%s: unknown operation (%u) [xpath %s]", __func__,
|
||||
|
@ -1606,28 +1608,28 @@ static int nb_callback_configuration(struct nb_context *context,
|
|||
flog_warn(EC_LIB_NB_CB_CONFIG_VALIDATE,
|
||||
"error processing configuration change: error [%s] event [%s] operation [%s] xpath [%s]%s%s",
|
||||
nb_err_name(ret), nb_event_name(event),
|
||||
nb_operation_name(operation), xpath,
|
||||
nb_cb_operation_name(operation), xpath,
|
||||
errmsg[0] ? " message: " : "", errmsg);
|
||||
break;
|
||||
case NB_EV_PREPARE:
|
||||
flog_warn(EC_LIB_NB_CB_CONFIG_PREPARE,
|
||||
"error processing configuration change: error [%s] event [%s] operation [%s] xpath [%s]%s%s",
|
||||
nb_err_name(ret), nb_event_name(event),
|
||||
nb_operation_name(operation), xpath,
|
||||
nb_cb_operation_name(operation), xpath,
|
||||
errmsg[0] ? " message: " : "", errmsg);
|
||||
break;
|
||||
case NB_EV_ABORT:
|
||||
flog_warn(EC_LIB_NB_CB_CONFIG_ABORT,
|
||||
"error processing configuration change: error [%s] event [%s] operation [%s] xpath [%s]%s%s",
|
||||
nb_err_name(ret), nb_event_name(event),
|
||||
nb_operation_name(operation), xpath,
|
||||
nb_cb_operation_name(operation), xpath,
|
||||
errmsg[0] ? " message: " : "", errmsg);
|
||||
break;
|
||||
case NB_EV_APPLY:
|
||||
flog_err(EC_LIB_NB_CB_CONFIG_APPLY,
|
||||
"error processing configuration change: error [%s] event [%s] operation [%s] xpath [%s]%s%s",
|
||||
nb_err_name(ret), nb_event_name(event),
|
||||
nb_operation_name(operation), xpath,
|
||||
nb_cb_operation_name(operation), xpath,
|
||||
errmsg[0] ? " message: " : "", errmsg);
|
||||
break;
|
||||
default:
|
||||
|
@ -1775,7 +1777,7 @@ static void nb_transaction_apply_finish(struct nb_transaction *transaction,
|
|||
* (the 'apply_finish' callbacks from the node ancestors should
|
||||
* be called though).
|
||||
*/
|
||||
if (change->cb.operation == NB_OP_DESTROY) {
|
||||
if (change->cb.operation == NB_CB_DESTROY) {
|
||||
char xpath[XPATH_MAXLEN];
|
||||
|
||||
dnode = lyd_parent(dnode);
|
||||
|
@ -1826,15 +1828,15 @@ static void nb_transaction_apply_finish(struct nb_transaction *transaction,
|
|||
}
|
||||
}
|
||||
|
||||
bool nb_operation_is_valid(enum nb_operation operation,
|
||||
const struct lysc_node *snode)
|
||||
bool nb_cb_operation_is_valid(enum nb_cb_operation operation,
|
||||
const struct lysc_node *snode)
|
||||
{
|
||||
struct nb_node *nb_node = snode->priv;
|
||||
struct lysc_node_container *scontainer;
|
||||
struct lysc_node_leaf *sleaf;
|
||||
|
||||
switch (operation) {
|
||||
case NB_OP_CREATE:
|
||||
case NB_CB_CREATE:
|
||||
if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W))
|
||||
return false;
|
||||
|
||||
|
@ -1856,7 +1858,7 @@ bool nb_operation_is_valid(enum nb_operation operation,
|
|||
return false;
|
||||
}
|
||||
return true;
|
||||
case NB_OP_MODIFY:
|
||||
case NB_CB_MODIFY:
|
||||
if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W))
|
||||
return false;
|
||||
|
||||
|
@ -1874,7 +1876,7 @@ bool nb_operation_is_valid(enum nb_operation operation,
|
|||
return false;
|
||||
}
|
||||
return true;
|
||||
case NB_OP_DESTROY:
|
||||
case NB_CB_DESTROY:
|
||||
if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W))
|
||||
return false;
|
||||
|
||||
|
@ -1910,7 +1912,7 @@ bool nb_operation_is_valid(enum nb_operation operation,
|
|||
return false;
|
||||
}
|
||||
return true;
|
||||
case NB_OP_MOVE:
|
||||
case NB_CB_MOVE:
|
||||
if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W))
|
||||
return false;
|
||||
|
||||
|
@ -1924,12 +1926,12 @@ bool nb_operation_is_valid(enum nb_operation operation,
|
|||
return false;
|
||||
}
|
||||
return true;
|
||||
case NB_OP_PRE_VALIDATE:
|
||||
case NB_OP_APPLY_FINISH:
|
||||
case NB_CB_PRE_VALIDATE:
|
||||
case NB_CB_APPLY_FINISH:
|
||||
if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W))
|
||||
return false;
|
||||
return true;
|
||||
case NB_OP_GET_ELEM:
|
||||
case NB_CB_GET_ELEM:
|
||||
if (!CHECK_FLAG(snode->flags, LYS_CONFIG_R))
|
||||
return false;
|
||||
|
||||
|
@ -1946,7 +1948,7 @@ bool nb_operation_is_valid(enum nb_operation operation,
|
|||
return false;
|
||||
}
|
||||
return true;
|
||||
case NB_OP_GET_NEXT:
|
||||
case NB_CB_GET_NEXT:
|
||||
switch (snode->nodetype) {
|
||||
case LYS_LIST:
|
||||
if (CHECK_FLAG(nb_node->flags, F_NB_NODE_CONFIG_ONLY))
|
||||
|
@ -1960,8 +1962,8 @@ bool nb_operation_is_valid(enum nb_operation operation,
|
|||
return false;
|
||||
}
|
||||
return true;
|
||||
case NB_OP_GET_KEYS:
|
||||
case NB_OP_LOOKUP_ENTRY:
|
||||
case NB_CB_GET_KEYS:
|
||||
case NB_CB_LOOKUP_ENTRY:
|
||||
switch (snode->nodetype) {
|
||||
case LYS_LIST:
|
||||
if (CHECK_FLAG(nb_node->flags, F_NB_NODE_CONFIG_ONLY))
|
||||
|
@ -1973,7 +1975,7 @@ bool nb_operation_is_valid(enum nb_operation operation,
|
|||
return false;
|
||||
}
|
||||
return true;
|
||||
case NB_OP_RPC:
|
||||
case NB_CB_RPC:
|
||||
if (CHECK_FLAG(snode->flags, LYS_CONFIG_W | LYS_CONFIG_R))
|
||||
return false;
|
||||
|
||||
|
@ -2175,30 +2177,30 @@ const char *nb_event_name(enum nb_event event)
|
|||
assert(!"Reached end of function we should never hit");
|
||||
}
|
||||
|
||||
const char *nb_operation_name(enum nb_operation operation)
|
||||
const char *nb_cb_operation_name(enum nb_cb_operation operation)
|
||||
{
|
||||
switch (operation) {
|
||||
case NB_OP_CREATE:
|
||||
case NB_CB_CREATE:
|
||||
return "create";
|
||||
case NB_OP_MODIFY:
|
||||
case NB_CB_MODIFY:
|
||||
return "modify";
|
||||
case NB_OP_DESTROY:
|
||||
case NB_CB_DESTROY:
|
||||
return "destroy";
|
||||
case NB_OP_MOVE:
|
||||
case NB_CB_MOVE:
|
||||
return "move";
|
||||
case NB_OP_PRE_VALIDATE:
|
||||
case NB_CB_PRE_VALIDATE:
|
||||
return "pre_validate";
|
||||
case NB_OP_APPLY_FINISH:
|
||||
case NB_CB_APPLY_FINISH:
|
||||
return "apply_finish";
|
||||
case NB_OP_GET_ELEM:
|
||||
case NB_CB_GET_ELEM:
|
||||
return "get_elem";
|
||||
case NB_OP_GET_NEXT:
|
||||
case NB_CB_GET_NEXT:
|
||||
return "get_next";
|
||||
case NB_OP_GET_KEYS:
|
||||
case NB_CB_GET_KEYS:
|
||||
return "get_keys";
|
||||
case NB_OP_LOOKUP_ENTRY:
|
||||
case NB_CB_LOOKUP_ENTRY:
|
||||
return "lookup_entry";
|
||||
case NB_OP_RPC:
|
||||
case NB_CB_RPC:
|
||||
return "rpc";
|
||||
}
|
||||
|
||||
|
|
|
@ -83,28 +83,22 @@ enum nb_event {
|
|||
};
|
||||
|
||||
/*
|
||||
* Northbound operations.
|
||||
* Northbound callback operations.
|
||||
*
|
||||
* Refer to the documentation comments of nb_callbacks for more details.
|
||||
*/
|
||||
enum nb_operation {
|
||||
NB_OP_CREATE,
|
||||
NB_OP_MODIFY,
|
||||
NB_OP_DESTROY,
|
||||
NB_OP_MOVE,
|
||||
NB_OP_PRE_VALIDATE,
|
||||
NB_OP_APPLY_FINISH,
|
||||
NB_OP_GET_ELEM,
|
||||
NB_OP_GET_NEXT,
|
||||
NB_OP_GET_KEYS,
|
||||
NB_OP_LOOKUP_ENTRY,
|
||||
NB_OP_RPC,
|
||||
};
|
||||
|
||||
struct nb_cfg_change {
|
||||
char xpath[XPATH_MAXLEN];
|
||||
enum nb_operation operation;
|
||||
const char *value;
|
||||
enum nb_cb_operation {
|
||||
NB_CB_CREATE,
|
||||
NB_CB_MODIFY,
|
||||
NB_CB_DESTROY,
|
||||
NB_CB_MOVE,
|
||||
NB_CB_PRE_VALIDATE,
|
||||
NB_CB_APPLY_FINISH,
|
||||
NB_CB_GET_ELEM,
|
||||
NB_CB_GET_NEXT,
|
||||
NB_CB_GET_KEYS,
|
||||
NB_CB_LOOKUP_ENTRY,
|
||||
NB_CB_RPC,
|
||||
};
|
||||
|
||||
union nb_resource {
|
||||
|
@ -693,7 +687,7 @@ struct nb_context {
|
|||
/* Northbound configuration callback. */
|
||||
struct nb_config_cb {
|
||||
RB_ENTRY(nb_config_cb) entry;
|
||||
enum nb_operation operation;
|
||||
enum nb_cb_operation operation;
|
||||
uint32_t seq;
|
||||
const struct nb_node *nb_node;
|
||||
const struct lyd_node *dnode;
|
||||
|
@ -722,6 +716,20 @@ struct nb_config {
|
|||
uint32_t version;
|
||||
};
|
||||
|
||||
/* Northbound operations */
|
||||
enum nb_operation {
|
||||
NB_OP_CREATE,
|
||||
NB_OP_MODIFY,
|
||||
NB_OP_DESTROY,
|
||||
NB_OP_MOVE,
|
||||
};
|
||||
|
||||
struct nb_cfg_change {
|
||||
char xpath[XPATH_MAXLEN];
|
||||
enum nb_operation operation;
|
||||
const char *value;
|
||||
};
|
||||
|
||||
/* Callback function used by nb_oper_data_iterate(). */
|
||||
typedef int (*nb_oper_data_cb)(const struct lysc_node *snode,
|
||||
struct yang_translator *translator,
|
||||
|
@ -894,6 +902,32 @@ extern void nb_config_replace(struct nb_config *config_dst,
|
|||
struct nb_config *config_src,
|
||||
bool preserve_source);
|
||||
|
||||
/*
|
||||
* Return a human-readable string representing a northbound operation.
|
||||
*
|
||||
* operation
|
||||
* Northbound operation.
|
||||
*
|
||||
* Returns:
|
||||
* String representation of the given northbound operation.
|
||||
*/
|
||||
extern const char *nb_operation_name(enum nb_operation operation);
|
||||
|
||||
/*
|
||||
* Validate if the northbound operation is allowed for the given node.
|
||||
*
|
||||
* nb_node
|
||||
* Northbound node.
|
||||
*
|
||||
* operation
|
||||
* Operation we want to check.
|
||||
*
|
||||
* Returns:
|
||||
* true if the operation is allowed, false otherwise.
|
||||
*/
|
||||
extern bool nb_is_operation_allowed(struct nb_node *nb_node,
|
||||
enum nb_operation oper);
|
||||
|
||||
/*
|
||||
* Edit a candidate configuration.
|
||||
*
|
||||
|
@ -1368,7 +1402,7 @@ extern void nb_oper_cancel_walk(void *walk);
|
|||
extern void nb_oper_cancel_all_walks(void);
|
||||
|
||||
/*
|
||||
* Validate if the northbound operation is valid for the given node.
|
||||
* Validate if the northbound callback operation is valid for the given node.
|
||||
*
|
||||
* operation
|
||||
* Operation we want to check.
|
||||
|
@ -1379,8 +1413,8 @@ extern void nb_oper_cancel_all_walks(void);
|
|||
* Returns:
|
||||
* true if the operation is valid, false otherwise.
|
||||
*/
|
||||
extern bool nb_operation_is_valid(enum nb_operation operation,
|
||||
const struct lysc_node *snode);
|
||||
extern bool nb_cb_operation_is_valid(enum nb_cb_operation operation,
|
||||
const struct lysc_node *snode);
|
||||
|
||||
/*
|
||||
* Send a YANG notification. This is a no-op unless the 'nb_notification_send'
|
||||
|
@ -1504,15 +1538,15 @@ extern void *nb_running_get_entry_non_rec(const struct lyd_node *dnode,
|
|||
extern const char *nb_event_name(enum nb_event event);
|
||||
|
||||
/*
|
||||
* Return a human-readable string representing a northbound operation.
|
||||
* Return a human-readable string representing a northbound callback operation.
|
||||
*
|
||||
* operation
|
||||
* Northbound operation.
|
||||
* Northbound callback operation.
|
||||
*
|
||||
* Returns:
|
||||
* String representation of the given northbound operation.
|
||||
* String representation of the given northbound callback operation.
|
||||
*/
|
||||
extern const char *nb_operation_name(enum nb_operation operation);
|
||||
extern const char *nb_cb_operation_name(enum nb_cb_operation operation);
|
||||
|
||||
/*
|
||||
* Return a human-readable string representing a northbound error.
|
||||
|
|
|
@ -221,7 +221,7 @@ frr_confd_cdb_diff_iter(confd_hkeypath_t *kp, enum cdb_iter_op cdb_op,
|
|||
nb_op = NB_OP_DESTROY;
|
||||
break;
|
||||
case MOP_VALUE_SET:
|
||||
if (nb_operation_is_valid(NB_OP_MODIFY, nb_node->snode))
|
||||
if (nb_is_operation_allowed(nb_node, NB_OP_MODIFY))
|
||||
nb_op = NB_OP_MODIFY;
|
||||
else
|
||||
/* Ignore list keys modifications. */
|
||||
|
|
|
@ -186,12 +186,12 @@ static int frr_sr_process_change(struct nb_config *candidate,
|
|||
/* Map operation values. */
|
||||
switch (sr_op) {
|
||||
case SR_OP_CREATED:
|
||||
nb_op = NB_OP_CREATE;
|
||||
break;
|
||||
case SR_OP_MODIFIED:
|
||||
if (nb_operation_is_valid(NB_OP_CREATE, nb_node->snode))
|
||||
nb_op = NB_OP_CREATE;
|
||||
else if (nb_operation_is_valid(NB_OP_MODIFY, nb_node->snode)) {
|
||||
if (nb_is_operation_allowed(nb_node, NB_OP_MODIFY))
|
||||
nb_op = NB_OP_MODIFY;
|
||||
} else
|
||||
else
|
||||
/* Ignore list keys modifications. */
|
||||
return NB_OK;
|
||||
break;
|
||||
|
@ -201,7 +201,7 @@ static int frr_sr_process_change(struct nb_config *candidate,
|
|||
* notified about the removal of all of its leafs, even the ones
|
||||
* that are non-optional. We need to ignore these notifications.
|
||||
*/
|
||||
if (!nb_operation_is_valid(NB_OP_DESTROY, nb_node->snode))
|
||||
if (!nb_is_operation_allowed(nb_node, NB_OP_DESTROY))
|
||||
return NB_OK;
|
||||
|
||||
nb_op = NB_OP_DESTROY;
|
||||
|
|
|
@ -4004,16 +4004,9 @@ int vty_mgmt_send_config_data(struct vty *vty, const char *xpath_base,
|
|||
case NB_OP_CREATE:
|
||||
case NB_OP_MODIFY:
|
||||
case NB_OP_MOVE:
|
||||
case NB_OP_PRE_VALIDATE:
|
||||
case NB_OP_APPLY_FINISH:
|
||||
cfg_req[indx].req_type =
|
||||
MGMTD__CFG_DATA_REQ_TYPE__SET_DATA;
|
||||
break;
|
||||
case NB_OP_GET_ELEM:
|
||||
case NB_OP_GET_NEXT:
|
||||
case NB_OP_GET_KEYS:
|
||||
case NB_OP_LOOKUP_ENTRY:
|
||||
case NB_OP_RPC:
|
||||
default:
|
||||
assertf(false,
|
||||
"Invalid operation type for send config: %d",
|
||||
|
|
|
@ -911,7 +911,7 @@ static int mgmt_txn_create_config_batches(struct mgmt_txn_req *txn_req,
|
|||
batch->cfg_datap[batch->num_cfg_data] =
|
||||
&batch->cfg_data[batch->num_cfg_data];
|
||||
|
||||
if (chg->cb.operation == NB_OP_DESTROY)
|
||||
if (chg->cb.operation == NB_CB_DESTROY)
|
||||
batch->cfg_data[batch->num_cfg_data].req_type =
|
||||
MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA;
|
||||
else
|
||||
|
|
|
@ -31,62 +31,62 @@ static struct nb_callback_info {
|
|||
char arguments[128];
|
||||
} nb_callbacks[] = {
|
||||
{
|
||||
.operation = NB_OP_CREATE,
|
||||
.operation = NB_CB_CREATE,
|
||||
.return_type = "int ",
|
||||
.return_value = "NB_OK",
|
||||
.arguments = "struct nb_cb_create_args *args",
|
||||
},
|
||||
{
|
||||
.operation = NB_OP_MODIFY,
|
||||
.operation = NB_CB_MODIFY,
|
||||
.return_type = "int ",
|
||||
.return_value = "NB_OK",
|
||||
.arguments = "struct nb_cb_modify_args *args",
|
||||
},
|
||||
{
|
||||
.operation = NB_OP_DESTROY,
|
||||
.operation = NB_CB_DESTROY,
|
||||
.return_type = "int ",
|
||||
.return_value = "NB_OK",
|
||||
.arguments = "struct nb_cb_destroy_args *args",
|
||||
},
|
||||
{
|
||||
.operation = NB_OP_MOVE,
|
||||
.operation = NB_CB_MOVE,
|
||||
.return_type = "int ",
|
||||
.return_value = "NB_OK",
|
||||
.arguments = "struct nb_cb_move_args *args",
|
||||
},
|
||||
{
|
||||
.operation = NB_OP_APPLY_FINISH,
|
||||
.operation = NB_CB_APPLY_FINISH,
|
||||
.optional = true,
|
||||
.return_type = "void ",
|
||||
.return_value = "",
|
||||
.arguments = "struct nb_cb_apply_finish_args *args",
|
||||
},
|
||||
{
|
||||
.operation = NB_OP_GET_ELEM,
|
||||
.operation = NB_CB_GET_ELEM,
|
||||
.return_type = "struct yang_data *",
|
||||
.return_value = "NULL",
|
||||
.arguments = "struct nb_cb_get_elem_args *args",
|
||||
},
|
||||
{
|
||||
.operation = NB_OP_GET_NEXT,
|
||||
.operation = NB_CB_GET_NEXT,
|
||||
.return_type = "const void *",
|
||||
.return_value = "NULL",
|
||||
.arguments = "struct nb_cb_get_next_args *args",
|
||||
},
|
||||
{
|
||||
.operation = NB_OP_GET_KEYS,
|
||||
.operation = NB_CB_GET_KEYS,
|
||||
.return_type = "int ",
|
||||
.return_value = "NB_OK",
|
||||
.arguments = "struct nb_cb_get_keys_args *args",
|
||||
},
|
||||
{
|
||||
.operation = NB_OP_LOOKUP_ENTRY,
|
||||
.operation = NB_CB_LOOKUP_ENTRY,
|
||||
.return_type = "const void *",
|
||||
.return_value = "NULL",
|
||||
.arguments = "struct nb_cb_lookup_entry_args *args",
|
||||
},
|
||||
{
|
||||
.operation = NB_OP_RPC,
|
||||
.operation = NB_CB_RPC,
|
||||
.return_type = "int ",
|
||||
.return_value = "NB_OK",
|
||||
.arguments = "struct nb_cb_rpc_args *args",
|
||||
|
@ -107,7 +107,7 @@ static void replace_hyphens_by_underscores(char *str)
|
|||
}
|
||||
|
||||
static void generate_callback_name(const struct lysc_node *snode,
|
||||
enum nb_operation operation, char *buffer,
|
||||
enum nb_cb_operation operation, char *buffer,
|
||||
size_t size)
|
||||
{
|
||||
struct list *snodes;
|
||||
|
@ -129,7 +129,7 @@ static void generate_callback_name(const struct lysc_node *snode,
|
|||
strlcat(buffer, snode->name, size);
|
||||
strlcat(buffer, "_", size);
|
||||
}
|
||||
strlcat(buffer, nb_operation_name(operation), size);
|
||||
strlcat(buffer, nb_cb_operation_name(operation), size);
|
||||
list_delete(&snodes);
|
||||
|
||||
replace_hyphens_by_underscores(buffer);
|
||||
|
@ -160,7 +160,7 @@ static int generate_prototypes(const struct lysc_node *snode, void *arg)
|
|||
char cb_name[BUFSIZ];
|
||||
|
||||
if (cb->optional
|
||||
|| !nb_operation_is_valid(cb->operation, snode))
|
||||
|| !nb_cb_operation_is_valid(cb->operation, snode))
|
||||
continue;
|
||||
|
||||
generate_callback_name(snode, cb->operation, cb_name,
|
||||
|
@ -178,10 +178,10 @@ static void generate_callback(const struct nb_callback_info *ncinfo,
|
|||
ncinfo->return_type, cb_name, ncinfo->arguments);
|
||||
|
||||
switch (ncinfo->operation) {
|
||||
case NB_OP_CREATE:
|
||||
case NB_OP_MODIFY:
|
||||
case NB_OP_DESTROY:
|
||||
case NB_OP_MOVE:
|
||||
case NB_CB_CREATE:
|
||||
case NB_CB_MODIFY:
|
||||
case NB_CB_DESTROY:
|
||||
case NB_CB_MOVE:
|
||||
printf("\tswitch (args->event) {\n"
|
||||
"\tcase NB_EV_VALIDATE:\n"
|
||||
"\tcase NB_EV_PREPARE:\n"
|
||||
|
@ -222,7 +222,7 @@ static int generate_callbacks(const struct lysc_node *snode, void *arg)
|
|||
char cb_name[BUFSIZ];
|
||||
|
||||
if (cb->optional
|
||||
|| !nb_operation_is_valid(cb->operation, snode))
|
||||
|| !nb_cb_operation_is_valid(cb->operation, snode))
|
||||
continue;
|
||||
|
||||
if (first) {
|
||||
|
@ -267,7 +267,7 @@ static int generate_nb_nodes(const struct lysc_node *snode, void *arg)
|
|||
char cb_name[BUFSIZ];
|
||||
|
||||
if (cb->optional
|
||||
|| !nb_operation_is_valid(cb->operation, snode))
|
||||
|| !nb_cb_operation_is_valid(cb->operation, snode))
|
||||
continue;
|
||||
|
||||
if (first) {
|
||||
|
@ -285,7 +285,8 @@ static int generate_nb_nodes(const struct lysc_node *snode, void *arg)
|
|||
|
||||
generate_callback_name(snode, cb->operation, cb_name,
|
||||
sizeof(cb_name));
|
||||
printf("\t\t\t\t.%s = %s,\n", nb_operation_name(cb->operation),
|
||||
printf("\t\t\t\t.%s = %s,\n",
|
||||
nb_cb_operation_name(cb->operation),
|
||||
cb_name);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue