route_verification_common_regex/set.rs
1//! > A set's name is an rpsl word with the following restrictions: All
2//! > as-set names start with prefix "as-". All route-set names start with
3//! > prefix "rs-". All rtr-set names start with prefix "rtrs-". All
4//! > filter-set names start with prefix "fltr-". All peering-set names
5//! > start with prefix "prng-". For example, as-foo is a valid as-set
6//! > name.
7//!
8//! > Set names can also be hierarchical. A hierarchical set name is a
9//! > sequence of set names and AS numbers separated by colons ":". At
10//! > least one component of such a name must be an actual set name (i.e.
11//! > start with one of the prefixes above). All the set name components
12//! > of an hierarchical name has to be of the same type. For example, the
13//! > following names are valid: AS1:AS-CUSTOMERS, AS1:RS-EXPORT:AS2, RS-
14//! > EXCEPTIONS:RS-BOGUS.
15//!
16//! <https://www.rfc-editor.org/rfc/rfc2622#section-5>.
17
18use super::*;
19
20/// RPSL object name, without restriction on first letter.
21///
22/// > Many objects in RPSL have a name. An `<object-name>` is made up of
23/// > letters, digits, the character underscore "_", and the character
24/// > hyphen "-"; the first character of a name must be a letter, and
25/// > the last character of a name must be a letter or a digit.
26pub const OBJECT_NAME: &str = r"[A-Za-z0-9_\-]*[A-Za-z0-9]";
27
28/// AS number.
29pub const ASN: &str = "as[0-9]+";
30
31macro_rules! set_of {
32 ($base:expr, $or_name:ident, $set_name:ident, $doc:expr) => {
33 pub const $or_name: &str = formatcp!("(?:{}|{})", $base, ASN);
34
35 #[doc = $doc]
36 pub const $set_name: &str = formatcp!("(?:{}:)*{}(?::{})*", $or_name, $base, $or_name);
37 };
38}
39
40/// > The keyword ANY matches all routes.
41pub const ANY: &str = "any";
42
43/// > The keyword PeerAS can be used instead of the AS number of the peer
44/// > AS. PeerAS is particularly useful when the peering is specified
45/// > using an AS expression.
46pub const PEERAS: &str = "peeras";
47
48/// Base AS Set name, including `peeras`.
49pub const AS_SET_BASE: &str = formatcp!("(?:as-{}|{})", OBJECT_NAME, PEERAS);
50
51set_of!(
52 AS_SET_BASE,
53 AS_SET_BASE_OR_ASN,
54 AS_SET,
55 r#"> The as-set attribute defines the name of the set. It is an RPSL name that starts with "as-"."#
56);
57
58/// Base Route Set name.
59pub const ROUTE_SET_BASE: &str = formatcp!("(?:rs-{}|{})", OBJECT_NAME, PEERAS);
60
61set_of!(
62 ROUTE_SET_BASE,
63 ROUTE_SET_BASE_OR_ASN,
64 ROUTE_SET,
65 r#"> The route-set attribute defines the name of the set. It is an RPSL name that starts with "rs-"."#
66);
67
68/// Base Filter Set name.
69pub const FILTER_SET_BASE: &str = formatcp!("fltr-{}", OBJECT_NAME);
70
71set_of!(
72 FILTER_SET_BASE,
73 FILTER_SET_BASE_OR_ASN,
74 FILTER_SET,
75 r#"> The filter-set attribute defines the name of the filter. It is an RPSL name that starts with "fltr-"."#
76);
77
78/// Base Peering Set name.
79pub const PEERING_SET_BASE: &str = formatcp!("prng-{}", OBJECT_NAME);
80
81set_of!(
82 PEERING_SET_BASE,
83 PEERING_SET_BASE_OR_ASN,
84 PEERING_SET,
85 r#"> The peering-set attribute defines the name of the set. It is an RPSL name that starts with "prng-". "#
86);