@@ -16,6 +16,7 @@ use vey_socket::util::AddressFamily;
1616
1717use super :: DirectFloatEscaper ;
1818use crate :: escape:: direct_fixed:: udp_relay:: { DirectUdpRelayRemoteRecv , DirectUdpRelayRemoteSend } ;
19+ use crate :: escape:: { EgressNotes , EgressSocketType } ;
1920use crate :: module:: udp_connect:: UdpConnectError ;
2021use crate :: module:: udp_relay:: {
2122 ArcUdpRelayTaskRemoteStats , UdpRelayRemoteWrapperStats , UdpRelaySetupResult , UdpRelayTaskConf ,
@@ -26,9 +27,12 @@ impl DirectFloatEscaper {
2627 pub ( super ) async fn udp_setup_relay (
2728 & self ,
2829 task_conf : & UdpRelayTaskConf < ' _ > ,
30+ egress_notes : & mut EgressNotes ,
2931 task_notes : & ServerTaskNotes ,
3032 task_stats : ArcUdpRelayTaskRemoteStats ,
3133 ) -> UdpRelaySetupResult {
34+ egress_notes. socket_type = Some ( EgressSocketType :: Direct ) ;
35+
3236 let mut wrapper_stats = UdpRelayRemoteWrapperStats :: new ( self . stats . clone ( ) , task_stats) ;
3337 wrapper_stats. push_user_io_stats ( self . fetch_user_upstream_io_stats ( task_notes) ) ;
3438 let wrapper_stats = Arc :: new ( wrapper_stats) ;
@@ -46,19 +50,31 @@ impl DirectFloatEscaper {
4650 ) ;
4751
4852 if !self . config . no_ipv4
49- && let Ok ( ( bind, r, w) ) =
50- self . get_relay_socket ( AddressFamily :: Ipv4 , task_conf, task_notes, & wrapper_stats)
53+ && let Ok ( ( bind, r, w) ) = self . get_relay_socket (
54+ AddressFamily :: Ipv4 ,
55+ task_conf,
56+ egress_notes,
57+ task_notes,
58+ & wrapper_stats,
59+ )
5160 {
5261 recv. enable_v4 ( r, bind) ;
5362 send. enable_v4 ( w, bind) ;
63+ egress_notes. udp_relay_v4 . local = Some ( bind) ;
5464 }
5565
5666 if !self . config . no_ipv6
57- && let Ok ( ( bind, r, w) ) =
58- self . get_relay_socket ( AddressFamily :: Ipv6 , task_conf, task_notes, & wrapper_stats)
67+ && let Ok ( ( bind, r, w) ) = self . get_relay_socket (
68+ AddressFamily :: Ipv6 ,
69+ task_conf,
70+ egress_notes,
71+ task_notes,
72+ & wrapper_stats,
73+ )
5974 {
6075 recv. enable_v6 ( r, bind) ;
6176 send. enable_v6 ( w, bind) ;
77+ egress_notes. udp_relay_v6 . local = Some ( bind) ;
6278 }
6379
6480 if !send. usable ( ) {
@@ -74,6 +90,7 @@ impl DirectFloatEscaper {
7490 & self ,
7591 family : AddressFamily ,
7692 task_conf : & UdpRelayTaskConf < ' _ > ,
93+ egress_notes : & mut EgressNotes ,
7794 task_notes : & ServerTaskNotes ,
7895 stats : & Arc < UdpRelayRemoteWrapperStats > ,
7996 ) -> Result <
@@ -87,6 +104,19 @@ impl DirectFloatEscaper {
87104 let bind = self
88105 . select_bind ( family, task_notes)
89106 . map_err ( UdpConnectError :: EscaperNotUsable ) ?;
107+ let bind_addr = BindAddr :: Ip ( bind. ip ) ;
108+ match family {
109+ AddressFamily :: Ipv4 => {
110+ egress_notes. egress = Some ( bind. egress_info ) ;
111+ egress_notes. expire = bind. expire_datetime ;
112+ egress_notes. udp_relay_v4 . bind = Some ( bind_addr) ;
113+ }
114+ AddressFamily :: Ipv6 => {
115+ egress_notes. egress = Some ( bind. egress_info ) ;
116+ egress_notes. expire = bind. expire_datetime ;
117+ egress_notes. udp_relay_v6 . bind = Some ( bind_addr) ;
118+ }
119+ }
90120
91121 let misc_opts = if let Some ( user_ctx) = task_notes. user_ctx ( ) {
92122 user_ctx
@@ -96,7 +126,7 @@ impl DirectFloatEscaper {
96126 self . config . udp_misc_opts
97127 } ;
98128
99- let ( socket, bind_addr ) = vey_socket:: udp:: new_std_bind_relay (
129+ let ( socket, local_addr ) = vey_socket:: udp:: new_std_bind_relay (
100130 & BindAddr :: Ip ( bind. ip ) ,
101131 family,
102132 task_conf. sock_buf ,
@@ -121,6 +151,6 @@ impl DirectFloatEscaper {
121151 stats. clone ( ) ,
122152 ) ;
123153
124- Ok ( ( bind_addr , recv, send) )
154+ Ok ( ( local_addr , recv, send) )
125155 }
126156}
0 commit comments