Skip to main content

asterust_junos/protocols/bgp/peer_options/
multihop.rs

1//! `multihop`
2//! `protocols { bgp { group <name> { multihop { ttl <n>; no-nexthop-change; } } } }`.
3//!
4//! # See also
5//!
6//! - [multihop](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/multihop-edit-protocols-bgp.html)
7
8use crate::{statement_words, value_after};
9use asterust::config::ConfigLine;
10
11/// The `multihop` statement for sessions to peers that are not directly connected.
12#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct Multihop {
15    pub ttl: Option<String>,
16    pub no_nexthop_change: bool,
17}
18
19/// Reads the block form and the older `multihop <ttl>;` form.
20pub(super) fn parse_multihop(line: &ConfigLine) -> Option<Multihop> {
21    let words = statement_words(line, "multihop")?;
22    let bare_ttl = words
23        .first()
24        .filter(|word| word.chars().all(|c| c.is_ascii_digit()))
25        .map(|word| word.to_string());
26    Some(Multihop {
27        ttl: value_after(&words, "ttl").or(bare_ttl),
28        no_nexthop_change: words.contains(&"no-nexthop-change"),
29    })
30}