1 /*
2 * Copyright (c) 2018 Harsha Sharma <harshasharmaiitr@gmail.com>
3 * Copyright (c) 2018-2021 The strace developers.
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: LGPL-2.1-or-later
7 */
8
9 #include "defs.h"
10 #include "netlink_kobject_uevent.h"
11
12 #include <arpa/inet.h>
13
14 #define PRINT_FIELD_HTONL_X(where_, field_) \
15 do { \
16 tprints_field_name(#field_); \
17 tprints_arg_begin("htonl"); \
18 PRINT_VAL_X(ntohl((where_).field_)); \
19 tprint_arg_end(); \
20 } while (0)
21
22 void
23 decode_netlink_kobject_uevent(struct tcb *tcp, kernel_ulong_t addr,
24 kernel_ulong_t len)
25 {
26 struct udev_monitor_netlink_header uh;
27 const char *prefix = "libudev";
28 unsigned int offset = sizeof(uh);
29
30 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
31 !addr || len < offset || umove(tcp, addr, &uh) ||
32 strcmp(uh.prefix, prefix) != 0) {
33 printstrn(tcp, addr, len);
34 return;
35 }
36
37 if (len > offset)
38 tprint_array_begin();
39 tprint_struct_begin();
40 PRINT_FIELD_CSTRING(uh, prefix);
41 tprint_struct_next();
42
43 PRINT_FIELD_HTONL_X(uh, magic);
44 tprint_struct_next();
45
46 PRINT_FIELD_U(uh, header_size);
47 tprint_struct_next();
48
49 PRINT_FIELD_U(uh, properties_off);
50 tprint_struct_next();
51
52 PRINT_FIELD_U(uh, properties_len);
53 tprint_struct_next();
54
55 PRINT_FIELD_HTONL_X(uh, filter_subsystem_hash);
56 tprint_struct_next();
57
58 PRINT_FIELD_HTONL_X(uh, filter_devtype_hash);
59 tprint_struct_next();
60
61 PRINT_FIELD_HTONL_X(uh, filter_tag_bloom_hi);
62 tprint_struct_next();
63
64 PRINT_FIELD_HTONL_X(uh, filter_tag_bloom_lo);
65 tprint_struct_end();
66
67 if (len > offset) {
68 tprint_array_next();
69 printstrn(tcp, addr + offset, len - offset);
70 tprint_array_end();
71 }
72 }