1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ 2 // Copyright (C) 2018 Facebook 3 4 #ifndef _NETLINK_DUMPER_H_ 5 #define _NETLINK_DUMPER_H_ 6 7 #define NET_START_OBJECT \ 8 { \ 9 if (json_output) \ 10 jsonw_start_object(json_wtr); \ 11 } 12 13 #define NET_START_OBJECT_NESTED(name) \ 14 { \ 15 if (json_output) { \ 16 jsonw_name(json_wtr, name); \ 17 jsonw_start_object(json_wtr); \ 18 } else { \ 19 fprintf(stdout, "%s {", name); \ 20 } \ 21 } 22 23 #define NET_START_OBJECT_NESTED2 \ 24 { \ 25 if (json_output) \ 26 jsonw_start_object(json_wtr); \ 27 else \ 28 fprintf(stdout, "{"); \ 29 } 30 31 #define NET_END_OBJECT_NESTED \ 32 { \ 33 if (json_output) \ 34 jsonw_end_object(json_wtr); \ 35 else \ 36 fprintf(stdout, "}"); \ 37 } 38 39 #define NET_END_OBJECT \ 40 { \ 41 if (json_output) \ 42 jsonw_end_object(json_wtr); \ 43 } 44 45 #define NET_END_OBJECT_FINAL \ 46 { \ 47 if (json_output) \ 48 jsonw_end_object(json_wtr); \ 49 else \ 50 fprintf(stdout, "\n"); \ 51 } 52 53 #define NET_START_ARRAY(name, fmt_str) \ 54 { \ 55 if (json_output) { \ 56 jsonw_name(json_wtr, name); \ 57 jsonw_start_array(json_wtr); \ 58 } else { \ 59 fprintf(stdout, fmt_str, name); \ 60 } \ 61 } 62 63 #define NET_END_ARRAY(endstr) \ 64 { \ 65 if (json_output) \ 66 jsonw_end_array(json_wtr); \ 67 else \ 68 fprintf(stdout, "%s", endstr); \ 69 } 70 71 #define NET_DUMP_UINT(name, fmt_str, val) \ 72 { \ 73 if (json_output) \ 74 jsonw_uint_field(json_wtr, name, val); \ 75 else \ 76 fprintf(stdout, fmt_str, val); \ 77 } 78 79 #define NET_DUMP_UINT_ONLY(str) \ 80 { \ 81 if (json_output) \ 82 jsonw_uint(json_wtr, str); \ 83 else \ 84 fprintf(stdout, "%u ", str); \ 85 } 86 87 #define NET_DUMP_STR(name, fmt_str, str) \ 88 { \ 89 if (json_output) \ 90 jsonw_string_field(json_wtr, name, str);\ 91 else \ 92 fprintf(stdout, fmt_str, str); \ 93 } 94 95 #define NET_DUMP_STR_ONLY(str) \ 96 { \ 97 if (json_output) \ 98 jsonw_string(json_wtr, str); \ 99 else \ 100 fprintf(stdout, "%s ", str); \ 101 } 102 103 #endif 104