Skip to main content

asterust_junos/interfaces/unit/family/
next_hop_tunnel.rs

1//! `next-hop-tunnel`
2//! `interfaces { <name> { unit <n> { family <name> { next-hop-tunnel <gateway> ipsec-vpn <vpn>; } } } }`.
3//!
4//! # See also
5//!
6//! - [next-hop-tunnel](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/interfaces-edit-next-hop-tunnel.html)
7
8use crate::{active_children, value_after};
9use asterust::config::ConfigLine;
10
11/// A `next-hop-tunnel` of a family: an IPsec VPN tunnel to a gateway.
12#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct NextHopTunnel {
15    pub gateway_address: String,
16    pub ipsec_vpn: String,
17}
18
19pub(super) fn parse_next_hop_tunnels(family: &ConfigLine) -> Vec<NextHopTunnel> {
20    active_children(family)
21        .filter_map(|c| {
22            let words: Vec<&str> = c.arg("next-hop-tunnel")?.split_whitespace().collect();
23            Some(NextHopTunnel {
24                gateway_address: words.first()?.to_string(),
25                ipsec_vpn: value_after(&words, "ipsec-vpn")?,
26            })
27        })
28        .collect()
29}