]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Lib: Add VPN route target datatype oz-test2
authorIgor Putovny <igor.putovny@nic.cz>
Wed, 17 Jun 2026 13:39:51 +0000 (15:39 +0200)
committerOndrej Zajicek <santiago@crfreenet.org>
Wed, 17 Jun 2026 14:13:26 +0000 (16:13 +0200)
conf/confbase.Y
lib/ip.h

index 49a9d4e692a592947d4ee2b543b3f11ee51f009c..642b76fd795a7393d31007cd1eed10666e79d1ed 100644 (file)
@@ -84,6 +84,7 @@ CF_DECLS
   u32 i32;
   u64 i64;
   vpn_rd rd;
+  vpn_rt rt;
   ip_addr a;
   ip4_addr ip4;
   ip6_addr ip6;
index bae05261a5b363c274d469cfefc78c55fb0235d3..a8bd28279d11f638577ebb62e333687aa95f6279 100644 (file)
--- a/lib/ip.h
+++ b/lib/ip.h
@@ -531,4 +531,47 @@ static inline void * put_rd(void *buf, vpn_rd rd)
   return buf+8;
 }
 
+
+/*
+ *     VPN route targets
+ */
+
+typedef struct vpn_rt {
+  u32 hi;
+  u32 lo;
+} vpn_rt;
+
+#define RT_NONE                (vpn_rt){}
+
+static inline vpn_rt rt_from_u64(u64 val)
+{ return (vpn_rt) { .hi = val >> 32, .lo = val }; }
+
+static inline u64 rt_to_u64(vpn_rt rt)
+{ return (((u64)rt.hi) << 32) | rt.lo; }
+
+static inline int rt_equal(vpn_rt a, vpn_rt b)
+{ return a.hi == b.hi && a.lo == b.lo; }
+
+static inline int rt_zero(vpn_rt a)
+{ return !a.hi && !a.lo; }
+
+static inline int rt_nonzero(vpn_rt a)
+{ return a.hi || a.lo; }
+
+static inline int rt_compare(vpn_rt a, vpn_rt b)
+{ return uint_cmp(a.hi, b.hi) ?: uint_cmp(a.lo, b.lo); }
+
+static inline u64 rt_hash0(vpn_rt rt, u32 p, u64 acc)
+{ return u32_hash0(rt.hi, p, u32_hash0(rt.lo, p, acc)); }
+
+static inline vpn_rt get_rt(const void *buf)
+{ return (vpn_rt) { .hi = get_u32(buf), .lo = get_u32(buf + 4) }; }
+
+static inline void *put_rt(void *buf, vpn_rt rt)
+{
+  put_u32(buf, rt.hi);
+  put_u32(buf + 4, rt.lo);
+  return buf + 8;
+}
+
 #endif