debug.c 11 KB

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