diff options
author | Maria Matejka <mq@ucw.cz> | 2023-10-15 16:04:36 +0200 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2024-03-25 14:15:30 +0100 |
commit | 08571b20598c58877e1565403d970efc2b90dba6 (patch) | |
tree | 0471beb4512650ff31f179ba375757f4f9400e01 /nest | |
parent | b95dc8f29f18eb177f91fdc4bf0716fac9b15366 (diff) | |
download | bird-08571b20598c58877e1565403d970efc2b90dba6.tar.gz |
ASPA: basic data structures and Static protocol support
Diffstat (limited to 'nest')
-rw-r--r-- | nest/a-set.c | 18 | ||||
-rw-r--r-- | nest/a-set_test.c | 14 | ||||
-rw-r--r-- | nest/attrs.h | 7 | ||||
-rw-r--r-- | nest/config.Y | 11 | ||||
-rw-r--r-- | nest/route.h | 1 | ||||
-rw-r--r-- | nest/rt-attr.c | 13 | ||||
-rw-r--r-- | nest/rt-fib.c | 2 |
7 files changed, 50 insertions, 16 deletions
diff --git a/nest/a-set.c b/nest/a-set.c index 40ed573c..e84d7058 100644 --- a/nest/a-set.c +++ b/nest/a-set.c @@ -34,7 +34,7 @@ * the buffer to indicate truncation. */ int -int_set_format(const struct adata *set, int way, int from, byte *buf, uint size) +int_set_format(const struct adata *set, enum isf_way way, int from, byte *buf, uint size) { u32 *z = (u32 *) set->data; byte *end = buf + size - 24; @@ -56,10 +56,18 @@ int_set_format(const struct adata *set, int way, int from, byte *buf, uint size) if (i > from2) *buf++ = ' '; - if (way) - buf += bsprintf(buf, "(%d,%d)", z[i] >> 16, z[i] & 0xffff); - else - buf += bsprintf(buf, "%R", z[i]); + switch (way) + { + case ISF_COMMUNITY_LIST: + buf += bsprintf(buf, "(%d,%d)", z[i] >> 16, z[i] & 0xffff); + break; + case ISF_ROUTER_ID: + buf += bsprintf(buf, "%R", z[i]); + break; + case ISF_NUMBERS: + buf += bsprintf(buf, "%u", z[i]); + break; + } } *buf = 0; return 0; diff --git a/nest/a-set_test.c b/nest/a-set_test.c index 904e6764..c52b1d49 100644 --- a/nest/a-set_test.c +++ b/nest/a-set_test.c @@ -92,11 +92,11 @@ t_set_int_union(void) const struct adata *set_union; set_union = int_set_union(tmp_linpool, set_sequence, set_sequence_same); bt_assert(int_set_get_size(set_union) == SET_SIZE); - bt_assert(int_set_format(set_union, 0, 2, buf, BUFFER_SIZE) == 0); + bt_assert(int_set_format(set_union, ISF_ROUTER_ID, 2, buf, BUFFER_SIZE) == 0); set_union = int_set_union(tmp_linpool, set_sequence, set_sequence_higher); bt_assert_msg(int_set_get_size(set_union) == SET_SIZE*2, "int_set_get_size(set_union) %d, SET_SIZE*2 %d", int_set_get_size(set_union), SET_SIZE*2); - bt_assert(int_set_format(set_union, 0, 2, buf, BUFFER_SIZE) == 0); + bt_assert(int_set_format(set_union, ISF_ROUTER_ID, 2, buf, BUFFER_SIZE) == 0); return 1; } @@ -106,17 +106,21 @@ t_set_int_format(void) { generate_set_sequence(SET_TYPE_INT, SET_SIZE_FOR_FORMAT_OUTPUT); - bt_assert(int_set_format(set_sequence, 0, 0, buf, BUFFER_SIZE) == 0); + bt_assert(int_set_format(set_sequence, ISF_ROUTER_ID, 0, buf, BUFFER_SIZE) == 0); bt_assert(strcmp(buf, "0.0.0.0 0.0.0.1 0.0.0.2 0.0.0.3 0.0.0.4 0.0.0.5 0.0.0.6 0.0.0.7 0.0.0.8 0.0.0.9") == 0); bzero(buf, BUFFER_SIZE); - bt_assert(int_set_format(set_sequence, 0, 2, buf, BUFFER_SIZE) == 0); + bt_assert(int_set_format(set_sequence, ISF_ROUTER_ID, 2, buf, BUFFER_SIZE) == 0); bt_assert(strcmp(buf, "0.0.0.2 0.0.0.3 0.0.0.4 0.0.0.5 0.0.0.6 0.0.0.7 0.0.0.8 0.0.0.9") == 0); bzero(buf, BUFFER_SIZE); - bt_assert(int_set_format(set_sequence, 1, 0, buf, BUFFER_SIZE) == 0); + bt_assert(int_set_format(set_sequence, ISF_COMMUNITY_LIST, 0, buf, BUFFER_SIZE) == 0); bt_assert(strcmp(buf, "(0,0) (0,1) (0,2) (0,3) (0,4) (0,5) (0,6) (0,7) (0,8) (0,9)") == 0); + bzero(buf, BUFFER_SIZE); + bt_assert(int_set_format(set_sequence, ISF_NUMBERS, 0, buf, BUFFER_SIZE) == 0); + bt_assert(strcmp(buf, "0 1 2 3 4 5 6 7 8 9") == 0); + return 1; } diff --git a/nest/attrs.h b/nest/attrs.h index aee3468b..8b13e7a4 100644 --- a/nest/attrs.h +++ b/nest/attrs.h @@ -206,8 +206,13 @@ static inline int lc_match(const u32 *l, int i, lcomm v) static inline u32 *lc_copy(u32 *dst, const u32 *src) { memcpy(dst, src, LCOMM_LENGTH); return dst + 3; } +enum isf_way { + ISF_NUMBERS, + ISF_COMMUNITY_LIST, + ISF_ROUTER_ID, +}; -int int_set_format(const struct adata *set, int way, int from, byte *buf, uint size); +int int_set_format(const struct adata *set, enum isf_way way, int from, byte *buf, uint size); int ec_format(byte *buf, u64 ec); int ec_set_format(const struct adata *set, int from, byte *buf, uint size); int lc_format(byte *buf, lcomm lc); diff --git a/nest/config.Y b/nest/config.Y index 20186ece..5d2f8d99 100644 --- a/nest/config.Y +++ b/nest/config.Y @@ -115,7 +115,7 @@ CF_DECLS CF_KEYWORDS(ROUTER, ID, HOSTNAME, PROTOCOL, TEMPLATE, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT) CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, VRF, DEFAULT, TABLE, TABLES, STATES, ROUTES, FILTERS) -CF_KEYWORDS(IPV4, IPV6, VPN4, VPN6, ROA4, ROA6, FLOW4, FLOW6, SADR, MPLS) +CF_KEYWORDS(IPV4, IPV6, VPN4, VPN6, ROA4, ROA6, FLOW4, FLOW6, SADR, MPLS, ASPA) CF_KEYWORDS(RECEIVE, LIMIT, ACTION, WARN, BLOCK, RESTART, DISABLE, KEEP, FILTERED, RPKI) CF_KEYWORDS(PASSWORD, KEY, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, CHANNELS, INTERFACES) CF_KEYWORDS(ALGORITHM, KEYED, HMAC, MD5, SHA1, SHA256, SHA384, SHA512, BLAKE2S128, BLAKE2S256, BLAKE2B256, BLAKE2B512) @@ -128,9 +128,10 @@ CF_KEYWORDS(MIN, IDLE, RX, TX, INTERVAL, MULTIPLIER, PASSIVE) CF_KEYWORDS(CHECK, LINK) CF_KEYWORDS(SORTED, TRIE, MIN, MAX, SETTLE, TIME, GC, THRESHOLD, PERIOD) CF_KEYWORDS(MPLS_LABEL, MPLS_POLICY, MPLS_CLASS) +CF_KEYWORDS(ASPA_PROVIDERS) /* For r_args_channel */ -CF_KEYWORDS(IPV4, IPV4_MC, IPV4_MPLS, IPV6, IPV6_MC, IPV6_MPLS, IPV6_SADR, VPN4, VPN4_MC, VPN4_MPLS, VPN6, VPN6_MC, VPN6_MPLS, ROA4, ROA6, FLOW4, FLOW6, MPLS, PRI, SEC) +CF_KEYWORDS(IPV4, IPV4_MC, IPV4_MPLS, IPV6, IPV6_MC, IPV6_MPLS, IPV6_SADR, VPN4, VPN4_MC, VPN4_MPLS, VPN6, VPN6_MC, VPN6_MPLS, ROA4, ROA6, FLOW4, FLOW6, MPLS, PRI, SEC, ASPA) CF_ENUM(T_ENUM_RTS, RTS_, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT, RIP, OSPF, OSPF_IA, OSPF_EXT1, OSPF_EXT2, BGP, PIPE, BABEL, RPKI, L3VPN, @@ -202,6 +203,7 @@ net_type_base: | ROA6 { $$ = NET_ROA6; } | FLOW4{ $$ = NET_FLOW4; } | FLOW6{ $$ = NET_FLOW6; } + | ASPA { $$ = NET_ASPA; } ; net_type: @@ -209,7 +211,7 @@ net_type: | MPLS { $$ = NET_MPLS; } ; -CF_ENUM(T_ENUM_NETTYPE, NET_, IP4, IP6, VPN4, VPN6, ROA4, ROA6, FLOW4, FLOW6, IP6_SADR, MPLS) +CF_ENUM(T_ENUM_NETTYPE, NET_, IP4, IP6, VPN4, VPN6, ROA4, ROA6, FLOW4, FLOW6, IP6_SADR, MPLS, ASPA) /* Creation of routing tables */ @@ -840,6 +842,7 @@ channel_sym: | FLOW4 { $$ = "flow4"; } | FLOW6 { $$ = "flow6"; } | MPLS { $$ = "mpls"; } + | ASPA { $$ = "aspa"; } | PRI { $$ = "pri"; } | SEC { $$ = "sec"; } ; @@ -972,6 +975,8 @@ proto_patt2: dynamic_attr: IGP_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_GEN_IGP_METRIC); } ; +dynamic_attr: ASPA_PROVIDERS { $$ = f_new_dynamic_attr(EAF_TYPE_INT_SET, T_CLIST, EA_ASPA_PROVIDERS); } ; + dynamic_attr: MPLS_LABEL { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_MPLS_LABEL); } ; dynamic_attr: MPLS_POLICY { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_ENUM_MPLS_POLICY, EA_MPLS_POLICY); } ; dynamic_attr: MPLS_CLASS { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_MPLS_CLASS); } ; diff --git a/nest/route.h b/nest/route.h index 659783a8..9140b9e1 100644 --- a/nest/route.h +++ b/nest/route.h @@ -536,6 +536,7 @@ const char *ea_custom_name(uint ea); #define EA_MPLS_LABEL EA_CODE(PROTOCOL_NONE, 1) #define EA_MPLS_POLICY EA_CODE(PROTOCOL_NONE, 2) #define EA_MPLS_CLASS EA_CODE(PROTOCOL_NONE, 3) +#define EA_ASPA_PROVIDERS EA_CODE(PROTOCOL_NONE, 4) #define EA_CODE_MASK 0xffff #define EA_CUSTOM_BIT 0x8000 diff --git a/nest/rt-attr.c b/nest/rt-attr.c index c8ef8e08..09176632 100644 --- a/nest/rt-attr.c +++ b/nest/rt-attr.c @@ -823,8 +823,10 @@ ea_free(ea_list *o) } static int -get_generic_attr(const eattr *a, byte **buf, int buflen UNUSED) +get_generic_attr(const eattr *a, byte **buf, int buflen) { + byte *end = (*buf) + buflen; + switch (a->id) { case EA_GEN_IGP_METRIC: @@ -843,6 +845,13 @@ get_generic_attr(const eattr *a, byte **buf, int buflen UNUSED) *buf += bsprintf(*buf, "mpls_class"); return GA_NAME; + case EA_ASPA_PROVIDERS: + *buf += bsprintf(*buf, "aspa_providers"); + *(*buf)++ = ':'; + *(*buf)++ = ' '; + *buf += int_set_format(a->u.ptr, ISF_NUMBERS, -1, *buf, end - *buf); + return GA_FULL; + default: return GA_UNKNOWN; } @@ -1007,7 +1016,7 @@ ea_show(struct cli *c, const eattr *e) bsprintf(pos, "%08x", e->u.data); break; case EAF_TYPE_INT_SET: - ea_show_int_set(c, ad, 1, pos, buf, end); + ea_show_int_set(c, ad, ISF_COMMUNITY_LIST, pos, buf, end); return; case EAF_TYPE_EC_SET: ea_show_ec_set(c, ad, pos, buf, end); diff --git a/nest/rt-fib.c b/nest/rt-fib.c index 43e3039d..688d0b96 100644 --- a/nest/rt-fib.c +++ b/nest/rt-fib.c @@ -279,6 +279,7 @@ fib_find(struct fib *f, const net_addr *a) case NET_FLOW6: return FIB_FIND(f, a, flow6); case NET_IP6_SADR: return FIB_FIND(f, a, ip6_sadr); case NET_MPLS: return FIB_FIND(f, a, mpls); + case NET_ASPA: return FIB_FIND(f, a, aspa); default: bug("invalid type"); } } @@ -300,6 +301,7 @@ fib_insert(struct fib *f, const net_addr *a, struct fib_node *e) case NET_FLOW6: FIB_INSERT(f, a, e, flow6); return; case NET_IP6_SADR: FIB_INSERT(f, a, e, ip6_sadr); return; case NET_MPLS: FIB_INSERT(f, a, e, mpls); return; + case NET_ASPA: FIB_INSERT(f, a, e, aspa); return; default: bug("invalid type"); } } |