1
1
//! Socket options as used by `setsockopt` and `getsockopt`.
2
- #[ cfg( linux_android) ]
2
+ #[ cfg( any ( linux_android, target_os = "illumos" ) ) ]
3
3
use super :: SetSockOpt ;
4
4
use crate :: sys:: time:: TimeVal ;
5
- #[ cfg( linux_android) ]
5
+ #[ cfg( any ( linux_android, target_os = "illumos" ) ) ]
6
6
use crate :: { errno:: Errno , Result } ;
7
7
use cfg_if:: cfg_if;
8
8
use libc:: { self , c_int, c_void, socklen_t} ;
@@ -11,7 +11,7 @@ use std::ffi::CString;
11
11
use std:: ffi:: { CStr , OsStr , OsString } ;
12
12
use std:: mem:: { self , MaybeUninit } ;
13
13
use std:: os:: unix:: ffi:: OsStrExt ;
14
- #[ cfg( linux_android) ]
14
+ #[ cfg( any ( linux_android, target_os = "illumos" ) ) ]
15
15
use std:: os:: unix:: io:: { AsFd , AsRawFd } ;
16
16
17
17
// Constants
@@ -20,6 +20,10 @@ use std::os::unix::io::{AsFd, AsRawFd};
20
20
#[ cfg( feature = "net" ) ]
21
21
const TCP_CA_NAME_MAX : usize = 16 ;
22
22
23
+ #[ cfg( target_os = "illumos" ) ]
24
+ #[ cfg( feature = "net" ) ]
25
+ const FILNAME_MAX : usize = 32 ;
26
+
23
27
/// Helper for implementing `SetSockOpt` for a given socket option. See
24
28
/// [`::sys::socket::SetSockOpt`](sys/socket/trait.SetSockOpt.html).
25
29
///
@@ -987,25 +991,6 @@ sockopt_impl!(
987
991
libc:: SO_ACCEPTFILTER ,
988
992
libc:: accept_filter_arg
989
993
) ;
990
- #[ cfg( target_os = "illumos" ) ]
991
- sockopt_impl ! (
992
- /// Attach a named filter to this socket to be able to
993
- /// defer when anough byte had been buffered by the kernel
994
- FilAttach ,
995
- SetOnly ,
996
- libc:: SOL_FILTER ,
997
- libc:: FIL_ATTACH ,
998
- SetOsString <' static >
999
- ) ;
1000
- #[ cfg( target_os = "illumos" ) ]
1001
- sockopt_impl ! (
1002
- /// Detach a socket filter previously attached with FIL_ATTACH
1003
- FilDetach ,
1004
- SetOnly ,
1005
- libc:: SOL_FILTER ,
1006
- libc:: FIL_DETACH ,
1007
- SetOsString <' static >
1008
- ) ;
1009
994
#[ cfg( target_os = "linux" ) ]
1010
995
sockopt_impl ! (
1011
996
/// Set the mark for each packet sent through this socket (similar to the
@@ -1501,6 +1486,82 @@ impl SetSockOpt for TcpTlsRx {
1501
1486
}
1502
1487
}
1503
1488
1489
+ #[ cfg( target_os = "illumos" ) ]
1490
+ #[ derive( Copy , Clone , Debug ) ]
1491
+ /// Attach a named filter to this socket to be able to
1492
+ /// defer when anough byte had been buffered by the kernel
1493
+ pub struct FilterAttach < ' a > {
1494
+ _marker : std:: marker:: PhantomData < & ' a ( ) > ,
1495
+ }
1496
+
1497
+ #[ cfg( target_os = "illumos" ) ]
1498
+ impl < ' a > FilterAttach < ' a > {
1499
+ #[ allow( missing_docs) ]
1500
+ pub fn new ( ) -> Self {
1501
+ Self {
1502
+ _marker : std:: marker:: PhantomData ,
1503
+ }
1504
+ }
1505
+ }
1506
+
1507
+ #[ cfg( target_os = "illumos" ) ]
1508
+ impl < ' a > SetSockOpt for FilterAttach < ' a > {
1509
+ type Val = & ' a OsStr ;
1510
+
1511
+ fn set < F : AsFd > ( & self , fd : & F , val : & Self :: Val ) -> Result < ( ) > {
1512
+ if val. len ( ) > FILNAME_MAX {
1513
+ return Err ( Errno :: EINVAL ) ;
1514
+ }
1515
+ unsafe {
1516
+ let res = libc:: setsockopt (
1517
+ fd. as_fd ( ) . as_raw_fd ( ) ,
1518
+ libc:: SOL_FILTER ,
1519
+ libc:: FIL_ATTACH ,
1520
+ val. to_string_lossy ( ) . as_ptr ( ) . cast ( ) ,
1521
+ val. len ( ) as libc:: socklen_t ,
1522
+ ) ;
1523
+ Errno :: result ( res) . map ( drop)
1524
+ }
1525
+ }
1526
+ }
1527
+
1528
+ #[ cfg( target_os = "illumos" ) ]
1529
+ #[ derive( Copy , Clone , Debug ) ]
1530
+ /// Detach a socket filter previously attached with FIL_ATTACH
1531
+ pub struct FilterDetach < ' a > {
1532
+ _marker : std:: marker:: PhantomData < & ' a ( ) > ,
1533
+ }
1534
+
1535
+ #[ cfg( target_os = "illumos" ) ]
1536
+ impl < ' a > FilterDetach < ' a > {
1537
+ #[ allow( missing_docs) ]
1538
+ pub fn new ( ) -> Self {
1539
+ Self {
1540
+ _marker : std:: marker:: PhantomData ,
1541
+ }
1542
+ }
1543
+ }
1544
+
1545
+ #[ cfg( target_os = "illumos" ) ]
1546
+ impl < ' a > SetSockOpt for FilterDetach < ' a > {
1547
+ type Val = & ' a OsStr ;
1548
+
1549
+ fn set < F : AsFd > ( & self , fd : & F , val : & Self :: Val ) -> Result < ( ) > {
1550
+ if val. len ( ) > FILNAME_MAX {
1551
+ return Err ( Errno :: EINVAL ) ;
1552
+ }
1553
+ unsafe {
1554
+ let res = libc:: setsockopt (
1555
+ fd. as_fd ( ) . as_raw_fd ( ) ,
1556
+ libc:: SOL_FILTER ,
1557
+ libc:: FIL_DETACH ,
1558
+ val. to_string_lossy ( ) . as_ptr ( ) . cast ( ) ,
1559
+ val. len ( ) as libc:: socklen_t ,
1560
+ ) ;
1561
+ Errno :: result ( res) . map ( drop)
1562
+ }
1563
+ }
1564
+ }
1504
1565
/*
1505
1566
*
1506
1567
* ===== Accessor helpers =====
0 commit comments