From 4c553c5a5b40c21ba67bd82455e79678b204cd07 Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Thu, 27 Dec 2018 14:26:11 +0100 Subject: Filter refactoring: dropped the recursion from the interpreter This is a major change of how the filters are interpreted. If everything works how it should, it should not affect you unless you are hacking the filters themselves. Anyway, this change should make a huge improvement in the filter performance as previous benchmarks showed that our major problem lies in the recursion itself. There are also some changes in nest and protocols, related mostly to spreading const declarations throughout the whole BIRD and also to refactored dynamic attribute definitions. The need of these came up during the whole work and it is too difficult to split out these not-so-related changes. --- sysdep/linux/krt-sys.h | 21 ------------------ sysdep/linux/netlink.Y | 58 ++++++++++++++++++++++++++------------------------ sysdep/linux/netlink.c | 9 +++++--- sysdep/unix/krt.Y | 4 ++-- 4 files changed, 38 insertions(+), 54 deletions(-) (limited to 'sysdep') diff --git a/sysdep/linux/krt-sys.h b/sysdep/linux/krt-sys.h index 2b8cdaa7..a8af4c95 100644 --- a/sysdep/linux/krt-sys.h +++ b/sysdep/linux/krt-sys.h @@ -65,27 +65,6 @@ static inline struct ifa * kif_get_primary_ip(struct iface *i UNUSED) { return N #define EA_KRT_INITRWND EA_CODE(PROTOCOL_KERNEL, 0x2e) #define EA_KRT_QUICKACK EA_CODE(PROTOCOL_KERNEL, 0x2f) -/* Bits of EA_KRT_LOCK, also based on RTAX_* constants */ -#define EA_KRT_LOCK_MTU EA_KRT_LOCK | EA_BIT(0x2) -#define EA_KRT_LOCK_WINDOW EA_KRT_LOCK | EA_BIT(0x3) -#define EA_KRT_LOCK_RTT EA_KRT_LOCK | EA_BIT(0x4) -#define EA_KRT_LOCK_RTTVAR EA_KRT_LOCK | EA_BIT(0x5) -#define EA_KRT_LOCK_SSTHRESH EA_KRT_LOCK | EA_BIT(0x6) -#define EA_KRT_LOCK_CWND EA_KRT_LOCK | EA_BIT(0x7) -#define EA_KRT_LOCK_ADVMSS EA_KRT_LOCK | EA_BIT(0x8) -#define EA_KRT_LOCK_REORDERING EA_KRT_LOCK | EA_BIT(0x9) -#define EA_KRT_LOCK_HOPLIMIT EA_KRT_LOCK | EA_BIT(0xa) -// define EA_KRT_LOCK_INITCWND EA_KRT_LOCK | EA_BIT(0xb) -// define EA_KRT_LOCK_FEATURES EA_KRT_LOCK | EA_BIT(0xc) -#define EA_KRT_LOCK_RTO_MIN EA_KRT_LOCK | EA_BIT(0xd) -// define EA_KRT_LOCK_INITRWND EA_KRT_LOCK | EA_BIT(0xe) - -/* Bits of EA_KRT_FEATURES, based on RTAX_FEATURE_* constants */ -#define EA_KRT_FEATURE_ECN EA_KRT_FEATURES | EA_BIT(0x0) -// define EA_KRT_FEATURE_SACK EA_KRT_FEATURES | EA_BIT(0x1) -// define EA_KRT_FEATURE_TSTAMP EA_KRT_FEATURES | EA_BIT(0x2) -#define EA_KRT_FEATURE_ALLFRAG EA_KRT_FEATURES | EA_BIT(0x3) - struct krt_params { u32 table_id; /* Kernel table ID we sync with */ diff --git a/sysdep/linux/netlink.Y b/sysdep/linux/netlink.Y index 1030e5d4..8f0a91c1 100644 --- a/sysdep/linux/netlink.Y +++ b/sysdep/linux/netlink.Y @@ -26,37 +26,39 @@ kern_sys_item: | METRIC expr { THIS_KRT->sys.metric = $2; } ; -dynamic_attr: KRT_PREFSRC { $$ = f_new_dynamic_attr(EAF_TYPE_IP_ADDRESS, T_IP, EA_KRT_PREFSRC); } ; -dynamic_attr: KRT_REALM { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_REALM); } ; -dynamic_attr: KRT_SCOPE { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_SCOPE); } ; +dynamic_attr: KRT_PREFSRC { $$ = f_new_dynamic_attr(EAF_TYPE_IP_ADDRESS, 0, T_IP, EA_KRT_PREFSRC); } ; +dynamic_attr: KRT_REALM { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_REALM); } ; +dynamic_attr: KRT_SCOPE { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_SCOPE); } ; -dynamic_attr: KRT_MTU { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_MTU); } ; -dynamic_attr: KRT_WINDOW { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_WINDOW); } ; -dynamic_attr: KRT_RTT { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_RTT); } ; -dynamic_attr: KRT_RTTVAR { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_RTTVAR); } ; -dynamic_attr: KRT_SSTRESH { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_SSTRESH); } ; -dynamic_attr: KRT_CWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_CWND); } ; -dynamic_attr: KRT_ADVMSS { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_ADVMSS); } ; -dynamic_attr: KRT_REORDERING { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_REORDERING); } ; -dynamic_attr: KRT_HOPLIMIT { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_HOPLIMIT); } ; -dynamic_attr: KRT_INITCWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_INITCWND); } ; -dynamic_attr: KRT_RTO_MIN { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_RTO_MIN); } ; -dynamic_attr: KRT_INITRWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_INITRWND); } ; -dynamic_attr: KRT_QUICKACK { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_QUICKACK); } ; +dynamic_attr: KRT_MTU { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_MTU); } ; +dynamic_attr: KRT_WINDOW { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_WINDOW); } ; +dynamic_attr: KRT_RTT { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_RTT); } ; +dynamic_attr: KRT_RTTVAR { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_RTTVAR); } ; +dynamic_attr: KRT_SSTRESH { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_SSTRESH); } ; +dynamic_attr: KRT_CWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_CWND); } ; +dynamic_attr: KRT_ADVMSS { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_ADVMSS); } ; +dynamic_attr: KRT_REORDERING { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_REORDERING); } ; +dynamic_attr: KRT_HOPLIMIT { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_HOPLIMIT); } ; +dynamic_attr: KRT_INITCWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_INITCWND); } ; +dynamic_attr: KRT_RTO_MIN { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_RTO_MIN); } ; +dynamic_attr: KRT_INITRWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_INITRWND); } ; +dynamic_attr: KRT_QUICKACK { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_QUICKACK); } ; -dynamic_attr: KRT_LOCK_MTU { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_MTU); } ; -dynamic_attr: KRT_LOCK_WINDOW { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_WINDOW); } ; -dynamic_attr: KRT_LOCK_RTT { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_RTT); } ; -dynamic_attr: KRT_LOCK_RTTVAR { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_RTTVAR); } ; -dynamic_attr: KRT_LOCK_SSTRESH { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_SSTHRESH); } ; -dynamic_attr: KRT_LOCK_CWND { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_CWND); } ; -dynamic_attr: KRT_LOCK_ADVMSS { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_ADVMSS); } ; -dynamic_attr: KRT_LOCK_REORDERING { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_REORDERING); } ; -dynamic_attr: KRT_LOCK_HOPLIMIT { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_HOPLIMIT); } ; -dynamic_attr: KRT_LOCK_RTO_MIN { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_LOCK_RTO_MIN); } ; +/* Bits of EA_KRT_LOCK, based on RTAX_* constants */ -dynamic_attr: KRT_FEATURE_ECN { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_FEATURE_ECN); } ; -dynamic_attr: KRT_FEATURE_ALLFRAG { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, T_BOOL, EA_KRT_FEATURE_ALLFRAG); } ; +dynamic_attr: KRT_LOCK_MTU { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 2, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_WINDOW { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 3, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_RTT { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 4, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_RTTVAR { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 5, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_SSTRESH { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 6, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_CWND { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 7, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_ADVMSS { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 8, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_REORDERING { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 9, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_HOPLIMIT { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 10, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_RTO_MIN { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 13, T_BOOL, EA_KRT_LOCK); } ; + +dynamic_attr: KRT_FEATURE_ECN { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 0, T_BOOL, EA_KRT_FEATURES); } ; +dynamic_attr: KRT_FEATURE_ALLFRAG { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 3, T_BOOL, EA_KRT_FEATURES); } ; CF_CODE diff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c index d773743d..e21f4039 100644 --- a/sysdep/linux/netlink.c +++ b/sysdep/linux/netlink.c @@ -1719,9 +1719,12 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h) ea->attrs[0].id = EA_KRT_PREFSRC; ea->attrs[0].flags = 0; ea->attrs[0].type = EAF_TYPE_IP_ADDRESS; - ea->attrs[0].u.ptr = lp_alloc(s->pool, sizeof(struct adata) + sizeof(ps)); - ea->attrs[0].u.ptr->length = sizeof(ps); - memcpy(ea->attrs[0].u.ptr->data, &ps, sizeof(ps)); + + struct adata *ad = lp_alloc(s->pool, sizeof(struct adata) + sizeof(ps)); + ad->length = sizeof(ps); + memcpy(ad->data, &ps, sizeof(ps)); + + ea->attrs[0].u.ptr = ad; } if (a[RTA_FLOW]) diff --git a/sysdep/unix/krt.Y b/sysdep/unix/krt.Y index 95b54d65..e3f6271c 100644 --- a/sysdep/unix/krt.Y +++ b/sysdep/unix/krt.Y @@ -122,8 +122,8 @@ kif_iface: kif_iface_start iface_patt_list_nopx kif_iface_opt_list; -dynamic_attr: KRT_SOURCE { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_SOURCE); } ; -dynamic_attr: KRT_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_METRIC); } ; +dynamic_attr: KRT_SOURCE { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_SOURCE); } ; +dynamic_attr: KRT_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_METRIC); } ; CF_CODE -- cgit v1.2.3 From 8bdb05edb2b4e1d2989ed98d67992047ad69443c Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Thu, 7 Feb 2019 21:25:38 +0100 Subject: Filters: split the large filter.h file to smaller files. This should be revised, there are still ugly things in the filter API. --- conf/cf-lex.l | 1 + filter/config.Y | 3 + filter/f-inst.h | 276 +++++++++++++++++++++++++-------------- filter/f-util.c | 2 +- filter/f-util.h | 151 ++++++++++++++++++++++ filter/filter.c | 36 +++++- filter/filter.h | 358 +-------------------------------------------------- filter/filter_test.c | 2 + filter/new.m4 | 2 +- filter/tree.c | 1 + filter/tree_test.c | 1 + filter/trie.c | 1 + filter/trie_test.c | 1 + nest/a-path.c | 2 +- nest/cmds.c | 1 + nest/rt-table.c | 1 + sysdep/unix/main.c | 1 + 17 files changed, 381 insertions(+), 459 deletions(-) create mode 100644 filter/f-util.h (limited to 'sysdep') diff --git a/conf/cf-lex.l b/conf/cf-lex.l index 5e7c8418..6cc09425 100644 --- a/conf/cf-lex.l +++ b/conf/cf-lex.l @@ -45,6 +45,7 @@ #include "nest/route.h" #include "nest/protocol.h" #include "filter/filter.h" +#include "filter/f-inst.h" #include "conf/conf.h" #include "conf/cf-parse.tab.h" #include "lib/string.h" diff --git a/filter/config.Y b/filter/config.Y index 1306849f..31ceb3f5 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -10,6 +10,9 @@ CF_HDR +#include "filter/f-inst.h" +#include "filter/f-util.h" + CF_DEFINES static inline u32 pair(u32 a, u32 b) { return (a << 16) | b; } diff --git a/filter/f-inst.h b/filter/f-inst.h index 5c3d1d58..63124aa1 100644 --- a/filter/f-inst.h +++ b/filter/f-inst.h @@ -1,76 +1,99 @@ /* * BIRD Internet Routing Daemon -- Filter instructions * + * (c) 1999 Pavel Machek * (c) 2018--2019 Maria Matejka * * Can be freely distributed and used under the terms of the GNU GPL. */ -/* Filter instruction words */ -#define FI__TWOCHAR(a,b) ((a<<8) | b) +#ifndef _BIRD_F_INST_H_ +#define _BIRD_F_INST_H_ + +#include "filter/filter.h" +#include "filter/f-util.h" + +/* Filter l-value type */ +enum f_lval_type { + F_LVAL_VARIABLE, + F_LVAL_PREFERENCE, + F_LVAL_SA, + F_LVAL_EA, +}; + +/* Filter l-value */ +struct f_lval { + enum f_lval_type type; + union { + const struct symbol *sym; + struct f_dynamic_attr da; + struct f_static_attr sa; + }; +}; + +/* Filter instruction declarations */ #define FI__LIST \ - F(FI_NOP, 0, '0') \ - F(FI_ADD, 0, '+') \ - F(FI_SUBTRACT, 0, '-') \ - F(FI_MULTIPLY, 0, '*') \ - F(FI_DIVIDE, 0, '/') \ - F(FI_AND, 0, '&') \ - F(FI_OR, 0, '|') \ - F(FI_PAIR_CONSTRUCT, 'm', 'p') \ - F(FI_EC_CONSTRUCT, 'm', 'c') \ - F(FI_LC_CONSTRUCT, 'm', 'l') \ - F(FI_PATHMASK_CONSTRUCT, 'm', 'P') \ - F(FI_NEQ, '!', '=') \ - F(FI_EQ, '=', '=') \ - F(FI_LT, 0, '<') \ - F(FI_LTE, '<', '=') \ - F(FI_NOT, 0, '!') \ - F(FI_MATCH, 0, '~') \ - F(FI_NOT_MATCH, '!', '~') \ - F(FI_DEFINED, 'd', 'e') \ - F(FI_TYPE, 0, 'T') \ - F(FI_IS_V4, 'I', 'i') \ - F(FI_SET, 0, 's') \ - F(FI_CONSTANT, 0, 'c') \ - F(FI_VARIABLE, 0, 'V') \ - F(FI_CONSTANT_INDIRECT, 0, 'C') \ - F(FI_PRINT, 0, 'p') \ - F(FI_CONDITION, 0, '?') \ - F(FI_PRINT_AND_DIE, 'p', ',') \ - F(FI_RTA_GET, 0, 'a') \ - F(FI_RTA_SET, 'a', 'S') \ - F(FI_EA_GET, 'e', 'a') \ - F(FI_EA_SET, 'e', 'S') \ - F(FI_PREF_GET, 0, 'P') \ - F(FI_PREF_SET, 'P', 'S') \ - F(FI_LENGTH, 0, 'L') \ - F(FI_ROA_MAXLEN, 'R', 'M') \ - F(FI_ROA_ASN, 'R', 'A') \ - F(FI_SADR_SRC, 'n', 's') \ - F(FI_IP, 'c', 'p') \ - F(FI_ROUTE_DISTINGUISHER, 'R', 'D') \ - F(FI_AS_PATH_FIRST, 'a', 'f') \ - F(FI_AS_PATH_LAST, 'a', 'l') \ - F(FI_AS_PATH_LAST_NAG, 'a', 'L') \ - F(FI_RETURN, 0, 'r') \ - F(FI_CALL, 'c', 'a') \ - F(FI_DROP_RESULT, 'd', 'r') \ - F(FI_CLEAR_LOCAL_VARS, 'c', 'V') \ - F(FI_SWITCH, 'S', 'W') \ - F(FI_IP_MASK, 'i', 'M') \ - F(FI_PATH_PREPEND, 'A', 'p') \ - F(FI_CLIST_ADD, 'C', 'a') \ - F(FI_CLIST_DEL, 'C', 'd') \ - F(FI_CLIST_FILTER, 'C', 'f') \ - F(FI_ROA_CHECK_IMPLICIT, 'R', 'i') \ - F(FI_ROA_CHECK_EXPLICIT, 'R', 'e') \ - F(FI_FORMAT, 0, 'F') \ - F(FI_ASSERT, 'a', 's') + F(FI_NOP) \ + F(FI_ADD, ARG, ARG) \ + F(FI_SUBTRACT, ARG, ARG) \ + F(FI_MULTIPLY, ARG, ARG) \ + F(FI_DIVIDE, ARG, ARG) \ + F(FI_AND, ARG, LINE) \ + F(FI_OR, ARG, LINE) \ + F(FI_PAIR_CONSTRUCT, ARG, ARG) \ + F(FI_EC_CONSTRUCT, ARG, ARG, ECS) \ + F(FI_LC_CONSTRUCT, ARG, ARG, ARG) \ + F(FI_PATHMASK_CONSTRUCT, ARG, COUNT) \ + F(FI_NEQ, ARG, ARG) \ + F(FI_EQ, ARG, ARG) \ + F(FI_LT, ARG, ARG) \ + F(FI_LTE, ARG, ARG) \ + F(FI_NOT, ARG) \ + F(FI_MATCH, ARG, ARG) \ + F(FI_NOT_MATCH, ARG, ARG) \ + F(FI_DEFINED, ARG) \ + F(FI_TYPE, ARG) \ + F(FI_IS_V4, ARG) \ + F(FI_SET, ARG, SYMBOL) \ + F(FI_CONSTANT, VALI) \ + F(FI_VARIABLE, SYMBOL) \ + F(FI_CONSTANT_INDIRECT, VALP) \ + F(FI_PRINT, ARG) \ + F(FI_CONDITION, ARG, LINE, LINE) \ + F(FI_PRINT_AND_DIE, ARG, FRET) \ + F(FI_RTA_GET, SA) \ + F(FI_RTA_SET, ARG, SA) \ + F(FI_EA_GET, EA) \ + F(FI_EA_SET, ARG, EA) \ + F(FI_EA_UNSET, EA) \ + F(FI_PREF_GET) \ + F(FI_PREF_SET, ARG) \ + F(FI_LENGTH, ARG) \ + F(FI_ROA_MAXLEN, ARG) \ + F(FI_ROA_ASN, ARG) \ + F(FI_SADR_SRC, ARG) \ + F(FI_IP, ARG) \ + F(FI_ROUTE_DISTINGUISHER, ARG) \ + F(FI_AS_PATH_FIRST, ARG) \ + F(FI_AS_PATH_LAST, ARG) \ + F(FI_AS_PATH_LAST_NAG, ARG) \ + F(FI_RETURN, ARG) \ + F(FI_CALL, SYMBOL, LINE) \ + F(FI_DROP_RESULT, ARG) \ + F(FI_SWITCH, ARG, TREE) \ + F(FI_IP_MASK, ARG, ARG) \ + F(FI_PATH_PREPEND, ARG, ARG) \ + F(FI_CLIST_ADD, ARG, ARG) \ + F(FI_CLIST_DEL, ARG, ARG) \ + F(FI_CLIST_FILTER, ARG, ARG) \ + F(FI_ROA_CHECK_IMPLICIT, RTC) \ + F(FI_ROA_CHECK_EXPLICIT, ARG, ARG, RTC) \ + F(FI_FORMAT, ARG) \ + F(FI_ASSERT, ARG, STRING) /* The enum itself */ enum f_instruction_code { -#define F(c,a,b) \ - c, +#define F(c, ...) c, FI__LIST #undef F FI__MAX, @@ -79,46 +102,107 @@ FI__LIST /* Convert the instruction back to the enum name */ const char *f_instruction_name(enum f_instruction_code fi); +struct f_inst; +void f_inst_next(struct f_inst *first, const struct f_inst *append); +struct f_inst *f_clear_local_vars(struct f_inst *decls); + +#define FIA(x) , FIA_##x +#define FIA_ARG const struct f_inst * +#define FIA_LINE const struct f_inst * +#define FIA_COUNT uint +#define FIA_SYMBOL const struct symbol * +#define FIA_VALI struct f_val +#define FIA_VALP const struct f_val * +#define FIA_FRET enum filter_return +#define FIA_ECS enum ec_subtype +#define FIA_SA struct f_static_attr +#define FIA_EA struct f_dynamic_attr +#define FIA_RTC const struct rtable_config * +#define FIA_TREE const struct f_tree * +#define FIA_STRING const char * +#define F(c, ...) \ + struct f_inst *f_new_inst_##c(enum f_instruction_code MACRO_IFELSE(MACRO_ISLAST(__VA_ARGS__))()(MACRO_FOREACH(FIA, __VA_ARGS__))); +FI__LIST +#undef F +#undef FIA_ARG +#undef FIA_LINE +#undef FIA_LINEP +#undef FIA_COUNT +#undef FIA_SYMBOL +#undef FIA_VALI +#undef FIA_VALP +#undef FIA_FRET +#undef FIA_ECS +#undef FIA_SA +#undef FIA_EA +#undef FIA_RTC +#undef FIA_STRING +#undef FIA + +#define f_new_inst(...) MACRO_CONCAT_AFTER(f_new_inst_, MACRO_FIRST(__VA_ARGS__))(__VA_ARGS__) + +/* Flags for instructions */ +enum f_instruction_flags { + FIF_PRINTED = 1, /* FI_PRINT_AND_DIE: message put in buffer */ +}; +/* Filter structures for execution */ +struct f_line; -/* Instruction structure for config */ -struct f_inst { - const struct f_inst *next; /* Next instruction to be executed */ - union { /* Instruction content */ - struct { /* Instruction code for dispatching purposes */ - enum f_instruction_code fi_code; - }; - +/* The single instruction item */ +struct f_line_item { + enum f_instruction_code fi_code; /* What to do */ + enum f_instruction_flags flags; /* Flags, instruction-specific */ + uint lineno; /* Where */ + union { struct { - enum f_instruction_code fi_code_a; - const struct f_inst *p[3]; /* Three arguments at most */ + const struct f_val *vp; + const struct symbol *sym; }; + struct f_val val; + const struct f_line *lines[2]; + enum filter_return fret; + struct f_static_attr sa; + struct f_dynamic_attr da; + enum ec_subtype ecs; + const char *s; + const struct f_tree *tree; + const struct rtable_config *rtc; + uint count; + }; /* Additional instruction data */ +}; - struct { - - - - struct { - enum f_instruction_code - - - - - enum f_iknst - u16 aux; /* Extension to instruction code, T_*, EA_*, EAF_* */ - union { +/* Line of instructions to be unconditionally executed one after another */ +struct f_line { + uint len; /* Line length */ + struct f_line_item items[0]; /* The items themselves */ +}; - union f_inst_attr a[3]; /* The three arguments */ - struct f_val val; /* The value if FI_CONSTANT */ - struct { - union f_inst_attr sa_a[1]; - struct f_static_attr sa; /* Static attribute def for FI_RTA_* */ - }; - struct { - union f_inst_attr da_a[1]; - struct f_dynamic_attr da; /* Dynamic attribute def for FI_EA_* */ - }; - }; - int lineno; +/* Convert the f_inst infix tree to the f_line structures */ +struct f_line *f_postfixify_concat(const struct f_inst * const inst[], uint count); +static inline struct f_line *f_postfixify(const struct f_inst *root) +{ return f_postfixify_concat(&root, 1); } + +struct filter *f_new_where(const struct f_inst *); +static inline struct f_dynamic_attr f_new_dynamic_attr(u8 type, u8 bit, enum f_type f_type, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */ +{ return (struct f_dynamic_attr) { .type = type, .bit = bit, .f_type = f_type, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */ +static inline struct f_static_attr f_new_static_attr(int f_type, int code, int readonly) +{ return (struct f_static_attr) { .f_type = f_type, .sa_code = code, .readonly = readonly }; } +struct f_inst *f_generate_complex(enum f_instruction_code fi_code, struct f_dynamic_attr da, struct f_inst *argument); +struct f_inst *f_generate_roa_check(struct rtable_config *table, struct f_inst *prefix, struct f_inst *asn); + +/* Hook for call bt_assert() function in configuration */ +extern void (*bt_assert_hook)(int result, const struct f_line_item *assert); + +/* Bird Tests */ +struct f_bt_test_suite { + node n; /* Node in config->tests */ + struct f_line *fn; /* Root of function */ + const char *fn_name; /* Name of test */ + const char *dsc; /* Description */ }; +/* Include the auto-generated structures */ +#include "filter/f-inst-struct.h" + +#endif diff --git a/filter/f-util.c b/filter/f-util.c index e94331b6..eb948fa0 100644 --- a/filter/f-util.c +++ b/filter/f-util.c @@ -10,7 +10,7 @@ #include "nest/bird.h" #include "conf/conf.h" #include "filter/filter.h" -#include "filter/f-inst-struct.h" +#include "filter/f-inst.h" #include "lib/idm.h" #include "nest/protocol.h" #include "nest/route.h" diff --git a/filter/f-util.h b/filter/f-util.h new file mode 100644 index 00000000..a7d77bbd --- /dev/null +++ b/filter/f-util.h @@ -0,0 +1,151 @@ +/* + * BIRD Internet Routing Daemon -- Filter utils + * + * (c) 1999 Pavel Machek + * (c) 2018--2019 Maria Matejka + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +#ifndef _BIRD_F_UTIL_H_ +#define _BIRD_F_UTIL_H_ + +/* IP prefix range structure */ +struct f_prefix { + net_addr net; /* The matching prefix must match this net */ + u8 lo, hi; /* And its length must fit between lo and hi */ +}; + +/* Type numbers must be in 0..0xff range */ +#define T_MASK 0xff + +/* Internal types */ +enum f_type { +/* Do not use type of zero, that way we'll see errors easier. */ + T_VOID = 1, + +/* User visible types, which fit in int */ + T_INT = 0x10, + T_BOOL = 0x11, + T_PAIR = 0x12, /* Notice that pair is stored as integer: first << 16 | second */ + T_QUAD = 0x13, + +/* Put enumerational types in 0x30..0x3f range */ + T_ENUM_LO = 0x30, + T_ENUM_HI = 0x3f, + + T_ENUM_RTS = 0x30, + T_ENUM_BGP_ORIGIN = 0x31, + T_ENUM_SCOPE = 0x32, + T_ENUM_RTC = 0x33, + T_ENUM_RTD = 0x34, + T_ENUM_ROA = 0x35, + T_ENUM_NETTYPE = 0x36, + T_ENUM_RA_PREFERENCE = 0x37, + +/* new enums go here */ + T_ENUM_EMPTY = 0x3f, /* Special hack for atomic_aggr */ + +#define T_ENUM T_ENUM_LO ... T_ENUM_HI + +/* Bigger ones */ + T_IP = 0x20, + T_NET = 0x21, + T_STRING = 0x22, + T_PATH_MASK = 0x23, /* mask for BGP path */ + T_PATH = 0x24, /* BGP path */ + T_CLIST = 0x25, /* Community list */ + T_EC = 0x26, /* Extended community value, u64 */ + T_ECLIST = 0x27, /* Extended community list */ + T_LC = 0x28, /* Large community value, lcomm */ + T_LCLIST = 0x29, /* Large community list */ + T_RD = 0x2a, /* Route distinguisher for VPN addresses */ + T_PATH_MASK_ITEM = 0x2b, /* Path mask item for path mask constructors */ + + T_SET = 0x80, + T_PREFIX_SET = 0x81, +} PACKED; + +/* Filter value; size of this affects filter memory consumption */ +struct f_val { + enum f_type type; /* T_* */ + union { + uint i; + u64 ec; + lcomm lc; + ip_addr ip; + const net_addr *net; + char *s; + const struct f_tree *t; + const struct f_trie *ti; + const struct adata *ad; + const struct f_path_mask *path_mask; + struct f_path_mask_item pmi; + } val; +}; + +#define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val)); + +/* Dynamic attribute definition (eattrs) */ +struct f_dynamic_attr { + u8 type; /* EA type (EAF_*) */ + u8 bit; /* For bitfield accessors */ + enum f_type f_type; /* Filter type */ + uint ea_code; /* EA code */ +}; + +enum f_sa_code { + SA_FROM = 1, + SA_GW, + SA_NET, + SA_PROTO, + SA_SOURCE, + SA_SCOPE, + SA_DEST, + SA_IFNAME, + SA_IFINDEX, +} PACKED; + +/* Static attribute definition (members of struct rta) */ +struct f_static_attr { + enum f_type f_type; /* Filter type */ + enum f_sa_code sa_code; /* Static attribute id */ + int readonly:1; /* Don't allow writing */ +}; + +struct f_tree { + struct f_tree *left, *right; + struct f_val from, to; + void *data; +}; + +struct f_trie_node +{ + ip_addr addr, mask, accept; + uint plen; + struct f_trie_node *c[2]; +}; + +struct f_trie +{ + linpool *lp; + int zero; + uint node_size; + struct f_trie_node root[0]; /* Root trie node follows */ +}; + +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); +void tree_format(const struct f_tree *t, buffer *buf); + +struct f_trie *f_new_trie(linpool *lp, uint node_size); +void *trie_add_prefix(struct f_trie *t, const net_addr *n, uint l, uint h); +int trie_match_net(const struct f_trie *t, const net_addr *n); +int trie_same(const struct f_trie *t1, const struct f_trie *t2); +void trie_format(const struct f_trie *t, buffer *buf); + +extern const struct f_val f_const_empty_path, f_const_empty_clist, f_const_empty_eclist, f_const_empty_lclist; + +#endif diff --git a/filter/filter.c b/filter/filter.c index bb5e4235..ff702f2b 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -47,7 +47,8 @@ #include "nest/attrs.h" #include "conf/conf.h" #include "filter/filter.h" -#include "filter/f-inst-struct.h" +#include "filter/f-inst.h" +#include "filter/f-util.h" #define CMP_ERROR 999 @@ -715,12 +716,39 @@ f_postfixify_concat(const struct f_inst * const inst[], uint count) static enum filter_return interpret(struct filter_state *fs, const struct f_line *line, struct f_val *val) { - struct f_val_stack vstk; + +#define F_VAL_STACK_MAX 4096 + /* Value stack for execution */ + struct f_val_stack { + uint cnt; /* Current stack size; 0 for empty */ + struct f_val val[F_VAL_STACK_MAX]; /* The stack itself */ + } vstk; + + /* The stack itself is intentionally kept as-is for performance reasons. + * Do NOT rewrite this to initialization by struct literal. It's slow. + */ vstk.cnt = 0; +#define F_EXEC_STACK_MAX 4096 + + /* Exception bits */ + enum f_exception { + FE_RETURN = 0x1, + }; - struct f_exec_stack estk; + /* Instruction stack for execution */ + struct f_exec_stack { + struct { + const struct f_line *line; /* The line that is being executed */ + uint pos; /* Instruction index in the line */ + uint ventry; /* Value stack depth on entry */ + enum f_exception emask; /* Exception mask */ + } item[F_EXEC_STACK_MAX]; + uint cnt; /* Current stack size; 0 for empty */ + } estk; + + /* The same as with the value stack. Not resetting the stack for performance reasons. */ estk.cnt = 1; - estk.item[0].line = line; + estk.item[0].line = line; estk.item[0].pos = 0; #define curline estk.item[estk.cnt-1] diff --git a/filter/filter.h b/filter/filter.h index 15a24fd4..9b3886fb 100644 --- a/filter/filter.h +++ b/filter/filter.h @@ -16,107 +16,6 @@ #include "nest/route.h" #include "nest/attrs.h" -/* IP prefix range structure */ -struct f_prefix { - net_addr net; /* The matching prefix must match this net */ - u8 lo, hi; /* And its length must fit between lo and hi */ -}; - -/* Type numbers must be in 0..0xff range */ -#define T_MASK 0xff - -/* Internal types */ -enum f_type { -/* Do not use type of zero, that way we'll see errors easier. */ - T_VOID = 1, - -/* User visible types, which fit in int */ - T_INT = 0x10, - T_BOOL = 0x11, - T_PAIR = 0x12, /* Notice that pair is stored as integer: first << 16 | second */ - T_QUAD = 0x13, - -/* Put enumerational types in 0x30..0x3f range */ - T_ENUM_LO = 0x30, - T_ENUM_HI = 0x3f, - - T_ENUM_RTS = 0x30, - T_ENUM_BGP_ORIGIN = 0x31, - T_ENUM_SCOPE = 0x32, - T_ENUM_RTC = 0x33, - T_ENUM_RTD = 0x34, - T_ENUM_ROA = 0x35, - T_ENUM_NETTYPE = 0x36, - T_ENUM_RA_PREFERENCE = 0x37, - -/* new enums go here */ - T_ENUM_EMPTY = 0x3f, /* Special hack for atomic_aggr */ - -#define T_ENUM T_ENUM_LO ... T_ENUM_HI - -/* Bigger ones */ - T_IP = 0x20, - T_NET = 0x21, - T_STRING = 0x22, - T_PATH_MASK = 0x23, /* mask for BGP path */ - T_PATH = 0x24, /* BGP path */ - T_CLIST = 0x25, /* Community list */ - T_EC = 0x26, /* Extended community value, u64 */ - T_ECLIST = 0x27, /* Extended community list */ - T_LC = 0x28, /* Large community value, lcomm */ - T_LCLIST = 0x29, /* Large community list */ - T_RD = 0x2a, /* Route distinguisher for VPN addresses */ - T_PATH_MASK_ITEM = 0x2b, /* Path mask item for path mask constructors */ - - T_SET = 0x80, - T_PREFIX_SET = 0x81, -} PACKED; - -/* Filter value; size of this affects filter memory consumption */ -struct f_val { - enum f_type type; /* T_* */ - union { - uint i; - u64 ec; - lcomm lc; - ip_addr ip; - const net_addr *net; - char *s; - const struct f_tree *t; - const struct f_trie *ti; - const struct adata *ad; - const struct f_path_mask *path_mask; - struct f_path_mask_item pmi; - } val; -}; - -/* Dynamic attribute definition (eattrs) */ -struct f_dynamic_attr { - u8 type; /* EA type (EAF_*) */ - u8 bit; /* For bitfield accessors */ - enum f_type f_type; /* Filter type */ - uint ea_code; /* EA code */ -}; - -enum f_sa_code { - SA_FROM = 1, - SA_GW, - SA_NET, - SA_PROTO, - SA_SOURCE, - SA_SCOPE, - SA_DEST, - SA_IFNAME, - SA_IFINDEX, -} PACKED; - -/* Static attribute definition (members of struct rta) */ -struct f_static_attr { - enum f_type f_type; /* Filter type */ - enum f_sa_code sa_code; /* Static attribute id */ - int readonly:1; /* Don't allow writing */ -}; - /* Possible return values of filter execution */ enum filter_return { F_NOP = 0, @@ -128,230 +27,15 @@ enum filter_return { F_QUITBIRD, }; -/* Filter l-value type */ -enum f_lval_type { - F_LVAL_VARIABLE, - F_LVAL_PREFERENCE, - F_LVAL_SA, - F_LVAL_EA, -}; - -/* Filter l-value */ -struct f_lval { - enum f_lval_type type; - union { - const struct symbol *sym; - struct f_dynamic_attr da; - struct f_static_attr sa; - }; -}; - -/* Filter instruction declarations */ -#define FI__LIST \ - F(FI_NOP) \ - F(FI_ADD, ARG, ARG) \ - F(FI_SUBTRACT, ARG, ARG) \ - F(FI_MULTIPLY, ARG, ARG) \ - F(FI_DIVIDE, ARG, ARG) \ - F(FI_AND, ARG, LINE) \ - F(FI_OR, ARG, LINE) \ - F(FI_PAIR_CONSTRUCT, ARG, ARG) \ - F(FI_EC_CONSTRUCT, ARG, ARG, ECS) \ - F(FI_LC_CONSTRUCT, ARG, ARG, ARG) \ - F(FI_PATHMASK_CONSTRUCT, ARG, COUNT) \ - F(FI_NEQ, ARG, ARG) \ - F(FI_EQ, ARG, ARG) \ - F(FI_LT, ARG, ARG) \ - F(FI_LTE, ARG, ARG) \ - F(FI_NOT, ARG) \ - F(FI_MATCH, ARG, ARG) \ - F(FI_NOT_MATCH, ARG, ARG) \ - F(FI_DEFINED, ARG) \ - F(FI_TYPE, ARG) \ - F(FI_IS_V4, ARG) \ - F(FI_SET, ARG, SYMBOL) \ - F(FI_CONSTANT, VALI) \ - F(FI_VARIABLE, SYMBOL) \ - F(FI_CONSTANT_INDIRECT, VALP) \ - F(FI_PRINT, ARG) \ - F(FI_CONDITION, ARG, LINE, LINE) \ - F(FI_PRINT_AND_DIE, ARG, FRET) \ - F(FI_RTA_GET, SA) \ - F(FI_RTA_SET, ARG, SA) \ - F(FI_EA_GET, EA) \ - F(FI_EA_SET, ARG, EA) \ - F(FI_EA_UNSET, EA) \ - F(FI_PREF_GET) \ - F(FI_PREF_SET, ARG) \ - F(FI_LENGTH, ARG) \ - F(FI_ROA_MAXLEN, ARG) \ - F(FI_ROA_ASN, ARG) \ - F(FI_SADR_SRC, ARG) \ - F(FI_IP, ARG) \ - F(FI_ROUTE_DISTINGUISHER, ARG) \ - F(FI_AS_PATH_FIRST, ARG) \ - F(FI_AS_PATH_LAST, ARG) \ - F(FI_AS_PATH_LAST_NAG, ARG) \ - F(FI_RETURN, ARG) \ - F(FI_CALL, SYMBOL, LINE) \ - F(FI_DROP_RESULT, ARG) \ - F(FI_SWITCH, ARG, TREE) \ - F(FI_IP_MASK, ARG, ARG) \ - F(FI_PATH_PREPEND, ARG, ARG) \ - F(FI_CLIST_ADD, ARG, ARG) \ - F(FI_CLIST_DEL, ARG, ARG) \ - F(FI_CLIST_FILTER, ARG, ARG) \ - F(FI_ROA_CHECK_IMPLICIT, RTC) \ - F(FI_ROA_CHECK_EXPLICIT, ARG, ARG, RTC) \ - F(FI_FORMAT, ARG) \ - F(FI_ASSERT, ARG, STRING) - -/* The enum itself */ -enum f_instruction_code { -#define F(c, ...) c, -FI__LIST -#undef F - FI__MAX, -} PACKED; - -/* Convert the instruction back to the enum name */ -const char *f_instruction_name(enum f_instruction_code fi); - -struct f_inst; -void f_inst_next(struct f_inst *first, const struct f_inst *append); -struct f_inst *f_clear_local_vars(struct f_inst *decls); - -#define FIA(x) , FIA_##x -#define FIA_ARG const struct f_inst * -#define FIA_LINE const struct f_inst * -#define FIA_COUNT uint -#define FIA_SYMBOL const struct symbol * -#define FIA_VALI struct f_val -#define FIA_VALP const struct f_val * -#define FIA_FRET enum filter_return -#define FIA_ECS enum ec_subtype -#define FIA_SA struct f_static_attr -#define FIA_EA struct f_dynamic_attr -#define FIA_RTC const struct rtable_config * -#define FIA_TREE const struct f_tree * -#define FIA_STRING const char * -#define F(c, ...) \ - struct f_inst *f_new_inst_##c(enum f_instruction_code MACRO_IFELSE(MACRO_ISLAST(__VA_ARGS__))()(MACRO_FOREACH(FIA, __VA_ARGS__))); -FI__LIST -#undef F -#undef FIA_ARG -#undef FIA_LINE -#undef FIA_LINEP -#undef FIA_COUNT -#undef FIA_SYMBOL -#undef FIA_VALI -#undef FIA_VALP -#undef FIA_FRET -#undef FIA_ECS -#undef FIA_SA -#undef FIA_EA -#undef FIA_RTC -#undef FIA_STRING -#undef FIA - -#define f_new_inst(...) MACRO_CONCAT_AFTER(f_new_inst_, MACRO_FIRST(__VA_ARGS__))(__VA_ARGS__) - -/* Flags for instructions */ -enum f_instruction_flags { - FIF_PRINTED = 1, /* FI_PRINT_AND_DIE: message put in buffer */ -}; - -/* Filter structures for execution */ -struct f_line; - -/* The single instruction item */ -struct f_line_item { - enum f_instruction_code fi_code; /* What to do */ - enum f_instruction_flags flags; /* Flags, instruction-specific */ - uint lineno; /* Where */ - union { - struct { - const struct f_val *vp; - const struct symbol *sym; - }; - struct f_val val; - const struct f_line *lines[2]; - enum filter_return fret; - struct f_static_attr sa; - struct f_dynamic_attr da; - enum ec_subtype ecs; - const char *s; - const struct f_tree *tree; - const struct rtable_config *rtc; - uint count; - }; /* Additional instruction data */ -}; - -/* Line of instructions to be unconditionally executed one after another */ -struct f_line { - uint len; /* Line length */ - struct f_line_item items[0]; /* The items themselves */ -}; +struct f_val; /* The filter encapsulating structure to be pointed-to from outside */ +struct f_line; struct filter { char *name; struct f_line *root; }; -/* Convert the f_inst infix tree to the f_line structures */ -struct f_line *f_postfixify_concat(const struct f_inst * const inst[], uint count); -static inline struct f_line *f_postfixify(const struct f_inst *root) -{ return f_postfixify_concat(&root, 1); } - -#define F_VAL_STACK_MAX 4096 - -/* Value stack for execution */ -struct f_val_stack { - uint cnt; /* Current stack size; 0 for empty */ - struct f_val val[F_VAL_STACK_MAX]; /* The stack itself */ -}; - -#define F_EXEC_STACK_MAX 4096 - -/* Exception bits */ -enum f_exception { - FE_RETURN = 0x1, -}; - -/* Instruction stack for execution */ -struct f_exec_stack { - struct { - const struct f_line *line; /* The line that is being executed */ - uint pos; /* Instruction index in the line */ - uint ventry; /* Value stack depth on entry */ - enum f_exception emask; /* Exception mask */ - } item[F_EXEC_STACK_MAX]; - uint cnt; /* Current stack size; 0 for empty */ -}; - -struct filter *f_new_where(const struct f_inst *); -static inline struct f_dynamic_attr f_new_dynamic_attr(u8 type, u8 bit, enum f_type f_type, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */ -{ return (struct f_dynamic_attr) { .type = type, .bit = bit, .f_type = f_type, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */ -static inline struct f_static_attr f_new_static_attr(int f_type, int code, int readonly) -{ return (struct f_static_attr) { .f_type = f_type, .sa_code = code, .readonly = readonly }; } -struct f_tree *f_new_tree(void); -struct f_inst *f_generate_complex(enum f_instruction_code fi_code, struct f_dynamic_attr da, struct f_inst *argument); -struct f_inst *f_generate_roa_check(struct rtable_config *table, struct f_inst *prefix, struct f_inst *asn); - - -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 *t1, const struct f_tree *t2); -void tree_format(const struct f_tree *t, buffer *buf); - -struct f_trie *f_new_trie(linpool *lp, uint node_size); -void *trie_add_prefix(struct f_trie *t, const net_addr *n, uint l, uint h); -int trie_match_net(const struct f_trie *t, const net_addr *n); -int trie_same(const struct f_trie *t1, const struct f_trie *t2); -void trie_format(const struct f_trie *t, buffer *buf); - -struct ea_list; struct rte; enum filter_return f_run(const struct filter *filter, struct rte **rte, struct linpool *tmp_pool, int flags); @@ -361,43 +45,16 @@ uint f_eval_int(const struct f_line *expr); char *filter_name(struct filter *filter); int filter_same(struct filter *new, struct filter *old); - int f_same(const struct f_line *f1, const struct f_line *f2); int val_compare(const struct f_val *v1, const struct f_val *v2); void val_format(const struct f_val *v, buffer *buf); -extern const struct f_val f_const_empty_path, f_const_empty_clist, f_const_empty_eclist, f_const_empty_lclist; - #define FILTER_ACCEPT NULL #define FILTER_REJECT ((void *) 1) #define FILTER_UNDEF ((void *) 2) /* Used in BGP */ - -struct f_tree { - struct f_tree *left, *right; - struct f_val from, to; - void *data; -}; - -struct f_trie_node -{ - ip_addr addr, mask, accept; - uint plen; - struct f_trie_node *c[2]; -}; - -struct f_trie -{ - linpool *lp; - int zero; - uint node_size; - struct f_trie_node root[0]; /* Root trie node follows */ -}; - -#define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val)); - #define FF_SILENT 2 /* Silent filter execution */ /* Custom route attributes */ @@ -409,15 +66,4 @@ struct custom_attribute { struct custom_attribute *ca_lookup(pool *p, const char *name, int ea_type); -/* Bird Tests */ -struct f_bt_test_suite { - node n; /* Node in config->tests */ - struct f_line *fn; /* Root of function */ - const char *fn_name; /* Name of test */ - const char *dsc; /* Description */ -}; - -/* Hook for call bt_assert() function in configuration */ -extern void (*bt_assert_hook)(int result, const struct f_line_item *assert); - #endif diff --git a/filter/filter_test.c b/filter/filter_test.c index af6b590f..54ea3e9b 100644 --- a/filter/filter_test.c +++ b/filter/filter_test.c @@ -17,6 +17,8 @@ #include "test/bt-utils.h" #include "filter/filter.h" +#include "filter/f-util.h" +#include "filter/f-inst.h" #include "conf/conf.h" #define BT_CONFIG_FILE "filter/test.conf" diff --git a/filter/new.m4 b/filter/new.m4 index d499c94b..38295e5c 100644 --- a/filter/new.m4 +++ b/filter/new.m4 @@ -69,7 +69,7 @@ m4_divert(0) #include "nest/bird.h" #include "conf/conf.h" #include "filter/filter.h" -#include "filter/f-inst-struct.h" +#include "filter/f-inst.h" m4_undivert(1) diff --git a/filter/tree.c b/filter/tree.c index 80e1d395..879b0859 100644 --- a/filter/tree.c +++ b/filter/tree.c @@ -10,6 +10,7 @@ #include "nest/bird.h" #include "conf/conf.h" #include "filter/filter.h" +#include "filter/f-util.h" /** * find_tree diff --git a/filter/tree_test.c b/filter/tree_test.c index f3e8ce49..9e0de50f 100644 --- a/filter/tree_test.c +++ b/filter/tree_test.c @@ -10,6 +10,7 @@ #include "test/bt-utils.h" #include "filter/filter.h" +#include "filter/f-util.h" #include "conf/conf.h" #define MAX_TREE_HEIGHT 13 diff --git a/filter/trie.c b/filter/trie.c index a279e38c..dccf9130 100644 --- a/filter/trie.c +++ b/filter/trie.c @@ -73,6 +73,7 @@ #include "lib/string.h" #include "conf/conf.h" #include "filter/filter.h" +#include "filter/f-util.h" /* diff --git a/filter/trie_test.c b/filter/trie_test.c index 7529a5c5..b6959c4a 100644 --- a/filter/trie_test.c +++ b/filter/trie_test.c @@ -10,6 +10,7 @@ #include "test/bt-utils.h" #include "filter/filter.h" +#include "filter/f-util.h" #include "conf/conf.h" #define TESTS_NUM 10 diff --git a/nest/a-path.c b/nest/a-path.c index d3a1d636..ac13d0fa 100644 --- a/nest/a-path.c +++ b/nest/a-path.c @@ -13,7 +13,7 @@ #include "lib/resource.h" #include "lib/unaligned.h" #include "lib/string.h" -#include "filter/filter.h" +#include "filter/f-util.h" // static inline void put_as(byte *data, u32 as) { put_u32(data, as); } // static inline u32 get_as(byte *data) { return get_u32(data); } diff --git a/nest/cmds.c b/nest/cmds.c index 6daafcb3..40d397cc 100644 --- a/nest/cmds.c +++ b/nest/cmds.c @@ -15,6 +15,7 @@ #include "lib/string.h" #include "lib/resource.h" #include "filter/filter.h" +#include "filter/f-util.h" extern int shutting_down; extern int configuring; diff --git a/nest/rt-table.c b/nest/rt-table.c index 85afe838..d72a8695 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -39,6 +39,7 @@ #include "lib/string.h" #include "conf/conf.h" #include "filter/filter.h" +#include "filter/f-util.h" #include "lib/hash.h" #include "lib/string.h" #include "lib/alloca.h" diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index 921115b1..f9002d58 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -36,6 +36,7 @@ #include "nest/locks.h" #include "conf/conf.h" #include "filter/filter.h" +#include "filter/f-util.h" #include "unix.h" #include "krt.h" -- cgit v1.2.3 From 4f082dfa892e95f86ca8137410992a248110b6ef Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Fri, 8 Feb 2019 13:38:12 +0100 Subject: Filter: merged filter instruction constructors, counting line size on instruction construct --- configure.ac | 8 ++- filter/Makefile | 12 +--- filter/config.Y | 24 +++---- filter/data.h | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++ filter/decl.m4 | 128 ++++++++++++++++++++++++++++++++++++++ filter/f-inst.c | 36 +++++------ filter/f-inst.h | 131 ++------------------------------------ filter/f-util.c | 19 +----- filter/f-util.h | 151 -------------------------------------------- filter/filter.c | 86 ++++++++++++++++++++----- filter/filter_test.c | 2 +- filter/interpret.m4 | 7 ++- filter/line-size.m4 | 41 ------------ filter/new.m4 | 78 ----------------------- filter/struct.m4 | 73 ---------------------- filter/tree.c | 2 +- filter/tree_test.c | 2 +- filter/trie.c | 2 +- filter/trie_test.c | 2 +- nest/a-path.c | 2 +- nest/cmds.c | 2 +- nest/rt-table.c | 2 +- proto/static/config.Y | 2 +- sysdep/unix/main.c | 2 +- 24 files changed, 432 insertions(+), 551 deletions(-) create mode 100644 filter/data.h create mode 100644 filter/decl.m4 delete mode 100644 filter/f-util.h delete mode 100644 filter/line-size.m4 delete mode 100644 filter/new.m4 delete mode 100644 filter/struct.m4 (limited to 'sysdep') diff --git a/configure.ac b/configure.ac index 33bc9101..850e771f 100644 --- a/configure.ac +++ b/configure.ac @@ -18,6 +18,12 @@ AC_ARG_ENABLE([debug], [enable_debug=no] ) +AC_ARG_ENABLE([debug-generated], + [AS_HELP_STRING([--enable-debug-generated], [enable this to abstain from generating #line @<:@no@:>@])], + [], + [enable_debug_generated=no] +) + AC_ARG_ENABLE([memcheck], [AS_HELP_STRING([--enable-memcheck], [check memory allocations when debugging @<:@yes@:>@])], [], @@ -156,7 +162,7 @@ test -z "$M4" && AC_MSG_ERROR([M4 is missing.]) AC_MSG_CHECKING([bison version]) BIRD_CHECK_BISON_VERSION(BISON_VERSION) AC_MSG_RESULT([$BISON_VERSION]) -if test "$bird_bison_synclines" = yes; then +if test "$bird_bison_synclines" = yes && test "$enable_debug_generated" = no; then M4FLAGS="$M4FLAGS -s" fi diff --git a/filter/Makefile b/filter/Makefile index 15f2c3d0..f5f50045 100644 --- a/filter/Makefile +++ b/filter/Makefile @@ -1,13 +1,10 @@ -src := filter.c f-util.c tree.c trie.c f-inst-new.c +src := filter.c f-util.c tree.c trie.c obj := $(src-o-files) $(all-daemon) $(cf-local) M4FLAGS_FILTERS=$(filter-out -s,$(M4FLAGS)) -$(o)f-inst-line-size.c: $(s)line-size.m4 $(s)f-inst.c $(objdir)/.dir-stamp - $(M4) $(M4FLAGS_FILTERS) -P $^ >$@ - $(o)f-inst-postfixify.c: $(s)postfixify.m4 $(s)f-inst.c $(objdir)/.dir-stamp $(M4) $(M4FLAGS_FILTERS) -P $^ >$@ @@ -17,16 +14,13 @@ $(o)f-inst-interpret.c: $(s)interpret.m4 $(s)f-inst.c $(objdir)/.dir-stamp $(o)f-inst-same.c: $(s)same.m4 $(s)f-inst.c $(objdir)/.dir-stamp $(M4) $(M4FLAGS_FILTERS) -P $^ >$@ -$(o)f-inst-struct.h: $(s)struct.m4 $(s)f-inst.c $(objdir)/.dir-stamp - $(M4) $(M4FLAGS_FILTERS) -P $^ >$@ - -$(o)f-inst-new.c: $(s)new.m4 $(s)f-inst.c $(objdir)/.dir-stamp +$(o)f-inst-decl.h: $(s)decl.m4 $(s)f-inst.c $(objdir)/.dir-stamp $(M4) $(M4FLAGS_FILTERS) -P $^ >$@ $(o)f-inst-dump.c: $(s)dump.m4 $(s)f-inst.c $(objdir)/.dir-stamp $(M4) $(M4FLAGS_FILTERS) -P $^ >$@ -$(o)filter.o: $(o)f-inst-interpret.c $(o)f-inst-line-size.c $(o)f-inst-postfixify.c $(o)f-inst-same.c $(o)f-inst-dump.c $(o)f-inst-struct.h +$(o)filter.o: $(o)f-inst-interpret.c $(o)f-inst-postfixify.c $(o)f-inst-same.c $(o)f-inst-dump.c $(o)f-inst-decl.h tests_src := tree_test.c filter_test.c trie_test.c tests_targets := $(tests_targets) $(tests-target-files) diff --git a/filter/config.Y b/filter/config.Y index 31ceb3f5..42624f44 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -11,7 +11,7 @@ CF_HDR #include "filter/f-inst.h" -#include "filter/f-util.h" +#include "filter/data.h" CF_DEFINES @@ -418,7 +418,7 @@ assert_assign(struct f_lval *lval, struct f_inst *expr, const char *start, const } checker = f_new_inst(FI_EQ, expr, getter); - f_inst_next(setter, checker); + setter->next = checker; return assert_done(setter, start, end); } @@ -550,7 +550,7 @@ one_decl: decls: /* EMPTY */ { $$ = NULL; } | one_decl ';' decls { $$ = $1; - f_inst_next($$, $3); + $$->next = $3; } ; @@ -559,7 +559,7 @@ declsn: one_decl { $$.inst = $1; $$.count = 1; } | one_decl ';' declsn { $$ = $3; $$.count++; - f_inst_next($$.inst, $1); + $$.inst->next = $1; } ; @@ -640,7 +640,7 @@ cmds: /* EMPTY */ { $$ = NULL; } ; cmds_int: cmd { $$[0] = $$[1] = $1; } - | cmds_int cmd { $$[1] = $2; f_inst_next($1[1], $2); $$[0] = $1[0]; } + | cmds_int cmd { $$[1] = $2; $1[1]->next = $2; $$[0] = $1[0]; } ; block: @@ -803,11 +803,11 @@ bgp_path: ; bgp_path_tail: - NUM bgp_path_tail { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_PATH_MASK_ITEM, .val.pmi = { .asn = $1, .kind = PM_ASN, }, }); f_inst_next($$, $2); } - | NUM DDOT NUM bgp_path_tail { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_PATH_MASK_ITEM, .val.pmi = { .from = $1, .to = $3, .kind = PM_ASN_RANGE }, }); f_inst_next($$, $4); } - | '*' bgp_path_tail { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_PATH_MASK_ITEM, .val.pmi = { .kind = PM_ASTERISK }, }); f_inst_next($$, $2); } - | '?' bgp_path_tail { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_PATH_MASK_ITEM, .val.pmi = { .kind = PM_QUESTION }, }); f_inst_next($$, $2); } - | bgp_path_expr bgp_path_tail { $$ = $1; f_inst_next($$, $2); } + NUM bgp_path_tail { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_PATH_MASK_ITEM, .val.pmi = { .asn = $1, .kind = PM_ASN, }, }); $$->next = $2; } + | NUM DDOT NUM bgp_path_tail { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_PATH_MASK_ITEM, .val.pmi = { .from = $1, .to = $3, .kind = PM_ASN_RANGE }, }); $$->next = $4; } + | '*' bgp_path_tail { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_PATH_MASK_ITEM, .val.pmi = { .kind = PM_ASTERISK }, }); $$->next = $2; } + | '?' bgp_path_tail { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_PATH_MASK_ITEM, .val.pmi = { .kind = PM_QUESTION }, }); $$->next = $2; } + | bgp_path_expr bgp_path_tail { $$ = $1; $$->next = $2; } | { $$ = NULL; } ; @@ -946,7 +946,7 @@ print_list: /* EMPTY */ { $$ = NULL; } | print_one { $$ = $1; } | print_one ',' print_list { if ($1) { - f_inst_next($1, $3); + $1->next = $3; $$ = $1; } else $$ = $3; } @@ -957,7 +957,7 @@ var_listn: term { } | term ',' var_listn { $$ = $1; - f_inst_next($$, $3); + $$->next = $3; } ; diff --git a/filter/data.h b/filter/data.h new file mode 100644 index 00000000..58db3e44 --- /dev/null +++ b/filter/data.h @@ -0,0 +1,169 @@ +/* + * BIRD Internet Routing Daemon -- Dynamic data structures + * + * (c) 1999 Pavel Machek + * (c) 2018--2019 Maria Matejka + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +#ifndef _BIRD_FILTER_DATA_H_ +#define _BIRD_FILTER_DATA_H_ + +#include "nest/bird.h" + +/* Type numbers must be in 0..0xff range */ +#define T_MASK 0xff + +/* Internal types */ +enum f_type { +/* Do not use type of zero, that way we'll see errors easier. */ + T_VOID = 1, + +/* User visible types, which fit in int */ + T_INT = 0x10, + T_BOOL = 0x11, + T_PAIR = 0x12, /* Notice that pair is stored as integer: first << 16 | second */ + T_QUAD = 0x13, + +/* Put enumerational types in 0x30..0x3f range */ + T_ENUM_LO = 0x30, + T_ENUM_HI = 0x3f, + + T_ENUM_RTS = 0x30, + T_ENUM_BGP_ORIGIN = 0x31, + T_ENUM_SCOPE = 0x32, + T_ENUM_RTC = 0x33, + T_ENUM_RTD = 0x34, + T_ENUM_ROA = 0x35, + T_ENUM_NETTYPE = 0x36, + T_ENUM_RA_PREFERENCE = 0x37, + +/* new enums go here */ + T_ENUM_EMPTY = 0x3f, /* Special hack for atomic_aggr */ + +#define T_ENUM T_ENUM_LO ... T_ENUM_HI + +/* Bigger ones */ + T_IP = 0x20, + T_NET = 0x21, + T_STRING = 0x22, + T_PATH_MASK = 0x23, /* mask for BGP path */ + T_PATH = 0x24, /* BGP path */ + T_CLIST = 0x25, /* Community list */ + T_EC = 0x26, /* Extended community value, u64 */ + T_ECLIST = 0x27, /* Extended community list */ + T_LC = 0x28, /* Large community value, lcomm */ + T_LCLIST = 0x29, /* Large community list */ + T_RD = 0x2a, /* Route distinguisher for VPN addresses */ + T_PATH_MASK_ITEM = 0x2b, /* Path mask item for path mask constructors */ + + T_SET = 0x80, + T_PREFIX_SET = 0x81, +} PACKED; + +/* Filter value; size of this affects filter memory consumption */ +struct f_val { + enum f_type type; /* T_* */ + union { + uint i; + u64 ec; + lcomm lc; + ip_addr ip; + const net_addr *net; + char *s; + const struct f_tree *t; + const struct f_trie *ti; + const struct adata *ad; + const struct f_path_mask *path_mask; + struct f_path_mask_item pmi; + } val; +}; + +/* Dynamic attribute definition (eattrs) */ +struct f_dynamic_attr { + u8 type; /* EA type (EAF_*) */ + u8 bit; /* For bitfield accessors */ + enum f_type f_type; /* Filter type */ + uint ea_code; /* EA code */ +}; + +enum f_sa_code { + SA_FROM = 1, + SA_GW, + SA_NET, + SA_PROTO, + SA_SOURCE, + SA_SCOPE, + SA_DEST, + SA_IFNAME, + SA_IFINDEX, +} PACKED; + +/* Static attribute definition (members of struct rta) */ +struct f_static_attr { + enum f_type f_type; /* Filter type */ + enum f_sa_code sa_code; /* Static attribute id */ + int readonly:1; /* Don't allow writing */ +}; + +/* Filter l-value type */ +enum f_lval_type { + F_LVAL_VARIABLE, + F_LVAL_PREFERENCE, + F_LVAL_SA, + F_LVAL_EA, +}; + +/* Filter l-value */ +struct f_lval { + enum f_lval_type type; + union { + const struct symbol *sym; + struct f_dynamic_attr da; + struct f_static_attr sa; + }; +}; + +/* IP prefix range structure */ +struct f_prefix { + net_addr net; /* The matching prefix must match this net */ + u8 lo, hi; /* And its length must fit between lo and hi */ +}; + +struct f_tree { + struct f_tree *left, *right; + struct f_val from, to; + void *data; +}; + +struct f_trie_node +{ + ip_addr addr, mask, accept; + uint plen; + struct f_trie_node *c[2]; +}; + +struct f_trie +{ + linpool *lp; + int zero; + uint node_size; + struct f_trie_node root[0]; /* Root trie node follows */ +}; + +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); +void tree_format(const struct f_tree *t, buffer *buf); + +struct f_trie *f_new_trie(linpool *lp, uint node_size); +void *trie_add_prefix(struct f_trie *t, const net_addr *n, uint l, uint h); +int trie_match_net(const struct f_trie *t, const net_addr *n); +int trie_same(const struct f_trie *t1, const struct f_trie *t2); +void trie_format(const struct f_trie *t, buffer *buf); + +extern const struct f_val f_const_empty_path, f_const_empty_clist, f_const_empty_eclist, f_const_empty_lclist; + +#endif diff --git a/filter/decl.m4 b/filter/decl.m4 new file mode 100644 index 00000000..bdbb3e27 --- /dev/null +++ b/filter/decl.m4 @@ -0,0 +1,128 @@ +m4_divert(-1)m4_dnl +# +# BIRD -- Construction of per-instruction structures +# +# (c) 2018 Maria Matejka +# +# Can be freely distributed and used under the terms of the GNU GPL. +# +# +# Global Diversions: +# 4 enum fi_code +# 1 struct f_inst_FI_... +# 2 union in struct f_inst +# 3 constructors +# +# Per-inst Diversions: +# 11 content of struct f_inst_FI_... +# 12 constructor arguments +# 13 constructor body + +# Flush the completed instruction + +m4_define(FID_END, `m4_divert(-1)') + +m4_define(FID_ZONE, `m4_divert($1) /* $2 for INST_NAME() */') +m4_define(FID_STRUCT, `FID_ZONE(1, Per-instruction structure)') +m4_define(FID_UNION, `FID_ZONE(2, Union member)') +m4_define(FID_NEW, `FID_ZONE(3, Constructor)') +m4_define(FID_ENUM, `FID_ZONE(4, Code enum)') + +m4_define(FID_STRUCT_IN, `m4_divert(101)') +m4_define(FID_NEW_ARGS, `m4_divert(102)') +m4_define(FID_NEW_BODY, `m4_divert(103)') + +m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[ +FID_ENUM +INST_NAME(), +FID_STRUCT +struct f_inst_[[]]INST_NAME() { +m4_undivert(101) +}; +FID_UNION +struct f_inst_[[]]INST_NAME() i_[[]]INST_NAME(); +FID_NEW +static inline struct f_inst *f_new_inst_]]INST_NAME()[[(enum f_instruction_code fi_code +m4_undivert(102) +) { + struct f_inst *what_ = cfg_allocz(sizeof(struct f_inst)); + what_->fi_code = fi_code; + what_->lineno = ifs->lino; + what_->size = 1; + struct f_inst_[[]]INST_NAME() *what UNUSED = &(what_->i_[[]]INST_NAME()); +m4_undivert(103) + return what_; +} +FID_END +]])') + +m4_define(INST, `INST_FLUSH()m4_define([[INST_NAME]], [[$1]])') + +m4_define(FID_MEMBER, `m4_dnl +FID_STRUCT_IN +$1 $2; +FID_NEW_ARGS +, $1 $2 +FID_NEW_BODY +what->$2 = $2; +FID_END') + +m4_define(ARG, `FID_MEMBER(const struct f_inst *, f$1) +FID_NEW_BODY +for (const struct f_inst *child = f$1; child; child = child->next) what_->size += child->size; +FID_END') +m4_define(ARG_ANY, `FID_MEMBER(const struct f_inst *, f$1) +FID_NEW_BODY +for (const struct f_inst *child = f$1; child; child = child->next) what_->size += child->size; +FID_END') +m4_define(LINE, `FID_MEMBER(const struct f_inst *, f$1)') +m4_define(LINEP, `FID_STRUCT_IN +const struct f_line *fl$1; +FID_END') +m4_define(SYMBOL, `FID_MEMBER(const struct symbol *, sym)') +m4_define(VALI, `FID_MEMBER(struct f_val, vali)') +m4_define(VALP, `FID_MEMBER(const struct f_val *, valp)') +m4_define(VAR, `m4_dnl +FID_STRUCT_IN +const struct f_val *valp; +const struct symbol *sym; +FID_NEW_ARGS +, const struct symbol *sym +FID_NEW_BODY +what->valp = (what->sym = sym)->def; +FID_END') +m4_define(FRET, `FID_MEMBER(enum filter_return, fret)') +m4_define(ECS, `FID_MEMBER(enum ec_subtype, ecs)') +m4_define(RTC, `FID_MEMBER(const struct rtable_config *, rtc)') +m4_define(STATIC_ATTR, `FID_MEMBER(struct f_static_attr, sa)') +m4_define(DYNAMIC_ATTR, `FID_MEMBER(struct f_dynamic_attr, da)') +m4_define(COUNT, `FID_MEMBER(uint, count)') +m4_define(TREE, `FID_MEMBER(const struct f_tree *, tree)') +m4_define(STRING, `FID_MEMBER(const char *, s)') + +m4_m4wrap(` +INST_FLUSH() +m4_divert(0) +/* Filter instruction codes */ +enum f_instruction_code { +m4_undivert(4) +}; + +/* Per-instruction structures */ +m4_undivert(1) + +struct f_inst { + const struct f_inst *next; /* Next instruction */ + enum f_instruction_code fi_code; /* Instruction code */ + int size; /* How many instructions are underneath */ + int lineno; /* Line number */ + union { + m4_undivert(2) + }; +}; + +/* Instruction constructors */ +m4_undivert(3) +') + +m4_changequote([[,]]) diff --git a/filter/f-inst.c b/filter/f-inst.c index 0dd9f9f6..afb895c5 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -109,15 +109,15 @@ ARG_ANY(1); COUNT(2); - NEW(, [[ - uint len = 0; - uint dyn = 0; - for (const struct f_inst *tt = f1; tt; tt = tt->next, len++) - if (tt->fi_code != FI_CONSTANT) - dyn++; + FID_NEW_BODY + uint len = 0; + uint dyn = 0; + for (const struct f_inst *tt = f1; tt; tt = tt->next, len++) + if (tt->fi_code != FI_CONSTANT) + dyn++; - WHAT().count = len; - ]]); + what->count = len; + FID_END if (vstk.cnt < what->count) /* TODO: make this check systematic */ runtime("Construction of BGP path mask from %u elements must have at least that number of elements", what->count); @@ -719,17 +719,17 @@ /* Then push the arguments */ LINE(1,1); - NEW(, [[ - if (sym->class != SYM_FUNCTION) - cf_error("You can't call something which is not a function. Really."); + FID_NEW_BODY + if (sym->class != SYM_FUNCTION) + cf_error("You can't call something which is not a function. Really."); - uint count = 0; - for (const struct f_inst *inst = f1; inst; inst = inst->next) - count++; - - if (count != sym->aux2) - cf_error("Function %s takes %u arguments, got %u.", sym->name, sym->aux2, count); - ]]); + uint count = 0; + for (const struct f_inst *inst = f1; inst; inst = inst->next) + count++; + + if (count != sym->aux2) + cf_error("Function %s takes %u arguments, got %u.", sym->name, sym->aux2, count); + FID_END } INST(FI_DROP_RESULT, 1, 0) { diff --git a/filter/f-inst.h b/filter/f-inst.h index 63124aa1..1423e685 100644 --- a/filter/f-inst.h +++ b/filter/f-inst.h @@ -10,137 +10,21 @@ #ifndef _BIRD_F_INST_H_ #define _BIRD_F_INST_H_ +#include "nest/bird.h" +#include "conf/conf.h" #include "filter/filter.h" -#include "filter/f-util.h" +#include "filter/data.h" -/* Filter l-value type */ -enum f_lval_type { - F_LVAL_VARIABLE, - F_LVAL_PREFERENCE, - F_LVAL_SA, - F_LVAL_EA, -}; - -/* Filter l-value */ -struct f_lval { - enum f_lval_type type; - union { - const struct symbol *sym; - struct f_dynamic_attr da; - struct f_static_attr sa; - }; -}; +/* Include generated filter instruction declarations */ +#include "filter/f-inst-decl.h" -/* Filter instruction declarations */ -#define FI__LIST \ - F(FI_NOP) \ - F(FI_ADD, ARG, ARG) \ - F(FI_SUBTRACT, ARG, ARG) \ - F(FI_MULTIPLY, ARG, ARG) \ - F(FI_DIVIDE, ARG, ARG) \ - F(FI_AND, ARG, LINE) \ - F(FI_OR, ARG, LINE) \ - F(FI_PAIR_CONSTRUCT, ARG, ARG) \ - F(FI_EC_CONSTRUCT, ARG, ARG, ECS) \ - F(FI_LC_CONSTRUCT, ARG, ARG, ARG) \ - F(FI_PATHMASK_CONSTRUCT, ARG, COUNT) \ - F(FI_NEQ, ARG, ARG) \ - F(FI_EQ, ARG, ARG) \ - F(FI_LT, ARG, ARG) \ - F(FI_LTE, ARG, ARG) \ - F(FI_NOT, ARG) \ - F(FI_MATCH, ARG, ARG) \ - F(FI_NOT_MATCH, ARG, ARG) \ - F(FI_DEFINED, ARG) \ - F(FI_TYPE, ARG) \ - F(FI_IS_V4, ARG) \ - F(FI_SET, ARG, SYMBOL) \ - F(FI_CONSTANT, VALI) \ - F(FI_VARIABLE, SYMBOL) \ - F(FI_CONSTANT_INDIRECT, VALP) \ - F(FI_PRINT, ARG) \ - F(FI_CONDITION, ARG, LINE, LINE) \ - F(FI_PRINT_AND_DIE, ARG, FRET) \ - F(FI_RTA_GET, SA) \ - F(FI_RTA_SET, ARG, SA) \ - F(FI_EA_GET, EA) \ - F(FI_EA_SET, ARG, EA) \ - F(FI_EA_UNSET, EA) \ - F(FI_PREF_GET) \ - F(FI_PREF_SET, ARG) \ - F(FI_LENGTH, ARG) \ - F(FI_ROA_MAXLEN, ARG) \ - F(FI_ROA_ASN, ARG) \ - F(FI_SADR_SRC, ARG) \ - F(FI_IP, ARG) \ - F(FI_ROUTE_DISTINGUISHER, ARG) \ - F(FI_AS_PATH_FIRST, ARG) \ - F(FI_AS_PATH_LAST, ARG) \ - F(FI_AS_PATH_LAST_NAG, ARG) \ - F(FI_RETURN, ARG) \ - F(FI_CALL, SYMBOL, LINE) \ - F(FI_DROP_RESULT, ARG) \ - F(FI_SWITCH, ARG, TREE) \ - F(FI_IP_MASK, ARG, ARG) \ - F(FI_PATH_PREPEND, ARG, ARG) \ - F(FI_CLIST_ADD, ARG, ARG) \ - F(FI_CLIST_DEL, ARG, ARG) \ - F(FI_CLIST_FILTER, ARG, ARG) \ - F(FI_ROA_CHECK_IMPLICIT, RTC) \ - F(FI_ROA_CHECK_EXPLICIT, ARG, ARG, RTC) \ - F(FI_FORMAT, ARG) \ - F(FI_ASSERT, ARG, STRING) - -/* The enum itself */ -enum f_instruction_code { -#define F(c, ...) c, -FI__LIST -#undef F - FI__MAX, -} PACKED; +#define f_new_inst(...) MACRO_CONCAT_AFTER(f_new_inst_, MACRO_FIRST(__VA_ARGS__))(__VA_ARGS__) /* Convert the instruction back to the enum name */ const char *f_instruction_name(enum f_instruction_code fi); -struct f_inst; -void f_inst_next(struct f_inst *first, const struct f_inst *append); struct f_inst *f_clear_local_vars(struct f_inst *decls); -#define FIA(x) , FIA_##x -#define FIA_ARG const struct f_inst * -#define FIA_LINE const struct f_inst * -#define FIA_COUNT uint -#define FIA_SYMBOL const struct symbol * -#define FIA_VALI struct f_val -#define FIA_VALP const struct f_val * -#define FIA_FRET enum filter_return -#define FIA_ECS enum ec_subtype -#define FIA_SA struct f_static_attr -#define FIA_EA struct f_dynamic_attr -#define FIA_RTC const struct rtable_config * -#define FIA_TREE const struct f_tree * -#define FIA_STRING const char * -#define F(c, ...) \ - struct f_inst *f_new_inst_##c(enum f_instruction_code MACRO_IFELSE(MACRO_ISLAST(__VA_ARGS__))()(MACRO_FOREACH(FIA, __VA_ARGS__))); -FI__LIST -#undef F -#undef FIA_ARG -#undef FIA_LINE -#undef FIA_LINEP -#undef FIA_COUNT -#undef FIA_SYMBOL -#undef FIA_VALI -#undef FIA_VALP -#undef FIA_FRET -#undef FIA_ECS -#undef FIA_SA -#undef FIA_EA -#undef FIA_RTC -#undef FIA_STRING -#undef FIA - -#define f_new_inst(...) MACRO_CONCAT_AFTER(f_new_inst_, MACRO_FIRST(__VA_ARGS__))(__VA_ARGS__) - /* Flags for instructions */ enum f_instruction_flags { FIF_PRINTED = 1, /* FI_PRINT_AND_DIE: message put in buffer */ @@ -202,7 +86,4 @@ struct f_bt_test_suite { const char *dsc; /* Description */ }; -/* Include the auto-generated structures */ -#include "filter/f-inst-struct.h" - #endif diff --git a/filter/f-util.c b/filter/f-util.c index eb948fa0..82aaa385 100644 --- a/filter/f-util.c +++ b/filter/f-util.c @@ -17,22 +17,6 @@ #define P(a,b) ((a<<8) | b) -static const char * const f_instruction_name_str[] = { -#define F(c,...) \ - [c] = #c, -FI__LIST -#undef F -}; - -const char * -f_instruction_name(enum f_instruction_code fi) -{ - if (fi < FI__MAX) - return f_instruction_name_str[fi]; - else - bug("Got unknown instruction code: %d", fi); -} - char * filter_name(struct filter *filter) { @@ -56,18 +40,21 @@ struct filter *f_new_where(const struct f_inst *where) struct f_inst acc = { .fi_code = FI_PRINT_AND_DIE, .lineno = ifs->lino, + .size = 1, .i_FI_PRINT_AND_DIE = { .fret = F_ACCEPT, }, }; struct f_inst rej = { .fi_code = FI_PRINT_AND_DIE, .lineno = ifs->lino, + .size = 1, .i_FI_PRINT_AND_DIE = { .fret = F_REJECT, }, }; struct f_inst i = { .fi_code = FI_CONDITION, .lineno = ifs->lino, + .size = 3, .i_FI_CONDITION = { .f1 = where, .f2 = &acc, diff --git a/filter/f-util.h b/filter/f-util.h deleted file mode 100644 index a7d77bbd..00000000 --- a/filter/f-util.h +++ /dev/null @@ -1,151 +0,0 @@ -/* - * BIRD Internet Routing Daemon -- Filter utils - * - * (c) 1999 Pavel Machek - * (c) 2018--2019 Maria Matejka - * - * Can be freely distributed and used under the terms of the GNU GPL. - */ - -#ifndef _BIRD_F_UTIL_H_ -#define _BIRD_F_UTIL_H_ - -/* IP prefix range structure */ -struct f_prefix { - net_addr net; /* The matching prefix must match this net */ - u8 lo, hi; /* And its length must fit between lo and hi */ -}; - -/* Type numbers must be in 0..0xff range */ -#define T_MASK 0xff - -/* Internal types */ -enum f_type { -/* Do not use type of zero, that way we'll see errors easier. */ - T_VOID = 1, - -/* User visible types, which fit in int */ - T_INT = 0x10, - T_BOOL = 0x11, - T_PAIR = 0x12, /* Notice that pair is stored as integer: first << 16 | second */ - T_QUAD = 0x13, - -/* Put enumerational types in 0x30..0x3f range */ - T_ENUM_LO = 0x30, - T_ENUM_HI = 0x3f, - - T_ENUM_RTS = 0x30, - T_ENUM_BGP_ORIGIN = 0x31, - T_ENUM_SCOPE = 0x32, - T_ENUM_RTC = 0x33, - T_ENUM_RTD = 0x34, - T_ENUM_ROA = 0x35, - T_ENUM_NETTYPE = 0x36, - T_ENUM_RA_PREFERENCE = 0x37, - -/* new enums go here */ - T_ENUM_EMPTY = 0x3f, /* Special hack for atomic_aggr */ - -#define T_ENUM T_ENUM_LO ... T_ENUM_HI - -/* Bigger ones */ - T_IP = 0x20, - T_NET = 0x21, - T_STRING = 0x22, - T_PATH_MASK = 0x23, /* mask for BGP path */ - T_PATH = 0x24, /* BGP path */ - T_CLIST = 0x25, /* Community list */ - T_EC = 0x26, /* Extended community value, u64 */ - T_ECLIST = 0x27, /* Extended community list */ - T_LC = 0x28, /* Large community value, lcomm */ - T_LCLIST = 0x29, /* Large community list */ - T_RD = 0x2a, /* Route distinguisher for VPN addresses */ - T_PATH_MASK_ITEM = 0x2b, /* Path mask item for path mask constructors */ - - T_SET = 0x80, - T_PREFIX_SET = 0x81, -} PACKED; - -/* Filter value; size of this affects filter memory consumption */ -struct f_val { - enum f_type type; /* T_* */ - union { - uint i; - u64 ec; - lcomm lc; - ip_addr ip; - const net_addr *net; - char *s; - const struct f_tree *t; - const struct f_trie *ti; - const struct adata *ad; - const struct f_path_mask *path_mask; - struct f_path_mask_item pmi; - } val; -}; - -#define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val)); - -/* Dynamic attribute definition (eattrs) */ -struct f_dynamic_attr { - u8 type; /* EA type (EAF_*) */ - u8 bit; /* For bitfield accessors */ - enum f_type f_type; /* Filter type */ - uint ea_code; /* EA code */ -}; - -enum f_sa_code { - SA_FROM = 1, - SA_GW, - SA_NET, - SA_PROTO, - SA_SOURCE, - SA_SCOPE, - SA_DEST, - SA_IFNAME, - SA_IFINDEX, -} PACKED; - -/* Static attribute definition (members of struct rta) */ -struct f_static_attr { - enum f_type f_type; /* Filter type */ - enum f_sa_code sa_code; /* Static attribute id */ - int readonly:1; /* Don't allow writing */ -}; - -struct f_tree { - struct f_tree *left, *right; - struct f_val from, to; - void *data; -}; - -struct f_trie_node -{ - ip_addr addr, mask, accept; - uint plen; - struct f_trie_node *c[2]; -}; - -struct f_trie -{ - linpool *lp; - int zero; - uint node_size; - struct f_trie_node root[0]; /* Root trie node follows */ -}; - -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); -void tree_format(const struct f_tree *t, buffer *buf); - -struct f_trie *f_new_trie(linpool *lp, uint node_size); -void *trie_add_prefix(struct f_trie *t, const net_addr *n, uint l, uint h); -int trie_match_net(const struct f_trie *t, const net_addr *n); -int trie_same(const struct f_trie *t1, const struct f_trie *t2); -void trie_format(const struct f_trie *t, buffer *buf); - -extern const struct f_val f_const_empty_path, f_const_empty_clist, f_const_empty_eclist, f_const_empty_lclist; - -#endif diff --git a/filter/filter.c b/filter/filter.c index ff702f2b..0cb56fe4 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -48,7 +48,7 @@ #include "conf/conf.h" #include "filter/filter.h" #include "filter/f-inst.h" -#include "filter/f-util.h" +#include "filter/data.h" #define CMP_ERROR 999 @@ -64,6 +64,75 @@ struct filter_state { void (*bt_assert_hook)(int result, const struct f_line_item *assert); +static const char * const f_instruction_name_str[] = { + /* TODO: Make this better */ + [FI_ADD] = "FI_ADD", + [FI_SUBTRACT] = "FI_SUBTRACT", + [FI_MULTIPLY] = "FI_MULTIPLY", + [FI_DIVIDE] = "FI_DIVIDE", + [FI_AND] = "FI_AND", + [FI_OR] = "FI_OR", + [FI_PAIR_CONSTRUCT] = "FI_PAIR_CONSTRUCT", + [FI_EC_CONSTRUCT] = "FI_EC_CONSTRUCT", + [FI_LC_CONSTRUCT] = "FI_LC_CONSTRUCT", + [FI_PATHMASK_CONSTRUCT] = "FI_PATHMASK_CONSTRUCT", + [FI_NEQ] = "FI_NEQ", + [FI_EQ] = "FI_EQ", + [FI_LT] = "FI_LT", + [FI_LTE] = "FI_LTE", + [FI_NOT] = "FI_NOT", + [FI_MATCH] = "FI_MATCH", + [FI_NOT_MATCH] = "FI_NOT_MATCH", + [FI_DEFINED] = "FI_DEFINED", + [FI_TYPE] = "FI_TYPE", + [FI_IS_V4] = "FI_IS_V4", + [FI_SET] = "FI_SET", + [FI_CONSTANT] = "FI_CONSTANT", + [FI_VARIABLE] = "FI_VARIABLE", + [FI_CONSTANT_INDIRECT] = "FI_CONSTANT_INDIRECT", + [FI_PRINT] = "FI_PRINT", + [FI_CONDITION] = "FI_CONDITION", + [FI_PRINT_AND_DIE] = "FI_PRINT_AND_DIE", + [FI_RTA_GET] = "FI_RTA_GET", + [FI_RTA_SET] = "FI_RTA_SET", + [FI_EA_GET] = "FI_EA_GET", + [FI_EA_SET] = "FI_EA_SET", + [FI_EA_UNSET] = "FI_EA_UNSET", + [FI_PREF_GET] = "FI_PREF_GET", + [FI_PREF_SET] = "FI_PREF_SET", + [FI_LENGTH] = "FI_LENGTH", + [FI_SADR_SRC] = "FI_SADR_SRC", + [FI_ROA_MAXLEN] = "FI_ROA_MAXLEN", + [FI_ROA_ASN] = "FI_ROA_ASN", + [FI_IP] = "FI_IP", + [FI_ROUTE_DISTINGUISHER] = "FI_ROUTE_DISTINGUISHER", + [FI_AS_PATH_FIRST] = "FI_AS_PATH_FIRST", + [FI_AS_PATH_LAST] = "FI_AS_PATH_LAST", + [FI_AS_PATH_LAST_NAG] = "FI_AS_PATH_LAST_NAG", + [FI_RETURN] = "FI_RETURN", + [FI_CALL] = "FI_CALL", + [FI_DROP_RESULT] = "FI_DROP_RESULT", + [FI_SWITCH] = "FI_SWITCH", + [FI_IP_MASK] = "FI_IP_MASK", + [FI_PATH_PREPEND] = "FI_PATH_PREPEND", + [FI_CLIST_ADD] = "FI_CLIST_ADD", + [FI_CLIST_DEL] = "FI_CLIST_DEL", + [FI_CLIST_FILTER] = "FI_CLIST_FILTER", + [FI_ROA_CHECK_IMPLICIT] = "FI_ROA_CHECK_IMPLICIT", + [FI_ROA_CHECK_EXPLICIT] = "FI_ROA_CHECK_EXPLICIT", + [FI_FORMAT] = "FI_FORMAT", + [FI_ASSERT] = "FI_ASSERT", +}; + +const char * +f_instruction_name(enum f_instruction_code fi) +{ + if (fi < (sizeof(f_instruction_name_str) / sizeof(f_instruction_name_str[0]))) + return f_instruction_name_str[fi]; + else + bug("Got unknown instruction code: %d", fi); +} + /* Special undef value for paths and clists */ static inline int undef_value(struct f_val v) @@ -615,18 +684,6 @@ val_format_str(struct filter_state *fs, struct f_val *v) { static struct tbf rl_runtime_err = TBF_DEFAULT_LOG_LIMITS; -static uint -inst_line_size(const struct f_inst *what_) -{ - uint cnt = 0; - for ( ; what_; what_ = what_->next) { - switch (what_->fi_code) { -#include "filter/f-inst-line-size.c" - } - } - return cnt; -} - #define INDENT (((const char *) f_dump_line_indent_str) + sizeof(f_dump_line_indent_str) - (indent) - 1) static const char f_dump_line_indent_str[] = " "; @@ -685,7 +742,8 @@ f_postfixify_concat(const struct f_inst * const inst[], uint count) { uint len = 0; for (uint i=0; inext) + len += what->size; struct f_line *out = cfg_allocz(sizeof(struct f_line) + sizeof(struct f_line_item)*len); diff --git a/filter/filter_test.c b/filter/filter_test.c index a02f0832..edd73ac8 100644 --- a/filter/filter_test.c +++ b/filter/filter_test.c @@ -17,7 +17,7 @@ #include "test/bt-utils.h" #include "filter/filter.h" -#include "filter/f-util.h" +#include "filter/data.h" #include "filter/f-inst.h" #include "conf/conf.h" diff --git a/filter/interpret.m4 b/filter/interpret.m4 index dfd5c6a7..e32b3a76 100644 --- a/filter/interpret.m4 +++ b/filter/interpret.m4 @@ -63,10 +63,11 @@ m4_define(TREE, `') m4_define(STRING, `') m4_define(COUNT, `') m4_define(POSTFIXIFY, `') -m4_define(LINE_SIZE, `') m4_define(SAME, `') -m4_define(STRUCT, `') -m4_define(NEW, `') +m4_define(FID_STRUCT_IN, `m4_divert(-1)') +m4_define(FID_NEW_ARGS, `m4_divert(-1)') +m4_define(FID_NEW_BODY, `m4_divert(-1)') +m4_define(FID_END, `m4_divert(2)') m4_m4wrap(` INST_FLUSH() diff --git a/filter/line-size.m4 b/filter/line-size.m4 deleted file mode 100644 index 051d3b90..00000000 --- a/filter/line-size.m4 +++ /dev/null @@ -1,41 +0,0 @@ -m4_divert(-1)m4_dnl -# -# BIRD -- Line size counting -# -# (c) 2018 Maria Matejka -# -# Can be freely distributed and used under the terms of the GNU GPL. -# - -# Common aliases -m4_define(DNL, `m4_dnl') - -m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[ -m4_divert(1) -case INST_NAME(): -cnt += 1; -#define what ((const struct f_inst_]]INST_NAME()[[ *) &(what_->i_]]INST_NAME()[[)) -m4_undivert(2) -#undef what -break; -m4_divert(-1) -]])') -m4_define(INST, `INST_FLUSH()m4_define([[INST_NAME]], [[$1]])') - -m4_define(ARG, `m4_divert(2)cnt += inst_line_size(what->f$1); -m4_divert(-1)') -m4_define(ARG_T, `m4_divert(2)cnt += inst_line_size(what->f$1); -m4_divert(-1)') -m4_define(ARG_ANY, `m4_divert(2)cnt += inst_line_size(what->f$1); -m4_divert(-1)') -m4_define(LINE_SIZE, `m4_divert(2)$1m4_divert(-1)') - -m4_m4wrap(` -INST_FLUSH() -m4_divert(0)DNL -m4_undivert(1) - -default: bug( "Unknown instruction %d (%c)", what_->fi_code, what_->fi_code & 0xff); -') - -m4_changequote([[,]]) diff --git a/filter/new.m4 b/filter/new.m4 deleted file mode 100644 index 38295e5c..00000000 --- a/filter/new.m4 +++ /dev/null @@ -1,78 +0,0 @@ -m4_divert(-1)m4_dnl -# -# BIRD -- Construction of per-instruction structures -# -# (c) 2018 Maria Matejka -# -# Can be freely distributed and used under the terms of the GNU GPL. -# -# -# Diversions: -# 1 for prepared output -# 2 for function arguments -# 3 for function body - -# Common aliases -m4_define(DNL, `m4_dnl') - -m4_define(FNSTOP, `m4_divert(-1)') -m4_define(FNOUT, `m4_divert(1)') -m4_define(FNARG, `m4_divert(2)') -m4_define(FNBODY, `m4_divert(3)') - -m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[ -FNOUT()DNL -struct f_inst *f_new_inst_]]INST_NAME()[[(enum f_instruction_code fi_code -m4_undivert(2) -) { - struct f_inst *what = cfg_allocz(sizeof(struct f_inst)); - what->fi_code = fi_code; - what->lineno = ifs->lino; -m4_undivert(3) - return what; -} -FNSTOP() -]]DNL -)') - -m4_define(INST, `INST_FLUSH()m4_define([[INST_NAME]], [[$1]])') - -m4_define(WHAT, `what->i_[[]]INST_NAME()') - -m4_define(FNMETAARG, `FNARG(), $1 $2 -FNBODY() WHAT().$2 = $2; -FNSTOP()') -m4_define(ARG, `FNMETAARG(const struct f_inst *, f$1)') -m4_define(ARG_ANY, `FNMETAARG(const struct f_inst *, f$1)') -m4_define(LINE, `FNMETAARG(const struct f_inst *, f$1)') -m4_define(SYMBOL, `FNMETAARG(const struct symbol *, sym)') -m4_define(VALI, `FNMETAARG(struct f_val, vali)') -m4_define(VALP, `FNMETAARG(const struct f_val *, valp)') -m4_define(VAR, `FNARG(), const struct symbol * sym -FNBODY() WHAT().valp = (WHAT().sym = sym)->def; -FNSTOP()') -m4_define(FRET, `FNMETAARG(enum filter_return, fret)') -m4_define(ECS, `FNMETAARG(enum ec_subtype, ecs)') -m4_define(RTC, `FNMETAARG(const struct rtable_config *, rtc)') -m4_define(STATIC_ATTR, `FNMETAARG(struct f_static_attr, sa)') -m4_define(DYNAMIC_ATTR, `FNMETAARG(struct f_dynamic_attr, da)') -m4_define(COUNT, `FNMETAARG(uint, count)') -m4_define(TREE, `FNMETAARG(const struct f_tree *, tree)') -m4_define(STRING, `FNMETAARG(const char *, s)') -m4_define(NEW, `FNARG()$1 -FNBODY()$2 -FNSTOP()') - -m4_m4wrap(` -INST_FLUSH() -m4_divert(0) -#include "nest/bird.h" -#include "conf/conf.h" -#include "filter/filter.h" -#include "filter/f-inst.h" - -m4_undivert(1) - -') - -m4_changequote([[,]]) diff --git a/filter/struct.m4 b/filter/struct.m4 deleted file mode 100644 index 7af28cfd..00000000 --- a/filter/struct.m4 +++ /dev/null @@ -1,73 +0,0 @@ -m4_divert(-1)m4_dnl -# -# BIRD -- Definition of per-instruction structures -# -# (c) 2018 Maria Matejka -# -# Can be freely distributed and used under the terms of the GNU GPL. -# - -# Common aliases -m4_define(DNL, `m4_dnl') - -m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[ -m4_divert(1) -struct f_inst_[[]]INST_NAME() { -m4_undivert(2) -}; -m4_divert(3) -struct f_inst_[[]]INST_NAME() i_[[]]INST_NAME(); -m4_divert(-1) -]])') -m4_define(INST, `INST_FLUSH()m4_define([[INST_NAME]], [[$1]])') - -m4_define(ARG, `m4_divert(2)const struct f_inst *f$1; -m4_divert(-1)') -m4_define(ARG_ANY, `m4_divert(2)const struct f_inst *f$1; -m4_divert(-1)') -m4_define(LINE, `m4_divert(2)const struct f_inst *f$1; -m4_divert(-1)') -m4_define(LINEP, `m4_divert(2)const struct f_line *fl$1; -m4_divert(-1)') -m4_define(SYMBOL, `m4_divert(2)const struct symbol *sym; -m4_divert(-1)') -m4_define(VALI, `m4_divert(2)struct f_val vali; -m4_divert(-1)') -m4_define(VALP, `m4_divert(2)const struct f_val *valp; -m4_divert(-1)') -m4_define(VAR, `VALP()SYMBOL()') -m4_define(FRET, `m4_divert(2)enum filter_return fret; -m4_divert(-1)') -m4_define(ECS, `m4_divert(2)enum ec_subtype ecs; -m4_divert(-1)') -m4_define(RTC, `m4_divert(2)const struct rtable_config *rtc; -m4_divert(-1)') -m4_define(STATIC_ATTR, `m4_divert(2)struct f_static_attr sa; -m4_divert(-1)') -m4_define(DYNAMIC_ATTR, `m4_divert(2)struct f_dynamic_attr da; -m4_divert(-1)') -m4_define(COUNT, `m4_divert(2)uint count; -m4_divert(-1)') -m4_define(TREE, `m4_divert(2)const struct f_tree *tree; -m4_divert(-1)') -m4_define(STRING, `m4_divert(2)const char *s; -m4_divert(-1)') -m4_define(STRUCT, `m4_divert(2)$1 -m4_divert(-1)') - -m4_m4wrap(` -INST_FLUSH() -m4_divert(0)DNL -m4_undivert(1) - -struct f_inst { - const struct f_inst *next; /* Next instruction */ - enum f_instruction_code fi_code; /* Instruction code */ - int lineno; /* Line number */ - union { - m4_undivert(3) - }; -}; -') - -m4_changequote([[,]]) diff --git a/filter/tree.c b/filter/tree.c index 879b0859..46d6e529 100644 --- a/filter/tree.c +++ b/filter/tree.c @@ -10,7 +10,7 @@ #include "nest/bird.h" #include "conf/conf.h" #include "filter/filter.h" -#include "filter/f-util.h" +#include "filter/data.h" /** * find_tree diff --git a/filter/tree_test.c b/filter/tree_test.c index 9e0de50f..6472d17e 100644 --- a/filter/tree_test.c +++ b/filter/tree_test.c @@ -10,7 +10,7 @@ #include "test/bt-utils.h" #include "filter/filter.h" -#include "filter/f-util.h" +#include "filter/data.h" #include "conf/conf.h" #define MAX_TREE_HEIGHT 13 diff --git a/filter/trie.c b/filter/trie.c index dccf9130..3038f5ec 100644 --- a/filter/trie.c +++ b/filter/trie.c @@ -73,7 +73,7 @@ #include "lib/string.h" #include "conf/conf.h" #include "filter/filter.h" -#include "filter/f-util.h" +#include "filter/data.h" /* diff --git a/filter/trie_test.c b/filter/trie_test.c index b6959c4a..38c387b0 100644 --- a/filter/trie_test.c +++ b/filter/trie_test.c @@ -10,7 +10,7 @@ #include "test/bt-utils.h" #include "filter/filter.h" -#include "filter/f-util.h" +#include "filter/data.h" #include "conf/conf.h" #define TESTS_NUM 10 diff --git a/nest/a-path.c b/nest/a-path.c index ac13d0fa..62369af3 100644 --- a/nest/a-path.c +++ b/nest/a-path.c @@ -13,7 +13,7 @@ #include "lib/resource.h" #include "lib/unaligned.h" #include "lib/string.h" -#include "filter/f-util.h" +#include "filter/data.h" // static inline void put_as(byte *data, u32 as) { put_u32(data, as); } // static inline u32 get_as(byte *data) { return get_u32(data); } diff --git a/nest/cmds.c b/nest/cmds.c index 40d397cc..2b83033f 100644 --- a/nest/cmds.c +++ b/nest/cmds.c @@ -15,7 +15,7 @@ #include "lib/string.h" #include "lib/resource.h" #include "filter/filter.h" -#include "filter/f-util.h" +#include "filter/data.h" extern int shutting_down; extern int configuring; diff --git a/nest/rt-table.c b/nest/rt-table.c index d72a8695..6c8e662e 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -39,7 +39,7 @@ #include "lib/string.h" #include "conf/conf.h" #include "filter/filter.h" -#include "filter/f-util.h" +#include "filter/data.h" #include "lib/hash.h" #include "lib/string.h" #include "lib/alloca.h" diff --git a/proto/static/config.Y b/proto/static/config.Y index 0e53c978..3e9ac578 100644 --- a/proto/static/config.Y +++ b/proto/static/config.Y @@ -139,7 +139,7 @@ stat_route: stat_route_item: cmd { if (this_srt_last_cmd) - f_inst_next(this_srt_last_cmd, $1); + this_srt_last_cmd->next = $1; else this_srt_cmds = $1; this_srt_last_cmd = $1; diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index f9002d58..0fdd5b34 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -36,7 +36,7 @@ #include "nest/locks.h" #include "conf/conf.h" #include "filter/filter.h" -#include "filter/f-util.h" +#include "filter/data.h" #include "unix.h" #include "krt.h" -- cgit v1.2.3 From 0b39b1cbb70c6f37a30a3130e1c308ddd0ba36de Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Fri, 15 Feb 2019 13:53:17 +0100 Subject: Conf: Symbol implementation converted from void pointers to union ... and consted some declarations. --- conf/cf-lex.l | 59 +++++++++++++++++++++++------------------------------- conf/conf.h | 49 +++++++++++++++++++++++++++++++++++++-------- conf/confbase.Y | 5 +++-- filter/config.Y | 53 ++++++++++++++++++++++++++---------------------- filter/decl.m4 | 4 ++-- filter/f-inst.c | 10 ++++----- filter/f-inst.h | 5 +++-- filter/f-util.c | 4 ++-- filter/filter.c | 5 ++--- filter/filter.h | 6 +++--- nest/config.Y | 24 +++++++++++----------- nest/proto.c | 6 +++--- nest/protocol.h | 6 +++--- nest/route.h | 4 ++-- nest/rt-table.c | 14 ++++++------- proto/mrt/mrt.h | 6 +++--- sysdep/unix/krt.c | 2 +- sysdep/unix/main.c | 8 +++----- 18 files changed, 149 insertions(+), 121 deletions(-) (limited to 'sysdep') diff --git a/conf/cf-lex.l b/conf/cf-lex.l index 6cc09425..f1b402a0 100644 --- a/conf/cf-lex.l +++ b/conf/cf-lex.l @@ -539,11 +539,8 @@ cf_new_symbol(byte *c) if (l > SYM_MAX_LEN) cf_error("Symbol too long"); - s = cfg_alloc(sizeof(struct symbol) + l); - s->scope = conf_this_scope; - s->class = SYM_VOID; - s->def = NULL; - s->aux = 0; + s = cfg_allocz(sizeof(struct symbol) + l + 1); + *s = (struct symbol) { .scope = conf_this_scope, .class = SYM_VOID, }; strcpy(s->name, c); if (!new_config->sym_hash.data) @@ -574,6 +571,7 @@ cf_find_symbol(struct config *cfg, byte *c) (s = HASH_FIND(cfg->sym_hash, SYM, c, 1))) return s; + /* In CLI command parsing, fallback points to the current config, otherwise it is NULL. */ if (cfg->fallback && cfg->fallback->sym_hash.data && (s = HASH_FIND(cfg->fallback->sym_hash, SYM, c, 1))) @@ -597,6 +595,28 @@ cf_get_symbol(byte *c) return cf_find_symbol(new_config, c) ?: cf_new_symbol(c); } +/** + * cf_localize_symbol - get the local instance of given symbol + * @sym: the symbol to localize + * + * This functions finds the symbol that is local to current scope + * for purposes of cf_define_symbol(). + */ +struct symbol * +cf_localize_symbol(struct symbol *sym) +{ + /* If the symbol type is void, it has been recently allocated just in this scope. */ + if (!sym->class) + return sym; + + /* If the scope is the current, it is already defined in this scope. */ + if (sym->scope == conf_this_scope) + cf_error("Symbol already defined"); + + /* Not allocated here yet, doing it now. */ + return cf_new_symbol(sym->name); +} + struct symbol * cf_default_name(char *template, int *counter) { @@ -616,35 +636,6 @@ cf_default_name(char *template, int *counter) cf_error("Unable to generate default name"); } -/** - * cf_define_symbol - define meaning of a symbol - * @sym: symbol to be defined - * @type: symbol class to assign - * @def: class dependent data - * - * Defines new meaning of a symbol. If the symbol is an undefined - * one (%SYM_VOID), it's just re-defined to the new type. If it's defined - * in different scope, a new symbol in current scope is created and the - * meaning is assigned to it. If it's already defined in the current scope, - * an error is reported via cf_error(). - * - * Result: Pointer to the newly defined symbol. If we are in the top-level - * scope, it's the same @sym as passed to the function. - */ -struct symbol * -cf_define_symbol(struct symbol *sym, int type, void *def) -{ - if (sym->class) - { - if (sym->scope == conf_this_scope) - cf_error("Symbol already defined"); - sym = cf_new_symbol(sym->name); - } - sym->class = type; - sym->def = def; - return sym; -} - static void cf_lex_init_kh(void) { diff --git a/conf/conf.h b/conf/conf.h index 4e3addb3..21d4f1e2 100644 --- a/conf/conf.h +++ b/conf/conf.h @@ -105,11 +105,19 @@ extern int (*cf_read_hook)(byte *buf, uint max, int fd); struct symbol { struct symbol *next; struct sym_scope *scope; - int class; - int aux; - uint aux2; - void *def; - char name[1]; + int class; /* SYM_* */ + uint flags; /* SYM_FLAG_* */ + + union { + struct proto_config *proto; /* For SYM_PROTO and SYM_TEMPLATE */ + const struct f_line *function; /* For SYM_FUNCTION */ + const struct filter *filter; /* For SYM_FILTER */ + struct rtable_config *table; /* For SYM_TABLE */ + struct f_dynamic_attr *attribute; /* For SYM_ATTRIBUTE */ + struct f_val *val; /* For SYM_CONSTANT or SYM_VARIABLE */ + }; + + char name[0]; }; struct sym_scope { @@ -134,8 +142,11 @@ struct sym_scope { #define SYM_CONSTANT 0x200 /* 0x200-0x2ff are variable types */ #define SYM_CONSTANT_RANGE SYM_CONSTANT ... (SYM_CONSTANT | 0xff) -#define SYM_TYPE(s) (((struct f_val *) (s)->def)->type) -#define SYM_VAL(s) (((struct f_val *) (s)->def)->val) +#define SYM_TYPE(s) ((s)->val->type) +#define SYM_VAL(s) ((s)->val->val) + +/* Symbol flags */ +#define SYM_FLAG_SAME 0x1 /* For SYM_FUNCTION and SYM_FILTER */ struct include_file_stack { void *buffer; /* Internal lexer state */ @@ -160,7 +171,29 @@ struct symbol *cf_find_symbol(struct config *cfg, byte *c); struct symbol *cf_get_symbol(byte *c); struct symbol *cf_default_name(char *template, int *counter); -struct symbol *cf_define_symbol(struct symbol *symbol, int type, void *def); +struct symbol *cf_localize_symbol(struct symbol *sym); + +/** + * cf_define_symbol - define meaning of a symbol + * @sym: symbol to be defined + * @type: symbol class to assign + * @def: class dependent data + * + * Defines new meaning of a symbol. If the symbol is an undefined + * one (%SYM_VOID), it's just re-defined to the new type. If it's defined + * in different scope, a new symbol in current scope is created and the + * meaning is assigned to it. If it's already defined in the current scope, + * an error is reported via cf_error(). + * + * Result: Pointer to the newly defined symbol. If we are in the top-level + * scope, it's the same @sym as passed to the function. + */ +#define cf_define_symbol(sym_, type_, var_, def_) ({ \ + struct symbol *sym = cf_localize_symbol(sym_); \ + sym->class = type_; \ + sym->var_ = def_; \ + sym; }) + void cf_push_scope(struct symbol *); void cf_pop_scope(void); char *cf_symbol_class_name(struct symbol *sym); diff --git a/conf/confbase.Y b/conf/confbase.Y index 2195e8fc..62415b4c 100644 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@ -56,7 +56,8 @@ CF_DECLS struct f_dynamic_attr fda; struct f_static_attr fsa; struct f_lval flv; - struct filter *f; + const struct f_line *fl; + const struct filter *f; struct f_tree *e; struct f_trie *trie; struct f_val v; @@ -130,7 +131,7 @@ definition: DEFINE CF_SYM_VOID '=' term ';' { struct f_val *val = cfg_alloc(sizeof(struct f_val)); if (f_eval(f_postfixify($4), cfg_mem, val) > F_RETURN) cf_error("Runtime error"); - cf_define_symbol($2, SYM_CONSTANT | val->type, val); + cf_define_symbol($2, SYM_CONSTANT | val->type, val, val); } ; diff --git a/filter/config.Y b/filter/config.Y index 488b9ced..b3a04958 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -451,7 +451,8 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN, %type term block cmd cmds constant constructor print_one print_list var_list var_listn function_call symbol_value bgp_path_expr bgp_path bgp_path_tail one_decl decls %type dynamic_attr %type static_attr -%type filter filter_body where_filter +%type filter where_filter +%type filter_body %type lvalue %type type %type ec_kind @@ -467,11 +468,12 @@ CF_GRAMMAR conf: filter_def ; filter_def: - FILTER CF_SYM_VOID { $2 = cf_define_symbol($2, SYM_FILTER, NULL); cf_push_scope( $2 ); } + FILTER CF_SYM_VOID { $2 = cf_define_symbol($2, SYM_FILTER, filter, NULL); cf_push_scope( $2 ); } filter_body { - $2->def = $4; - $4->name = $2->name; - DBG( "We have new filter defined (%s)\n", $2->name ); + struct filter *f = cfg_alloc(sizeof(struct filter)); + *f = (struct filter) { .name = $2->name, .root = $4 }; + $2->filter = f; + cf_pop_scope(); } ; @@ -483,14 +485,14 @@ filter_eval: conf: custom_attr ; custom_attr: ATTRIBUTE type CF_SYM_VOID ';' { - cf_define_symbol($3, SYM_ATTRIBUTE, ca_lookup(new_config->pool, $3->name, $2)->fda); + cf_define_symbol($3, SYM_ATTRIBUTE, attribute, ca_lookup(new_config->pool, $3->name, $2)->fda); }; conf: bt_test_suite ; bt_test_suite: BT_TEST_SUITE '(' CF_SYM_FUNCTION ',' text ')' { struct f_bt_test_suite *t = cfg_allocz(sizeof(struct f_bt_test_suite)); - t->fn = $3->def; + t->fn = $3->function; t->fn_name = $3->name; t->dsc = $5; @@ -502,8 +504,8 @@ conf: bt_test_same ; bt_test_same: BT_TEST_SAME '(' CF_SYM_FUNCTION ',' CF_SYM_FUNCTION ',' NUM ')' { struct f_bt_test_suite *t = cfg_allocz(sizeof(struct f_bt_test_suite)); - t->fn = $3->def; - t->cmp = $5->def; + t->fn = $3->function; + t->cmp = $5->function; t->result = $7; t->fn_name = $3->name; t->dsc = $5->name; @@ -553,7 +555,7 @@ one_decl: type CF_SYM_VOID { struct f_val * val = cfg_alloc(sizeof(struct f_val)); val->type = T_VOID; - $2 = cf_define_symbol($2, SYM_VARIABLE | $1, val); + $2 = cf_define_symbol($2, SYM_VARIABLE | $1, val, val); DBG( "New variable %s type %x\n", $2->name, $1 ); $$ = f_new_inst(FI_SET, NULL, $2); } @@ -578,22 +580,24 @@ declsn: one_decl { $$.inst = $1; $$.count = 1; } filter_body: function_body { - $$ = cfg_alloc(sizeof(struct filter)); - $$->name = NULL; if ($1[0]) { const struct f_inst *inst[2] = { $1[0], $1[1] }; - $$->root = f_postfixify_concat(inst, 2); + $$ = f_postfixify_concat(inst, 2); } else - $$->root = f_postfixify($1[1]); + $$ = f_postfixify($1[1]); } ; filter: CF_SYM_FILTER { - $$ = $1->def; + $$ = $1->filter; + } + | filter_body { + struct filter *f = cfg_alloc(sizeof(struct filter)); + *f = (struct filter) { .root = $1 }; + $$ = f; } - | filter_body ; where_filter: @@ -618,7 +622,7 @@ function_body: conf: function_def ; function_def: FUNCTION CF_SYM_VOID { DBG( "Beginning of function %s\n", $2->name ); - $2 = cf_define_symbol($2, SYM_FUNCTION, NULL); + $2 = cf_define_symbol($2, SYM_FUNCTION, function, NULL); cf_push_scope($2); } function_params function_body { const struct f_inst *catlist[4]; @@ -639,9 +643,10 @@ function_def: if ($5[1]) catlist[count++] = $5[1]; - $2->def = f_postfixify_concat(catlist, count); - $2->aux2 = $4.count; - DBG("Hmm, we've got one function here - %s\n", $2->name); + struct f_line *fl = f_postfixify_concat(catlist, count); + fl->args = $4.count; + $2->function = fl; + cf_pop_scope(); } ; @@ -693,7 +698,7 @@ set_atom: } | CF_SYM_CONSTANT { if (!f_valid_set_type(SYM_TYPE($1))) cf_error("%s: set-incompatible type", $1->name); - $$ = *(struct f_val *)($1->def); + $$ = *$1->val; } ; @@ -856,9 +861,9 @@ function_call: ; symbol_value: - CF_SYM_CONSTANT { $$ = f_new_inst(FI_CONSTANT_INDIRECT, $1->def); } + CF_SYM_CONSTANT { $$ = f_new_inst(FI_CONSTANT_INDIRECT, $1->val); } | CF_SYM_VARIABLE { $$ = f_new_inst(FI_VARIABLE, $1); } - | CF_SYM_ATTRIBUTE { $$ = f_new_inst(FI_EA_GET, *((struct f_dynamic_attr *) $1->def)); } + | CF_SYM_ATTRIBUTE { $$ = f_new_inst(FI_EA_GET, *$1->attribute); } ; static_attr: @@ -986,7 +991,7 @@ cmd: $$ = f_new_inst(FI_CONDITION, $2, $4, $6); } | CF_SYM_ATTRIBUTE '=' term ';' { - $$ = f_new_inst(FI_EA_SET, $3, *((struct f_dynamic_attr *) $1->def)); + $$ = f_new_inst(FI_EA_SET, $3, *$1->attribute); } | CF_SYM_VARIABLE '=' term ';' { $$ = f_new_inst(FI_SET, $3, $1); diff --git a/filter/decl.m4 b/filter/decl.m4 index 5ac62cbd..3043f4fc 100644 --- a/filter/decl.m4 +++ b/filter/decl.m4 @@ -188,9 +188,9 @@ const struct symbol *sym; FID_NEW_ARGS , const struct symbol *sym FID_NEW_BODY -what->valp = (what->sym = sym)->def; +what->valp = (what->sym = sym)->val; FID_POSTFIXIFY_BODY -dest->items[pos].vp = (dest->items[pos].sym = what->sym)->def; +dest->items[pos].vp = (dest->items[pos].sym = what->sym)->val; FID_SAME_BODY if (strcmp(f1->sym->name, f2->sym->name) || (f1->sym->class != f2->sym->class)) return 0; FID_DUMP_BODY diff --git a/filter/f-inst.c b/filter/f-inst.c index 4ab46529..6f563873 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -233,7 +233,7 @@ /* IP->Quad implicit conversion */ if ((sym->class == (SYM_VARIABLE | T_QUAD)) && val_is_ip4(&v1)) { - *((struct f_val *) sym->def) = (struct f_val) { + *(sym->val) = (struct f_val) { .type = T_QUAD, .val.i = ipa_to_u32(v1.val.ip), }; @@ -241,7 +241,7 @@ } runtime( "Assigning to variable of incompatible type" ); } - *((struct f_val *) sym->def) = v1; + *(sym->val) = v1; } /* some constants have value in a[1], some in *a[0].p, strange. */ @@ -709,7 +709,7 @@ /* Postfixify extracts the function body from the symbol */ FID_POSTFIXIFY_BODY - dest->items[pos].lines[0] = what->sym->def; + dest->items[pos].lines[0] = what->sym->function; FID_END /* First push the body on stack */ @@ -727,8 +727,8 @@ for (const struct f_inst *inst = f1; inst; inst = inst->next) count++; - if (count != sym->aux2) - cf_error("Function %s takes %u arguments, got %u.", sym->name, sym->aux2, count); + if (count != sym->function->args) + cf_error("Function %s takes %u arguments, got %u.", sym->name, sym->function->args, count); FID_END /* FIXME: Optimization of function comparison. */ diff --git a/filter/f-inst.h b/filter/f-inst.h index e1d0b675..201be5f8 100644 --- a/filter/f-inst.h +++ b/filter/f-inst.h @@ -59,6 +59,7 @@ struct f_line_item { /* Line of instructions to be unconditionally executed one after another */ struct f_line { uint len; /* Line length */ + u16 args; /* Function: Args required */ struct f_line_item items[0]; /* The items themselves */ }; @@ -81,8 +82,8 @@ extern void (*bt_assert_hook)(int result, const struct f_line_item *assert); /* Bird Tests */ struct f_bt_test_suite { node n; /* Node in config->tests */ - struct f_line *fn; /* Root of function */ - struct f_line *cmp; /* Compare to this function */ + const struct f_line *fn; /* Root of function */ + const struct f_line *cmp; /* Compare to this function */ const char *fn_name; /* Name of test */ const char *dsc; /* Description */ int result; /* Desired result */ diff --git a/filter/f-util.c b/filter/f-util.c index 82aaa385..85f5d1c4 100644 --- a/filter/f-util.c +++ b/filter/f-util.c @@ -17,8 +17,8 @@ #define P(a,b) ((a<<8) | b) -char * -filter_name(struct filter *filter) +const char * +filter_name(const struct filter *filter) { if (!filter) return "ACCEPT"; diff --git a/filter/filter.c b/filter/filter.c index 29e78204..4249d4ee 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -359,15 +359,14 @@ f_eval_buf(const struct f_line *expr, struct linpool *tmp_pool, buffer *buf) /** * filter_same - compare two filters * @new: first filter to be compared - * @old: second filter to be compared, notice that this filter is - * damaged while comparing. + * @old: second filter to be compared * * Returns 1 in case filters are same, otherwise 0. If there are * underlying bugs, it will rather say 0 on same filters than say * 1 on different. */ int -filter_same(struct filter *new, struct filter *old) +filter_same(const struct filter *new, const struct filter *old) { if (old == new) /* Handle FILTER_ACCEPT and FILTER_REJECT */ return 1; diff --git a/filter/filter.h b/filter/filter.h index d03c6438..26faeaa3 100644 --- a/filter/filter.h +++ b/filter/filter.h @@ -48,7 +48,7 @@ struct f_val; struct f_line; struct filter { char *name; - struct f_line *root; + const struct f_line *root; }; struct rte; @@ -58,8 +58,8 @@ enum filter_return f_eval_rte(const struct f_line *expr, struct rte **rte, struc uint f_eval_int(const struct f_line *expr); enum filter_return f_eval_buf(const struct f_line *expr, struct linpool *tmp_pool, buffer *buf); -char *filter_name(struct filter *filter); -int filter_same(struct filter *new, struct filter *old); +const char *filter_name(const struct filter *filter); +int filter_same(const struct filter *new, const struct filter *old); int f_same(const struct f_line *f1, const struct f_line *f2); #define FILTER_ACCEPT NULL diff --git a/nest/config.Y b/nest/config.Y index fb75c593..c2622ed2 100644 --- a/nest/config.Y +++ b/nest/config.Y @@ -179,28 +179,28 @@ proto_name: /* EMPTY */ { struct symbol *s = cf_default_name(this_proto->protocol->template, &this_proto->protocol->name_counter); s->class = this_proto->class; - s->def = this_proto; + s->proto = this_proto; this_proto->name = s->name; } | CF_SYM_VOID { - cf_define_symbol($1, this_proto->class, this_proto); + cf_define_symbol($1, this_proto->class, proto, this_proto); this_proto->name = $1->name; } | FROM sym_proto_or_template { struct symbol *s = cf_default_name(this_proto->protocol->template, &this_proto->protocol->name_counter); s->class = this_proto->class; - s->def = this_proto; + s->proto = this_proto; this_proto->name = s->name; if (($2->class != SYM_TEMPLATE) && ($2->class != SYM_PROTO)) cf_error("Template or protocol name expected"); - proto_copy_config(this_proto, $2->def); + proto_copy_config(this_proto, $2->proto); } | CF_SYM_VOID FROM sym_proto_or_template { - cf_define_symbol($1, this_proto->class, this_proto); + cf_define_symbol($1, this_proto->class, proto, this_proto); this_proto->name = $1->name; if (($3->class != SYM_TEMPLATE) && ($3->class != SYM_PROTO)) cf_error("Template or protocol name expected"); - proto_copy_config(this_proto, $3->def); + proto_copy_config(this_proto, $3->proto); } ; @@ -256,7 +256,7 @@ channel_end: proto_channel: channel_start channel_opt_list channel_end; -rtable: CF_SYM_TABLE { $$ = $1->def; } ; +rtable: CF_SYM_TABLE { $$ = $1->table; } ; imexport: FILTER filter { $$ = $2; } @@ -544,7 +544,7 @@ r_args: } | r_args TABLE CF_SYM_TABLE { $$ = $1; - rt_show_add_table($$, ((struct rtable_config *)$3->def)->table); + rt_show_add_table($$, $3->table->table); $$->tables_defined_by = RSD_TDB_DIRECT; } | r_args TABLE ALL { @@ -556,7 +556,7 @@ r_args: } | r_args IMPORT TABLE CF_SYM_PROTO '.' r_args_channel { $$ = $1; - struct proto_config *cf = (void *) $4->def; + struct proto_config *cf = $4->proto; if (!cf->proto) cf_error("%s is not a protocol", $4->name); struct channel *c = proto_find_channel_by_name(cf->proto, $6); if (!c) cf_error("Channel %s.%s not found", $4->name, $6); @@ -587,7 +587,7 @@ r_args: $$->filtered = 1; } | r_args export_mode CF_SYM_PROTO { - struct proto_config *c = (struct proto_config *) $3->def; + struct proto_config *c = (struct proto_config *) $3->proto; $$ = $1; if ($$->export_mode) cf_error("Export specified twice"); if (!c->proto) cf_error("%s is not a protocol", $3->name); @@ -596,7 +596,7 @@ r_args: $$->tables_defined_by = RSD_TDB_INDIRECT; } | r_args export_mode CF_SYM_PROTO '.' r_args_channel { - struct proto_config *c = (struct proto_config *) $3->def; + struct proto_config *c = (struct proto_config *) $3->proto; $$ = $1; if ($$->export_mode) cf_error("Export specified twice"); if (!c->proto) cf_error("%s is not a protocol", $3->name); @@ -606,7 +606,7 @@ r_args: $$->tables_defined_by = RSD_TDB_INDIRECT; } | r_args PROTOCOL CF_SYM_PROTO { - struct proto_config *c = (struct proto_config *) $3->def; + struct proto_config *c = (struct proto_config *) $3->proto; $$ = $1; if ($$->show_protocol) cf_error("Protocol specified twice"); if (!c->proto) cf_error("%s is not a protocol", $3->name); diff --git a/nest/proto.c b/nest/proto.c index d4a333d0..77bf082a 100644 --- a/nest/proto.c +++ b/nest/proto.c @@ -977,7 +977,7 @@ protos_commit(struct config *new, struct config *old, int force_reconfig, int ty { /* Found match, let's check if we can smoothly switch to new configuration */ /* No need to check description */ - nc = sym->def; + nc = sym->proto; nc->proto = p; /* We will try to reconfigure protocol p */ @@ -1905,7 +1905,7 @@ proto_apply_cmd_symbol(struct symbol *s, void (* cmd)(struct proto *, uintptr_t, return; } - cmd(((struct proto_config *)s->def)->proto, arg, 0); + cmd(s->proto->proto, arg, 0); cli_msg(0, ""); } @@ -1948,7 +1948,7 @@ proto_get_named(struct symbol *sym, struct protocol *pr) if (sym->class != SYM_PROTO) cf_error("%s: Not a protocol", sym->name); - p = ((struct proto_config *) sym->def)->proto; + p = sym->proto->proto; if (!p || p->proto != pr) cf_error("%s: Not a %s protocol", sym->name, pr->name); } diff --git a/nest/protocol.h b/nest/protocol.h index 6c04071b..82b46261 100644 --- a/nest/protocol.h +++ b/nest/protocol.h @@ -489,7 +489,7 @@ struct channel_config { struct proto_config *parent; /* Where channel is defined (proto or template) */ struct rtable_config *table; /* Table we're attached to */ - struct filter *in_filter, *out_filter; /* Attached filters */ + const struct filter *in_filter, *out_filter; /* Attached filters */ struct channel_limit rx_limit; /* Limit for receiving routes from protocol (relevant when in_keep_filtered is active) */ struct channel_limit in_limit; /* Limit for importing routes from protocol */ @@ -511,8 +511,8 @@ struct channel { struct proto *proto; struct rtable *table; - struct filter *in_filter; /* Input filter */ - struct filter *out_filter; /* Output filter */ + const struct filter *in_filter; /* Input filter */ + const struct filter *out_filter; /* Output filter */ struct channel_limit rx_limit; /* Receive limit (for in_keep_filtered) */ struct channel_limit in_limit; /* Input limit */ struct channel_limit out_limit; /* Output limit */ diff --git a/nest/route.h b/nest/route.h index c7ed80ff..7c9f3005 100644 --- a/nest/route.h +++ b/nest/route.h @@ -297,7 +297,7 @@ rte *rte_find(net *net, struct rte_src *src); rte *rte_get_temp(struct rta *); void rte_update2(struct channel *c, const net_addr *n, rte *new, struct rte_src *src); /* rte_update() moved to protocol.h to avoid dependency conflicts */ -int rt_examine(rtable *t, net_addr *a, struct proto *p, struct filter *filter); +int rt_examine(rtable *t, net_addr *a, struct proto *p, const struct filter *filter); rte *rt_export_merged(struct channel *c, net *net, rte **rt_free, linpool *pool, int silent); void rt_refresh_begin(rtable *t, struct channel *c); void rt_refresh_end(rtable *t, struct channel *c); @@ -335,7 +335,7 @@ struct rt_show_data { struct rt_show_data_rtable *last_table; /* Last table in output */ struct fib_iterator fit; /* Iterator over networks in table */ int verbose, tables_defined_by; - struct filter *filter; + const struct filter *filter; struct proto *show_protocol; struct proto *export_protocol; struct channel *export_channel; diff --git a/nest/rt-table.c b/nest/rt-table.c index 6c8e662e..f05bd718 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -398,7 +398,7 @@ static rte * export_filter_(struct channel *c, rte *rt0, rte **rt_free, linpool *pool, int silent) { struct proto *p = c->proto; - struct filter *filter = c->out_filter; + const struct filter *filter = c->out_filter; struct proto_stats *stats = &c->stats; rte *rt; int v; @@ -1362,7 +1362,7 @@ rte_update2(struct channel *c, const net_addr *n, rte *new, struct rte_src *src) { struct proto *p = c->proto; struct proto_stats *stats = &c->stats; - struct filter *filter = c->in_filter; + const struct filter *filter = c->in_filter; rte *dummy = NULL; net *nn; @@ -1503,7 +1503,7 @@ rte_modify(rte *old) /* Check rtable for best route to given net whether it would be exported do p */ int -rt_examine(rtable *t, net_addr *a, struct proto *p, struct filter *filter) +rt_examine(rtable *t, net_addr *a, struct proto *p, const struct filter *filter) { net *n = net_find(t, a); rte *rt = n ? n->routes : NULL; @@ -2106,13 +2106,13 @@ rt_new_table(struct symbol *s, uint addr_type) { /* Hack that allows to 'redefine' the master table */ if ((s->class == SYM_TABLE) && - (s->def == new_config->def_tables[addr_type]) && + (s->table == new_config->def_tables[addr_type]) && ((addr_type == NET_IP4) || (addr_type == NET_IP6))) - return s->def; + return s->table; struct rtable_config *c = cfg_allocz(sizeof(struct rtable_config)); - cf_define_symbol(s, SYM_TABLE, c); + cf_define_symbol(s, SYM_TABLE, table, c); c->name = s->name; c->addr_type = addr_type; c->gc_max_ops = 1000; @@ -2171,7 +2171,7 @@ static struct rtable_config * rt_find_table_config(struct config *cf, char *name) { struct symbol *sym = cf_find_symbol(cf, name); - return (sym && (sym->class == SYM_TABLE)) ? sym->def : NULL; + return (sym && (sym->class == SYM_TABLE)) ? sym->table : NULL; } /** diff --git a/proto/mrt/mrt.h b/proto/mrt/mrt.h index b2cec09d..4dfb1b19 100644 --- a/proto/mrt/mrt.h +++ b/proto/mrt/mrt.h @@ -23,7 +23,7 @@ struct mrt_config { struct rtable_config *table_cf; const char *table_expr; - struct filter *filter; + const struct filter *filter; const char *filename; uint period; int always_add_path; @@ -41,7 +41,7 @@ struct mrt_proto { struct mrt_dump_data { const char *table_expr; struct rtable *table_ptr; - struct filter *filter; + const struct filter *filter; char *filename; }; @@ -61,7 +61,7 @@ struct mrt_table_dump_state { /* Configuration information */ const char *table_expr; /* Wildcard for table name (or NULL) */ struct rtable *table_ptr; /* Explicit table (or NULL) */ - struct filter *filter; /* Optional filter */ + const struct filter *filter; /* Optional filter */ const char *filename; /* Filename pattern */ int always_add_path; /* Always use *_ADDPATH message subtypes */ diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c index ded5dfe4..24a4168d 100644 --- a/sysdep/unix/krt.c +++ b/sysdep/unix/krt.c @@ -562,7 +562,7 @@ static struct rte * krt_export_net(struct krt_proto *p, net *net, rte **rt_free) { struct channel *c = p->p.main_channel; - struct filter *filter = c->out_filter; + const struct filter *filter = c->out_filter; rte *rt; if (c->ra_mode == RA_MERGED) diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index 0fdd5b34..b0d764fa 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -94,11 +94,9 @@ drop_gid(gid_t gid) static inline void add_num_const(char *name, int val) { - struct symbol *s = cf_get_symbol(name); - s->class = SYM_CONSTANT | T_INT; - s->def = cfg_allocz(sizeof(struct f_val)); - SYM_TYPE(s) = T_INT; - SYM_VAL(s).i = val; + struct f_val *v = cfg_alloc(sizeof(struct f_val)); + *v = (struct f_val) { .type = T_INT, .val.i = val }; + cf_define_symbol(cf_get_symbol(name), SYM_CONSTANT | T_INT, val, v); } /* the code of read_iproute_table() is based on -- cgit v1.2.3 From 7078aa63ae498b55c729df4a075eb28019917e81 Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Fri, 22 Mar 2019 21:40:35 +0100 Subject: Fixed one warning and one undefined value. --- nest/rt-table.c | 2 +- sysdep/unix/io.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'sysdep') diff --git a/nest/rt-table.c b/nest/rt-table.c index 12966eca..53f5d979 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -1576,7 +1576,7 @@ rte_update2(struct channel *c, const net_addr *n, rte *new, struct rte_src *src) } else if (filter) { - rta *old_attrs; + rta *old_attrs = NULL; rte_make_tmp_attrs(&new, rte_update_pool, &old_attrs); int fr = f_run(filter, &new, rte_update_pool, 0); diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index d1d86e3b..5b0e49c1 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -132,7 +132,7 @@ times_init(struct timeloop *loop) if (rv < 0) die("Monotonic clock is missing"); - if ((ts.tv_sec < 0) || (((s64) ts.tv_sec) > ((s64) 1 << 40))) + if ((ts.tv_sec < 0) || (((u64) ts.tv_sec) > ((u64) 1 << 40))) log(L_WARN "Monotonic clock is crazy"); loop->last_time = ts.tv_sec S + ts.tv_nsec NS; -- cgit v1.2.3 From 78976974e711e52c3b8fa6a80b290cf2fa4f692d Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Wed, 3 Jul 2019 00:00:11 +0200 Subject: Dynamic attributes definition split whether it is bitmask or not. --- filter/f-inst.h | 6 ++++-- filter/f-util.c | 2 +- nest/config.Y | 2 +- proto/babel/config.Y | 2 +- proto/bgp/config.Y | 24 +++++++++++----------- proto/ospf/config.Y | 8 ++++---- proto/radv/config.Y | 4 ++-- proto/rip/config.Y | 4 ++-- sysdep/linux/netlink.Y | 56 +++++++++++++++++++++++++------------------------- sysdep/unix/krt.Y | 4 ++-- 10 files changed, 57 insertions(+), 55 deletions(-) (limited to 'sysdep') diff --git a/filter/f-inst.h b/filter/f-inst.h index 2a2d050e..58a60f0f 100644 --- a/filter/f-inst.h +++ b/filter/f-inst.h @@ -80,8 +80,10 @@ static inline struct f_line *f_linearize(const struct f_inst *root) void f_dump_line(const struct f_line *, uint indent); struct filter *f_new_where(struct f_inst *); -static inline struct f_dynamic_attr f_new_dynamic_attr(u8 type, u8 bit, enum f_type f_type, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */ -{ return (struct f_dynamic_attr) { .type = type, .bit = bit, .f_type = f_type, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */ +static inline struct f_dynamic_attr f_new_dynamic_attr(u8 type, enum f_type f_type, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */ +{ return (struct f_dynamic_attr) { .type = type, .f_type = f_type, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */ +static inline struct f_dynamic_attr f_new_dynamic_attr_bit(u8 bit, enum f_type f_type, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */ +{ return (struct f_dynamic_attr) { .type = EAF_TYPE_BITFIELD, .bit = bit, .f_type = f_type, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */ static inline struct f_static_attr f_new_static_attr(int f_type, int code, int readonly) { return (struct f_static_attr) { .f_type = f_type, .sa_code = code, .readonly = readonly }; } struct f_inst *f_generate_complex(enum f_instruction_code fi_code, struct f_dynamic_attr da, struct f_inst *argument); diff --git a/filter/f-util.c b/filter/f-util.c index 4b580fb9..b4105aad 100644 --- a/filter/f-util.c +++ b/filter/f-util.c @@ -174,7 +174,7 @@ ca_lookup(pool *p, const char *name, int f_type) } cas = mb_allocz(&root_pool, sizeof(struct ca_storage) + strlen(name) + 1); - cas->fda = f_new_dynamic_attr(ea_type, 0, f_type, EA_CUSTOM(id)); + cas->fda = f_new_dynamic_attr(ea_type, f_type, EA_CUSTOM(id)); cas->uc = 1; strcpy(cas->name, name); diff --git a/nest/config.Y b/nest/config.Y index e4dedc66..430c9f29 100644 --- a/nest/config.Y +++ b/nest/config.Y @@ -791,7 +791,7 @@ proto_patt2: | TEXT { $$.ptr = $1; $$.patt = 1; } ; -dynamic_attr: IGP_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_GEN_IGP_METRIC); } ; +dynamic_attr: IGP_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_GEN_IGP_METRIC); } ; CF_CODE diff --git a/proto/babel/config.Y b/proto/babel/config.Y index 78175323..b6bc70fa 100644 --- a/proto/babel/config.Y +++ b/proto/babel/config.Y @@ -125,7 +125,7 @@ babel_iface_opt_list: babel_iface: babel_iface_start iface_patt_list_nopx babel_iface_opt_list babel_iface_finish; -dynamic_attr: BABEL_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_BABEL_METRIC); } ; +dynamic_attr: BABEL_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_BABEL_METRIC); } ; CF_CLI_HELP(SHOW BABEL, ..., [[Show information about Babel protocol]]); diff --git a/proto/bgp/config.Y b/proto/bgp/config.Y index f9e5efaf..ac8d024a 100644 --- a/proto/bgp/config.Y +++ b/proto/bgp/config.Y @@ -272,29 +272,29 @@ bgp_proto_channel: bgp_channel_start bgp_channel_opt_list bgp_channel_end; dynamic_attr: BGP_ORIGIN - { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_ENUM_BGP_ORIGIN, EA_CODE(PROTOCOL_BGP, BA_ORIGIN)); } ; + { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_ENUM_BGP_ORIGIN, EA_CODE(PROTOCOL_BGP, BA_ORIGIN)); } ; dynamic_attr: BGP_PATH - { $$ = f_new_dynamic_attr(EAF_TYPE_AS_PATH, 0, T_PATH, EA_CODE(PROTOCOL_BGP, BA_AS_PATH)); } ; + { $$ = f_new_dynamic_attr(EAF_TYPE_AS_PATH, T_PATH, EA_CODE(PROTOCOL_BGP, BA_AS_PATH)); } ; dynamic_attr: BGP_NEXT_HOP - { $$ = f_new_dynamic_attr(EAF_TYPE_IP_ADDRESS, 0, T_IP, EA_CODE(PROTOCOL_BGP, BA_NEXT_HOP)); } ; + { $$ = f_new_dynamic_attr(EAF_TYPE_IP_ADDRESS, T_IP, EA_CODE(PROTOCOL_BGP, BA_NEXT_HOP)); } ; dynamic_attr: BGP_MED - { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_CODE(PROTOCOL_BGP, BA_MULTI_EXIT_DISC)); } ; + { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_CODE(PROTOCOL_BGP, BA_MULTI_EXIT_DISC)); } ; dynamic_attr: BGP_LOCAL_PREF - { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_CODE(PROTOCOL_BGP, BA_LOCAL_PREF)); } ; + { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_CODE(PROTOCOL_BGP, BA_LOCAL_PREF)); } ; dynamic_attr: BGP_ATOMIC_AGGR - { $$ = f_new_dynamic_attr(EAF_TYPE_OPAQUE, 0, T_ENUM_EMPTY, EA_CODE(PROTOCOL_BGP, BA_ATOMIC_AGGR)); } ; + { $$ = f_new_dynamic_attr(EAF_TYPE_OPAQUE, T_ENUM_EMPTY, EA_CODE(PROTOCOL_BGP, BA_ATOMIC_AGGR)); } ; dynamic_attr: BGP_AGGREGATOR - { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_CODE(PROTOCOL_BGP, BA_AGGREGATOR)); } ; + { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_CODE(PROTOCOL_BGP, BA_AGGREGATOR)); } ; dynamic_attr: BGP_COMMUNITY - { $$ = f_new_dynamic_attr(EAF_TYPE_INT_SET, 0, T_CLIST, EA_CODE(PROTOCOL_BGP, BA_COMMUNITY)); } ; + { $$ = f_new_dynamic_attr(EAF_TYPE_INT_SET, T_CLIST, EA_CODE(PROTOCOL_BGP, BA_COMMUNITY)); } ; dynamic_attr: BGP_ORIGINATOR_ID - { $$ = f_new_dynamic_attr(EAF_TYPE_ROUTER_ID, 0, T_QUAD, EA_CODE(PROTOCOL_BGP, BA_ORIGINATOR_ID)); } ; + { $$ = f_new_dynamic_attr(EAF_TYPE_ROUTER_ID, T_QUAD, EA_CODE(PROTOCOL_BGP, BA_ORIGINATOR_ID)); } ; dynamic_attr: BGP_CLUSTER_LIST - { $$ = f_new_dynamic_attr(EAF_TYPE_INT_SET, 0, T_CLIST, EA_CODE(PROTOCOL_BGP, BA_CLUSTER_LIST)); } ; + { $$ = f_new_dynamic_attr(EAF_TYPE_INT_SET, T_CLIST, EA_CODE(PROTOCOL_BGP, BA_CLUSTER_LIST)); } ; dynamic_attr: BGP_EXT_COMMUNITY - { $$ = f_new_dynamic_attr(EAF_TYPE_EC_SET, 0, T_ECLIST, EA_CODE(PROTOCOL_BGP, BA_EXT_COMMUNITY)); } ; + { $$ = f_new_dynamic_attr(EAF_TYPE_EC_SET, T_ECLIST, EA_CODE(PROTOCOL_BGP, BA_EXT_COMMUNITY)); } ; dynamic_attr: BGP_LARGE_COMMUNITY - { $$ = f_new_dynamic_attr(EAF_TYPE_LC_SET, 0, T_LCLIST, EA_CODE(PROTOCOL_BGP, BA_LARGE_COMMUNITY)); } ; + { $$ = f_new_dynamic_attr(EAF_TYPE_LC_SET, T_LCLIST, EA_CODE(PROTOCOL_BGP, BA_LARGE_COMMUNITY)); } ; diff --git a/proto/ospf/config.Y b/proto/ospf/config.Y index 66cf60c1..2e9ed0ac 100644 --- a/proto/ospf/config.Y +++ b/proto/ospf/config.Y @@ -498,10 +498,10 @@ ospf_iface: ospf_iface_start ospf_iface_patt_list ospf_iface_opt_list { ospf_iface_finish(); } ; -dynamic_attr: OSPF_METRIC1 { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_OSPF_METRIC1); } ; -dynamic_attr: OSPF_METRIC2 { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_OSPF_METRIC2); } ; -dynamic_attr: OSPF_TAG { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_OSPF_TAG); } ; -dynamic_attr: OSPF_ROUTER_ID { $$ = f_new_dynamic_attr(EAF_TYPE_ROUTER_ID, 0, T_QUAD, EA_OSPF_ROUTER_ID); } ; +dynamic_attr: OSPF_METRIC1 { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_OSPF_METRIC1); } ; +dynamic_attr: OSPF_METRIC2 { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_OSPF_METRIC2); } ; +dynamic_attr: OSPF_TAG { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_OSPF_TAG); } ; +dynamic_attr: OSPF_ROUTER_ID { $$ = f_new_dynamic_attr(EAF_TYPE_ROUTER_ID, T_QUAD, EA_OSPF_ROUTER_ID); } ; CF_CLI_HELP(SHOW OSPF, ..., [[Show information about OSPF protocol]]); CF_CLI(SHOW OSPF, optproto, [], [[Show information about OSPF protocol]]) diff --git a/proto/radv/config.Y b/proto/radv/config.Y index b8eeb439..53715f77 100644 --- a/proto/radv/config.Y +++ b/proto/radv/config.Y @@ -332,8 +332,8 @@ radv_sensitive: | SENSITIVE bool { $$ = $2; } ; -dynamic_attr: RA_PREFERENCE { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_ENUM_RA_PREFERENCE, EA_RA_PREFERENCE); } ; -dynamic_attr: RA_LIFETIME { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_RA_LIFETIME); } ; +dynamic_attr: RA_PREFERENCE { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_ENUM_RA_PREFERENCE, EA_RA_PREFERENCE); } ; +dynamic_attr: RA_LIFETIME { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_RA_LIFETIME); } ; CF_CODE diff --git a/proto/rip/config.Y b/proto/rip/config.Y index 4ab793d1..5b5f94a0 100644 --- a/proto/rip/config.Y +++ b/proto/rip/config.Y @@ -186,8 +186,8 @@ rip_iface: rip_iface_start iface_patt_list_nopx rip_iface_opt_list rip_iface_finish; -dynamic_attr: RIP_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_RIP_METRIC); } ; -dynamic_attr: RIP_TAG { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_RIP_TAG); } ; +dynamic_attr: RIP_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_RIP_METRIC); } ; +dynamic_attr: RIP_TAG { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_RIP_TAG); } ; CF_CLI_HELP(SHOW RIP, ..., [[Show information about RIP protocol]]); diff --git a/sysdep/linux/netlink.Y b/sysdep/linux/netlink.Y index 8f0a91c1..7097f577 100644 --- a/sysdep/linux/netlink.Y +++ b/sysdep/linux/netlink.Y @@ -26,39 +26,39 @@ kern_sys_item: | METRIC expr { THIS_KRT->sys.metric = $2; } ; -dynamic_attr: KRT_PREFSRC { $$ = f_new_dynamic_attr(EAF_TYPE_IP_ADDRESS, 0, T_IP, EA_KRT_PREFSRC); } ; -dynamic_attr: KRT_REALM { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_REALM); } ; -dynamic_attr: KRT_SCOPE { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_SCOPE); } ; +dynamic_attr: KRT_PREFSRC { $$ = f_new_dynamic_attr(EAF_TYPE_IP_ADDRESS, T_IP, EA_KRT_PREFSRC); } ; +dynamic_attr: KRT_REALM { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_REALM); } ; +dynamic_attr: KRT_SCOPE { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_SCOPE); } ; -dynamic_attr: KRT_MTU { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_MTU); } ; -dynamic_attr: KRT_WINDOW { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_WINDOW); } ; -dynamic_attr: KRT_RTT { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_RTT); } ; -dynamic_attr: KRT_RTTVAR { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_RTTVAR); } ; -dynamic_attr: KRT_SSTRESH { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_SSTRESH); } ; -dynamic_attr: KRT_CWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_CWND); } ; -dynamic_attr: KRT_ADVMSS { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_ADVMSS); } ; -dynamic_attr: KRT_REORDERING { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_REORDERING); } ; -dynamic_attr: KRT_HOPLIMIT { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_HOPLIMIT); } ; -dynamic_attr: KRT_INITCWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_INITCWND); } ; -dynamic_attr: KRT_RTO_MIN { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_RTO_MIN); } ; -dynamic_attr: KRT_INITRWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_INITRWND); } ; -dynamic_attr: KRT_QUICKACK { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_QUICKACK); } ; +dynamic_attr: KRT_MTU { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_MTU); } ; +dynamic_attr: KRT_WINDOW { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_WINDOW); } ; +dynamic_attr: KRT_RTT { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_RTT); } ; +dynamic_attr: KRT_RTTVAR { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_RTTVAR); } ; +dynamic_attr: KRT_SSTRESH { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_SSTRESH); } ; +dynamic_attr: KRT_CWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_CWND); } ; +dynamic_attr: KRT_ADVMSS { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_ADVMSS); } ; +dynamic_attr: KRT_REORDERING { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_REORDERING); } ; +dynamic_attr: KRT_HOPLIMIT { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_HOPLIMIT); } ; +dynamic_attr: KRT_INITCWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_INITCWND); } ; +dynamic_attr: KRT_RTO_MIN { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_RTO_MIN); } ; +dynamic_attr: KRT_INITRWND { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_INITRWND); } ; +dynamic_attr: KRT_QUICKACK { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_QUICKACK); } ; /* Bits of EA_KRT_LOCK, based on RTAX_* constants */ -dynamic_attr: KRT_LOCK_MTU { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 2, T_BOOL, EA_KRT_LOCK); } ; -dynamic_attr: KRT_LOCK_WINDOW { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 3, T_BOOL, EA_KRT_LOCK); } ; -dynamic_attr: KRT_LOCK_RTT { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 4, T_BOOL, EA_KRT_LOCK); } ; -dynamic_attr: KRT_LOCK_RTTVAR { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 5, T_BOOL, EA_KRT_LOCK); } ; -dynamic_attr: KRT_LOCK_SSTRESH { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 6, T_BOOL, EA_KRT_LOCK); } ; -dynamic_attr: KRT_LOCK_CWND { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 7, T_BOOL, EA_KRT_LOCK); } ; -dynamic_attr: KRT_LOCK_ADVMSS { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 8, T_BOOL, EA_KRT_LOCK); } ; -dynamic_attr: KRT_LOCK_REORDERING { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 9, T_BOOL, EA_KRT_LOCK); } ; -dynamic_attr: KRT_LOCK_HOPLIMIT { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 10, T_BOOL, EA_KRT_LOCK); } ; -dynamic_attr: KRT_LOCK_RTO_MIN { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 13, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_MTU { $$ = f_new_dynamic_attr_bit(2, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_WINDOW { $$ = f_new_dynamic_attr_bit(3, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_RTT { $$ = f_new_dynamic_attr_bit(4, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_RTTVAR { $$ = f_new_dynamic_attr_bit(5, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_SSTRESH { $$ = f_new_dynamic_attr_bit(6, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_CWND { $$ = f_new_dynamic_attr_bit(7, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_ADVMSS { $$ = f_new_dynamic_attr_bit(8, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_REORDERING { $$ = f_new_dynamic_attr_bit(9, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_HOPLIMIT { $$ = f_new_dynamic_attr_bit(10, T_BOOL, EA_KRT_LOCK); } ; +dynamic_attr: KRT_LOCK_RTO_MIN { $$ = f_new_dynamic_attr_bit(13, T_BOOL, EA_KRT_LOCK); } ; -dynamic_attr: KRT_FEATURE_ECN { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 0, T_BOOL, EA_KRT_FEATURES); } ; -dynamic_attr: KRT_FEATURE_ALLFRAG { $$ = f_new_dynamic_attr(EAF_TYPE_BITFIELD, 3, T_BOOL, EA_KRT_FEATURES); } ; +dynamic_attr: KRT_FEATURE_ECN { $$ = f_new_dynamic_attr_bit(0, T_BOOL, EA_KRT_FEATURES); } ; +dynamic_attr: KRT_FEATURE_ALLFRAG { $$ = f_new_dynamic_attr(3, T_BOOL, EA_KRT_FEATURES); } ; CF_CODE diff --git a/sysdep/unix/krt.Y b/sysdep/unix/krt.Y index e3f6271c..95b54d65 100644 --- a/sysdep/unix/krt.Y +++ b/sysdep/unix/krt.Y @@ -122,8 +122,8 @@ kif_iface: kif_iface_start iface_patt_list_nopx kif_iface_opt_list; -dynamic_attr: KRT_SOURCE { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_SOURCE); } ; -dynamic_attr: KRT_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, 0, T_INT, EA_KRT_METRIC); } ; +dynamic_attr: KRT_SOURCE { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_SOURCE); } ; +dynamic_attr: KRT_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_METRIC); } ; CF_CODE -- cgit v1.2.3