From: Igor Putovny Date: Wed, 17 Jun 2026 13:39:51 +0000 (+0200) Subject: Lib: Add VPN route target datatype X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=602d1700ef67e5df15b327e381dcdfaa7b1ee054;p=thirdparty%2Fbird.git Lib: Add VPN route target datatype --- diff --git a/conf/confbase.Y b/conf/confbase.Y index 49a9d4e69..642b76fd7 100644 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@ -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; diff --git a/lib/ip.h b/lib/ip.h index bae05261a..a8bd28279 100644 --- 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