debug.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * Zebra debug related function
  3. * Copyright (C) 1999 Kunihiro Ishiguro
  4. *
  5. * This file is part of GNU Zebra.
  6. *
  7. * GNU Zebra is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2, or (at your option) any
  10. * later version.
  11. *
  12. * GNU Zebra is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Zebra; see the file COPYING. If not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. */
  22. #include <zebra.h>
  23. #include "command.h"
  24. #include "debug.h"
  25. /* For debug statement. */
  26. unsigned long zebra_debug_event;
  27. unsigned long zebra_debug_packet;
  28. unsigned long zebra_debug_kernel;
  29. DEFUN (show_debugging_zebra,
  30. show_debugging_zebra_cmd,
  31. "show debugging zebra",
  32. SHOW_STR
  33. "Zebra configuration\n"
  34. "Debugging information\n")
  35. {
  36. vty_out (vty, "Zebra debugging status:%s", VTY_NEWLINE);
  37. if (IS_ZEBRA_DEBUG_EVENT)
  38. vty_out (vty, " Zebra event debugging is on%s", VTY_NEWLINE);
  39. if (IS_ZEBRA_DEBUG_PACKET)
  40. {
  41. if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
  42. {
  43. vty_out (vty, " Zebra packet%s debugging is on%s",
  44. IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  45. VTY_NEWLINE);
  46. }
  47. else
  48. {
  49. if (IS_ZEBRA_DEBUG_SEND)
  50. vty_out (vty, " Zebra packet send%s debugging is on%s",
  51. IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  52. VTY_NEWLINE);
  53. else
  54. vty_out (vty, " Zebra packet receive%s debugging is on%s",
  55. IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  56. VTY_NEWLINE);
  57. }
  58. }
  59. if (IS_ZEBRA_DEBUG_KERNEL)
  60. vty_out (vty, " Zebra kernel debugging is on%s", VTY_NEWLINE);
  61. return CMD_SUCCESS;
  62. }
  63. DEFUN (debug_zebra_events,
  64. debug_zebra_events_cmd,
  65. "debug zebra events",
  66. DEBUG_STR
  67. "Zebra configuration\n"
  68. "Debug option set for zebra events\n")
  69. {
  70. zebra_debug_event = ZEBRA_DEBUG_EVENT;
  71. return CMD_WARNING;
  72. }
  73. DEFUN (debug_zebra_packet,
  74. debug_zebra_packet_cmd,
  75. "debug zebra packet",
  76. DEBUG_STR
  77. "Zebra configuration\n"
  78. "Debug option set for zebra packet\n")
  79. {
  80. zebra_debug_packet = ZEBRA_DEBUG_PACKET;
  81. zebra_debug_packet |= ZEBRA_DEBUG_SEND;
  82. zebra_debug_packet |= ZEBRA_DEBUG_RECV;
  83. return CMD_SUCCESS;
  84. }
  85. DEFUN (debug_zebra_packet_direct,
  86. debug_zebra_packet_direct_cmd,
  87. "debug zebra packet (recv|send)",
  88. DEBUG_STR
  89. "Zebra configuration\n"
  90. "Debug option set for zebra packet\n"
  91. "Debug option set for receive packet\n"
  92. "Debug option set for send packet\n")
  93. {
  94. zebra_debug_packet = ZEBRA_DEBUG_PACKET;
  95. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  96. zebra_debug_packet |= ZEBRA_DEBUG_SEND;
  97. if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  98. zebra_debug_packet |= ZEBRA_DEBUG_RECV;
  99. zebra_debug_packet &= ~ZEBRA_DEBUG_DETAIL;
  100. return CMD_SUCCESS;
  101. }
  102. DEFUN (debug_zebra_packet_detail,
  103. debug_zebra_packet_detail_cmd,
  104. "debug zebra packet (recv|send) detail",
  105. DEBUG_STR
  106. "Zebra configuration\n"
  107. "Debug option set for zebra packet\n"
  108. "Debug option set for receive packet\n"
  109. "Debug option set for send packet\n"
  110. "Debug option set detaied information\n")
  111. {
  112. zebra_debug_packet = ZEBRA_DEBUG_PACKET;
  113. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  114. zebra_debug_packet |= ZEBRA_DEBUG_SEND;
  115. if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  116. zebra_debug_packet |= ZEBRA_DEBUG_RECV;
  117. zebra_debug_packet |= ZEBRA_DEBUG_DETAIL;
  118. return CMD_SUCCESS;
  119. }
  120. DEFUN (debug_zebra_kernel,
  121. debug_zebra_kernel_cmd,
  122. "debug zebra kernel",
  123. DEBUG_STR
  124. "Zebra configuration\n"
  125. "Debug option set for zebra between kernel interface\n")
  126. {
  127. zebra_debug_kernel = ZEBRA_DEBUG_KERNEL;
  128. return CMD_SUCCESS;
  129. }
  130. DEFUN (no_debug_zebra_events,
  131. no_debug_zebra_events_cmd,
  132. "no debug zebra events",
  133. NO_STR
  134. DEBUG_STR
  135. "Zebra configuration\n"
  136. "Debug option set for zebra events\n")
  137. {
  138. zebra_debug_event = 0;
  139. return CMD_SUCCESS;
  140. }
  141. DEFUN (no_debug_zebra_packet,
  142. no_debug_zebra_packet_cmd,
  143. "no debug zebra packet",
  144. NO_STR
  145. DEBUG_STR
  146. "Zebra configuration\n"
  147. "Debug option set for zebra packet\n")
  148. {
  149. zebra_debug_packet = 0;
  150. return CMD_SUCCESS;
  151. }
  152. DEFUN (no_debug_zebra_packet_direct,
  153. no_debug_zebra_packet_direct_cmd,
  154. "no debug zebra packet (recv|send)",
  155. NO_STR
  156. DEBUG_STR
  157. "Zebra configuration\n"
  158. "Debug option set for zebra packet\n"
  159. "Debug option set for receive packet\n"
  160. "Debug option set for send packet\n")
  161. {
  162. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  163. zebra_debug_packet &= ~ZEBRA_DEBUG_SEND;
  164. if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  165. zebra_debug_packet &= ~ZEBRA_DEBUG_RECV;
  166. return CMD_SUCCESS;
  167. }
  168. DEFUN (no_debug_zebra_kernel,
  169. no_debug_zebra_kernel_cmd,
  170. "no debug zebra kernel",
  171. NO_STR
  172. DEBUG_STR
  173. "Zebra configuration\n"
  174. "Debug option set for zebra between kernel interface\n")
  175. {
  176. zebra_debug_kernel = 0;
  177. return CMD_SUCCESS;
  178. }
  179. /* Debug node. */
  180. struct cmd_node debug_node =
  181. {
  182. DEBUG_NODE,
  183. "", /* Debug node has no interface. */
  184. 1
  185. };
  186. int
  187. config_write_debug (struct vty *vty)
  188. {
  189. int write = 0;
  190. if (IS_ZEBRA_DEBUG_EVENT)
  191. {
  192. vty_out (vty, "debug zebra events%s", VTY_NEWLINE);
  193. write++;
  194. }
  195. if (IS_ZEBRA_DEBUG_PACKET)
  196. {
  197. if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
  198. {
  199. vty_out (vty, "debug zebra packet%s%s",
  200. IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  201. VTY_NEWLINE);
  202. write++;
  203. }
  204. else
  205. {
  206. if (IS_ZEBRA_DEBUG_SEND)
  207. vty_out (vty, "debug zebra packet send%s%s",
  208. IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  209. VTY_NEWLINE);
  210. else
  211. vty_out (vty, "debug zebra packet recv%s%s",
  212. IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  213. VTY_NEWLINE);
  214. write++;
  215. }
  216. }
  217. if (IS_ZEBRA_DEBUG_KERNEL)
  218. {
  219. vty_out (vty, "debug zebra kernel%s", VTY_NEWLINE);
  220. write++;
  221. }
  222. return write;
  223. }
  224. void
  225. zebra_debug_init ()
  226. {
  227. zebra_debug_event = 0;
  228. zebra_debug_packet = 0;
  229. install_node (&debug_node, config_write_debug);
  230. install_element (VIEW_NODE, &show_debugging_zebra_cmd);
  231. install_element (ENABLE_NODE, &show_debugging_zebra_cmd);
  232. install_element (ENABLE_NODE, &debug_zebra_events_cmd);
  233. install_element (ENABLE_NODE, &debug_zebra_packet_cmd);
  234. install_element (ENABLE_NODE, &debug_zebra_packet_direct_cmd);
  235. install_element (ENABLE_NODE, &debug_zebra_packet_detail_cmd);
  236. install_element (ENABLE_NODE, &debug_zebra_kernel_cmd);
  237. install_element (ENABLE_NODE, &no_debug_zebra_events_cmd);
  238. install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd);
  239. install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd);
  240. install_element (CONFIG_NODE, &debug_zebra_events_cmd);
  241. install_element (CONFIG_NODE, &debug_zebra_packet_cmd);
  242. install_element (CONFIG_NODE, &debug_zebra_packet_direct_cmd);
  243. install_element (CONFIG_NODE, &debug_zebra_packet_detail_cmd);
  244. install_element (CONFIG_NODE, &debug_zebra_kernel_cmd);
  245. install_element (CONFIG_NODE, &no_debug_zebra_events_cmd);
  246. install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd);
  247. install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd);
  248. }