@@ -3191,6 +3191,54 @@ impl crate::Socket {
31913191 )
31923192 }
31933193 }
3194+
3195+ /// Get the value of the `IPV6_TRANSPARENT` option on this socket.
3196+ ///
3197+ /// For more information about this option, see [`set_ip_transparent_v6`].
3198+ ///
3199+ /// [`set_ip_transparent_v6`]: crate::Socket::set_ip_transparent_v6
3200+ #[ cfg( all( feature = "all" , any( target_os = "android" , target_os = "linux" ) ) ) ]
3201+ #[ cfg_attr(
3202+ docsrs,
3203+ doc( cfg( all( feature = "all" , any( target_os = "android" , target_os = "linux" ) ) ) )
3204+ ) ]
3205+ pub fn ip_transparent_v6 ( & self ) -> io:: Result < bool > {
3206+ unsafe {
3207+ getsockopt :: < c_int > ( self . as_raw ( ) , libc:: IPPROTO_IPV6 , libc:: IPV6_TRANSPARENT )
3208+ . map ( |transparent| transparent != 0 )
3209+ }
3210+ }
3211+
3212+ /// Set the value of the `IPV6_TRANSPARENT` option on this socket.
3213+ ///
3214+ /// Setting this boolean option enables transparent proxying
3215+ /// on this socket. This socket option allows the calling
3216+ /// application to bind to a nonlocal IP address and operate
3217+ /// both as a client and a server with the foreign address as
3218+ /// the local endpoint. NOTE: this requires that routing be
3219+ /// set up in a way that packets going to the foreign address
3220+ /// are routed through the TProxy box (i.e., the system
3221+ /// hosting the application that employs the IPV6_TRANSPARENT
3222+ /// socket option). Enabling this socket option requires
3223+ /// superuser privileges (the `CAP_NET_ADMIN` capability).
3224+ ///
3225+ /// TProxy redirection with the iptables TPROXY target also
3226+ /// requires that this option be set on the redirected socket.
3227+ #[ cfg( all( feature = "all" , any( target_os = "android" , target_os = "linux" ) ) ) ]
3228+ #[ cfg_attr(
3229+ docsrs,
3230+ doc( cfg( all( feature = "all" , any( target_os = "android" , target_os = "linux" ) ) ) )
3231+ ) ]
3232+ pub fn set_ip_transparent_v6 ( & self , transparent : bool ) -> io:: Result < ( ) > {
3233+ unsafe {
3234+ setsockopt (
3235+ self . as_raw ( ) ,
3236+ libc:: IPPROTO_IPV6 ,
3237+ libc:: IPV6_TRANSPARENT ,
3238+ transparent as c_int ,
3239+ )
3240+ }
3241+ }
31943242}
31953243
31963244/// See [`Socket::dccp_available_ccids`].
0 commit comments