]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: add YANG model enumerations for filter
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Fri, 5 Jun 2020 18:05:34 +0000 (15:05 -0300)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Fri, 5 Jun 2020 19:42:11 +0000 (16:42 -0300)
Avoid magic numbers by using enumerations.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
lib/filter.h
lib/filter_cli.c
lib/filter_nb.c

index f4bd62e40d50b19bc9e13b6351afd7e697a71b8f..76e992bf8ed330151289c88c30a4270a39016798 100644 (file)
@@ -148,6 +148,24 @@ struct filter *filter_lookup_zebra(struct access_list *access,
 
 extern const struct frr_yang_module_info frr_filter_info;
 
+
+/* filter_nb.c */
+enum yang_access_list_type {
+       YALT_IPV4 = 0,
+       YALT_IPV6 = 1,
+       YALT_MAC = 2,
+};
+
+enum yang_prefix_list_type {
+       YPLT_IPV4 = 0,
+       YPLT_IPV6 = 1,
+};
+
+enum yang_prefix_list_action {
+       YPLA_DENY = 0,
+       YPLA_PERMIT = 1,
+};
+
 /* filter_cli.c */
 struct lyd_node;
 struct vty;
index a7d6b7b6e459dd0249151c8cebf778fe4ab899a9..7800db6e0fc70d18c29206633c62d79a92143f33 100644 (file)
@@ -1161,14 +1161,14 @@ void access_list_show(struct vty *vty, struct lyd_node *dnode,
 
        is_any = yang_dnode_exists(dnode, "./any");
        switch (type) {
-       case 0: /* ipv4 */
+       case YALT_IPV4:
                if (is_any)
                        break;
 
                yang_dnode_get_prefix(&p, dnode, "./ipv4-prefix");
                is_exact = yang_dnode_get_bool(dnode, "./ipv4-exact-match");
                break;
-       case 1: /* ipv6 */
+       case YALT_IPV6: /* ipv6 */
                vty_out(vty, "ipv6 ");
                if (is_any)
                        break;
@@ -1176,7 +1176,7 @@ void access_list_show(struct vty *vty, struct lyd_node *dnode,
                yang_dnode_get_prefix(&p, dnode, "./ipv6-prefix");
                is_exact = yang_dnode_get_bool(dnode, "./ipv6-exact-match");
                break;
-       case 2: /* mac */
+       case YALT_MAC: /* mac */
                vty_out(vty, "mac ");
                if (is_any)
                        break;
@@ -1212,12 +1212,12 @@ void access_list_remark_show(struct vty *vty, struct lyd_node *dnode,
        int type = yang_dnode_get_enum(dnode, "../type");
 
        switch (type) {
-       case 0: /* ipv4 */
+       case YALT_IPV4:
                break;
-       case 1: /* ipv6 */
+       case YALT_IPV6:
                vty_out(vty, "ipv6 ");
                break;
-       case 2: /* mac */
+       case YALT_MAC:
                vty_out(vty, "mac ");
                break;
        }
@@ -1693,7 +1693,7 @@ void prefix_list_show(struct vty *vty, struct lyd_node *dnode,
 
        is_any = yang_dnode_exists(dnode, "./any");
        switch (type) {
-       case 0: /* ipv4 */
+       case YPLT_IPV4:
                if (!is_any)
                        yang_dnode_get_prefix(&p, dnode, "./ipv4-prefix");
                if (yang_dnode_exists(dnode,
@@ -1707,7 +1707,7 @@ void prefix_list_show(struct vty *vty, struct lyd_node *dnode,
 
                vty_out(vty, "ip ");
                break;
-       case 1: /* ipv6 */
+       case YPLT_IPV6:
                if (!is_any)
                        yang_dnode_get_prefix(&p, dnode, "ipv6-prefix");
                if (yang_dnode_exists(dnode,
@@ -1748,10 +1748,10 @@ void prefix_list_remark_show(struct vty *vty, struct lyd_node *dnode,
        int type = yang_dnode_get_enum(dnode, "../type");
 
        switch (type) {
-       case 0: /* ipv4 */
+       case YPLT_IPV4:
                vty_out(vty, "ip ");
                break;
-       case 1: /* ipv6 */
+       case YPLT_IPV6:
                vty_out(vty, "ipv6 ");
                break;
        }
index f2f334d9f4ac7c6515ad3f18967700451b4e33f8..1daefa8f107223a1021e8e9e8f5e48dfbccd45a5 100644 (file)
@@ -47,7 +47,7 @@ prefix_list_length_validate(const struct lyd_node *dnode)
        struct prefix p;
        uint8_t le, ge;
 
-       if (type == 0 /* ipv4 */) {
+       if (type == YPLT_IPV4) {
                yang_dnode_get_prefix(&p, dnode, "../ipv4-prefix");
                xpath_le = "../ipv4-prefix-length-lesser-or-equal";
                xpath_ge = "../ipv4-prefix-length-greater-or-equal";
@@ -498,13 +498,13 @@ static int lib_access_list_create(struct nb_cb_create_args *args)
        acl_name = yang_dnode_get_string(args->dnode, "./name");
 
        switch (type) {
-       case 0: /* ipv4 */
+       case YALT_IPV4:
                acl = access_list_get(AFI_IP, acl_name);
                break;
-       case 1: /* ipv6 */
+       case YALT_IPV6:
                acl = access_list_get(AFI_IP6, acl_name);
                break;
-       case 2: /* mac */
+       case YALT_MAC:
                acl = access_list_get(AFI_L2VPN, acl_name);
                break;
        }
@@ -723,13 +723,13 @@ static int lib_access_list_entry_any_create(struct nb_cb_create_args *args)
 
        type = yang_dnode_get_enum(args->dnode, "../../type");
        switch (type) {
-       case 0: /* ipv4 */
+       case YALT_IPV4:
                fz->prefix.family = AF_INET;
                break;
-       case 1: /* ipv6 */
+       case YALT_IPV6:
                fz->prefix.family = AF_INET6;
                break;
-       case 2: /* mac */
+       case YALT_MAC:
                fz->prefix.family = AF_ETHERNET;
                break;
        }
@@ -876,7 +876,7 @@ static int lib_prefix_list_entry_destroy(struct nb_cb_destroy_args *args)
 static int lib_prefix_list_entry_action_modify(struct nb_cb_modify_args *args)
 {
        struct prefix_list_entry *ple;
-       const char *action_str;
+       int action_type;
 
        if (args->event != NB_EV_APPLY)
                return NB_OK;
@@ -886,8 +886,8 @@ static int lib_prefix_list_entry_action_modify(struct nb_cb_modify_args *args)
        /* Start prefix entry update procedure. */
        prefix_list_entry_update_start(ple);
 
-       action_str = yang_dnode_get_string(args->dnode, NULL);
-       if (strcmp(action_str, "permit") == 0)
+       action_type = yang_dnode_get_enum(args->dnode, NULL);
+       if (action_type == YPLA_PERMIT)
                ple->type = PREFIX_PERMIT;
        else
                ple->type = PREFIX_DENY;
@@ -1137,12 +1137,12 @@ static int lib_prefix_list_entry_any_create(struct nb_cb_create_args *args)
 
        type = yang_dnode_get_enum(args->dnode, "../../type");
        switch (type) {
-       case 0: /* ipv4 */
+       case YPLT_IPV4:
                ple->prefix.family = AF_INET;
                ple->ge = 0;
                ple->le = IPV4_MAX_BITLEN;
                break;
-       case 1: /* ipv6 */
+       case YPLT_IPV6:
                ple->prefix.family = AF_INET6;
                ple->ge = 0;
                ple->le = IPV6_MAX_BITLEN;