diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-11-25 23:34:03 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-11-25 23:34:03 +0100 |
commit | d83b1c9e067f707ec51ea14385ebe5ce000d0c73 (patch) | |
tree | 4341888d55ebd89bece2a95efe2e55ecc9e9b663 | |
parent | f92ffd893919d6b1e46cded7337bb39c5a3fd84e (diff) | |
parent | a0fb0eaa6780e60b7c5434dfe0e2ed402e5a4ea4 (diff) |
Merge commit 'a0fb0eaa' into wireguard-next-tmp7-1
-rw-r--r-- | doc/bird.sgml | 7 | ||||
-rw-r--r-- | filter/data.h | 1 | ||||
-rw-r--r-- | filter/f-inst.c | 2 | ||||
-rw-r--r-- | filter/f-inst.h | 15 | ||||
-rw-r--r-- | proto/bgp/config.Y | 11 |
5 files changed, 34 insertions, 2 deletions
diff --git a/doc/bird.sgml b/doc/bird.sgml index 3be266cb..366797ba 100644 --- a/doc/bird.sgml +++ b/doc/bird.sgml @@ -3287,6 +3287,13 @@ some of them (marked with `<tt/O/') are optional. name="local Role"> is configured it set automatically. </descrip> +<p>For attributes unknown by BIRD, the user can assign a name (on top level) +to an attribute by its number. This defined name can be used then to both set +(by a bytestring literal, transitive) or unset the given attribute even though +BIRD knows nothing about it: + +<tt><label id="bgp-attribute-custom">attribute bgp <m/number/ bytestring <m/name/;</tt> + <sect1>Example <label id="bgp-exam"> diff --git a/filter/data.h b/filter/data.h index fa8503d5..73242f94 100644 --- a/filter/data.h +++ b/filter/data.h @@ -105,6 +105,7 @@ struct f_dynamic_attr { u8 bit; /* For bitfield accessors */ enum f_type f_type; /* Filter type */ uint ea_code; /* EA code */ + uint flags; }; enum f_sa_code { diff --git a/filter/f-inst.c b/filter/f-inst.c index 44558c43..59f3415d 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -865,7 +865,7 @@ l->flags = EALF_SORTED; l->count = 1; l->attrs[0].id = da.ea_code; - l->attrs[0].flags = 0; + l->attrs[0].flags = da.flags; l->attrs[0].type = da.type; l->attrs[0].originated = 1; l->attrs[0].fresh = 1; diff --git a/filter/f-inst.h b/filter/f-inst.h index 2bde6378..955cfbdc 100644 --- a/filter/f-inst.h +++ b/filter/f-inst.h @@ -118,6 +118,21 @@ static inline struct f_dynamic_attr f_new_dynamic_attr_bit(u8 bit, enum f_type f 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 }; } +static inline int f_type_attr(int f_type) { + switch (f_type) { + case T_INT: return EAF_TYPE_INT; + case T_IP: return EAF_TYPE_IP_ADDRESS; + case T_QUAD: return EAF_TYPE_ROUTER_ID; + case T_PATH: return EAF_TYPE_AS_PATH; + case T_CLIST: return EAF_TYPE_INT_SET; + case T_ECLIST: return EAF_TYPE_EC_SET; + case T_LCLIST: return EAF_TYPE_LC_SET; + case T_BYTESTRING: return EAF_TYPE_OPAQUE; + default: + cf_error("Custom route attribute of unsupported type"); + } +} + /* Hook for call bt_assert() function in configuration */ extern void (*bt_assert_hook)(int result, const struct f_line_item *assert); diff --git a/proto/bgp/config.Y b/proto/bgp/config.Y index 7311a160..2252d7fe 100644 --- a/proto/bgp/config.Y +++ b/proto/bgp/config.Y @@ -364,7 +364,16 @@ dynamic_attr: BGP_OTC dynamic_attr: BGP_TUNNEL_ENCAP { $$ = f_new_dynamic_attr(EAF_TYPE_TUNNEL_ENCAP, T_TLVLIST, EA_CODE(PROTOCOL_BGP, BA_TUNNEL_ENCAP)); } ; - +custom_attr: ATTRIBUTE BGP NUM type symbol ';' { + if($3 > 255 || $3 < 1) + cf_error("Invalid attribute number. (Given %i, must be 1-255.)", $3); + if($4 != T_BYTESTRING) + cf_error("Attribute type must be bytestring, not %s.", f_type_name($4)); + struct f_dynamic_attr* a = (struct f_dynamic_attr*) malloc(sizeof(struct f_dynamic_attr)); + *a = f_new_dynamic_attr(f_type_attr($4), T_BYTESTRING, EA_CODE(PROTOCOL_BGP, $3)); + a->flags = BAF_TRANSITIVE | BAF_OPTIONAL; + cf_define_symbol(new_config, $5, SYM_ATTRIBUTE, attribute, a); +}; CF_ENUM(T_ENUM_BGP_ORIGIN, ORIGIN_, IGP, EGP, INCOMPLETE) |