Skip to main content

asterust_junos/policy_options/
community.rs

1//! `policy-options { community <name> members ...; }`.
2
3use crate::{active_children, list_values, split_keyword, split_name};
4use asterust::config::ConfigLine;
5
6/// A `community <name> members ...`, which may be a standard, extended or large community.
7#[derive(Clone, Debug, PartialEq, Eq)]
8#[non_exhaustive]
9pub struct Community {
10    pub name: String,
11    pub members: Vec<String>,
12    pub invert_match: bool,
13}
14
15/// A `community` statement written either on one line (`community X members 1:1;`) or as a block.
16pub(super) fn parse_community(line: &ConfigLine) -> Option<Community> {
17    let (name, rest) = split_name(line.arg("community")?);
18    let (keyword, members) = split_keyword(rest);
19    let mut community = Community {
20        name: name.to_string(),
21        members: if keyword == "members" {
22            list_values(members)
23        } else {
24            Vec::new()
25        },
26        invert_match: false,
27    };
28    for child in active_children(line) {
29        if let Some(members) = child.arg("members") {
30            community.members.extend(list_values(members));
31        } else if child.text == "invert-match" {
32            community.invert_match = true;
33        }
34    }
35    Some(community)
36}