]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter: Add some minor functions for f_tree and EC
authorOndrej Zajicek <santiago@crfreenet.org>
Tue, 27 Sep 2022 14:47:52 +0000 (16:47 +0200)
committerOndrej Zajicek <santiago@crfreenet.org>
Mon, 3 Oct 2022 18:18:12 +0000 (20:18 +0200)
Add some supportive functions for f_tree and EC. These functions are used
by L3VPN code.

filter/data.c
filter/data.h
filter/tree.c
nest/attrs.h

index 87c438fcf9d1f07d5d21b3468a56202b7b0afd48..56d746fde6db418160004cd3e2efb68ebb43bfd6 100644 (file)
@@ -336,7 +336,7 @@ clist_set_type(const struct f_tree *set, struct f_val *v)
   }
 }
 
-static int
+int
 clist_match_set(const struct adata *clist, const struct f_tree *set)
 {
   if (!clist)
@@ -357,7 +357,7 @@ clist_match_set(const struct adata *clist, const struct f_tree *set)
   return 0;
 }
 
-static int
+int
 eclist_match_set(const struct adata *list, const struct f_tree *set)
 {
   if (!list)
@@ -381,7 +381,7 @@ eclist_match_set(const struct adata *list, const struct f_tree *set)
   return 0;
 }
 
-static int
+int
 lclist_match_set(const struct adata *list, const struct f_tree *set)
 {
   if (!list)
index c96856ce3d56e2b8681bd4c45494a3f2a8218c1d..051f0932e2d1bb24c030a00e53593bc014cec080 100644 (file)
@@ -192,6 +192,7 @@ struct f_tree *f_new_tree(void);
 struct f_tree *build_tree(struct f_tree *);
 const struct f_tree *find_tree(const struct f_tree *t, const struct f_val *val);
 int same_tree(const struct f_tree *t0, const struct f_tree *t2);
+int tree_node_count(const struct f_tree *t);
 void tree_format(const struct f_tree *t, buffer *buf);
 void tree_walk(const struct f_tree *t, void (*hook)(const struct f_tree *, void *), void *data);
 
@@ -286,6 +287,10 @@ static inline int lclist_set_type(const struct f_tree *set)
 static inline int path_set_type(const struct f_tree *set)
 { return !set || set->from.type == T_INT; }
 
+int clist_match_set(const struct adata *clist, const struct f_tree *set);
+int eclist_match_set(const struct adata *list, const struct f_tree *set);
+int lclist_match_set(const struct adata *list, const struct f_tree *set);
+
 const struct adata *clist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos);
 const struct adata *eclist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos);
 const struct adata *lclist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos);
index 5da86b9d28679dae272831bcfe1e63b45867d015..97bf7dae5eff788455f23d1c10574b1094f15045 100644 (file)
@@ -134,6 +134,14 @@ same_tree(const struct f_tree *t1, const struct f_tree *t2)
   return 1;
 }
 
+int
+tree_node_count(const struct f_tree *t)
+{
+  if (t == NULL)
+    return 0;
+
+  return 1 + tree_node_count(t->left) + tree_node_count(t->right);
+}
 
 static void
 tree_node_format(const struct f_tree *t, buffer *buf)
index 9412439bf4a9e07141deb172fafa567515b8ec68..fcd5ac16a31b07af4fff8de3a898055894f473d9 100644 (file)
@@ -138,6 +138,11 @@ static inline const char *ec_subtype_str(const enum ec_subtype ecs) {
   }
 }
 
+/* Check for EC_RT subtype within different types (0-2) */
+static inline int ec_type_is_rt(uint type)
+{ return (type == EC_RT) || (type == (0x0100 | EC_RT)) || (type == (0x0200 | EC_RT)); }
+
+
 /* Transitive bit (for first u32 half of EC) */
 #define EC_TBIT 0x40000000
 
@@ -157,9 +162,13 @@ static inline u32 *int_set_get_data(const struct adata *list)
 
 static inline u32 ec_hi(u64 ec) { return ec >> 32; }
 static inline u32 ec_lo(u64 ec) { return ec; }
+
 static inline u64 ec_get(const u32 *l, int i)
 { return (((u64) l[i]) << 32) | l[i+1]; }
 
+static inline void ec_put(u32 *l, int i, u64 val)
+{ l[i] = ec_hi(val); l[i+1] = ec_lo(val); }
+
 /* RFC 4360 3.1.  Two-Octet AS Specific Extended Community */
 static inline u64 ec_as2(enum ec_subtype kind, u64 key, u64 val)
 { return (((u64) kind | 0x0000) << 48) | (key << 32) | val; }