xref: /freebsd/tools/regression/sockets/unix_cmsg/README (revision b57181586ca9e82482f3286303b5b57273d4c8ee)
15368db27SMaxim Konovalov$FreeBSD$
25368db27SMaxim Konovalov
35368db27SMaxim KonovalovAbout unix_cmsg
4*b5718158SSergey Kandaurov===============
55368db27SMaxim Konovalov
6*b5718158SSergey KandaurovThis program is a collection of regression tests for ancillary data
7*b5718158SSergey Kandaurov(control information) for PF_LOCAL sockets (local domain or Unix domain
8*b5718158SSergey Kandaurovsockets).  There are tests for stream and datagram sockets.
95368db27SMaxim Konovalov
10*b5718158SSergey KandaurovUsually each test does following steps: creates Server, forks Client,
11*b5718158SSergey KandaurovClient sends something to Server, Server verifies whether everything is
12*b5718158SSergey Kandaurovcorrect in received message(s).
135368db27SMaxim Konovalov
145368db27SMaxim KonovalovIt is better to change the owner of unix_cmsg to some safe user
15*b5718158SSergey Kandaurov(eg. nobody:nogroup) and set SUID and SGID bits, else some tests that
16*b5718158SSergey Kandaurovcheck credentials can give correct results for wrong implementation.
17*b5718158SSergey Kandaurov
18*b5718158SSergey KandaurovIt is better to run this program by a user that belongs to more
19*b5718158SSergey Kandaurovthan 16 groups.
205368db27SMaxim Konovalov
215368db27SMaxim KonovalovAvailable options
225368db27SMaxim Konovalov=================
235368db27SMaxim Konovalov
24*b5718158SSergey Kandaurovusage: unix_cmsg [-dh] [-n num] [-s size] [-t type] [-z value] [testno]
255368db27SMaxim Konovalov
26*b5718158SSergey Kandaurov Options are:
27*b5718158SSergey Kandaurov  -d            Output debugging information
28*b5718158SSergey Kandaurov  -h            Output the help message and exit
29*b5718158SSergey Kandaurov  -n num        Number of messages to send
30*b5718158SSergey Kandaurov  -s size       Specify size of data for IPC
31*b5718158SSergey Kandaurov  -t type       Specify socket type (stream, dgram) for tests
32*b5718158SSergey Kandaurov  -z value      Do not send data in a message (bit 0x1), do not send
33*b5718158SSergey Kandaurov                data array associated with a cmsghdr structure (bit 0x2)
34*b5718158SSergey Kandaurov  testno        Run one test by its number (require the -t option)
355368db27SMaxim Konovalov
36*b5718158SSergey KandaurovDescription
37*b5718158SSergey Kandaurov===========
385368db27SMaxim Konovalov
39*b5718158SSergey KandaurovIf Client sends something to Server, then it sends 5 messages by default.
40*b5718158SSergey KandaurovNumber of messages can be changed in the -n command line option.  Number
41*b5718158SSergey Kandaurovof messages will be given as N in the following descriptions.
425368db27SMaxim Konovalov
43*b5718158SSergey KandaurovIf Client sends something to Server, then it sends some data (few bytes)
44*b5718158SSergey Kandaurovin each message by default.  The size of this data can be changed by the -s
45*b5718158SSergey Kandaurovcommand line option.  The "-s 0" command line option means, that Client will
46*b5718158SSergey Kandaurovsend zero bytes represented by { NULL, 0 } value of struct iovec{}, referenced
47*b5718158SSergey Kandaurovby the msg_iov field from struct msghdr{}.  The "-z 1" or "-z 3" command line
48*b5718158SSergey Kandaurovoption means, that Client will send zero bytes represented by the NULL value
49*b5718158SSergey Kandaurovin the msg_iov field from struct msghdr{}.
505368db27SMaxim Konovalov
51*b5718158SSergey KandaurovIf Client sends some ancillary data object, then this ancillary data object
52*b5718158SSergey Kandaurovalways has associated data array by default.  The "-z 2" or "-z 3" option
53*b5718158SSergey Kandaurovmeans, that Client will not send associated data array if possible.
545368db27SMaxim Konovalov
555368db27SMaxim KonovalovFor SOCK_STREAM sockets:
565368db27SMaxim Konovalov-----------------------
575368db27SMaxim Konovalov
585368db27SMaxim Konovalov 1: Sending, receiving cmsgcred
595368db27SMaxim Konovalov
60*b5718158SSergey Kandaurov    Client connects to Server and sends N messages with SCM_CREDS ancillary
61*b5718158SSergey Kandaurov    data object.  Server should receive N messages, each message should
62*b5718158SSergey Kandaurov    have SCM_CREDS ancillary data object followed by struct cmsgcred{}.
635368db27SMaxim Konovalov
64*b5718158SSergey Kandaurov 2: Receiving sockcred (listening socket)
655368db27SMaxim Konovalov
66*b5718158SSergey Kandaurov    Server creates a listening stream socket and sets the LOCAL_CREDS
67*b5718158SSergey Kandaurov    socket option for it.  Client connects to Server two times, each time
68*b5718158SSergey Kandaurov    it sends N messages.  Server accepts two connections and receives N
69*b5718158SSergey Kandaurov    messages from each connection.  The first message from each connection
70*b5718158SSergey Kandaurov    should have SCM_CREDS ancillary data object followed by struct sockcred{},
71*b5718158SSergey Kandaurov    next messages from the same connection should not have ancillary data.
725368db27SMaxim Konovalov
73*b5718158SSergey Kandaurov 3: Receiving sockcred (accepted socket)
745368db27SMaxim Konovalov
75*b5718158SSergey Kandaurov    Client connects to Server.  Server accepts connection and sets the
76*b5718158SSergey Kandaurov    LOCAL_CREDS socket option for just accepted socket.  Client sends N
77*b5718158SSergey Kandaurov    messages to Server.  Server should receive N messages, the first
78*b5718158SSergey Kandaurov    message should have SCM_CREDS ancillary data object followed by
79*b5718158SSergey Kandaurov    struct sockcred{}, next messages should not have ancillary data.
805368db27SMaxim Konovalov
815368db27SMaxim Konovalov 4: Sending cmsgcred, receiving sockcred
825368db27SMaxim Konovalov
83*b5718158SSergey Kandaurov    Server creates a listening stream socket and sets the LOCAL_CREDS
84*b5718158SSergey Kandaurov    socket  option for it.  Client connects to Server and sends N messages
85*b5718158SSergey Kandaurov    with SCM_CREDS ancillary data object.  Server should receive N messages,
86*b5718158SSergey Kandaurov    the first message should have SCM_CREDS ancillary data object followed
87*b5718158SSergey Kandaurov    by struct sockcred{}, each of next messages should have SCM_CREDS
88*b5718158SSergey Kandaurov    ancillary data object followed by struct cmsgcred{}.
895368db27SMaxim Konovalov
90*b5718158SSergey Kandaurov 5: Sending, receiving timeval
915368db27SMaxim Konovalov
92*b5718158SSergey Kandaurov    Client connects to Server and sends message with SCM_TIMESTAMP ancillary
93*b5718158SSergey Kandaurov    data object.  Server should receive one message with SCM_TIMESTAMP
94*b5718158SSergey Kandaurov    ancillary data object followed by struct timeval{}.
95*b5718158SSergey Kandaurov
96*b5718158SSergey Kandaurov 6: Sending, receiving bintime
97*b5718158SSergey Kandaurov
98*b5718158SSergey Kandaurov    Client connects to Server and sends message with SCM_BINTIME ancillary
99*b5718158SSergey Kandaurov    data object.  Server should receive one message with SCM_BINTIME
100*b5718158SSergey Kandaurov    ancillary data object followed by struct bintime{}.
101*b5718158SSergey Kandaurov
102*b5718158SSergey Kandaurov 7: Checking cmsghdr.cmsg_len
103*b5718158SSergey Kandaurov
104*b5718158SSergey Kandaurov    Client connects to Server and tries to send several messages with
105*b5718158SSergey Kandaurov    SCM_CREDS ancillary data object that has wrong cmsg_len field in its
106*b5718158SSergey Kandaurov    struct cmsghdr{}.  All these attempts should fail, since cmsg_len
107*b5718158SSergey Kandaurov    in all requests is less than CMSG_LEN(0).
108*b5718158SSergey Kandaurov
109*b5718158SSergey Kandaurov 8: Check LOCAL_PEERCRED socket option
110*b5718158SSergey Kandaurov
111*b5718158SSergey Kandaurov    This test does not use ancillary data, but can be implemented here.
112*b5718158SSergey Kandaurov    Client connects to Server.  Both Client and Server verify that
113*b5718158SSergey Kandaurov    credentials of the peer are correct using LOCAL_PEERCRED socket option.
1145368db27SMaxim Konovalov
1155368db27SMaxim KonovalovFor SOCK_DGRAM sockets:
1165368db27SMaxim Konovalov----------------------
1175368db27SMaxim Konovalov
1185368db27SMaxim Konovalov 1: Sending, receiving cmsgcred
1195368db27SMaxim Konovalov
120*b5718158SSergey Kandaurov    Client connects to Server and sends N messages with SCM_CREDS ancillary
121*b5718158SSergey Kandaurov    data object.  Server should receive N messages, each message should
122*b5718158SSergey Kandaurov    have SCM_CREDS ancillary data object followed by struct cmsgcred{}.
1235368db27SMaxim Konovalov
1245368db27SMaxim Konovalov 2: Receiving sockcred
1255368db27SMaxim Konovalov
126*b5718158SSergey Kandaurov    Server creates datagram socket and sets the LOCAL_CREDS socket option
127*b5718158SSergey Kandaurov    for it.  Client sends N messages to Server.  Server should receive N
128*b5718158SSergey Kandaurov    messages, each message should have SCM_CREDS ancillary data object
129*b5718158SSergey Kandaurov    followed by struct sockcred{}.
1305368db27SMaxim Konovalov
1315368db27SMaxim Konovalov 3: Sending cmsgcred, receiving sockcred
1325368db27SMaxim Konovalov
133*b5718158SSergey Kandaurov    Server creates datagram socket and sets the LOCAL_CREDS socket option
134*b5718158SSergey Kandaurov    for it.  Client sends N messages with SCM_CREDS ancillary data object
135*b5718158SSergey Kandaurov    to Server.  Server should receive N messages, the first message should
136*b5718158SSergey Kandaurov    have SCM_CREDS ancillary data object followed by struct sockcred{},
137*b5718158SSergey Kandaurov    each of next messages should have SCM_CREDS ancillary data object
138*b5718158SSergey Kandaurov    followed by struct cmsgcred{}.
1395368db27SMaxim Konovalov
140*b5718158SSergey Kandaurov 4: Sending, receiving timeval
1415368db27SMaxim Konovalov
142*b5718158SSergey Kandaurov    Client sends one message with SCM_TIMESTAMP ancillary data object
143*b5718158SSergey Kandaurov    to Server.  Server should receive one message with SCM_TIMESTAMP
144*b5718158SSergey Kandaurov    ancillary data object followed by struct timeval{}.
145*b5718158SSergey Kandaurov
146*b5718158SSergey Kandaurov 5: Sending, receiving bintime
147*b5718158SSergey Kandaurov
148*b5718158SSergey Kandaurov    Client sends one message with SCM_BINTIME ancillary data object
149*b5718158SSergey Kandaurov    to Server.  Server should receive one message with SCM_BINTIME
150*b5718158SSergey Kandaurov    ancillary data object followed by struct bintime{}.
151*b5718158SSergey Kandaurov
152*b5718158SSergey Kandaurov 6: Checking cmsghdr.cmsg_len
153*b5718158SSergey Kandaurov
154*b5718158SSergey Kandaurov    Client tries to send Server several messages with SCM_CREDS ancillary
155*b5718158SSergey Kandaurov    data object that has wrong cmsg_len field in its struct cmsghdr{}.
156*b5718158SSergey Kandaurov    All these attempts should fail, since cmsg_len in all requests is less
157*b5718158SSergey Kandaurov    than CMSG_LEN(0).
1585368db27SMaxim Konovalov
1595368db27SMaxim Konovalov- Andrey Simonenko
160*b5718158SSergey Kandaurovandreysimonenko@users.sourceforge.net
161