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
@@ -987,25 +987,6 @@ sockopt_impl!(
987
987
libc:: SO_ACCEPTFILTER ,
988
988
libc:: accept_filter_arg
989
989
) ;
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
990
#[ cfg( target_os = "linux" ) ]
1010
991
sockopt_impl ! (
1011
992
/// Set the mark for each packet sent through this socket (similar to the
@@ -1501,6 +1482,82 @@ impl SetSockOpt for TcpTlsRx {
1501
1482
}
1502
1483
}
1503
1484
1485
+ #[ cfg( target_os = "illumos" ) ]
1486
+ #[ derive( Copy , Clone , Debug ) ]
1487
+ /// Attach a named filter to this socket to be able to
1488
+ /// defer when anough byte had been buffered by the kernel
1489
+ pub struct FilterAttach < ' a > {
1490
+ _marker : std:: marker:: PhantomData < & ' a ( ) > ,
1491
+ }
1492
+
1493
+ #[ cfg( target_os = "illumos" ) ]
1494
+ impl < ' a > FilterAttach < ' a > {
1495
+ #[ allow( missing_docs) ]
1496
+ pub fn new ( ) -> Self {
1497
+ Self {
1498
+ _marker : std:: marker:: PhantomData ,
1499
+ }
1500
+ }
1501
+ }
1502
+
1503
+ #[ cfg( target_os = "illumos" ) ]
1504
+ impl < ' a > SetSockOpt for FilterAttach < ' a > {
1505
+ type Val = & ' a OsStr ;
1506
+
1507
+ fn set < F : AsFd > ( & self , fd : & F , val : & Self :: Val ) -> Result < ( ) > {
1508
+ if val. len ( ) > libc:: FILNAME_MAX as usize {
1509
+ return Err ( Errno :: EINVAL ) ;
1510
+ }
1511
+ unsafe {
1512
+ let res = libc:: setsockopt (
1513
+ fd. as_fd ( ) . as_raw_fd ( ) ,
1514
+ libc:: SOL_FILTER ,
1515
+ libc:: FIL_ATTACH ,
1516
+ val. to_string_lossy ( ) . as_ptr ( ) . cast ( ) ,
1517
+ val. len ( ) as libc:: socklen_t ,
1518
+ ) ;
1519
+ Errno :: result ( res) . map ( drop)
1520
+ }
1521
+ }
1522
+ }
1523
+
1524
+ #[ cfg( target_os = "illumos" ) ]
1525
+ #[ derive( Copy , Clone , Debug ) ]
1526
+ /// Detach a socket filter previously attached with FIL_ATTACH
1527
+ pub struct FilterDetach < ' a > {
1528
+ _marker : std:: marker:: PhantomData < & ' a ( ) > ,
1529
+ }
1530
+
1531
+ #[ cfg( target_os = "illumos" ) ]
1532
+ impl < ' a > FilterDetach < ' a > {
1533
+ #[ allow( missing_docs) ]
1534
+ pub fn new ( ) -> Self {
1535
+ Self {
1536
+ _marker : std:: marker:: PhantomData ,
1537
+ }
1538
+ }
1539
+ }
1540
+
1541
+ #[ cfg( target_os = "illumos" ) ]
1542
+ impl < ' a > SetSockOpt for FilterDetach < ' a > {
1543
+ type Val = & ' a OsStr ;
1544
+
1545
+ fn set < F : AsFd > ( & self , fd : & F , val : & Self :: Val ) -> Result < ( ) > {
1546
+ if val. len ( ) > libc:: FILNAME_MAX as usize {
1547
+ return Err ( Errno :: EINVAL ) ;
1548
+ }
1549
+ unsafe {
1550
+ let res = libc:: setsockopt (
1551
+ fd. as_fd ( ) . as_raw_fd ( ) ,
1552
+ libc:: SOL_FILTER ,
1553
+ libc:: FIL_DETACH ,
1554
+ val. to_string_lossy ( ) . as_ptr ( ) . cast ( ) ,
1555
+ val. len ( ) as libc:: socklen_t ,
1556
+ ) ;
1557
+ Errno :: result ( res) . map ( drop)
1558
+ }
1559
+ }
1560
+ }
1504
1561
/*
1505
1562
*
1506
1563
* ===== Accessor helpers =====
0 commit comments