]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Modify prefix_list_apply to allow retrieval of prefix
authorDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 29 Aug 2017 12:29:34 +0000 (08:29 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 31 Aug 2017 14:30:19 +0000 (10:30 -0400)
Create a new function prefix_list_apply_which_prefix which
will return a pointer to the matching prefix that caused
the acceptance/denial.

This change will be used in future commits.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/plist.c
lib/plist.h

index ebd628d7249cfcc448b34fadf3b76bb5bab441b7..da6406d334d61121c8212ac47f793b9a18cddbb9 100644 (file)
@@ -679,7 +679,9 @@ static int prefix_list_entry_match(struct prefix_list_entry *pentry,
        return 1;
 }
 
-enum prefix_list_type prefix_list_apply(struct prefix_list *plist, void *object)
+enum prefix_list_type prefix_list_apply_which_prefix(struct prefix_list *plist,
+                                                    struct prefix **which,
+                                                    void *object)
 {
        struct prefix_list_entry *pentry, *pbest = NULL;
 
@@ -689,11 +691,17 @@ enum prefix_list_type prefix_list_apply(struct prefix_list *plist, void *object)
        size_t validbits = p->prefixlen;
        struct pltrie_table *table;
 
-       if (plist == NULL)
+       if (plist == NULL) {
+               if (which)
+                       *which = NULL;
                return PREFIX_DENY;
+       }
 
-       if (plist->count == 0)
+       if (plist->count == 0) {
+               if (which)
+                       *which = NULL;
                return PREFIX_PERMIT;
+       }
 
        depth = plist->master->trie_depth;
        table = plist->trie;
@@ -729,6 +737,13 @@ enum prefix_list_type prefix_list_apply(struct prefix_list *plist, void *object)
                break;
        }
 
+       if (which) {
+               if (pbest)
+                       *which = &pbest->prefix;
+               else
+                       *which = NULL;
+       }
+
        if (pbest == NULL)
                return PREFIX_DENY;
 
index 3eba3046ae6b269f0a690b1a6c0635ea77b162d5..bf06e74d36e2b00f97425dfe1e49397a87ba9e34 100644 (file)
@@ -50,7 +50,21 @@ extern void prefix_list_delete_hook(void (*func)(struct prefix_list *));
 extern const char *prefix_list_name(struct prefix_list *);
 extern afi_t prefix_list_afi(struct prefix_list *);
 extern struct prefix_list *prefix_list_lookup(afi_t, const char *);
-extern enum prefix_list_type prefix_list_apply(struct prefix_list *, void *);
+
+/*
+ * prefix_list_apply_which_prefix
+ *
+ * Allow calling function to learn which prefix
+ * caused the DENY or PERMIT.
+ *
+ * If no pointer is sent in, do not return anything.
+ * If it is a empty plist return a NULL pointer.
+ */
+extern enum prefix_list_type prefix_list_apply_which_prefix(
+       struct prefix_list *plist,
+       struct prefix **which,
+       void *object);
+#define prefix_list_apply(A, B) prefix_list_apply_which_prefix((A), NULL, (B))
 
 extern struct prefix_list *prefix_bgp_orf_lookup(afi_t, const char *);
 extern struct stream *prefix_bgp_orf_entry(struct stream *,