diff options
author | Ivan Babrou <[email protected]> | 2024-06-12 10:28:44 -0700 |
---|---|---|
committer | Matthew (mbg) <[email protected]> | 2024-06-21 09:54:09 -0700 |
commit | bf07ed3f10be667b8206a122e28c7f75d7eb3599 (patch) | |
tree | 298eb4769564b97d4db0c515ff05323abf6c5987 | |
parent | d86c5855a0f2138e6d9afd6a6b07e59017d4e878 (diff) | |
download | pingora-bf07ed3f10be667b8206a122e28c7f75d7eb3599.tar.gz pingora-bf07ed3f10be667b8206a122e28c7f75d7eb3599.zip |
add get_socket_cookie helper
This cab be used for tracing to match the sockets in the kernel.
-rw-r--r-- | .bleep | 2 | ||||
-rw-r--r-- | pingora-core/src/protocols/l4/ext.rs | 22 |
2 files changed, 22 insertions, 2 deletions
@@ -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. |