debug.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. unsigned long zebra_debug_rib;
  30. unsigned long zebra_debug_fpm;
  31. DEFUN (show_debugging_zebra,
  32. show_debugging_zebra_cmd,
  33. "show debugging zebra",
  34. SHOW_STR
  35. "Zebra configuration\n"
  36. "Debugging information\n")
  37. {
  38. vty_out (vty, "Zebra debugging status:%s", VTY_NEWLINE);
  39. if (IS_ZEBRA_DEBUG_EVENT)
  40. vty_out (vty, " Zebra event debugging is on%s", VTY_NEWLINE);
  41. if (IS_ZEBRA_DEBUG_PACKET)
  42. {
  43. if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
  44. {
  45. vty_out (vty, " Zebra packet%s debugging is on%s",
  46. IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  47. VTY_NEWLINE);
  48. }
  49. else
  50. {
  51. if (IS_ZEBRA_DEBUG_SEND)
  52. vty_out (vty, " Zebra packet send%s debugging is on%s",
  53. IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  54. VTY_NEWLINE);
  55. else
  56. vty_out (vty, " Zebra packet receive%s debugging is on%s",
  57. IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  58. VTY_NEWLINE);
  59. }
  60. }
  61. if (IS_ZEBRA_DEBUG_KERNEL)
  62. vty_out (vty, " Zebra kernel debugging is on%s", VTY_NEWLINE);
  63. if (IS_ZEBRA_DEBUG_RIB)
  64. vty_out (vty, " Zebra RIB debugging is on%s", VTY_NEWLINE);
  65. if (IS_ZEBRA_DEBUG_RIB_Q)
  66. vty_out (vty, " Zebra RIB queue debugging is on%s", VTY_NEWLINE);
  67. if (IS_ZEBRA_DEBUG_FPM)
  68. vty_out (vty, " Zebra FPM debugging is on%s", VTY_NEWLINE);
  69. return CMD_SUCCESS;
  70. }
  71. DEFUN (debug_zebra_events,
  72. debug_zebra_events_cmd,
  73. "debug zebra events",
  74. DEBUG_STR
  75. "Zebra configuration\n"
  76. "Debug option set for zebra events\n")
  77. {
  78. zebra_debug_event = ZEBRA_DEBUG_EVENT;
  79. return CMD_WARNING;
  80. }
  81. DEFUN (debug_zebra_packet,
  82. debug_zebra_packet_cmd,
  83. "debug zebra packet",
  84. DEBUG_STR
  85. "Zebra configuration\n"
  86. "Debug option set for zebra packet\n")
  87. {
  88. zebra_debug_packet = ZEBRA_DEBUG_PACKET;
  89. zebra_debug_packet |= ZEBRA_DEBUG_SEND;
  90. zebra_debug_packet |= ZEBRA_DEBUG_RECV;
  91. return CMD_SUCCESS;
  92. }
  93. DEFUN (debug_zebra_packet_direct,
  94. debug_zebra_packet_direct_cmd,
  95. "debug zebra packet (recv|send)",
  96. DEBUG_STR
  97. "Zebra configuration\n"
  98. "Debug option set for zebra packet\n"
  99. "Debug option set for receive packet\n"
  100. "Debug option set for send packet\n")
  101. {
  102. zebra_debug_packet = ZEBRA_DEBUG_PACKET;
  103. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  104. zebra_debug_packet |= ZEBRA_DEBUG_SEND;
  105. if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  106. zebra_debug_packet |= ZEBRA_DEBUG_RECV;
  107. zebra_debug_packet &= ~ZEBRA_DEBUG_DETAIL;
  108. return CMD_SUCCESS;
  109. }
  110. DEFUN (debug_zebra_packet_detail,
  111. debug_zebra_packet_detail_cmd,
  112. "debug zebra packet (recv|send) detail",
  113. DEBUG_STR
  114. "Zebra configuration\n"
  115. "Debug option set for zebra packet\n"
  116. "Debug option set for receive packet\n"
  117. "Debug option set for send packet\n"
  118. "Debug option set detaied information\n")
  119. {
  120. zebra_debug_packet = ZEBRA_DEBUG_PACKET;
  121. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  122. zebra_debug_packet |= ZEBRA_DEBUG_SEND;
  123. if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  124. zebra_debug_packet |= ZEBRA_DEBUG_RECV;
  125. zebra_debug_packet |= ZEBRA_DEBUG_DETAIL;
  126. return CMD_SUCCESS;
  127. }
  128. DEFUN (debug_zebra_kernel,
  129. debug_zebra_kernel_cmd,
  130. "debug zebra kernel",
  131. DEBUG_STR
  132. "Zebra configuration\n"
  133. "Debug option set for zebra between kernel interface\n")
  134. {
  135. zebra_debug_kernel = ZEBRA_DEBUG_KERNEL;
  136. return CMD_SUCCESS;
  137. }
  138. DEFUN (debug_zebra_rib,
  139. debug_zebra_rib_cmd,
  140. "debug zebra rib",
  141. DEBUG_STR
  142. "Zebra configuration\n"
  143. "Debug RIB events\n")
  144. {
  145. SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB);
  146. return CMD_SUCCESS;
  147. }
  148. DEFUN (debug_zebra_rib_q,
  149. debug_zebra_rib_q_cmd,
  150. "debug zebra rib queue",
  151. DEBUG_STR
  152. "Zebra configuration\n"
  153. "Debug RIB events\n"
  154. "Debug RIB queueing\n")
  155. {
  156. SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_Q);
  157. return CMD_SUCCESS;
  158. }
  159. DEFUN (debug_zebra_fpm,
  160. debug_zebra_fpm_cmd,
  161. "debug zebra fpm",
  162. DEBUG_STR
  163. "Zebra configuration\n"
  164. "Debug zebra FPM events\n")
  165. {
  166. SET_FLAG (zebra_debug_fpm, ZEBRA_DEBUG_FPM);
  167. return CMD_SUCCESS;
  168. }
  169. DEFUN (no_debug_zebra_events,
  170. no_debug_zebra_events_cmd,
  171. "no debug zebra events",
  172. NO_STR
  173. DEBUG_STR
  174. "Zebra configuration\n"
  175. "Debug option set for zebra events\n")
  176. {
  177. zebra_debug_event = 0;
  178. return CMD_SUCCESS;
  179. }
  180. DEFUN (no_debug_zebra_packet,
  181. no_debug_zebra_packet_cmd,
  182. "no debug zebra packet",
  183. NO_STR
  184. DEBUG_STR
  185. "Zebra configuration\n"
  186. "Debug option set for zebra packet\n")
  187. {
  188. zebra_debug_packet = 0;
  189. return CMD_SUCCESS;
  190. }
  191. DEFUN (no_debug_zebra_packet_direct,
  192. no_debug_zebra_packet_direct_cmd,
  193. "no debug zebra packet (recv|send)",
  194. NO_STR
  195. DEBUG_STR
  196. "Zebra configuration\n"
  197. "Debug option set for zebra packet\n"
  198. "Debug option set for receive packet\n"
  199. "Debug option set for send packet\n")
  200. {
  201. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  202. zebra_debug_packet &= ~ZEBRA_DEBUG_SEND;
  203. if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  204. zebra_debug_packet &= ~ZEBRA_DEBUG_RECV;
  205. return CMD_SUCCESS;
  206. }
  207. DEFUN (no_debug_zebra_kernel,
  208. no_debug_zebra_kernel_cmd,
  209. "no debug zebra kernel",
  210. NO_STR
  211. DEBUG_STR
  212. "Zebra configuration\n"
  213. "Debug option set for zebra between kernel interface\n")
  214. {
  215. zebra_debug_kernel = 0;
  216. return CMD_SUCCESS;
  217. }
  218. DEFUN (no_debug_zebra_rib,
  219. no_debug_zebra_rib_cmd,
  220. "no debug zebra rib",
  221. NO_STR
  222. DEBUG_STR
  223. "Zebra configuration\n"
  224. "Debug zebra RIB\n")
  225. {
  226. zebra_debug_rib = 0;
  227. return CMD_SUCCESS;
  228. }
  229. DEFUN (no_debug_zebra_rib_q,
  230. no_debug_zebra_rib_q_cmd,
  231. "no debug zebra rib queue",
  232. NO_STR
  233. DEBUG_STR
  234. "Zebra configuration\n"
  235. "Debug zebra RIB\n"
  236. "Debug RIB queueing\n")
  237. {
  238. UNSET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_Q);
  239. return CMD_SUCCESS;
  240. }
  241. DEFUN (no_debug_zebra_fpm,
  242. no_debug_zebra_fpm_cmd,
  243. "no debug zebra fpm",
  244. NO_STR
  245. DEBUG_STR
  246. "Zebra configuration\n"
  247. "Debug zebra FPM events\n")
  248. {
  249. zebra_debug_fpm = 0;
  250. return CMD_SUCCESS;
  251. }
  252. /* Debug node. */
  253. struct cmd_node debug_node =
  254. {
  255. DEBUG_NODE,
  256. "", /* Debug node has no interface. */
  257. 1
  258. };
  259. static int
  260. config_write_debug (struct vty *vty)
  261. {
  262. int write = 0;
  263. if (IS_ZEBRA_DEBUG_EVENT)
  264. {
  265. vty_out (vty, "debug zebra events%s", VTY_NEWLINE);
  266. write++;
  267. }
  268. if (IS_ZEBRA_DEBUG_PACKET)
  269. {
  270. if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
  271. {
  272. vty_out (vty, "debug zebra packet%s%s",
  273. IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  274. VTY_NEWLINE);
  275. write++;
  276. }
  277. else
  278. {
  279. if (IS_ZEBRA_DEBUG_SEND)
  280. vty_out (vty, "debug zebra packet send%s%s",
  281. IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  282. VTY_NEWLINE);
  283. else
  284. vty_out (vty, "debug zebra packet recv%s%s",
  285. IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
  286. VTY_NEWLINE);
  287. write++;
  288. }
  289. }
  290. if (IS_ZEBRA_DEBUG_KERNEL)
  291. {
  292. vty_out (vty, "debug zebra kernel%s", VTY_NEWLINE);
  293. write++;
  294. }
  295. if (IS_ZEBRA_DEBUG_RIB)
  296. {
  297. vty_out (vty, "debug zebra rib%s", VTY_NEWLINE);
  298. write++;
  299. }
  300. if (IS_ZEBRA_DEBUG_RIB_Q)
  301. {
  302. vty_out (vty, "debug zebra rib queue%s", VTY_NEWLINE);
  303. write++;
  304. }
  305. if (IS_ZEBRA_DEBUG_FPM)
  306. {
  307. vty_out (vty, "debug zebra fpm%s", VTY_NEWLINE);
  308. write++;
  309. }
  310. return write;
  311. }
  312. void
  313. zebra_debug_init (void)
  314. {
  315. zebra_debug_event = 0;
  316. zebra_debug_packet = 0;
  317. zebra_debug_kernel = 0;
  318. zebra_debug_rib = 0;
  319. zebra_debug_fpm = 0;
  320. install_node (&debug_node, config_write_debug);
  321. install_element (VIEW_NODE, &show_debugging_zebra_cmd);
  322. install_element (ENABLE_NODE, &show_debugging_zebra_cmd);
  323. install_element (ENABLE_NODE, &debug_zebra_events_cmd);
  324. install_element (ENABLE_NODE, &debug_zebra_packet_cmd);
  325. install_element (ENABLE_NODE, &debug_zebra_packet_direct_cmd);
  326. install_element (ENABLE_NODE, &debug_zebra_packet_detail_cmd);
  327. install_element (ENABLE_NODE, &debug_zebra_kernel_cmd);
  328. install_element (ENABLE_NODE, &debug_zebra_rib_cmd);
  329. install_element (ENABLE_NODE, &debug_zebra_rib_q_cmd);
  330. install_element (ENABLE_NODE, &debug_zebra_fpm_cmd);
  331. install_element (ENABLE_NODE, &no_debug_zebra_events_cmd);
  332. install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd);
  333. install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd);
  334. install_element (ENABLE_NODE, &no_debug_zebra_rib_cmd);
  335. install_element (ENABLE_NODE, &no_debug_zebra_rib_q_cmd);
  336. install_element (ENABLE_NODE, &no_debug_zebra_fpm_cmd);
  337. install_element (CONFIG_NODE, &debug_zebra_events_cmd);
  338. install_element (CONFIG_NODE, &debug_zebra_packet_cmd);
  339. install_element (CONFIG_NODE, &debug_zebra_packet_direct_cmd);
  340. install_element (CONFIG_NODE, &debug_zebra_packet_detail_cmd);
  341. install_element (CONFIG_NODE, &debug_zebra_kernel_cmd);
  342. install_element (CONFIG_NODE, &debug_zebra_rib_cmd);
  343. install_element (CONFIG_NODE, &debug_zebra_rib_q_cmd);
  344. install_element (CONFIG_NODE, &debug_zebra_fpm_cmd);
  345. install_element (CONFIG_NODE, &no_debug_zebra_events_cmd);
  346. install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd);
  347. install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd);
  348. install_element (CONFIG_NODE, &no_debug_zebra_rib_cmd);
  349. install_element (CONFIG_NODE, &no_debug_zebra_rib_q_cmd);
  350. install_element (CONFIG_NODE, &no_debug_zebra_fpm_cmd);
  351. }