Skip to content

Commit 212557a

Browse files
committed
add udp_max_payload_size config option to PlainQuicPort
1 parent 5ab522b commit 212557a

8 files changed

Lines changed: 55 additions & 32 deletions

File tree

lib/vey-daemon/src/listen/quic.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::time::Duration;
1212
use anyhow::anyhow;
1313
use async_trait::async_trait;
1414
use log::{info, warn};
15-
use quinn::{Connection, Endpoint, Incoming};
15+
use quinn::{Connection, Endpoint, EndpointConfig, Incoming, ServerConfig};
1616
use tokio::runtime::Handle;
1717
use tokio::sync::broadcast;
1818

@@ -43,6 +43,7 @@ pub struct ListenQuicRuntime<S> {
4343
server: S,
4444
listen_config: UdpListenConfig,
4545
listen_stats: Arc<ListenStats>,
46+
payload_max_size: Option<u16>,
4647
#[cfg(feature = "ebpf")]
4748
socket_selector: Option<QuicSocketSelector>,
4849
}
@@ -51,11 +52,17 @@ impl<S> ListenQuicRuntime<S>
5152
where
5253
S: AcceptQuicServer + ReloadServer + Clone + Send + Sync + 'static,
5354
{
54-
pub fn new(server: S, listen_stats: Arc<ListenStats>, listen_config: UdpListenConfig) -> Self {
55+
pub fn new(
56+
server: S,
57+
listen_stats: Arc<ListenStats>,
58+
listen_config: UdpListenConfig,
59+
payload_max_size: Option<u16>,
60+
) -> Self {
5561
ListenQuicRuntime {
5662
server,
5763
listen_config,
5864
listen_stats,
65+
payload_max_size,
5966
#[cfg(feature = "ebpf")]
6067
socket_selector: None,
6168
}
@@ -64,7 +71,7 @@ where
6471
pub fn run_all_instances(
6572
&mut self,
6673
listen_in_worker: bool,
67-
quic_config: &quinn::ServerConfig,
74+
quic_config: &ServerConfig,
6875
ingress_net_filter: Option<&Arc<AclNetworkRule>>,
6976
accept_timeout: Duration,
7077
server_reload_sender: &broadcast::Sender<ServerReloadCommand<ListenQuicInPlaceConfig>>,
@@ -116,6 +123,13 @@ where
116123
};
117124
let listen_addr = socket.local_addr()?;
118125

126+
let mut endpoint_config = EndpointConfig::default();
127+
if let Some(payload_max_size) = self.payload_max_size
128+
&& let Err(e) = endpoint_config.max_udp_payload_size(payload_max_size)
129+
{
130+
warn!("ignored UDP payload size {payload_max_size}: {e}");
131+
}
132+
119133
let runtime = ListenQuicRuntimeInstance {
120134
server: self.server.clone(),
121135
server_type: self.server.r#type(),
@@ -134,6 +148,7 @@ where
134148
};
135149
runtime.into_running(
136150
socket,
151+
endpoint_config,
137152
quic_config.clone(),
138153
server_reload_sender.subscribe(),
139154
);
@@ -460,16 +475,17 @@ where
460475
fn into_running(
461476
mut self,
462477
socket: UdpSocket,
463-
config: quinn::ServerConfig,
478+
endpoint_config: EndpointConfig,
479+
server_config: ServerConfig,
464480
server_reload_channel: broadcast::Receiver<ServerReloadCommand<ListenQuicInPlaceConfig>>,
465481
) {
466482
let handle = self.get_rt_handle();
467483
handle.spawn(async move {
468484
let raw_socket = RawSocket::from(&socket);
469485
// make sure the listen socket associated with the correct reactor
470486
match Endpoint::new(
471-
Default::default(),
472-
Some(config),
487+
endpoint_config,
488+
Some(server_config),
473489
socket,
474490
Arc::new(quinn::TokioRuntime),
475491
) {

sphinx/vey-gateway/configuration/servers/plain_quic_port.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ quic_server
2828

2929
Set the cryptographic configuration for this QUIC server.
3030

31-
offline_rebind_port
32-
-------------------
31+
udp_payload_max_size
32+
--------------------
3333

3434
**optional**, **type**: u16
3535

36-
Set a rebind port used during graceful shutdown.
36+
Set the max UDP payload size. The value should be in inclusive range 1200..65527.
3737

38-
The new port must be reachable by clients or the handoff will not work as
39-
expected.
38+
**default**: not set, which should be 1472 in underlying quic implementation.
4039

41-
**default**: not set
40+
.. versionadded:: 0.4.0
4241

4342
server
4443
------

sphinx/vey-proxy/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
project = 'vey-proxy'
77
copyright = '2020 - %Y, Zhang Jingqiang'
88
author = 'Zhang Jingqiang'
9-
release = '1.13.8'
9+
release = '1.13.9'
1010

1111
# -- General configuration ---------------------------------------------------
1212
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

sphinx/vey-proxy/configuration/servers/plain_quic_port.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ quic_server
3232

3333
Cryptographic configuration for this QUIC server.
3434

35-
offline_rebind_port
36-
-------------------
35+
udp_payload_max_size
36+
--------------------
3737

3838
**optional**, **type**: u16
3939

40-
Rebind port used for graceful shutdown.
40+
Set the max UDP payload size. The value should be in inclusive range 1200..65527.
4141

42-
The new port should be reachable from the client or it won't work as expected.
42+
**default**: not set, which should be 1472 in underlying quic implementation.
4343

44-
**default**: not set
44+
.. versionadded:: 1.13.9
4545

4646
server
4747
------

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(crate) struct PlainQuicPortConfig {
4141
pub(crate) tls_ticketer: Option<TlsTicketConfig>,
4242
pub(crate) ingress_net_filter: Option<AclNetworkRuleBuilder>,
4343
pub(crate) server: NodeName,
44-
pub(crate) offline_rebind_port: Option<u16>,
44+
pub(crate) udp_payload_max_size: Option<u16>,
4545
}
4646

4747
impl PlainQuicPortConfig {
@@ -55,7 +55,7 @@ impl PlainQuicPortConfig {
5555
tls_ticketer: None,
5656
ingress_net_filter: None,
5757
server: NodeName::default(),
58-
offline_rebind_port: None,
58+
udp_payload_max_size: None,
5959
}
6060
}
6161

@@ -87,9 +87,9 @@ impl PlainQuicPortConfig {
8787
self.listen_in_worker = vey_yaml::value::as_bool(v)?;
8888
Ok(())
8989
}
90-
"offline_rebind_port" => {
91-
let port = vey_yaml::value::as_u16(v)?;
92-
self.offline_rebind_port = Some(port);
90+
"udp_payload_max_size" => {
91+
let size = vey_yaml::value::as_u16(v)?;
92+
self.udp_payload_max_size = Some(size);
9393
Ok(())
9494
}
9595
"quic_server" => {

vey-gateway/src/serve/plain_quic_port/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,12 @@ impl ServerInternal for PlainQuicPort {
238238
fn _start_runtime(&self, server: ArcServer) -> anyhow::Result<()> {
239239
let config = self.config.load();
240240
let listen_stats = server.get_listen_stats();
241-
let mut runtime =
242-
ListenQuicRuntime::new(WrapArcServer(server), listen_stats, config.listen.clone());
241+
let mut runtime = ListenQuicRuntime::new(
242+
WrapArcServer(server),
243+
listen_stats,
244+
config.listen.clone(),
245+
config.udp_payload_max_size,
246+
);
243247
runtime.run_all_instances(
244248
config.listen_in_worker,
245249
&self.quinn_config,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(crate) struct PlainQuicPortConfig {
4141
pub(crate) tls_ticketer: Option<TlsTicketConfig>,
4242
pub(crate) ingress_net_filter: Option<AclNetworkRuleBuilder>,
4343
pub(crate) server: NodeName,
44-
pub(crate) offline_rebind_port: Option<u16>,
44+
pub(crate) udp_payload_max_size: Option<u16>,
4545
}
4646

4747
impl PlainQuicPortConfig {
@@ -55,7 +55,7 @@ impl PlainQuicPortConfig {
5555
tls_ticketer: None,
5656
ingress_net_filter: None,
5757
server: NodeName::default(),
58-
offline_rebind_port: None,
58+
udp_payload_max_size: None,
5959
}
6060
}
6161

@@ -87,9 +87,9 @@ impl PlainQuicPortConfig {
8787
self.listen_in_worker = vey_yaml::value::as_bool(v)?;
8888
Ok(())
8989
}
90-
"offline_rebind_port" => {
91-
let port = vey_yaml::value::as_u16(v)?;
92-
self.offline_rebind_port = Some(port);
90+
"udp_payload_max_size" => {
91+
let size = vey_yaml::value::as_u16(v)?;
92+
self.udp_payload_max_size = Some(size);
9393
Ok(())
9494
}
9595
"quic_server" => {

vey-proxy/src/serve/plain_quic_port/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,12 @@ impl ServerInternal for PlainQuicPort {
244244
fn _start_runtime(&self, server: ArcServer) -> anyhow::Result<()> {
245245
let config = self.config.load();
246246
let listen_stats = server.get_listen_stats();
247-
let mut runtime =
248-
ListenQuicRuntime::new(WrapArcServer(server), listen_stats, config.listen.clone());
247+
let mut runtime = ListenQuicRuntime::new(
248+
WrapArcServer(server),
249+
listen_stats,
250+
config.listen.clone(),
251+
config.udp_payload_max_size,
252+
);
249253
runtime.run_all_instances(
250254
config.listen_in_worker,
251255
&self.quinn_config,

0 commit comments

Comments
 (0)