netlink_protocol.c revision 77c3ff8e0644f1e120e4b2ebc7222150b0446f3b
1/*
2 * Check decoding of netlink protocol.
3 *
4 * Copyright (c) 2014-2017 Dmitry V. Levin <ldv@altlinux.org>
5 * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 *    derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "tests.h"
32
33#ifdef HAVE_SYS_XATTR_H
34
35# include <stdio.h>
36# include <stdlib.h>
37# include <string.h>
38# include <unistd.h>
39# include <sys/xattr.h>
40# include <netinet/in.h>
41# include "netlink.h"
42# include <linux/sock_diag.h>
43# include <linux/netlink_diag.h>
44
45static void
46send_query(const int fd)
47{
48	static const struct req {
49		struct nlmsghdr nlh;
50		const char magic[4];
51	} c_req = {
52		.nlh = {
53			.nlmsg_len = sizeof(struct req),
54			.nlmsg_type = NLMSG_NOOP,
55			.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST
56		},
57		.magic = "abcd"
58	};
59	struct req *const req = tail_memdup(&c_req, sizeof(c_req));
60	long rc;
61	const char *errstr;
62
63	/* zero address */
64	rc = sendto(fd, NULL, sizeof(*req), MSG_DONTWAIT, NULL, 0);
65	printf("sendto(%d, NULL, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
66	       fd, (unsigned) sizeof(*req), sprintrc(rc));
67
68	/* zero length */
69	rc = sendto(fd, req, 0, MSG_DONTWAIT, NULL, 0);
70	printf("sendto(%d, \"\", 0, MSG_DONTWAIT, NULL, 0) = %s\n",
71	       fd, sprintrc(rc));
72
73	/* zero address and length */
74	rc = sendto(fd, NULL, 0, MSG_DONTWAIT, NULL, 0);
75	printf("sendto(%d, NULL, 0, MSG_DONTWAIT, NULL, 0) = %s\n",
76	       fd, sprintrc(rc));
77
78	/* unfetchable struct nlmsghdr */
79	const void *const efault = tail_alloc(sizeof(struct nlmsghdr) - 1);
80	rc = sendto(fd, efault, sizeof(struct nlmsghdr), MSG_DONTWAIT, NULL, 0);
81	printf("sendto(%d, %p, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
82	       fd, efault, (unsigned) sizeof(struct nlmsghdr), sprintrc(rc));
83
84	/* whole message length < sizeof(struct nlmsghdr) */
85	rc = sendto(fd, req->magic, sizeof(req->magic), MSG_DONTWAIT, NULL, 0);
86	printf("sendto(%d, \"\\x61\\x62\\x63\\x64\""
87	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
88	       fd, (unsigned) sizeof(req->magic), sprintrc(rc));
89
90	/* a single message with some data */
91	rc = sendto(fd, req, sizeof(*req), MSG_DONTWAIT, NULL, 0);
92	printf("sendto(%d, {{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
93	       ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}"
94	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
95	       fd, req->nlh.nlmsg_len, NLM_F_DUMP,
96	       (unsigned) sizeof(*req), sprintrc(rc));
97
98	/* a single message without data */
99	req->nlh.nlmsg_len = sizeof(req->nlh);
100	rc = sendto(fd, &req->nlh, sizeof(req->nlh), MSG_DONTWAIT, NULL, 0);
101	printf("sendto(%d, {len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
102	       ", seq=0, pid=0}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
103	       fd, req->nlh.nlmsg_len, NLM_F_DUMP,
104	       (unsigned) sizeof(req->nlh), sprintrc(rc));
105
106	/* nlmsg_len > whole message length */
107	req->nlh.nlmsg_len = sizeof(*req) + 8;
108	rc = sendto(fd, req, sizeof(*req), MSG_DONTWAIT, NULL, 0);
109	printf("sendto(%d, {{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
110	       ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}"
111	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
112	       fd, req->nlh.nlmsg_len, NLM_F_DUMP,
113	       (unsigned) sizeof(*req), sprintrc(rc));
114
115	/* nlmsg_len < sizeof(struct nlmsghdr) */
116	req->nlh.nlmsg_len = 8;
117	rc = sendto(fd, req, sizeof(*req), MSG_DONTWAIT, NULL, 0);
118	printf("sendto(%d, {len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
119	       ", seq=0, pid=0}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
120	       fd, req->nlh.nlmsg_len, NLM_F_DUMP,
121	       (unsigned) sizeof(*req), sprintrc(rc));
122
123	/* a sequence of two nlmsg objects */
124	struct reqs {
125		struct req req1;
126		char padding[NLMSG_ALIGN(sizeof(struct req)) - sizeof(struct req)];
127		struct req req2;
128	} *const reqs = tail_alloc(sizeof(*reqs));
129	memcpy(&reqs->req1, &c_req, sizeof(c_req));
130	memcpy(&reqs->req2, &c_req, sizeof(c_req));
131
132	rc = sendto(fd, reqs, sizeof(*reqs), MSG_DONTWAIT, NULL, 0);
133	printf("sendto(%d, [{{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
134	       ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}"
135	       ", {{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
136	       ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}]"
137	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
138	       fd, reqs->req1.nlh.nlmsg_len, NLM_F_DUMP,
139	       reqs->req2.nlh.nlmsg_len, NLM_F_DUMP,
140	       (unsigned) sizeof(*reqs), sprintrc(rc));
141
142	/* unfetchable second struct nlmsghdr */
143	void *const efault2 = tail_memdup(&reqs->req1, sizeof(reqs->req1));
144	rc = sendto(fd, efault2, sizeof(*reqs), MSG_DONTWAIT, NULL, 0);
145	printf("sendto(%d, [{{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
146	       ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}"
147	       ", %p], %u, MSG_DONTWAIT, NULL, 0) = %s\n",
148	       fd, reqs->req1.nlh.nlmsg_len, NLM_F_DUMP,
149	       &((struct reqs *) efault2)->req2, (unsigned) sizeof(*reqs),
150	       sprintrc(rc));
151
152	/* message length is not enough for the second struct nlmsghdr */
153	rc = sendto(fd, reqs, sizeof(*reqs) - sizeof(req->nlh), MSG_DONTWAIT,
154		    NULL, 0);
155	errstr = sprintrc(rc);
156	printf("sendto(%d, [{{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
157	       ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}, ",
158	       fd, reqs->req1.nlh.nlmsg_len, NLM_F_DUMP);
159	print_quoted_hex(&reqs->req2.nlh,
160			 sizeof(reqs->req2) - sizeof(req->nlh));
161	printf("], %u, MSG_DONTWAIT, NULL, 0) = %s\n",
162	       (unsigned) (sizeof(*reqs) - sizeof(req->nlh)), errstr);
163
164	/* second nlmsg_len < sizeof(struct nlmsghdr) */
165	reqs->req2.nlh.nlmsg_len = 4;
166	rc = sendto(fd, reqs, sizeof(*reqs), MSG_DONTWAIT, NULL, 0);
167	printf("sendto(%d, [{{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
168	       ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}"
169	       ", {len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
170	       ", seq=0, pid=0}], %u, MSG_DONTWAIT, NULL, 0) = %s\n",
171	       fd, reqs->req1.nlh.nlmsg_len, NLM_F_DUMP,
172	       reqs->req2.nlh.nlmsg_len, NLM_F_DUMP,
173	       (unsigned) sizeof(*reqs), sprintrc(rc));
174
175	/* abbreviated output */
176# define ABBREV_LEN (DEFAULT_STRLEN + 1)
177	const unsigned int msg_len = sizeof(struct nlmsghdr) * ABBREV_LEN;
178	struct nlmsghdr *const msgs = tail_alloc(msg_len);
179	unsigned int i;
180	for (i = 0; i < ABBREV_LEN; ++i) {
181		msgs[i].nlmsg_len = sizeof(*msgs);
182		msgs[i].nlmsg_type = NLMSG_NOOP;
183		msgs[i].nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST;
184		msgs[i].nlmsg_seq = i;
185		msgs[i].nlmsg_pid = 0;
186	}
187
188	rc = sendto(fd, msgs, msg_len, MSG_DONTWAIT, NULL, 0);
189	errstr = sprintrc(rc);
190	printf("sendto(%d, [", fd);
191	for (i = 0; i < DEFAULT_STRLEN; ++i) {
192		if (i)
193			printf(", ");
194		printf("{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
195		       ", seq=%u, pid=0}",
196		       msgs[i].nlmsg_len, NLM_F_DUMP, msgs[i].nlmsg_seq);
197	}
198	printf(", ...], %u, MSG_DONTWAIT, NULL, 0) = %s\n", msg_len, errstr);
199}
200
201static void
202test_nlmsgerr(const int fd)
203{
204	struct nlmsgerr *err;
205	struct nlmsghdr *nlh;
206	void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
207	long rc;
208
209	/* error message without enough room for the error code */
210	nlh = nlh0;
211	nlh->nlmsg_len = NLMSG_HDRLEN + 4;
212	nlh->nlmsg_type = NLMSG_ERROR;
213	nlh->nlmsg_flags = NLM_F_REQUEST;
214	nlh->nlmsg_seq = 0;
215	nlh->nlmsg_pid = 0;
216
217	rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
218	printf("sendto(%d, {{len=%u, type=NLMSG_ERROR, flags=NLM_F_REQUEST"
219	       ", seq=0, pid=0}, %p}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
220	       fd, nlh->nlmsg_len, nlh0 + NLMSG_HDRLEN,
221	       nlh->nlmsg_len, sprintrc(rc));
222
223	nlh->nlmsg_len = NLMSG_HDRLEN + 2;
224	nlh = nlh0 - 2;
225	memmove(nlh, nlh0, sizeof(*nlh));
226	memcpy(NLMSG_DATA(nlh), "42", 2);
227
228	rc = sendto(fd, nlh, NLMSG_HDRLEN + 2, MSG_DONTWAIT, NULL, 0);
229	printf("sendto(%d, {{len=%u, type=NLMSG_ERROR, flags=NLM_F_REQUEST"
230	       ", seq=0, pid=0}, \"\\x34\\x32\"}"
231	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
232	       fd, NLMSG_HDRLEN + 2, NLMSG_HDRLEN + 2, sprintrc(rc));
233
234	/* error message with room for the error code only */
235	nlh = nlh0 - sizeof(err->error);
236	nlh->nlmsg_len = NLMSG_HDRLEN + sizeof(err->error);
237	nlh->nlmsg_type = NLMSG_ERROR;
238	nlh->nlmsg_flags = NLM_F_REQUEST;
239	nlh->nlmsg_seq = 0;
240	nlh->nlmsg_pid = 0;
241	err = NLMSG_DATA(nlh);
242	err->error = 42;
243
244	rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
245	printf("sendto(%d, {{len=%u, type=NLMSG_ERROR, flags=NLM_F_REQUEST"
246	       ", seq=0, pid=0}, {error=42}}, %u, MSG_DONTWAIT, NULL, 0)"
247	       " = %s\n", fd, nlh->nlmsg_len, nlh->nlmsg_len, sprintrc(rc));
248
249	err->error = -1;
250
251	rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
252	printf("sendto(%d, {{len=%u, type=NLMSG_ERROR, flags=NLM_F_REQUEST"
253	       ", seq=0, pid=0}, {error=-EPERM}}, %u, MSG_DONTWAIT, NULL, 0)"
254	       " = %s\n", fd, nlh->nlmsg_len, nlh->nlmsg_len, sprintrc(rc));
255
256	err->error = -32767;
257	nlh->nlmsg_len += sizeof(err->msg.nlmsg_len);
258
259	rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
260	printf("sendto(%d, {{len=%u, type=NLMSG_ERROR, flags=NLM_F_REQUEST"
261	       ", seq=0, pid=0}, {error=-32767, msg=%p}}"
262	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
263	       fd, nlh->nlmsg_len, nlh0 + NLMSG_HDRLEN,
264	       nlh->nlmsg_len, sprintrc(rc));
265
266	/* error message with room for the error code and a header */
267	nlh = nlh0 - sizeof(*err);
268	nlh->nlmsg_len = NLMSG_HDRLEN + sizeof(*err);
269	nlh->nlmsg_type = NLMSG_ERROR;
270	nlh->nlmsg_flags = NLM_F_REQUEST;
271	nlh->nlmsg_seq = 0;
272	nlh->nlmsg_pid = 0;
273	err = NLMSG_DATA(nlh);
274	err->error = -13;
275	err->msg.nlmsg_len = NLMSG_HDRLEN;
276	err->msg.nlmsg_type = NLMSG_NOOP;
277	err->msg.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST;
278	err->msg.nlmsg_seq = 42;
279	err->msg.nlmsg_pid = 1234;
280
281	rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
282	printf("sendto(%d, {{len=%u, type=NLMSG_ERROR, flags=NLM_F_REQUEST"
283	       ", seq=0, pid=0}, {error=-EACCES"
284	       ", msg={len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
285	       ", seq=%u, pid=%u}}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
286	       fd, nlh->nlmsg_len, err->msg.nlmsg_len, NLM_F_DUMP,
287	       err->msg.nlmsg_seq, err->msg.nlmsg_pid,
288	       nlh->nlmsg_len, sprintrc(rc));
289
290	/* error message with room for the error code, a header, and some data */
291	nlh = nlh0 - sizeof(*err) - 4;
292	nlh->nlmsg_len = NLMSG_HDRLEN + sizeof(*err) + 4;
293	nlh->nlmsg_type = NLMSG_ERROR;
294	nlh->nlmsg_flags = NLM_F_REQUEST;
295	nlh->nlmsg_seq = 0;
296	nlh->nlmsg_pid = 0;
297	err = NLMSG_DATA(nlh);
298	err->error = -13;
299	err->msg.nlmsg_len = NLMSG_HDRLEN + 4;
300	err->msg.nlmsg_type = NLMSG_NOOP;
301	err->msg.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST;
302	err->msg.nlmsg_seq = 421;
303	err->msg.nlmsg_pid = 12345;
304	memcpy(NLMSG_DATA(&err->msg), "abcd", 4);
305
306	rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
307	printf("sendto(%d, {{len=%u, type=NLMSG_ERROR, flags=NLM_F_REQUEST"
308	       ", seq=0, pid=0}, {error=-EACCES"
309	       ", msg={{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
310	       ", seq=%u, pid=%u}, \"\\x61\\x62\\x63\\x64\"}}}"
311	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
312	       fd, nlh->nlmsg_len, err->msg.nlmsg_len, NLM_F_DUMP,
313	       err->msg.nlmsg_seq, err->msg.nlmsg_pid,
314	       nlh->nlmsg_len, sprintrc(rc));
315}
316
317static void
318test_nlmsg_done(const int fd)
319{
320	struct nlmsghdr *nlh;
321	void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
322	long rc;
323	const int num = 0xfacefeed;
324
325	/* NLMSG_DONE message without enough room for an integer payload */
326	nlh = nlh0;
327	*nlh = (struct nlmsghdr) {
328		.nlmsg_len = NLMSG_HDRLEN + sizeof(num),
329		.nlmsg_type = NLMSG_DONE,
330		.nlmsg_flags = NLM_F_MULTI
331	};
332
333	rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
334	printf("sendto(%d, {{len=%u, type=NLMSG_DONE, flags=NLM_F_MULTI"
335	       ", seq=0, pid=0}, %p}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
336	       fd, nlh->nlmsg_len, nlh0 + NLMSG_HDRLEN,
337	       nlh->nlmsg_len, sprintrc(rc));
338
339	/* NLMSG_DONE message with enough room for an oddly short payload */
340	nlh->nlmsg_len = NLMSG_HDRLEN + 2;
341	nlh = nlh0 - 2;
342	/* Beware of unaligned access to nlh members. */
343	memmove(nlh, nlh0, sizeof(*nlh));
344	memcpy(NLMSG_DATA(nlh), "42", 2);
345
346	rc = sendto(fd, nlh, NLMSG_HDRLEN + 2, MSG_DONTWAIT, NULL, 0);
347	printf("sendto(%d, {{len=%u, type=NLMSG_DONE, flags=NLM_F_MULTI, seq=0"
348	       ", pid=0}, \"\\x34\\x32\"}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
349	       fd, NLMSG_HDRLEN + 2, NLMSG_HDRLEN + 2, sprintrc(rc));
350
351	/* NLMSG_DONE message with enough room for an integer payload */
352	nlh = nlh0 - sizeof(num);
353	*nlh = (struct nlmsghdr) {
354		.nlmsg_len = NLMSG_HDRLEN + sizeof(num),
355		.nlmsg_type = NLMSG_DONE,
356		.nlmsg_flags = NLM_F_MULTI
357	};
358	memcpy(NLMSG_DATA(nlh), &num, sizeof(num));
359
360	rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0);
361	printf("sendto(%d, {{len=%u, type=NLMSG_DONE, flags=NLM_F_MULTI"
362	       ", seq=0, pid=0}, %d}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
363	       fd, nlh->nlmsg_len, num, nlh->nlmsg_len, sprintrc(rc));
364}
365
366#if defined NLM_F_CAPPED || defined NLM_F_ACK_TLVS
367static void
368test_ack_flags(const int fd)
369{
370	long rc;
371	struct nlmsghdr nlh = {
372		.nlmsg_len = sizeof(nlh),
373		.nlmsg_type = NLMSG_ERROR,
374	};
375
376#ifdef NLM_F_CAPPED
377	nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_CAPPED,
378	rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
379	printf("sendto(%d, {len=%u, type=NLMSG_ERROR"
380	       ", flags=NLM_F_REQUEST|NLM_F_CAPPED, seq=0, pid=0}"
381	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
382	       fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
383#endif
384
385#ifdef NLM_F_ACK_TLVS
386	nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK_TLVS;
387	rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
388	printf("sendto(%d, {len=%u, type=NLMSG_ERROR"
389	       ", flags=NLM_F_REQUEST|NLM_F_ACK_TLVS, seq=0, pid=0}"
390	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
391	       fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
392#endif
393
394#if defined NLM_F_CAPPED && defined NLM_F_ACK_TLVS
395	nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_CAPPED | NLM_F_ACK_TLVS;
396	rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
397	printf("sendto(%d, {len=%u, type=NLMSG_ERROR"
398	       ", flags=NLM_F_REQUEST|NLM_F_CAPPED|NLM_F_ACK_TLVS, seq=0, pid=0}"
399	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
400	       fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
401#endif
402}
403#endif
404
405int main(void)
406{
407	const int fd = create_nl_socket(NETLINK_SOCK_DIAG);
408
409	char *path;
410	if (asprintf(&path, "/proc/self/fd/%u", fd) < 0)
411		perror_msg_and_fail("asprintf");
412	char buf[256];
413	if (getxattr(path, "system.sockprotoname", buf, sizeof(buf) - 1) < 0)
414		perror_msg_and_skip("getxattr");
415	free(path);
416
417	send_query(fd);
418	test_nlmsgerr(fd);
419	test_nlmsg_done(fd);
420#if defined NLM_F_CAPPED || defined NLM_F_ACK_TLVS
421	test_ack_flags(fd);
422#endif
423
424	puts("+++ exited with 0 +++");
425	return 0;
426}
427
428#else
429
430SKIP_MAIN_UNDEFINED("HAVE_SYS_XATTR_H")
431
432#endif
433