]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/filter.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / filter.c
index c01ee4ee1060b2a2ed89a9cd5533f5fd842b0dca..1aae58b61ca59c1b53ab7cf3c2f83548cba0fe1e 100644 (file)
@@ -90,7 +90,7 @@ struct access_master {
        void (*delete_hook)(struct access_list *);
 };
 
-/* Static structure for IPv4 access_list's master. */
+/* Static structure for mac access_list's master. */
 static struct access_master access_master_mac = {
        {NULL, NULL},
        {NULL, NULL},
@@ -156,36 +156,13 @@ static const char *filter_type_str(struct filter *filter)
        }
 }
 
-/*
- * mac filter match
- * n is of type struct prefix_eth
- * p can be of type struct ethaddr
- */
-static int mac_filter_match(struct prefix *n, struct ethaddr *p)
-{
-       if (!n && !p)
-               return 1;
-
-       if (!n || !p)
-               return 0;
-
-       /* check if we are matching on any mac */
-       if (is_zero_mac(&(n->u.prefix_eth)))
-               return 1;
-
-       if (memcmp(&(n->u.prefix), p, sizeof(struct ethaddr)) == 0)
-               return 1;
-
-       return 0;
-}
-
 /* If filter match to the prefix then return 1. */
-static int filter_match_cisco(struct filter *mfilter, struct prefix *p)
+static int filter_match_cisco(struct filter *mfilter, const struct prefix *p)
 {
        struct filter_cisco *filter;
        struct in_addr mask;
-       u_int32_t check_addr;
-       u_int32_t check_mask;
+       uint32_t check_addr;
+       uint32_t check_mask;
 
        filter = &mfilter->u.cfilter;
        check_addr = p->u.prefix4.s_addr & ~filter->addr_mask.s_addr;
@@ -204,37 +181,22 @@ static int filter_match_cisco(struct filter *mfilter, struct prefix *p)
 }
 
 /* If filter match to the prefix then return 1. */
-static int filter_match_zebra(struct filter *mfilter, void *obj)
+static int filter_match_zebra(struct filter *mfilter, const struct prefix *p)
 {
        struct filter_zebra *filter = NULL;
 
        filter = &mfilter->u.zfilter;
 
-       if (filter->prefix.family == AF_ETHERNET) {
-               struct ethaddr *p = NULL;
-
-               p = (struct ethaddr *)obj;
-               return mac_filter_match(&filter->prefix, p);
-       }
-
-       if (filter->prefix.family == AF_INET
-           || filter->prefix.family == AF_INET6) {
-               struct prefix *p = NULL;
-
-               p = (struct prefix *)obj;
-               if (filter->prefix.family == p->family) {
-                       if (filter->exact) {
-                               if (filter->prefix.prefixlen == p->prefixlen)
-                                       return prefix_match(&filter->prefix, p);
-                               else
-                                       return 0;
-                       } else
+       if (filter->prefix.family == p->family) {
+               if (filter->exact) {
+                       if (filter->prefix.prefixlen == p->prefixlen)
                                return prefix_match(&filter->prefix, p);
+                       else
+                               return 0;
                } else
-                       return 0;
-       }
-
-       return 0;
+                       return prefix_match(&filter->prefix, p);
+       } else
+               return 0;
 }
 
 /* Allocate new access list structure. */
@@ -410,12 +372,11 @@ static struct access_list *access_list_get(afi_t afi, const char *name)
 }
 
 /* Apply access list to object (which should be struct prefix *). */
-enum filter_type access_list_apply(struct access_list *access, void *object)
+enum filter_type access_list_apply(struct access_list *access,
+                                  const void *object)
 {
        struct filter *filter;
-       struct prefix *p;
-
-       p = (struct prefix *)object;
+       const struct prefix *p = (const struct prefix *)object;
 
        if (access == NULL)
                return FILTER_DENY;
@@ -425,7 +386,7 @@ enum filter_type access_list_apply(struct access_list *access, void *object)
                        if (filter_match_cisco(filter, p))
                                return filter->type;
                } else {
-                       if (filter_match_zebra(filter, object))
+                       if (filter_match_zebra(filter, p))
                                return filter->type;
                }
        }
@@ -566,16 +527,8 @@ static struct filter *filter_lookup_zebra(struct access_list *access,
 
                if (filter->exact == new->exact
                    && mfilter->type == mnew->type) {
-                       if (new->prefix.family == AF_ETHERNET) {
-                               if (prefix_eth_same(
-                                           (struct prefix_eth *)&filter
-                                                   ->prefix,
-                                           (struct prefix_eth *)&new->prefix))
-                                       return mfilter;
-                       } else {
-                               if (prefix_same(&filter->prefix, &new->prefix))
-                                       return mfilter;
-                       }
+                       if (prefix_same(&filter->prefix, &new->prefix))
+                               return mfilter;
                }
        }
        return NULL;
@@ -597,8 +550,7 @@ static int vty_access_list_remark_unset(struct vty *vty, afi_t afi,
                access->remark = NULL;
        }
 
-       if (access->head == NULL && access->tail == NULL
-           && access->remark == NULL)
+       if (access->head == NULL && access->tail == NULL)
                access_list_delete(access);
 
        return CMD_SUCCESS;
@@ -1350,7 +1302,7 @@ static int filter_set_zebra(struct vty *vty, const char *name_str,
 
 DEFUN (mac_access_list,
        mac_access_list_cmd,
-       "mac access-list WORD <deny|permit> MAC",
+       "mac access-list WORD <deny|permit> X:X:X:X:X:X",
        "Add a mac access-list\n"
        "Add an access list entry\n"
        "MAC zebra access-list name\n"
@@ -1364,7 +1316,7 @@ DEFUN (mac_access_list,
 
 DEFUN (no_mac_access_list,
        no_mac_access_list_cmd,
-       "no mac access-list WORD <deny|permit> MAC",
+       "no mac access-list WORD <deny|permit> X:X:X:X:X:X",
        NO_STR
        "Remove a mac access-list\n"
        "Remove an access list entry\n"
@@ -1416,7 +1368,7 @@ DEFUN (access_list_exact,
        "Prefix to match. e.g. 10.0.0.0/8\n"
        "Exact match of the prefixes\n")
 {
-       int idx;
+       int idx = 0;
        int exact = 0;
        int idx_word = 1;
        int idx_permit_deny = 2;
@@ -1458,7 +1410,7 @@ DEFUN (no_access_list_exact,
        "Prefix to match. e.g. 10.0.0.0/8\n"
        "Exact match of the prefixes\n")
 {
-       int idx;
+       int idx = 0;
        int exact = 0;
        int idx_word = 2;
        int idx_permit_deny = 3;
@@ -1597,7 +1549,7 @@ DEFUN (ipv6_access_list_exact,
        "IPv6 prefix\n"
        "Exact match of the prefixes\n")
 {
-       int idx;
+       int idx = 0;
        int exact = 0;
        int idx_word = 2;
        int idx_allow = 3;
@@ -1640,7 +1592,7 @@ DEFUN (no_ipv6_access_list_exact,
        "Prefix to match. e.g. 3ffe:506::/32\n"
        "Exact match of the prefixes\n")
 {
-       int idx;
+       int idx = 0;
        int exact = 0;
        int idx_word = 3;
        int idx_permit_deny = 4;
@@ -1793,9 +1745,9 @@ static int filter_show(struct vty *vty, const char *name, afi_t afi)
                                                                  : "Standard")
                                                       : "Zebra",
                                        (afi == AFI_IP)
-                                               ? ("")
-                                               : ((afi == AFI_IP6) ? ("ipv6 ")
-                                                                   : ("mac ")),
+                                               ? ("IP")
+                                               : ((afi == AFI_IP6) ? ("IPv6 ")
+                                                                   : ("MAC ")),
                                        access->name);
                                write = 0;
                        }
@@ -1840,9 +1792,9 @@ static int filter_show(struct vty *vty, const char *name, afi_t afi)
                                                                  : "Standard")
                                                       : "Zebra",
                                        (afi == AFI_IP)
-                                               ? ("")
-                                               : ((afi == AFI_IP6) ? ("ipv6 ")
-                                                                   : ("mac ")),
+                                               ? ("IP")
+                                               : ((afi == AFI_IP6) ? ("IPv6 ")
+                                                                   : ("MAC ")),
                                        access->name);
                                write = 0;
                        }
@@ -1888,10 +1840,9 @@ DEFUN (show_mac_access_list_name,
        show_mac_access_list_name_cmd,
        "show mac access-list WORD",
        SHOW_STR
-       "mac\n"
+       "mac access lists\n"
        "List mac access lists\n"
-       "mac zebra access-list\n"
-       "mac address")
+       "mac address\n")
 {
        return filter_show(vty, argv[3]->arg, AFI_L2VPN);
 }
@@ -1999,7 +1950,7 @@ void config_write_access_zebra(struct vty *vty, struct filter *mfilter)
                        inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ),
                        p->prefixlen, filter->exact ? " exact-match" : "");
        else if (p->family == AF_ETHERNET) {
-               if (is_zero_mac(&(p->u.prefix_eth)))
+               if (p->prefixlen == 0)
                        vty_out(vty, " any");
                else
                        vty_out(vty, " %s", prefix_mac2str(&(p->u.prefix_eth),