]> granicus.if.org Git - strace/blob - netlink.c
xlat: update V4L2_CID_* constants
[strace] / netlink.c
1 /*
2  * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
3  * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
4  * Copyright (c) 2016-2018 The strace developers.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include "defs.h"
31 #include "netlink.h"
32 #include "nlattr.h"
33 #include <linux/audit.h>
34 #include <linux/rtnetlink.h>
35 #include <linux/xfrm.h>
36 #include "xlat/netlink_ack_flags.h"
37 #include "xlat/netlink_delete_flags.h"
38 #include "xlat/netlink_flags.h"
39 #include "xlat/netlink_get_flags.h"
40 #include "xlat/netlink_new_flags.h"
41 #include "xlat/netlink_protocols.h"
42 #include "xlat/netlink_types.h"
43 #include "xlat/nf_acct_msg_types.h"
44 #include "xlat/nf_cthelper_msg_types.h"
45 #include "xlat/nf_ctnetlink_exp_msg_types.h"
46 #include "xlat/nf_ctnetlink_msg_types.h"
47 #include "xlat/nf_cttimeout_msg_types.h"
48 #include "xlat/nf_ipset_msg_types.h"
49 #include "xlat/nf_nft_compat_msg_types.h"
50 #include "xlat/nf_nftables_msg_types.h"
51 #include "xlat/nf_osf_msg_types.h"
52 #include "xlat/nf_queue_msg_types.h"
53 #include "xlat/nf_ulog_msg_types.h"
54 #include "xlat/nl_audit_types.h"
55 #include "xlat/nl_crypto_types.h"
56 #include "xlat/nl_netfilter_subsys_ids.h"
57 #include "xlat/nl_selinux_types.h"
58 #include "xlat/nl_sock_diag_types.h"
59 #include "xlat/nl_xfrm_types.h"
60 #include "xlat/nlmsgerr_attrs.h"
61
62 /*
63  * Fetch a struct nlmsghdr from the given address.
64  */
65 static bool
66 fetch_nlmsghdr(struct tcb *const tcp, struct nlmsghdr *const nlmsghdr,
67                const kernel_ulong_t addr, const kernel_ulong_t len)
68 {
69         if (len < sizeof(struct nlmsghdr)) {
70                 printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
71                 return false;
72         }
73
74         if (umove_or_printaddr(tcp, addr, nlmsghdr))
75                 return false;
76
77         return true;
78 }
79
80 static int
81 get_fd_nl_family(struct tcb *const tcp, const int fd)
82 {
83         const unsigned long inode = getfdinode(tcp, fd);
84         if (!inode)
85                 return -1;
86
87         const char *const details = get_sockaddr_by_inode(tcp, fd, inode);
88         if (!details)
89                 return -1;
90
91         const char *const nl_details = STR_STRIP_PREFIX(details, "NETLINK:[");
92         if (nl_details == details)
93                 return -1;
94
95         const struct xlat *xlats = netlink_protocols;
96         for (; xlats->str; ++xlats) {
97                 const char *name = STR_STRIP_PREFIX(xlats->str, "NETLINK_");
98                 if (!strncmp(nl_details, name, strlen(name)))
99                         return xlats->val;
100         }
101
102         if (*nl_details >= '0' && *nl_details <= '9')
103                 return atoi(nl_details);
104
105         return -1;
106 }
107
108 static void
109 decode_nlmsg_type_default(struct tcb *tcp, const struct xlat *const xlat,
110                           const uint16_t type,
111                           const char *const dflt)
112 {
113         printxval(xlat, type, dflt);
114 }
115
116 static void
117 decode_nlmsg_type_generic(struct tcb *tcp, const struct xlat *const xlat,
118                           const uint16_t type,
119                           const char *const dflt)
120 {
121         printxval(genl_families_xlat(tcp), type, dflt);
122 }
123
124 static const struct {
125         const struct xlat *const xlat;
126         const char *const dflt;
127 } nf_nlmsg_types[] = {
128         [NFNL_SUBSYS_CTNETLINK] = {
129                 nf_ctnetlink_msg_types,
130                 "IPCTNL_MSG_CT_???"
131         },
132         [NFNL_SUBSYS_CTNETLINK_EXP] = {
133                 nf_ctnetlink_exp_msg_types,
134                 "IPCTNL_MSG_EXP_???"
135         },
136         [NFNL_SUBSYS_QUEUE] = { nf_queue_msg_types, "NFQNL_MSG_???" },
137         [NFNL_SUBSYS_ULOG] = { nf_ulog_msg_types, "NFULNL_MSG_???" },
138         [NFNL_SUBSYS_OSF] = { nf_osf_msg_types, "OSF_MSG_???" },
139         [NFNL_SUBSYS_IPSET] = { nf_ipset_msg_types, "IPSET_CMD_???" },
140         [NFNL_SUBSYS_ACCT] = { nf_acct_msg_types, "NFNL_MSG_ACCT_???" },
141         [NFNL_SUBSYS_CTNETLINK_TIMEOUT] = {
142                 nf_cttimeout_msg_types,
143                 "IPCTNL_MSG_TIMEOUT_???"
144         },
145         [NFNL_SUBSYS_CTHELPER] = {
146                 nf_cthelper_msg_types,
147                 "NFNL_MSG_CTHELPER_???"
148         },
149         [NFNL_SUBSYS_NFTABLES] = { nf_nftables_msg_types, "NFT_MSG_???" },
150         [NFNL_SUBSYS_NFT_COMPAT] = {
151                 nf_nft_compat_msg_types,
152                 "NFNL_MSG_COMPAT_???"
153         }
154 };
155
156 static void
157 decode_nlmsg_type_netfilter(struct tcb *tcp, const struct xlat *const xlat,
158                             const uint16_t type,
159                             const char *const dflt)
160 {
161         /* Reserved control nfnetlink messages first. */
162         const char *const text = xlookup(nl_netfilter_msg_types, type);
163         if (text) {
164                 print_xlat_ex(type, text, XLAT_STYLE_DEFAULT);
165                 return;
166         }
167
168         /*
169          * Other netfilter message types are split
170          * in two pieces: 8 bits subsystem and 8 bits type.
171          */
172         const uint8_t subsys_id = (uint8_t) (type >> 8);
173         const uint8_t msg_type = (uint8_t) type;
174
175         printxval(xlat, subsys_id, dflt);
176
177         tprints("<<8|");
178         if (subsys_id < ARRAY_SIZE(nf_nlmsg_types))
179                 printxval(nf_nlmsg_types[subsys_id].xlat,
180                           msg_type, nf_nlmsg_types[subsys_id].dflt);
181         else
182                 tprintf("%#x", msg_type);
183 }
184
185 typedef void (*nlmsg_types_decoder_t)(struct tcb *, const struct xlat *,
186                                       uint16_t type,
187                                       const char *dflt);
188
189 static const struct {
190         const nlmsg_types_decoder_t decoder;
191         const struct xlat *const xlat;
192         const char *const dflt;
193 } nlmsg_types[] = {
194         [NETLINK_AUDIT] = { NULL, nl_audit_types, "AUDIT_???" },
195         [NETLINK_CRYPTO] = { NULL, nl_crypto_types, "CRYPTO_MSG_???" },
196         [NETLINK_GENERIC] = {
197                 decode_nlmsg_type_generic,
198                 NULL,
199                 "GENERIC_FAMILY_???"
200         },
201         [NETLINK_NETFILTER] = {
202                 decode_nlmsg_type_netfilter,
203                 nl_netfilter_subsys_ids,
204                 "NFNL_SUBSYS_???"
205         },
206         [NETLINK_ROUTE] = { NULL, nl_route_types, "RTM_???" },
207         [NETLINK_SELINUX] = { NULL, nl_selinux_types, "SELNL_MSG_???" },
208         [NETLINK_SOCK_DIAG] = { NULL, nl_sock_diag_types, "SOCK_DIAG_???" },
209         [NETLINK_XFRM] = { NULL, nl_xfrm_types, "XFRM_MSG_???" }
210 };
211
212 /*
213  * As all valid netlink families are positive integers, use unsigned int
214  * for family here to filter out -1.
215  */
216 static void
217 decode_nlmsg_type(struct tcb *tcp, const uint16_t type,
218                   const unsigned int family)
219 {
220         nlmsg_types_decoder_t decoder = decode_nlmsg_type_default;
221         const struct xlat *xlat = netlink_types;
222         const char *dflt = "NLMSG_???";
223
224         /*
225          * type < NLMSG_MIN_TYPE are reserved control messages
226          * that need no family-specific decoding.
227          */
228         if (type >= NLMSG_MIN_TYPE && family < ARRAY_SIZE(nlmsg_types)) {
229                 if (nlmsg_types[family].decoder)
230                         decoder = nlmsg_types[family].decoder;
231                 if (nlmsg_types[family].xlat)
232                         xlat = nlmsg_types[family].xlat;
233                 if (nlmsg_types[family].dflt)
234                         dflt = nlmsg_types[family].dflt;
235         }
236
237         decoder(tcp, xlat, type, dflt);
238 }
239
240 static const struct xlat *
241 decode_nlmsg_flags_crypto(const uint16_t type)
242 {
243         switch (type) {
244         case CRYPTO_MSG_NEWALG:
245                 return netlink_new_flags;
246         case CRYPTO_MSG_DELALG:
247         case CRYPTO_MSG_DELRNG:
248                 return netlink_delete_flags;
249         case CRYPTO_MSG_GETALG:
250                 return netlink_get_flags;
251         }
252
253         return NULL;
254 }
255
256 static const struct xlat *
257 decode_nlmsg_flags_netfilter(const uint16_t type)
258 {
259         const uint8_t subsys_id = (uint8_t) (type >> 8);
260         const uint8_t msg_type = (uint8_t) type;
261
262         switch (subsys_id) {
263         case NFNL_SUBSYS_CTNETLINK:
264                 switch (msg_type) {
265                 case IPCTNL_MSG_CT_NEW:
266                         return netlink_new_flags;
267                 case IPCTNL_MSG_CT_GET:
268                 case IPCTNL_MSG_CT_GET_CTRZERO:
269                 case IPCTNL_MSG_CT_GET_STATS_CPU:
270                 case IPCTNL_MSG_CT_GET_STATS:
271                 case IPCTNL_MSG_CT_GET_DYING:
272                 case IPCTNL_MSG_CT_GET_UNCONFIRMED:
273                         return netlink_get_flags;
274                 case IPCTNL_MSG_CT_DELETE:
275                         return netlink_delete_flags;
276                 }
277                 break;
278         case NFNL_SUBSYS_CTNETLINK_EXP:
279                 switch (msg_type) {
280                 case IPCTNL_MSG_EXP_NEW:
281                         return netlink_new_flags;
282                 case IPCTNL_MSG_EXP_GET:
283                 case IPCTNL_MSG_EXP_GET_STATS_CPU:
284                         return netlink_get_flags;
285                 case IPCTNL_MSG_EXP_DELETE:
286                         return netlink_delete_flags;
287                 }
288                 break;
289         case NFNL_SUBSYS_ACCT:
290                 switch (msg_type) {
291                 case NFNL_MSG_ACCT_NEW:
292                         return netlink_new_flags;
293                 case NFNL_MSG_ACCT_GET:
294                 case NFNL_MSG_ACCT_GET_CTRZERO:
295                         return netlink_get_flags;
296                 case NFNL_MSG_ACCT_DEL:
297                         return netlink_delete_flags;
298                 }
299                 break;
300         case NFNL_SUBSYS_CTNETLINK_TIMEOUT:
301                 switch (msg_type) {
302                 case IPCTNL_MSG_TIMEOUT_NEW:
303                         return netlink_new_flags;
304                 case IPCTNL_MSG_TIMEOUT_GET:
305                         return netlink_get_flags;
306                 case IPCTNL_MSG_TIMEOUT_DELETE:
307                         return netlink_delete_flags;
308                 }
309                 break;
310         case NFNL_SUBSYS_CTHELPER:
311                 switch (msg_type) {
312                 case NFNL_MSG_CTHELPER_NEW:
313                         return netlink_new_flags;
314                 case NFNL_MSG_CTHELPER_GET:
315                         return netlink_get_flags;
316                 case NFNL_MSG_CTHELPER_DEL:
317                         return netlink_delete_flags;
318                 }
319                 break;
320         case NFNL_SUBSYS_NFTABLES:
321                 switch (msg_type) {
322                 case NFT_MSG_NEWTABLE:
323                 case NFT_MSG_NEWCHAIN:
324                 case NFT_MSG_NEWRULE:
325                 case NFT_MSG_NEWSET:
326                 case NFT_MSG_NEWSETELEM:
327                 case NFT_MSG_NEWGEN:
328                 case NFT_MSG_NEWOBJ:
329                         return netlink_new_flags;
330                 case NFT_MSG_GETTABLE:
331                 case NFT_MSG_GETCHAIN:
332                 case NFT_MSG_GETRULE:
333                 case NFT_MSG_GETSET:
334                 case NFT_MSG_GETSETELEM:
335                 case NFT_MSG_GETGEN:
336                 case NFT_MSG_GETOBJ:
337                 case NFT_MSG_GETOBJ_RESET:
338                         return netlink_get_flags;
339                 case NFT_MSG_DELTABLE:
340                 case NFT_MSG_DELCHAIN:
341                 case NFT_MSG_DELRULE:
342                 case NFT_MSG_DELSET:
343                 case NFT_MSG_DELSETELEM:
344                 case NFT_MSG_DELOBJ:
345                         return netlink_delete_flags;
346                 }
347                 break;
348         case NFNL_SUBSYS_NFT_COMPAT:
349                 switch (msg_type) {
350                 case NFNL_MSG_COMPAT_GET:
351                         return netlink_get_flags;
352                 }
353                 break;
354         }
355
356         return NULL;
357 }
358
359 static const struct xlat *
360 decode_nlmsg_flags_route(const uint16_t type)
361 {
362         /* RTM_DELACTION uses NLM_F_ROOT flags */
363         if (type == RTM_DELACTION)
364                 return netlink_get_flags;
365         switch (type & 3) {
366         case  0:
367                 return netlink_new_flags;
368         case  1:
369                 return netlink_delete_flags;
370         case  2:
371                 return netlink_get_flags;
372         }
373
374         return NULL;
375 }
376
377 static const struct xlat *
378 decode_nlmsg_flags_sock_diag(const uint16_t type)
379 {
380         return netlink_get_flags;
381 }
382
383 static const struct xlat *
384 decode_nlmsg_flags_xfrm(const uint16_t type)
385 {
386         switch (type) {
387         case XFRM_MSG_NEWSA:
388         case XFRM_MSG_NEWPOLICY:
389         case XFRM_MSG_NEWAE:
390         case XFRM_MSG_NEWSADINFO:
391         case XFRM_MSG_NEWSPDINFO:
392                 return netlink_new_flags;
393         case XFRM_MSG_DELSA:
394         case XFRM_MSG_DELPOLICY:
395                 return netlink_delete_flags;
396         case XFRM_MSG_GETSA:
397         case XFRM_MSG_GETPOLICY:
398         case XFRM_MSG_GETAE:
399         case XFRM_MSG_GETSADINFO:
400         case XFRM_MSG_GETSPDINFO:
401                 return netlink_get_flags;
402         }
403
404         return NULL;
405 }
406
407 typedef const struct xlat *(*nlmsg_flags_decoder_t)(const uint16_t type);
408
409 static const nlmsg_flags_decoder_t nlmsg_flags[] = {
410         [NETLINK_CRYPTO] = decode_nlmsg_flags_crypto,
411         [NETLINK_NETFILTER] = decode_nlmsg_flags_netfilter,
412         [NETLINK_ROUTE] = decode_nlmsg_flags_route,
413         [NETLINK_SOCK_DIAG] = decode_nlmsg_flags_sock_diag,
414         [NETLINK_XFRM] = decode_nlmsg_flags_xfrm
415 };
416
417 /*
418  * As all valid netlink families are positive integers, use unsigned int
419  * for family here to filter out -1.
420  */
421 static void
422 decode_nlmsg_flags(const uint16_t flags, const uint16_t type,
423                    const unsigned int family)
424 {
425         const struct xlat *table = NULL;
426
427         if (type < NLMSG_MIN_TYPE) {
428                 if (type == NLMSG_ERROR)
429                         table = netlink_ack_flags;
430         } else if (family < ARRAY_SIZE(nlmsg_flags) && nlmsg_flags[family])
431                 table = nlmsg_flags[family](type);
432
433         printflags_ex(flags, "NLM_F_???", XLAT_STYLE_ABBREV,
434                       netlink_flags, table, NULL);
435 }
436
437 static void
438 print_nlmsghdr(struct tcb *tcp,
439                const int fd,
440                const int family,
441                const struct nlmsghdr *const nlmsghdr)
442 {
443         /* print the whole structure regardless of its nlmsg_len */
444
445         tprintf("{len=%u, type=", nlmsghdr->nlmsg_len);
446
447         decode_nlmsg_type(tcp, nlmsghdr->nlmsg_type, family);
448
449         tprints(", flags=");
450         decode_nlmsg_flags(nlmsghdr->nlmsg_flags,
451                            nlmsghdr->nlmsg_type, family);
452
453         tprintf(", seq=%u, pid=%u}", nlmsghdr->nlmsg_seq,
454                 nlmsghdr->nlmsg_pid);
455 }
456
457 static bool
458 print_cookie(struct tcb *const tcp, void *const elem_buf,
459              const size_t elem_size, void *const opaque_data)
460 {
461         tprintf("%" PRIu8, *(uint8_t *) elem_buf);
462
463         return true;
464 }
465
466 static bool
467 decode_nlmsgerr_attr_cookie(struct tcb *const tcp,
468                             const kernel_ulong_t addr,
469                             const unsigned int len,
470                             const void *const opaque_data)
471 {
472         uint8_t cookie;
473         const size_t nmemb = len / sizeof(cookie);
474
475         print_array(tcp, addr, nmemb, &cookie, sizeof(cookie),
476                     umoven_or_printaddr, print_cookie, 0);
477
478         return true;
479 }
480
481 static const nla_decoder_t nlmsgerr_nla_decoders[] = {
482         [NLMSGERR_ATTR_MSG]     = decode_nla_str,
483         [NLMSGERR_ATTR_OFFS]    = decode_nla_u32,
484         [NLMSGERR_ATTR_COOKIE]  = decode_nlmsgerr_attr_cookie
485 };
486
487 static void
488 decode_nlmsghdr_with_payload(struct tcb *const tcp,
489                              const int fd,
490                              const int family,
491                              const struct nlmsghdr *const nlmsghdr,
492                              const kernel_ulong_t addr,
493                              const kernel_ulong_t len);
494
495 static void
496 decode_nlmsgerr(struct tcb *const tcp,
497                 const int fd,
498                 const int family,
499                 kernel_ulong_t addr,
500                 unsigned int len,
501                 const bool capped)
502 {
503         struct nlmsgerr err;
504
505         if (len < sizeof(err.error)) {
506                 printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
507                 return;
508         }
509
510         if (umove_or_printaddr(tcp, addr, &err.error))
511                 return;
512
513         tprints("{error=");
514         if (err.error < 0 && (unsigned) -err.error < nerrnos) {
515                 tprintf("-%s", errnoent[-err.error]);
516         } else {
517                 tprintf("%d", err.error);
518         }
519
520         addr += offsetof(struct nlmsgerr, msg);
521         len -= offsetof(struct nlmsgerr, msg);
522
523         if (len) {
524                 tprints(", msg=");
525                 if (fetch_nlmsghdr(tcp, &err.msg, addr, len)) {
526                         unsigned int payload =
527                                 capped ? sizeof(err.msg) : err.msg.nlmsg_len;
528                         if (payload > len)
529                                 payload = len;
530
531                         decode_nlmsghdr_with_payload(tcp, fd, family,
532                                                      &err.msg, addr, payload);
533                         if (len > payload) {
534                                 tprints(", ");
535                                 decode_nlattr(tcp, addr + payload,
536                                               len - payload, nlmsgerr_attrs,
537                                               "NLMSGERR_ATTR_???",
538                                               nlmsgerr_nla_decoders,
539                                               ARRAY_SIZE(nlmsgerr_nla_decoders),
540                                               NULL);
541                         }
542                 }
543         }
544
545         tprints("}");
546 }
547
548 static const netlink_decoder_t netlink_decoders[] = {
549 #ifdef HAVE_LINUX_CRYPTOUSER_H
550         [NETLINK_CRYPTO] = decode_netlink_crypto,
551 #endif
552 #ifdef HAVE_LINUX_NETFILTER_NFNETLINK_H
553         [NETLINK_NETFILTER] = decode_netlink_netfilter,
554 #endif
555         [NETLINK_ROUTE] = decode_netlink_route,
556         [NETLINK_SELINUX] = decode_netlink_selinux,
557         [NETLINK_SOCK_DIAG] = decode_netlink_sock_diag
558 };
559
560 static void
561 decode_payload(struct tcb *const tcp,
562                const int fd,
563                const int family,
564                const struct nlmsghdr *const nlmsghdr,
565                const kernel_ulong_t addr,
566                const unsigned int len)
567 {
568         if (nlmsghdr->nlmsg_type == NLMSG_ERROR) {
569                 decode_nlmsgerr(tcp, fd, family, addr, len,
570                                 nlmsghdr->nlmsg_flags & NLM_F_CAPPED);
571                 return;
572         }
573
574         /*
575          * While most of NLMSG_DONE messages indeed have payloads
576          * containing just a single integer, there are few exceptions,
577          * so pass payloads of NLMSG_DONE messages to family-specific
578          * netlink payload decoders.
579          *
580          * Other types of reserved control messages need no family-specific
581          * netlink payload decoding.
582          */
583         if ((nlmsghdr->nlmsg_type >= NLMSG_MIN_TYPE
584             || nlmsghdr->nlmsg_type == NLMSG_DONE)
585             && (unsigned int) family < ARRAY_SIZE(netlink_decoders)
586             && netlink_decoders[family]
587             && netlink_decoders[family](tcp, nlmsghdr, addr, len)) {
588                 return;
589         }
590
591         if (nlmsghdr->nlmsg_type == NLMSG_DONE && len == sizeof(int)) {
592                 int num;
593
594                 if (!umove_or_printaddr(tcp, addr, &num))
595                         tprintf("%d", num);
596                 return;
597         }
598
599         printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
600 }
601
602 static void
603 decode_nlmsghdr_with_payload(struct tcb *const tcp,
604                              const int fd,
605                              const int family,
606                              const struct nlmsghdr *const nlmsghdr,
607                              const kernel_ulong_t addr,
608                              const kernel_ulong_t len)
609 {
610         const unsigned int nlmsg_len =
611                 nlmsghdr->nlmsg_len > len ? len : nlmsghdr->nlmsg_len;
612
613         if (nlmsg_len > NLMSG_HDRLEN)
614                 tprints("{");
615
616         print_nlmsghdr(tcp, fd, family, nlmsghdr);
617
618         if (nlmsg_len > NLMSG_HDRLEN) {
619                 tprints(", ");
620                 decode_payload(tcp, fd, family, nlmsghdr, addr + NLMSG_HDRLEN,
621                                                      nlmsg_len - NLMSG_HDRLEN);
622                 tprints("}");
623         }
624 }
625
626 void
627 decode_netlink(struct tcb *const tcp,
628                const int fd,
629                kernel_ulong_t addr,
630                kernel_ulong_t len)
631 {
632         const int family = get_fd_nl_family(tcp, fd);
633
634         if (family == NETLINK_KOBJECT_UEVENT) {
635                 decode_netlink_kobject_uevent(tcp, addr, len);
636                 return;
637         }
638
639         struct nlmsghdr nlmsghdr;
640         bool print_array = false;
641         unsigned int elt;
642
643         for (elt = 0; fetch_nlmsghdr(tcp, &nlmsghdr, addr, len); elt++) {
644                 if (abbrev(tcp) && elt == max_strlen) {
645                         tprints("...");
646                         break;
647                 }
648
649                 unsigned int nlmsg_len = NLMSG_ALIGN(nlmsghdr.nlmsg_len);
650                 kernel_ulong_t next_addr = 0;
651                 kernel_ulong_t next_len = 0;
652
653                 if (nlmsghdr.nlmsg_len >= NLMSG_HDRLEN) {
654                         next_len = (len >= nlmsg_len) ? len - nlmsg_len : 0;
655
656                         if (next_len && addr + nlmsg_len > addr)
657                                 next_addr = addr + nlmsg_len;
658                 }
659
660                 if (!print_array && next_addr) {
661                         tprints("[");
662                         print_array = true;
663                 }
664
665                 decode_nlmsghdr_with_payload(tcp, fd, family,
666                                              &nlmsghdr, addr, len);
667
668                 if (!next_addr)
669                         break;
670
671                 tprints(", ");
672                 addr = next_addr;
673                 len = next_len;
674         }
675
676         if (print_array) {
677                 tprints("]");
678         }
679 }