rip_debug.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /* RIP debug routines
  2. * Copyright (C) 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * GNU Zebra is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  18. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. * 02111-1307, USA.
  20. */
  21. #include <zebra.h>
  22. #include "command.h"
  23. #include "ripd/rip_debug.h"
  24. /* For debug statement. */
  25. unsigned long rip_debug_event = 0;
  26. unsigned long rip_debug_packet = 0;
  27. unsigned long rip_debug_zebra = 0;
  28. DEFUN (show_debugging_rip,
  29. show_debugging_rip_cmd,
  30. "show debugging rip",
  31. SHOW_STR
  32. DEBUG_STR
  33. RIP_STR)
  34. {
  35. vty_out (vty, "RIP debugging status:%s", VTY_NEWLINE);
  36. if (IS_RIP_DEBUG_EVENT)
  37. vty_out (vty, " RIP event debugging is on%s", VTY_NEWLINE);
  38. if (IS_RIP_DEBUG_PACKET)
  39. {
  40. if (IS_RIP_DEBUG_SEND && IS_RIP_DEBUG_RECV)
  41. {
  42. vty_out (vty, " RIP packet%s debugging is on%s",
  43. IS_RIP_DEBUG_DETAIL ? " detail" : "",
  44. VTY_NEWLINE);
  45. }
  46. else
  47. {
  48. if (IS_RIP_DEBUG_SEND)
  49. vty_out (vty, " RIP packet send%s debugging is on%s",
  50. IS_RIP_DEBUG_DETAIL ? " detail" : "",
  51. VTY_NEWLINE);
  52. else
  53. vty_out (vty, " RIP packet receive%s debugging is on%s",
  54. IS_RIP_DEBUG_DETAIL ? " detail" : "",
  55. VTY_NEWLINE);
  56. }
  57. }
  58. if (IS_RIP_DEBUG_ZEBRA)
  59. vty_out (vty, " RIP zebra debugging is on%s", VTY_NEWLINE);
  60. return CMD_SUCCESS;
  61. }
  62. DEFUN (debug_rip_events,
  63. debug_rip_events_cmd,
  64. "debug rip events",
  65. DEBUG_STR
  66. RIP_STR
  67. "RIP events\n")
  68. {
  69. rip_debug_event = RIP_DEBUG_EVENT;
  70. return CMD_WARNING;
  71. }
  72. DEFUN (debug_rip_packet,
  73. debug_rip_packet_cmd,
  74. "debug rip packet",
  75. DEBUG_STR
  76. RIP_STR
  77. "RIP packet\n")
  78. {
  79. rip_debug_packet = RIP_DEBUG_PACKET;
  80. rip_debug_packet |= RIP_DEBUG_SEND;
  81. rip_debug_packet |= RIP_DEBUG_RECV;
  82. return CMD_SUCCESS;
  83. }
  84. DEFUN (debug_rip_packet_direct,
  85. debug_rip_packet_direct_cmd,
  86. "debug rip packet (recv|send)",
  87. DEBUG_STR
  88. RIP_STR
  89. "RIP packet\n"
  90. "RIP receive packet\n"
  91. "RIP send packet\n")
  92. {
  93. rip_debug_packet |= RIP_DEBUG_PACKET;
  94. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  95. rip_debug_packet |= RIP_DEBUG_SEND;
  96. if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  97. rip_debug_packet |= RIP_DEBUG_RECV;
  98. rip_debug_packet &= ~RIP_DEBUG_DETAIL;
  99. return CMD_SUCCESS;
  100. }
  101. DEFUN (debug_rip_packet_detail,
  102. debug_rip_packet_detail_cmd,
  103. "debug rip packet (recv|send) detail",
  104. DEBUG_STR
  105. RIP_STR
  106. "RIP packet\n"
  107. "RIP receive packet\n"
  108. "RIP send packet\n"
  109. "Detailed information display\n")
  110. {
  111. rip_debug_packet |= RIP_DEBUG_PACKET;
  112. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  113. rip_debug_packet |= RIP_DEBUG_SEND;
  114. if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  115. rip_debug_packet |= RIP_DEBUG_RECV;
  116. rip_debug_packet |= RIP_DEBUG_DETAIL;
  117. return CMD_SUCCESS;
  118. }
  119. DEFUN (debug_rip_zebra,
  120. debug_rip_zebra_cmd,
  121. "debug rip zebra",
  122. DEBUG_STR
  123. RIP_STR
  124. "RIP and ZEBRA communication\n")
  125. {
  126. rip_debug_zebra = RIP_DEBUG_ZEBRA;
  127. return CMD_WARNING;
  128. }
  129. DEFUN (no_debug_rip_events,
  130. no_debug_rip_events_cmd,
  131. "no debug rip events",
  132. NO_STR
  133. DEBUG_STR
  134. RIP_STR
  135. "RIP events\n")
  136. {
  137. rip_debug_event = 0;
  138. return CMD_SUCCESS;
  139. }
  140. DEFUN (no_debug_rip_packet,
  141. no_debug_rip_packet_cmd,
  142. "no debug rip packet",
  143. NO_STR
  144. DEBUG_STR
  145. RIP_STR
  146. "RIP packet\n")
  147. {
  148. rip_debug_packet = 0;
  149. return CMD_SUCCESS;
  150. }
  151. DEFUN (no_debug_rip_packet_direct,
  152. no_debug_rip_packet_direct_cmd,
  153. "no debug rip packet (recv|send)",
  154. NO_STR
  155. DEBUG_STR
  156. RIP_STR
  157. "RIP packet\n"
  158. "RIP option set for receive packet\n"
  159. "RIP option set for send packet\n")
  160. {
  161. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  162. {
  163. if (IS_RIP_DEBUG_RECV)
  164. rip_debug_packet &= ~RIP_DEBUG_SEND;
  165. else
  166. rip_debug_packet = 0;
  167. }
  168. else if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  169. {
  170. if (IS_RIP_DEBUG_SEND)
  171. rip_debug_packet &= ~RIP_DEBUG_RECV;
  172. else
  173. rip_debug_packet = 0;
  174. }
  175. return CMD_SUCCESS;
  176. }
  177. DEFUN (no_debug_rip_zebra,
  178. no_debug_rip_zebra_cmd,
  179. "no debug rip zebra",
  180. NO_STR
  181. DEBUG_STR
  182. RIP_STR
  183. "RIP and ZEBRA communication\n")
  184. {
  185. rip_debug_zebra = 0;
  186. return CMD_WARNING;
  187. }
  188. /* Debug node. */
  189. struct cmd_node debug_node =
  190. {
  191. DEBUG_NODE,
  192. "", /* Debug node has no interface. */
  193. 1
  194. };
  195. static int
  196. config_write_debug (struct vty *vty)
  197. {
  198. int write = 0;
  199. if (IS_RIP_DEBUG_EVENT)
  200. {
  201. vty_out (vty, "debug rip events%s", VTY_NEWLINE);
  202. write++;
  203. }
  204. if (IS_RIP_DEBUG_PACKET)
  205. {
  206. if (IS_RIP_DEBUG_SEND && IS_RIP_DEBUG_RECV)
  207. {
  208. vty_out (vty, "debug rip packet%s%s",
  209. IS_RIP_DEBUG_DETAIL ? " detail" : "",
  210. VTY_NEWLINE);
  211. write++;
  212. }
  213. else
  214. {
  215. if (IS_RIP_DEBUG_SEND)
  216. vty_out (vty, "debug rip packet send%s%s",
  217. IS_RIP_DEBUG_DETAIL ? " detail" : "",
  218. VTY_NEWLINE);
  219. else
  220. vty_out (vty, "debug rip packet recv%s%s",
  221. IS_RIP_DEBUG_DETAIL ? " detail" : "",
  222. VTY_NEWLINE);
  223. write++;
  224. }
  225. }
  226. if (IS_RIP_DEBUG_ZEBRA)
  227. {
  228. vty_out (vty, "debug rip zebra%s", VTY_NEWLINE);
  229. write++;
  230. }
  231. return write;
  232. }
  233. void
  234. rip_debug_reset (void)
  235. {
  236. rip_debug_event = 0;
  237. rip_debug_packet = 0;
  238. rip_debug_zebra = 0;
  239. }
  240. void
  241. rip_debug_init (void)
  242. {
  243. rip_debug_event = 0;
  244. rip_debug_packet = 0;
  245. rip_debug_zebra = 0;
  246. install_node (&debug_node, config_write_debug);
  247. install_element (ENABLE_NODE, &show_debugging_rip_cmd);
  248. install_element (ENABLE_NODE, &debug_rip_events_cmd);
  249. install_element (ENABLE_NODE, &debug_rip_packet_cmd);
  250. install_element (ENABLE_NODE, &debug_rip_packet_direct_cmd);
  251. install_element (ENABLE_NODE, &debug_rip_packet_detail_cmd);
  252. install_element (ENABLE_NODE, &debug_rip_zebra_cmd);
  253. install_element (ENABLE_NODE, &no_debug_rip_events_cmd);
  254. install_element (ENABLE_NODE, &no_debug_rip_packet_cmd);
  255. install_element (ENABLE_NODE, &no_debug_rip_packet_direct_cmd);
  256. install_element (ENABLE_NODE, &no_debug_rip_zebra_cmd);
  257. install_element (CONFIG_NODE, &debug_rip_events_cmd);
  258. install_element (CONFIG_NODE, &debug_rip_packet_cmd);
  259. install_element (CONFIG_NODE, &debug_rip_packet_direct_cmd);
  260. install_element (CONFIG_NODE, &debug_rip_packet_detail_cmd);
  261. install_element (CONFIG_NODE, &debug_rip_zebra_cmd);
  262. install_element (CONFIG_NODE, &no_debug_rip_events_cmd);
  263. install_element (CONFIG_NODE, &no_debug_rip_packet_cmd);
  264. install_element (CONFIG_NODE, &no_debug_rip_packet_direct_cmd);
  265. install_element (CONFIG_NODE, &no_debug_rip_zebra_cmd);
  266. }