Skip to content

Commit 73c3a50

Browse files
committed
split UdpListenConfig internally to reloadable and non-reloadable parts
1 parent b13504e commit 73c3a50

7 files changed

Lines changed: 74 additions & 85 deletions

File tree

lib/vey-daemon/src/listen/udp/receive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ where
113113
continue;
114114
}
115115
Ok(ServerReloadCommand::UpdateInPlace(_c)) => {
116-
// TODO
116+
// we have no in place config for now
117117
continue;
118118
}
119119
Ok(ServerReloadCommand::QuitRuntime) => {},

lib/vey-daemon/src/listen/unix/datagram.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ where
9898
continue;
9999
}
100100
Ok(ServerReloadCommand::UpdateInPlace(_c)) => {
101-
// TODO
101+
// we have no in place config for now
102102
continue;
103103
}
104104
Ok(ServerReloadCommand::QuitRuntime) => {},

lib/vey-types/src/net/udp/listen.rs

Lines changed: 68 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::net::Interface;
2121
use crate::net::{SocketBufferConfig, UdpMiscSockOpts};
2222

2323
#[derive(Clone, Debug, Eq, PartialEq)]
24-
pub struct UdpListenConfig {
24+
struct NonReloadablePart {
2525
address: SocketAddr,
2626
#[cfg(any(
2727
target_os = "linux",
@@ -35,8 +35,6 @@ pub struct UdpListenConfig {
3535
ipv6only: Option<bool>,
3636
#[cfg(target_os = "linux")]
3737
transparent: bool,
38-
buf_conf: SocketBufferConfig,
39-
misc_opts: UdpMiscSockOpts,
4038
instance: usize,
4139
scale: usize,
4240
#[cfg(target_os = "linux")]
@@ -45,6 +43,18 @@ pub struct UdpListenConfig {
4543
fail_on_ebpf_error: bool,
4644
}
4745

46+
#[derive(Clone, Debug, Eq, PartialEq)]
47+
struct ReloadablePart {
48+
buf_conf: SocketBufferConfig,
49+
misc_opts: UdpMiscSockOpts,
50+
}
51+
52+
#[derive(Clone, Debug, Eq, PartialEq)]
53+
pub struct UdpListenConfig {
54+
non_reloadable: NonReloadablePart,
55+
reloadable: ReloadablePart,
56+
}
57+
4858
impl Default for UdpListenConfig {
4959
fn default() -> Self {
5060
UdpListenConfig::new(SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), 0))
@@ -54,40 +64,44 @@ impl Default for UdpListenConfig {
5464
impl UdpListenConfig {
5565
pub fn new(address: SocketAddr) -> Self {
5666
UdpListenConfig {
57-
address,
58-
#[cfg(any(
59-
target_os = "linux",
60-
target_os = "android",
61-
target_os = "macos",
62-
target_os = "illumos",
63-
target_os = "solaris"
64-
))]
65-
interface: None,
66-
#[cfg(not(target_os = "openbsd"))]
67-
ipv6only: None,
68-
#[cfg(target_os = "linux")]
69-
transparent: false,
70-
buf_conf: SocketBufferConfig::default(),
71-
misc_opts: UdpMiscSockOpts::default(),
72-
instance: 1,
73-
scale: 0,
74-
#[cfg(target_os = "linux")]
75-
use_ebpf: None,
76-
#[cfg(target_os = "linux")]
77-
fail_on_ebpf_error: false,
67+
non_reloadable: NonReloadablePart {
68+
address,
69+
#[cfg(any(
70+
target_os = "linux",
71+
target_os = "android",
72+
target_os = "macos",
73+
target_os = "illumos",
74+
target_os = "solaris"
75+
))]
76+
interface: None,
77+
#[cfg(not(target_os = "openbsd"))]
78+
ipv6only: None,
79+
#[cfg(target_os = "linux")]
80+
transparent: false,
81+
instance: 1,
82+
scale: 0,
83+
#[cfg(target_os = "linux")]
84+
use_ebpf: None,
85+
#[cfg(target_os = "linux")]
86+
fail_on_ebpf_error: false,
87+
},
88+
reloadable: ReloadablePart {
89+
buf_conf: SocketBufferConfig::default(),
90+
misc_opts: UdpMiscSockOpts::default(),
91+
},
7892
}
7993
}
8094

8195
pub fn check(&mut self) -> anyhow::Result<()> {
82-
if self.address.port() == 0 {
96+
if self.non_reloadable.address.port() == 0 {
8397
return Err(anyhow!("no listen port is set"));
8498
}
8599
#[cfg(not(target_os = "openbsd"))]
86-
match self.address.ip() {
87-
IpAddr::V4(_) => self.ipv6only = None,
100+
match self.non_reloadable.address.ip() {
101+
IpAddr::V4(_) => self.non_reloadable.ipv6only = None,
88102
IpAddr::V6(v6) => {
89103
if !v6.is_unspecified() {
90-
self.ipv6only = None;
104+
self.non_reloadable.ipv6only = None;
91105
}
92106
}
93107
}
@@ -96,41 +110,16 @@ impl UdpListenConfig {
96110
}
97111

98112
pub fn need_respawn(&self, other: &Self) -> bool {
99-
if self.address != other.address {
100-
return true;
101-
}
102-
if self.instance() != other.instance() {
103-
return true;
104-
}
105-
#[cfg(any(
106-
target_os = "linux",
107-
target_os = "android",
108-
target_os = "macos",
109-
target_os = "illumos",
110-
target_os = "solaris"
111-
))]
112-
if self.interface != other.interface {
113-
return true;
114-
}
115-
#[cfg(not(target_os = "openbsd"))]
116-
if self.ipv6only != other.ipv6only {
117-
return true;
118-
}
119-
#[cfg(target_os = "linux")]
120-
if self.transparent != other.transparent {
121-
return true;
122-
}
123-
#[cfg(target_os = "linux")]
124-
if self.use_ebpf != other.use_ebpf || self.fail_on_ebpf_error != other.fail_on_ebpf_error {
125-
return true;
126-
}
113+
self.non_reloadable != other.non_reloadable
114+
}
127115

128-
false
116+
pub fn need_reloadable_change(&self, other: &Self) -> bool {
117+
self.reloadable != other.reloadable
129118
}
130119

131120
#[inline]
132121
pub fn address(&self) -> SocketAddr {
133-
self.address
122+
self.non_reloadable.address
134123
}
135124

136125
#[cfg(any(
@@ -142,39 +131,39 @@ impl UdpListenConfig {
142131
))]
143132
#[inline]
144133
pub fn interface(&self) -> Option<&Interface> {
145-
self.interface.as_ref()
134+
self.non_reloadable.interface.as_ref()
146135
}
147136

148137
#[inline]
149138
pub fn socket_buffer(&self) -> SocketBufferConfig {
150-
self.buf_conf
139+
self.reloadable.buf_conf
151140
}
152141

153142
#[inline]
154143
pub fn socket_misc_opts(&self) -> UdpMiscSockOpts {
155-
self.misc_opts
144+
self.reloadable.misc_opts
156145
}
157146

158147
#[cfg(not(target_os = "openbsd"))]
159148
#[inline]
160149
pub fn is_ipv6only(&self) -> Option<bool> {
161-
self.ipv6only
150+
self.non_reloadable.ipv6only
162151
}
163152

164153
#[cfg(target_os = "linux")]
165154
#[inline]
166155
pub fn transparent(&self) -> bool {
167-
self.transparent
156+
self.non_reloadable.transparent
168157
}
169158

170159
#[inline]
171160
pub fn instance(&self) -> usize {
172-
self.instance.max(self.scale)
161+
self.non_reloadable.instance.max(self.non_reloadable.scale)
173162
}
174163

175164
#[inline]
176165
pub fn set_socket_address(&mut self, addr: SocketAddr) {
177-
self.address = addr;
166+
self.non_reloadable.address = addr;
178167
}
179168

180169
#[cfg(any(
@@ -186,48 +175,48 @@ impl UdpListenConfig {
186175
))]
187176
#[inline]
188177
pub fn set_interface(&mut self, interface: Interface) {
189-
self.interface = Some(interface);
178+
self.non_reloadable.interface = Some(interface);
190179
}
191180

192181
#[inline]
193182
pub fn set_socket_buffer(&mut self, buf_conf: SocketBufferConfig) {
194-
self.buf_conf = buf_conf;
183+
self.reloadable.buf_conf = buf_conf;
195184
}
196185

197186
#[inline]
198187
pub fn set_socket_misc_opts(&mut self, misc_opts: UdpMiscSockOpts) {
199-
self.misc_opts = misc_opts;
188+
self.reloadable.misc_opts = misc_opts;
200189
}
201190

202191
#[inline]
203192
pub fn set_port(&mut self, port: u16) {
204-
self.address.set_port(port);
193+
self.non_reloadable.address.set_port(port);
205194
}
206195

207196
#[cfg(not(target_os = "openbsd"))]
208197
#[inline]
209198
pub fn set_ipv6_only(&mut self, ipv6only: bool) {
210-
self.ipv6only = Some(ipv6only);
199+
self.non_reloadable.ipv6only = Some(ipv6only);
211200
}
212201

213202
#[cfg(target_os = "linux")]
214203
#[inline]
215204
pub fn set_transparent(&mut self) {
216-
self.transparent = true;
205+
self.non_reloadable.transparent = true;
217206
}
218207

219208
pub fn set_instance(&mut self, instance: usize) {
220209
if instance == 0 {
221-
self.instance = 1;
210+
self.non_reloadable.instance = 1;
222211
} else {
223-
self.instance = instance;
212+
self.non_reloadable.instance = instance;
224213
}
225214
}
226215

227216
pub fn set_scale(&mut self, scale: f64) -> anyhow::Result<()> {
228217
if let Ok(p) = std::thread::available_parallelism() {
229218
let v = (p.get() as f64) * scale;
230-
self.scale = v
219+
self.non_reloadable.scale = v
231220
.round()
232221
.to_usize()
233222
.ok_or(anyhow!("out of range result: {v}"))?;
@@ -238,29 +227,29 @@ impl UdpListenConfig {
238227
pub fn set_fraction_scale(&mut self, numerator: usize, denominator: usize) {
239228
if let Ok(p) = std::thread::available_parallelism() {
240229
let v = p.get() * numerator / denominator;
241-
self.scale = v;
230+
self.non_reloadable.scale = v;
242231
}
243232
}
244233

245234
#[cfg(target_os = "linux")]
246235
pub fn use_ebpf(&self, uid: u32) -> bool {
247-
self.use_ebpf.unwrap_or(uid == 0)
236+
self.non_reloadable.use_ebpf.unwrap_or(uid == 0)
248237
}
249238

250239
#[cfg(target_os = "linux")]
251240
pub fn set_use_ebpf(&mut self, use_ebpf: bool) {
252-
self.use_ebpf = Some(use_ebpf);
241+
self.non_reloadable.use_ebpf = Some(use_ebpf);
253242
}
254243

255244
#[cfg(target_os = "linux")]
256245
#[inline]
257246
pub fn fail_on_ebpf_error(&self) -> bool {
258-
self.fail_on_ebpf_error
247+
self.non_reloadable.fail_on_ebpf_error
259248
}
260249

261250
#[cfg(target_os = "linux")]
262251
pub fn set_fail_on_ebpf_error(&mut self, fail: bool) {
263-
self.fail_on_ebpf_error = fail;
252+
self.non_reloadable.fail_on_ebpf_error = fail;
264253
}
265254
}
266255

vey-gateway/src/config/server/plain_quic_port.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl ServerConfig for PlainQuicPortConfig {
164164
}
165165

166166
let mut flags = PlainQuicPortUpdateFlags::empty();
167-
if self.listen != new.listen {
167+
if self.listen.need_reloadable_change(&new.listen) {
168168
flags.set(PlainQuicPortUpdateFlags::LISTEN_CONFIG, true);
169169
}
170170
if self.ingress_net_filter != new.ingress_net_filter {

vey-proxy/src/config/server/plain_quic_port.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl ServerConfig for PlainQuicPortConfig {
176176
}
177177

178178
let mut flags = PlainQuicPortUpdateFlags::empty();
179-
if self.listen != new.listen {
179+
if self.listen.need_reloadable_change(&new.listen) {
180180
flags.set(PlainQuicPortUpdateFlags::LISTEN_CONFIG, true);
181181
}
182182
if self.ingress_net_filter != new.ingress_net_filter {

vey-proxy/src/config/server/udp_stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl ServerConfig for UdpStreamServerConfig {
288288
if old.need_respawn(new) {
289289
return ServerConfigDiffAction::ReloadAndRespawn;
290290
}
291-
if old != new {
291+
if old.need_reloadable_change(new) {
292292
flags.set(UdpStreamServerUpdateFlags::LISTEN_CONFIG, true);
293293
}
294294
}

vey-proxy/src/config/server/udp_tproxy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl ServerConfig for UdpTProxyServerConfig {
279279
if self.listen.need_respawn(&new.listen) {
280280
return ServerConfigDiffAction::ReloadAndRespawn;
281281
}
282-
if self.listen != new.listen {
282+
if self.listen.need_reloadable_change(&new.listen) {
283283
flags.set(UdpTProxyServerUpdateFlags::LISTEN_CONFIG, true);
284284
}
285285

0 commit comments

Comments
 (0)