From 315f23a0470112ced04badbb117bc7854ee53e06 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Sat, 9 May 2015 18:50:15 +0200 Subject: Add bitfield route attribute type --- nest/rt-attr.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'nest/rt-attr.c') diff --git a/nest/rt-attr.c b/nest/rt-attr.c index 09691bf1..938b2b44 100644 --- a/nest/rt-attr.c +++ b/nest/rt-attr.c @@ -563,6 +563,32 @@ get_generic_attr(eattr *a, byte **buf, int buflen UNUSED) return GA_UNKNOWN; } +void +ea_format_bitfield(struct eattr *a, byte *buf, int bufsize, const char **names, int min, int max) +{ + byte *bound = buf + bufsize - 32; + u32 data = a->u.data; + int i; + + for (i = min; i < max; i++) + if ((data & (1u << i)) && names[i]) + { + if (buf > bound) + { + strcpy(buf, " ..."); + return; + } + + buf += bsprintf(buf, " %s", names[i]); + data &= ~(1u << i); + } + + if (data) + bsprintf(buf, " %08x", data); + + return; +} + static inline void opaque_format(struct adata *ad, byte *buf, unsigned int size) { @@ -665,6 +691,9 @@ ea_show(struct cli *c, eattr *e) case EAF_TYPE_AS_PATH: as_path_format(ad, pos, end - pos); break; + case EAF_TYPE_BITFIELD: + bsprintf(pos, "%08x", e->u.data); + break; case EAF_TYPE_INT_SET: ea_show_int_set(c, ad, 1, pos, buf, end); return; -- cgit v1.2.3