@@ -16,6 +16,8 @@ use std::collections::VecDeque;
1616use std:: future:: poll_fn;
1717use std:: io:: { self , IoSlice , IoSliceMut } ;
1818use std:: net:: SocketAddr ;
19+ #[ cfg( all( target_os = "linux" , feature = "ebpf" ) ) ]
20+ use std:: os:: fd:: AsRawFd ;
1921use std:: pin:: Pin ;
2022use std:: sync:: Arc ;
2123use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
@@ -33,6 +35,9 @@ use tokio::sync::{broadcast, mpsc};
3335
3436use vey_io_ext:: { UdpMoveRecv , UdpMoveSend , UdpSocketExt } ;
3537use vey_io_sys:: udp:: { RecvMsgHdr , SendMsgHdr } ;
38+ #[ cfg( all( target_os = "linux" , feature = "ebpf" ) ) ]
39+ use vey_reuseport:: udp:: UdpSocketSelector ;
40+ use vey_std_ext:: core:: NonZeroExt ;
3641use vey_types:: net:: { UdpConnectionTrackConfig , UdpListenConfig } ;
3742
3843use crate :: listen:: { ListenAliveGuard , ListenStats } ;
@@ -511,11 +516,21 @@ where
511516 }
512517 }
513518
519+ #[ cfg( all( target_os = "linux" , feature = "ebpf" ) ) ]
520+ let mut udp_reuseport_selector = UdpSocketSelector :: new (
521+ rustix:: process:: getpid ( ) . as_raw_pid ( ) ,
522+ self . server . version ( ) as u32 ,
523+ listen_config. address ( ) ,
524+ self . conn_track . max_sessions ( ) ,
525+ ) ?;
526+
514527 for i in 0 ..instance_count {
515528 let mut runtime = self . create_instance ( ) ;
516529 runtime. instance_id = i;
517530
518531 let socket = vey_socket:: udp:: new_std_bind_listen ( listen_config) ?;
532+ #[ cfg( all( target_os = "linux" , feature = "ebpf" ) ) ]
533+ udp_reuseport_selector. add_socket ( socket. as_raw_fd ( ) ) ;
519534 let listen_addr = socket. local_addr ( ) ?;
520535 runtime. into_running (
521536 socket,
@@ -524,6 +539,21 @@ where
524539 server_reload_sender. subscribe ( ) ,
525540 ) ;
526541 }
542+
543+ #[ cfg( all( target_os = "linux" , feature = "ebpf" ) ) ]
544+ {
545+ udp_reuseport_selector. load_and_attach ( ) ?;
546+ let mut server_reload_receiver = server_reload_sender. subscribe ( ) ;
547+ tokio:: spawn ( async move {
548+ while let Ok ( cmd) = server_reload_receiver. recv ( ) . await {
549+ if matches ! ( cmd, ServerReloadCommand :: QuitRuntime ) {
550+ break ;
551+ }
552+ }
553+ drop ( udp_reuseport_selector) ;
554+ } ) ;
555+ }
556+
527557 Ok ( ( ) )
528558 }
529559}
@@ -604,8 +634,10 @@ where
604634 ) {
605635 use broadcast:: error:: RecvError ;
606636
607- let mut ct_table =
608- LruCache :: with_hasher ( self . conn_track . max_sessions ( ) , FixedState :: with_seed ( 0 ) ) ;
637+ let mut ct_table = LruCache :: with_hasher (
638+ self . conn_track . max_sessions ( ) . cast_usize ( ) ,
639+ FixedState :: with_seed ( 0 ) ,
640+ ) ;
609641 let mut rt_state = RuntimeState :: new ( socket, self . conn_track . send_queue_size ( ) ) ;
610642
611643 let mut event_recv_buf: Vec < Event > = Vec :: with_capacity ( EVENT_RECV_BATCH_SIZE ) ;
0 commit comments