File tree Expand file tree Collapse file tree 3 files changed +86
-1
lines changed Expand file tree Collapse file tree 3 files changed +86
-1
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
3030 ([ #1841 ] ( https://github.com/nix-rust/nix/pull/1841 ) )
3131- Added ` eaccess() ` on FreeBSD, DragonFly and Linux (glibc and musl).
3232 ([ #1842 ] ( https://github.com/nix-rust/nix/pull/1842 ) )
33-
33+ - Added ` IP_TOS ` ` SO_PRIORITY ` and ` IPV6_TCLASS ` sockopts for Linux
34+ ([ #1853 ] ( https://github.com/nix-rust/nix/pull/1853 ) )
35+
3436### Changed
3537
3638- The MSRV is now 1.56.1
Original file line number Diff line number Diff line change @@ -371,6 +371,41 @@ sockopt_impl!(
371371 libc:: IP_MULTICAST_LOOP ,
372372 bool
373373) ;
374+ #[ cfg( target_os = "linux" ) ]
375+ #[ cfg( feature = "net" ) ]
376+ sockopt_impl ! (
377+ #[ cfg_attr( docsrs, doc( cfg( feature = "net" ) ) ) ]
378+ /// Set the protocol-defined priority for all packets to be
379+ /// sent on this socket
380+ Priority ,
381+ Both ,
382+ libc:: SOL_SOCKET ,
383+ libc:: SO_PRIORITY ,
384+ libc:: c_int
385+ ) ;
386+ #[ cfg( target_os = "linux" ) ]
387+ #[ cfg( feature = "net" ) ]
388+ sockopt_impl ! (
389+ #[ cfg_attr( docsrs, doc( cfg( feature = "net" ) ) ) ]
390+ /// Set or receive the Type-Of-Service (TOS) field that is
391+ /// sent with every IP packet originating from this socket
392+ IpTos ,
393+ Both ,
394+ libc:: IPPROTO_IP ,
395+ libc:: IP_TOS ,
396+ libc:: c_int
397+ ) ;
398+ #[ cfg( target_os = "linux" ) ]
399+ #[ cfg( feature = "net" ) ]
400+ sockopt_impl ! (
401+ #[ cfg_attr( docsrs, doc( cfg( feature = "net" ) ) ) ]
402+ /// Traffic class associated with outgoing packets
403+ Ipv6TClass ,
404+ Both ,
405+ libc:: IPPROTO_IPV6 ,
406+ libc:: IPV6_TCLASS ,
407+ libc:: c_int
408+ ) ;
374409#[ cfg( any( target_os = "android" , target_os = "fuchsia" , target_os = "linux" ) ) ]
375410#[ cfg( feature = "net" ) ]
376411sockopt_impl ! (
Original file line number Diff line number Diff line change @@ -327,3 +327,51 @@ fn test_v6dontfrag_opts() {
327327 "unsetting IPV6_DONTFRAG on an inet6 datagram socket should succeed" ,
328328 ) ;
329329}
330+
331+ #[ test]
332+ #[ cfg( target_os = "linux" ) ]
333+ fn test_so_priority ( ) {
334+ let fd = socket (
335+ AddressFamily :: Inet ,
336+ SockType :: Stream ,
337+ SockFlag :: empty ( ) ,
338+ SockProtocol :: Tcp ,
339+ )
340+ . unwrap ( ) ;
341+ let priority = 3 ;
342+ setsockopt ( fd, sockopt:: Priority , & priority) . unwrap ( ) ;
343+ assert_eq ! ( getsockopt( fd, sockopt:: Priority ) . unwrap( ) , priority) ;
344+ }
345+
346+ #[ test]
347+ #[ cfg( target_os = "linux" ) ]
348+ fn test_ip_tos ( ) {
349+ let fd = socket (
350+ AddressFamily :: Inet ,
351+ SockType :: Stream ,
352+ SockFlag :: empty ( ) ,
353+ SockProtocol :: Tcp ,
354+ )
355+ . unwrap ( ) ;
356+ let tos = 0x80 ; // CS4
357+ setsockopt ( fd, sockopt:: IpTos , & tos) . unwrap ( ) ;
358+ assert_eq ! ( getsockopt( fd, sockopt:: IpTos ) . unwrap( ) , tos) ;
359+ }
360+
361+ #[ test]
362+ #[ cfg( target_os = "linux" ) ]
363+ // Disable the test under emulation because it fails in Cirrus-CI. Lack
364+ // of QEMU support is suspected.
365+ #[ cfg_attr( qemu, ignore) ]
366+ fn test_ipv6_tclass ( ) {
367+ let fd = socket (
368+ AddressFamily :: Inet6 ,
369+ SockType :: Stream ,
370+ SockFlag :: empty ( ) ,
371+ SockProtocol :: Tcp ,
372+ )
373+ . unwrap ( ) ;
374+ let class = 0x80 ; // CS4
375+ setsockopt ( fd, sockopt:: Ipv6TClass , & class) . unwrap ( ) ;
376+ assert_eq ! ( getsockopt( fd, sockopt:: Ipv6TClass ) . unwrap( ) , class) ;
377+ }
You can’t perform that action at this time.
0 commit comments