summaryrefslogtreecommitdiff
path: root/lib/filter_nb.c
diff options
context:
space:
mode:
authorChirag Shah <chirag@nvidia.com>2021-02-03 09:51:40 -0800
committerChirag Shah <chirag@nvidia.com>2021-03-01 16:04:31 -0800
commit978ca5d5ba9842ad2be0937d696316a343fc9228 (patch)
treeb351e903c6041bf618748109dccb3ccdab7b544c /lib/filter_nb.c
parent4d2f546f82860d4680a7b17164d8ce0598c8ebb5 (diff)
lib: plist validation use enum type
In prefix-list nortbound callback's validation phase, use type as enum rather string for better performance. Signed-off-by: Chirag Shah <chirag@nvidia.com>
Diffstat (limited to 'lib/filter_nb.c')
-rw-r--r--lib/filter_nb.c93
1 files changed, 50 insertions, 43 deletions
diff --git a/lib/filter_nb.c b/lib/filter_nb.c
index 4e1bde676e..fabf71adf8 100644
--- a/lib/filter_nb.c
+++ b/lib/filter_nb.c
@@ -1167,13 +1167,20 @@ static int
lib_prefix_list_entry_ipv4_prefix_modify(struct nb_cb_modify_args *args)
{
+ int af_type;
+
if (args->event == NB_EV_VALIDATE) {
+ const struct lyd_node *plist_dnode =
+ yang_dnode_get_parent(args->dnode, "prefix-list");
+ af_type = yang_dnode_get_enum(plist_dnode, "./type");
+ if (af_type != YPLT_IPV4) {
+ snprintf(args->errmsg, args->errmsg_len,
+ "prefix-list type %u is mismatched.", af_type);
+ return NB_ERR_VALIDATION;
+ }
return NB_OK;
}
- if (args->event != NB_EV_APPLY)
- return NB_OK;
-
return lib_prefix_list_entry_prefix_modify(args);
}
@@ -1181,10 +1188,6 @@ static int
lib_prefix_list_entry_ipv4_prefix_destroy(struct nb_cb_destroy_args *args)
{
- if (args->event == NB_EV_VALIDATE) {
- return NB_OK;
- }
-
if (args->event != NB_EV_APPLY)
return NB_OK;
@@ -1198,13 +1201,20 @@ static int
lib_prefix_list_entry_ipv6_prefix_modify(struct nb_cb_modify_args *args)
{
+ int af_type;
+
if (args->event == NB_EV_VALIDATE) {
+ const struct lyd_node *plist_dnode =
+ yang_dnode_get_parent(args->dnode, "prefix-list");
+ af_type = yang_dnode_get_enum(plist_dnode, "./type");
+ if (af_type != YPLT_IPV6) {
+ snprintf(args->errmsg, args->errmsg_len,
+ "prefix-list type %u is mismatched.", af_type);
+ return NB_ERR_VALIDATION;
+ }
return NB_OK;
}
- if (args->event != NB_EV_APPLY)
- return NB_OK;
-
return lib_prefix_list_entry_prefix_modify(args);
}
@@ -1212,9 +1222,6 @@ static int
lib_prefix_list_entry_ipv6_prefix_destroy(struct nb_cb_destroy_args *args)
{
- if (args->event == NB_EV_VALIDATE) {
- }
-
if (args->event != NB_EV_APPLY)
return NB_OK;
@@ -1253,15 +1260,15 @@ static int lib_prefix_list_entry_ipv4_prefix_length_greater_or_equal_destroy(
struct nb_cb_destroy_args *args)
{
struct prefix_list_entry *ple;
- const char *af_type;
+ int af_type;
if (args->event == NB_EV_VALIDATE) {
- const struct lyd_node *entry_dnode =
+ const struct lyd_node *plist_dnode =
yang_dnode_get_parent(args->dnode, "prefix-list");
- af_type = yang_dnode_get_string(entry_dnode, "./type");
- if (strcmp(af_type, "ipv4")) {
+ af_type = yang_dnode_get_enum(plist_dnode, "./type");
+ if (af_type != YPLT_IPV4) {
snprintf(args->errmsg, args->errmsg_len,
- "prefix-list type %s is mismatched.", af_type);
+ "prefix-list type %u is mismatched.", af_type);
return NB_ERR_VALIDATION;
}
return NB_OK;
@@ -1315,15 +1322,15 @@ static int lib_prefix_list_entry_ipv4_prefix_length_lesser_or_equal_destroy(
struct nb_cb_destroy_args *args)
{
struct prefix_list_entry *ple;
- const char *af_type;
+ int af_type;
if (args->event == NB_EV_VALIDATE) {
- const struct lyd_node *entry_dnode =
+ const struct lyd_node *plist_dnode =
yang_dnode_get_parent(args->dnode, "prefix-list");
- af_type = yang_dnode_get_string(entry_dnode, "./type");
- if (strcmp(af_type, "ipv4")) {
+ af_type = yang_dnode_get_enum(plist_dnode, "./type");
+ if (af_type != YPLT_IPV4) {
snprintf(args->errmsg, args->errmsg_len,
- "prefix-list type %s is mismatched.", af_type);
+ "prefix-list type %u is mismatched.", af_type);
return NB_ERR_VALIDATION;
}
return NB_OK;
@@ -1352,19 +1359,19 @@ static int lib_prefix_list_entry_ipv6_prefix_length_greater_or_equal_modify(
struct nb_cb_modify_args *args)
{
struct prefix_list_entry *ple;
- const char *af_type;
+ int af_type;
if (args->event == NB_EV_VALIDATE
&& prefix_list_length_validate(args) != NB_OK)
return NB_ERR_VALIDATION;
if (args->event == NB_EV_VALIDATE) {
- const struct lyd_node *entry_dnode =
+ const struct lyd_node *plist_dnode =
yang_dnode_get_parent(args->dnode, "prefix-list");
- af_type = yang_dnode_get_string(entry_dnode, "./type");
- if (strcmp(af_type, "ipv6")) {
+ af_type = yang_dnode_get_enum(plist_dnode, "./type");
+ if (af_type != YPLT_IPV6) {
snprintf(args->errmsg, args->errmsg_len,
- "prefix-list type %s is mismatched.", af_type);
+ "prefix-list type %u is mismatched.", af_type);
return NB_ERR_VALIDATION;
}
@@ -1391,15 +1398,15 @@ static int lib_prefix_list_entry_ipv6_prefix_length_greater_or_equal_destroy(
struct nb_cb_destroy_args *args)
{
struct prefix_list_entry *ple;
- const char *af_type;
+ int af_type;
if (args->event == NB_EV_VALIDATE) {
- const struct lyd_node *entry_dnode =
+ const struct lyd_node *plist_dnode =
yang_dnode_get_parent(args->dnode, "prefix-list");
- af_type = yang_dnode_get_string(entry_dnode, "./type");
- if (strcmp(af_type, "ipv6")) {
+ af_type = yang_dnode_get_enum(plist_dnode, "./type");
+ if (af_type != YPLT_IPV6) {
snprintf(args->errmsg, args->errmsg_len,
- "prefix-list type %s is mismatched.", af_type);
+ "prefix-list type %u is mismatched.", af_type);
return NB_ERR_VALIDATION;
}
return NB_OK;
@@ -1428,19 +1435,19 @@ static int lib_prefix_list_entry_ipv6_prefix_length_lesser_or_equal_modify(
struct nb_cb_modify_args *args)
{
struct prefix_list_entry *ple;
- const char *af_type;
+ int af_type;
if (args->event == NB_EV_VALIDATE
&& prefix_list_length_validate(args) != NB_OK)
return NB_ERR_VALIDATION;
if (args->event == NB_EV_VALIDATE) {
- const struct lyd_node *entry_dnode =
+ const struct lyd_node *plist_dnode =
yang_dnode_get_parent(args->dnode, "prefix-list");
- af_type = yang_dnode_get_string(entry_dnode, "./type");
- if (strcmp(af_type, "ipv6")) {
+ af_type = yang_dnode_get_enum(plist_dnode, "./type");
+ if (af_type != YPLT_IPV6) {
snprintf(args->errmsg, args->errmsg_len,
- "prefix-list type %s is mismatched.", af_type);
+ "prefix-list type %u is mismatched.", af_type);
return NB_ERR_VALIDATION;
}
@@ -1467,15 +1474,15 @@ static int lib_prefix_list_entry_ipv6_prefix_length_lesser_or_equal_destroy(
struct nb_cb_destroy_args *args)
{
struct prefix_list_entry *ple;
- const char *af_type;
+ int af_type;
if (args->event == NB_EV_VALIDATE) {
- const struct lyd_node *entry_dnode =
+ const struct lyd_node *plist_dnode =
yang_dnode_get_parent(args->dnode, "prefix-list");
- af_type = yang_dnode_get_string(entry_dnode, "./type");
- if (strcmp(af_type, "ipv6")) {
+ af_type = yang_dnode_get_enum(plist_dnode, "./type");
+ if (af_type != YPLT_IPV6) {
snprintf(args->errmsg, args->errmsg_len,
- "prefix-list type %s is mismatched.", af_type);
+ "prefix-list type %u is mismatched.", af_type);
return NB_ERR_VALIDATION;
}
return NB_OK;