netlink_dumper.h 1.8 KB

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