@@ -5,8 +5,9 @@ use netlink_packet_utils::traits::{Emitable, Parseable};
55use crate :: {
66 constants:: * ,
77 unix:: {
8- nlas:: Nla , ShowFlags , StateFlags , UnixRequest , UnixResponse ,
9- UnixResponseBuffer , UnixResponseHeader ,
8+ nlas:: { Nla , UnixDiagName } ,
9+ ShowFlags , StateFlags , UnixRequest , UnixResponse , UnixResponseBuffer ,
10+ UnixResponseHeader ,
1011 } ,
1112} ;
1213
@@ -39,7 +40,7 @@ lazy_static! {
3940 cookie: [ 0xa0 , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
4041 } ,
4142 nlas: smallvec![
42- Nla :: Name ( "/tmp/.ICE-unix/1151" . to_string ( ) ) ,
43+ Nla :: Name ( UnixDiagName :: Pathname ( "/tmp/.ICE-unix/1151" . into ( ) ) ) ,
4344 Nla :: ReceiveQueueLength ( 0 , 128 ) ,
4445 Nla :: Shutdown ( 0 ) ,
4546 ]
@@ -101,7 +102,7 @@ lazy_static! {
101102 cookie: [ 0x22 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ]
102103 } ,
103104 nlas: smallvec![
104- Nla :: Name ( "/run/user/1000/bus" . to_string ( ) ) ,
105+ Nla :: Name ( UnixDiagName :: Pathname ( "/run/user/1000/bus" . into ( ) ) ) ,
105106 Nla :: Peer ( 31062 ) ,
106107 Nla :: ReceiveQueueLength ( 0 , 0 ) ,
107108 Nla :: Shutdown ( 0 ) ,
@@ -165,3 +166,65 @@ fn emit_socket_info() {
165166 SOCKET_INFO . emit ( & mut buf) ;
166167 assert_eq ! ( & buf[ ..] , & SOCKET_INFO_BUF [ ..] ) ;
167168}
169+
170+ lazy_static ! {
171+ static ref ABSTRACT_ADDRESS : UnixResponse = UnixResponse {
172+ header: UnixResponseHeader {
173+ kind: SOCK_STREAM ,
174+ state: TCP_LISTEN ,
175+ inode: 20238 ,
176+ cookie: [ 0xa0 , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
177+ } ,
178+ nlas: smallvec![
179+ Nla :: Name ( UnixDiagName :: Abstract (
180+ "1c1440c5f5e2a52e/bus/systemd/\0 /bus-api-user" . into( )
181+ ) ) ,
182+ Nla :: ReceiveQueueLength ( 0 , 128 ) ,
183+ Nla :: Shutdown ( 0 ) ,
184+ ]
185+ } ;
186+ }
187+
188+ #[ rustfmt:: skip]
189+ static ABSTRACT_ADDRESS_BUF : [ u8 ; 84 ] = [
190+ 0x01 , // family: AF_UNIX
191+ 0x01 , // type: SOCK_STREAM
192+ 0x0a , // state: TCP_LISTEN
193+ 0x00 , // padding
194+ 0x0e , 0x4f , 0x00 , 0x00 , // inode number
195+ 0xa0 , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , // cookie
196+
197+ // NLAs
198+ 0x30 , 0x00 , // length: 48
199+ 0x00 , 0x00 , // type: UNIX_DIAG_NAME
200+ // value: \01c1440c5f5e2a52e/bus/systemd/\0/bus-api-user
201+ 0x00 , 0x31 , 0x63 , 0x31 , 0x34 , 0x34 , 0x30 , 0x63 , 0x35 , 0x66 , 0x35 , 0x65 , 0x32 , 0x61 , 0x35 , 0x32 , 0x65 , 0x2f , 0x62 , 0x75 , 0x73 , 0x2f , 0x73 , 0x79 , 0x73 , 0x74 , 0x65 , 0x6d , 0x64 , 0x2f , 0x00 , 0x2f , 0x62 , 0x75 , 0x73 , 0x2d , 0x61 , 0x70 , 0x69 , 0x2d , 0x75 , 0x73 , 0x65 , 0x72 ,
202+
203+ 0x0c , 0x00 , // length: 12
204+ 0x04 , 0x00 , // type: UNIX_DIAG_RQLEN
205+ // value: ReceiveQueueLength(0, 128)
206+ 0x00 , 0x00 , 0x00 , 0x00 ,
207+ 0x80 , 0x00 , 0x00 , 0x00 ,
208+
209+ 0x05 , 0x00 , // length: 5
210+ 0x06 , 0x00 , // type: UNIX_DIAG_SHUTDOWN
211+ 0x00 , // value: 0
212+ 0x00 , 0x00 , 0x00 // padding
213+ ] ;
214+
215+ #[ test]
216+ fn parse_abstract_address ( ) {
217+ let parsed = UnixResponse :: parse (
218+ & UnixResponseBuffer :: new_checked ( & & ABSTRACT_ADDRESS_BUF [ ..] ) . unwrap ( ) ,
219+ )
220+ . unwrap ( ) ;
221+ assert_eq ! ( parsed, * ABSTRACT_ADDRESS ) ;
222+ }
223+
224+ #[ test]
225+ fn emit_abstract_address ( ) {
226+ assert_eq ! ( ABSTRACT_ADDRESS . buffer_len( ) , 84 ) ;
227+ let mut buf = vec ! [ 0xff ; ABSTRACT_ADDRESS . buffer_len( ) ] ;
228+ ABSTRACT_ADDRESS . emit ( & mut buf) ;
229+ assert_eq ! ( & buf[ ..] , & ABSTRACT_ADDRESS_BUF [ ..] ) ;
230+ }
0 commit comments