Skip to content

Commit f5fc36d

Browse files
committed
Move (set_)ip_transparent to sys unix module
1 parent 3a93893 commit f5fc36d

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

src/socket.rs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,48 +1212,6 @@ impl Socket {
12121212
}
12131213
}
12141214

1215-
/// Get the value of the `IP_TRANSPARENT` option on this socket.
1216-
///
1217-
/// For more information about this option, see [`set_ip_transparent`].
1218-
///
1219-
/// [`set_ip_transparent`]: Socket::set_ip_transparent
1220-
#[cfg(all(feature = "all", target_os = "linux"))]
1221-
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "linux"))))]
1222-
pub fn ip_transparent(&self) -> io::Result<bool> {
1223-
unsafe {
1224-
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IP, libc::IP_TRANSPARENT)
1225-
.map(|transparent| transparent != 0)
1226-
}
1227-
}
1228-
1229-
/// Set the value of the `IP_TRANSPARENT` option on this socket.
1230-
///
1231-
/// Setting this boolean option enables transparent proxying
1232-
/// on this socket. This socket option allows the calling
1233-
/// application to bind to a nonlocal IP address and operate
1234-
/// both as a client and a server with the foreign address as
1235-
/// the local endpoint. NOTE: this requires that routing be
1236-
/// set up in a way that packets going to the foreign address
1237-
/// are routed through the TProxy box (i.e., the system
1238-
/// hosting the application that employs the IP_TRANSPARENT
1239-
/// socket option). Enabling this socket option requires
1240-
/// superuser privileges (the `CAP_NET_ADMIN` capability).
1241-
///
1242-
/// TProxy redirection with the iptables TPROXY target also
1243-
/// requires that this option be set on the redirected socket.
1244-
#[cfg(all(feature = "all", target_os = "linux"))]
1245-
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "linux"))))]
1246-
pub fn set_ip_transparent(&self, transparent: bool) -> io::Result<()> {
1247-
unsafe {
1248-
setsockopt(
1249-
self.as_raw(),
1250-
sys::IPPROTO_IP,
1251-
libc::IP_TRANSPARENT,
1252-
transparent as c_int,
1253-
)
1254-
}
1255-
}
1256-
12571215
/// Join a multicast group using `IP_ADD_MEMBERSHIP` option on this socket.
12581216
///
12591217
/// This function specifies a new multicast group for this socket to join.

src/sys/unix.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3097,6 +3097,48 @@ impl crate::Socket {
30973097
)
30983098
}
30993099
}
3100+
3101+
/// Get the value of the `IP_TRANSPARENT` option on this socket.
3102+
///
3103+
/// For more information about this option, see [`set_ip_transparent`].
3104+
///
3105+
/// [`set_ip_transparent`]: Socket::set_ip_transparent
3106+
#[cfg(all(feature = "all", target_os = "linux"))]
3107+
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "linux"))))]
3108+
pub fn ip_transparent(&self) -> io::Result<bool> {
3109+
unsafe {
3110+
getsockopt::<c_int>(self.as_raw(), libc::IPPROTO_IP, libc::IP_TRANSPARENT)
3111+
.map(|transparent| transparent != 0)
3112+
}
3113+
}
3114+
3115+
/// Set the value of the `IP_TRANSPARENT` option on this socket.
3116+
///
3117+
/// Setting this boolean option enables transparent proxying
3118+
/// on this socket. This socket option allows the calling
3119+
/// application to bind to a nonlocal IP address and operate
3120+
/// both as a client and a server with the foreign address as
3121+
/// the local endpoint. NOTE: this requires that routing be
3122+
/// set up in a way that packets going to the foreign address
3123+
/// are routed through the TProxy box (i.e., the system
3124+
/// hosting the application that employs the IP_TRANSPARENT
3125+
/// socket option). Enabling this socket option requires
3126+
/// superuser privileges (the `CAP_NET_ADMIN` capability).
3127+
///
3128+
/// TProxy redirection with the iptables TPROXY target also
3129+
/// requires that this option be set on the redirected socket.
3130+
#[cfg(all(feature = "all", target_os = "linux"))]
3131+
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "linux"))))]
3132+
pub fn set_ip_transparent(&self, transparent: bool) -> io::Result<()> {
3133+
unsafe {
3134+
setsockopt(
3135+
self.as_raw(),
3136+
libc::IPPROTO_IP,
3137+
libc::IP_TRANSPARENT,
3138+
transparent as c_int,
3139+
)
3140+
}
3141+
}
31003142
}
31013143

31023144
/// See [`Socket::dccp_available_ccids`].

0 commit comments

Comments
 (0)