netplan_types/netplan/routing.rs
1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3
4#[cfg(feature = "derive_builder")]
5use derive_builder::Builder;
6
7/// The routes block defines standard static routes for an interface.
8/// At least to must be specified. If type is local or nat a
9/// default scope of host is assumed.
10/// If type is unicast and no gateway (via) is given or type is
11/// broadcast, multicast or anycast a default scope of link
12/// is assumend. Otherwise, a global scope is the default setting.
13///
14/// For from, to, and via, both IPv4 and IPv6 addresses are
15/// recognized, and must be in the form addr/prefixlen or addr.
16#[derive(Default, Debug, Clone, PartialEq, Eq)]
17#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
18#[cfg_attr(feature = "derive_builder", derive(Builder))]
19#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
20#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
21pub struct RoutingConfig {
22 /// Set a source IP address for traffic going through the route.
23 /// (NetworkManager: as of v1.8.0)
24 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
25 pub from: Option<String>,
26 /// Destination address for the route.
27 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
28 pub to: Option<String>,
29 /// Address to the gateway to use for this route.
30 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
31 pub via: Option<String>,
32 /// When set to “true”, specifies that the route is directly connected
33 /// to the interface.
34 /// (NetworkManager: as of v1.12.0 for IPv4 and v1.18.0 for IPv6)
35 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
36 #[cfg_attr(feature = "serde", serde(default))]
37 #[cfg_attr(
38 feature = "serde",
39 serde(deserialize_with = "crate::bool::string_or_bool_option")
40 )]
41 pub on_link: Option<bool>,
42 /// The relative priority of the route. Must be a positive integer value.
43 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
44 pub metric: Option<u16>,
45 /// The type of route. Valid options are “unicast” (default), “anycast”,
46 /// “blackhole”, “broadcast”, “local”, “multicast”, “nat”, “prohibit”,
47 /// “throw”, “unreachable” or “xresolve”.
48 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
49 pub r#type: Option<RouteType>,
50 /// The route scope, how wide-ranging it is to the network. Possible
51 /// values are “global”, “link”, or “host”.
52 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
53 pub scope: Option<RouteScope>,
54 /// The table number to use for the route. In some scenarios, it may be
55 /// useful to set routes in a separate routing table. It may also be used
56 /// to refer to routing policy rules which also accept a table
57 /// parameter. Allowed values are positive integers starting from 1.
58 /// Some values are already in use to refer to specific routing tables:
59 /// see /etc/iproute2/rt_tables.
60 /// (NetworkManager: as of v1.10.0)
61 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
62 pub table: Option<u16>,
63 /// The MTU to be used for the route, in bytes. Must be a positive integer
64 /// value.
65 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
66 pub mtu: Option<u16>,
67 /// The congestion window to be used for the route, represented by number
68 /// of segments. Must be a positive integer value.
69 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
70 pub congestion_window: Option<u16>,
71 /// The receive window to be advertised for the route, represented by
72 /// number of segments. Must be a positive integer value.
73 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
74 pub advertised_receive_window: Option<u16>,
75}
76
77/// The type of route. Valid options are “unicast” (default), “anycast”,
78/// “blackhole”, “broadcast”, “local”, “multicast”, “nat”, “prohibit”,
79/// “throw”, “unreachable” or “xresolve”.
80#[derive(Debug, Clone, PartialEq, Eq)]
81#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
82#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
83#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
84pub enum RouteType {
85 Unicast,
86 Anycast,
87 Blackhole,
88 Broadcast,
89 Local,
90 Multicast,
91 Nat,
92 Prohibit,
93 Throw,
94 Unreachable,
95 Xresolve,
96}
97
98/// The route scope, how wide-ranging it is to the network. Possible
99/// values are “global”, “link”, or “host”.
100#[derive(Debug, Clone, PartialEq, Eq)]
101#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
102#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
103#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
104pub enum RouteScope {
105 Global,
106 Link,
107 Host,
108}
109
110/// The routing-policy block defines extra routing policy for a network,
111/// where traffic may be handled specially based on the source IP, firewall
112/// marking, etc.
113///
114/// For from, to, both IPv4 and IPv6 addresses are recognized, and
115/// must be in the form addr/prefixlen or addr.
116#[derive(Default, Debug, Clone, PartialEq, Eq)]
117#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
118#[cfg_attr(feature = "derive_builder", derive(Builder))]
119#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
120#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
121pub struct RoutingPolicy {
122 /// Set a source IP address to match traffic for this policy rule.
123 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
124 pub from: Option<String>,
125 /// Match on traffic going to the specified destination.
126 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
127 pub to: Option<String>,
128 /// The table number to match for the route. In some scenarios, it may be
129 /// useful to set routes in a separate routing table. It may also be used
130 /// to refer to routes which also accept a table parameter.
131 /// Allowed values are positive integers starting from 1.
132 /// Some values are already in use to refer to specific routing tables:
133 /// see /etc/iproute2/rt_tables.
134 pub table: u16,
135 /// Specify a priority for the routing policy rule, to influence the order
136 /// in which routing rules are processed. A higher number means lower
137 /// priority: rules are processed in order by increasing priority number.
138 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
139 pub priority: Option<i32>,
140 /// Have this routing policy rule match on traffic that has been marked
141 /// by the iptables firewall with this value. Allowed values are positive
142 /// integers starting from 1.
143 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
144 pub mark: Option<u16>,
145 /// Match this policy rule based on the type of service number applied to
146 /// the traffic.
147 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
148 pub type_of_service: Option<String>,
149}
150
151/// Set DNS servers and search domains, for manual address configuration.
152#[derive(Default, Debug, Clone, PartialEq, Eq)]
153#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
154#[cfg_attr(feature = "derive_builder", derive(Builder))]
155#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
156pub struct NameserverConfig {
157 /// A list of IPv4 or IPv6 addresses
158 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
159 pub addresses: Option<Vec<String>>,
160 /// A list of search domains.
161 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
162 pub search: Option<Vec<String>>,
163}