aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.bleep2
-rw-r--r--pingora-core/src/protocols/l4/ext.rs22
2 files changed, 22 insertions, 2 deletions
diff --git a/.bleep b/.bleep
index 3bb0bc2..2d45003 100644
--- a/.bleep
+++ b/.bleep
@@ -1 +1 @@
-c72b23651d92588806f386d2fa41bc408f453add \ No newline at end of file
+f9ccfca0b81e38f866d5264559337e474e3fc4d4 \ No newline at end of file
diff --git a/pingora-core/src/protocols/l4/ext.rs b/pingora-core/src/protocols/l4/ext.rs
index aefd36c..90ad9ac 100644
--- a/pingora-core/src/protocols/l4/ext.rs
+++ b/pingora-core/src/protocols/l4/ext.rs
@@ -18,7 +18,7 @@
use libc::socklen_t;
#[cfg(target_os = "linux")]
-use libc::{c_int, c_void};
+use libc::{c_int, c_ulonglong, c_void};
use pingora_error::{Error, ErrorType::*, OrErr, Result};
use std::io::{self, ErrorKind};
use std::mem;
@@ -281,6 +281,26 @@ pub fn set_tcp_fastopen_backlog(_fd: RawFd, _backlog: usize) -> Result<()> {
Ok(())
}
+#[cfg(target_os = "linux")]
+pub fn get_socket_cookie(fd: RawFd) -> io::Result<u64> {
+ let mut cookie: c_ulonglong = 0;
+ let mut size = std::mem::size_of_val(&cookie) as socklen_t;
+ get_opt(
+ fd,
+ libc::SOL_SOCKET,
+ libc::SO_COOKIE,
+ &mut cookie,
+ &mut size,
+ )?;
+
+ Ok(cookie as u64)
+}
+
+#[cfg(not(target_os = "linux"))]
+pub fn get_socket_cookie(_fd: RawFd) -> io::Result<u64> {
+ Ok(0) // SO_COOKIE is a Linux concept
+}
+
/// connect() to the given address while optionally binding to the specific source address.
///
/// The `set_socket` callback can be used to tune the socket before `connect()` is called.