-
Notifications
You must be signed in to change notification settings - Fork 687
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
socket::sockopt adding SOL_FILTER level options for illumos. #2611
base: master
Are you sure you want to change the base?
Conversation
Respectively FIL_ATTACH/FIL_DETACH to bind/unbind a filter to a socket to for example delay connection acceptance until data (datafilt) is received.
src/sys/socket/sockopt.rs
Outdated
SetOnly, | ||
libc::SOL_FILTER, | ||
libc::FIL_ATTACH, | ||
SetOsString<'static> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking if this 'static
lifetime would be too restrictive? I do not see a way to specify lifetime parameter using the macro, maybe we can implement the nix::sys::socket::SetSockOpt
trait manually?
f3c875b
to
366ca97
Compare
src/sys/socket/sockopt.rs
Outdated
type Val = [u8; libc::FILNAME_MAX as usize]; | ||
|
||
fn set<F: AsFd>(&self, fd: &F, val: &[u8; libc::FILNAME_MAX as usize]) -> Result<()> { | ||
unsafe { | ||
let res = libc::setsockopt( | ||
fd.as_fd().as_raw_fd(), | ||
libc::SOL_FILTER, | ||
libc::FIL_ATTACH, | ||
val.as_ptr().cast(), | ||
val.len() as libc::socklen_t, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are passing the whole buffer to the syscall, is this something expected?
BTW, the below code should mirror the original implementation:
#[derive(Clone)]
pub struct FilterAttach<'a> {
_marker: std::marker::PhantomData<&'a ()>
}
impl<'a> FilterAttach<'a> {
pub fn new() -> Self {
Self {
_marker: std::marker::PhantomData,
}
}
}
impl<'a> SetSockOpt for FilterAttach<'a> {
type Val = &'a OsStr;
fn set<F: std::os::unix::prelude::AsFd>(&self, fd: &F, val: &Self::Val) -> nix::Result<()> {
unsafe {
let res = libc::setsockopt(
fd.as_fd().as_raw_fd(),
libc::SOL_FILTER,
libc::FIL_ATTACH,
val.as_ptr().cast(),
val.len() as libc::socklen_t,
);
Errno::result(res).map(drop)
}
}
}
915fcf8
to
21690ce
Compare
@@ -20,6 +20,10 @@ use std::os::unix::io::{AsFd, AsRawFd}; | |||
#[cfg(feature = "net")] | |||
const TCP_CA_NAME_MAX: usize = 16; | |||
|
|||
#[cfg(target_os = "illumos")] | |||
#[cfg(feature = "net")] | |||
const FILNAME_MAX: usize = 32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the constant from the libc crate:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I tried to avoid the cast ;) but ok
Can we have tests for this? |
Respectively FIL_ATTACH/FIL_DETACH to bind/unbind a filter to a socket to for example delay connection acceptance until data (datafilt) is received.