rip_debug.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 debugging is on%s",
  43. VTY_NEWLINE);
  44. }
  45. else
  46. {
  47. if (IS_RIP_DEBUG_SEND)
  48. vty_out (vty, " RIP packet send debugging is on%s",
  49. VTY_NEWLINE);
  50. else
  51. vty_out (vty, " RIP packet receive debugging is on%s",
  52. VTY_NEWLINE);
  53. }
  54. }
  55. if (IS_RIP_DEBUG_ZEBRA)
  56. vty_out (vty, " RIP zebra debugging is on%s", VTY_NEWLINE);
  57. return CMD_SUCCESS;
  58. }
  59. DEFUN (debug_rip_events,
  60. debug_rip_events_cmd,
  61. "debug rip events",
  62. DEBUG_STR
  63. RIP_STR
  64. "RIP events\n")
  65. {
  66. rip_debug_event = RIP_DEBUG_EVENT;
  67. return CMD_WARNING;
  68. }
  69. DEFUN (debug_rip_packet,
  70. debug_rip_packet_cmd,
  71. "debug rip packet",
  72. DEBUG_STR
  73. RIP_STR
  74. "RIP packet\n")
  75. {
  76. rip_debug_packet = RIP_DEBUG_PACKET;
  77. rip_debug_packet |= RIP_DEBUG_SEND;
  78. rip_debug_packet |= RIP_DEBUG_RECV;
  79. return CMD_SUCCESS;
  80. }
  81. DEFUN (debug_rip_packet_direct,
  82. debug_rip_packet_direct_cmd,
  83. "debug rip packet (recv|send)",
  84. DEBUG_STR
  85. RIP_STR
  86. "RIP packet\n"
  87. "RIP receive packet\n"
  88. "RIP send packet\n")
  89. {
  90. rip_debug_packet |= RIP_DEBUG_PACKET;
  91. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  92. rip_debug_packet |= RIP_DEBUG_SEND;
  93. if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  94. rip_debug_packet |= RIP_DEBUG_RECV;
  95. return CMD_SUCCESS;
  96. }
  97. /* N.B. the "detail" modifier is a no-op. we leave this command
  98. for legacy compatibility. */
  99. DEFUN_DEPRECATED (debug_rip_packet_detail,
  100. debug_rip_packet_detail_cmd,
  101. "debug rip packet (recv|send) detail",
  102. DEBUG_STR
  103. RIP_STR
  104. "RIP packet\n"
  105. "RIP receive packet\n"
  106. "RIP send packet\n"
  107. "Detailed information display\n")
  108. {
  109. rip_debug_packet |= RIP_DEBUG_PACKET;
  110. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  111. rip_debug_packet |= RIP_DEBUG_SEND;
  112. if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  113. rip_debug_packet |= RIP_DEBUG_RECV;
  114. return CMD_SUCCESS;
  115. }
  116. DEFUN (debug_rip_zebra,
  117. debug_rip_zebra_cmd,
  118. "debug rip zebra",
  119. DEBUG_STR
  120. RIP_STR
  121. "RIP and ZEBRA communication\n")
  122. {
  123. rip_debug_zebra = RIP_DEBUG_ZEBRA;
  124. return CMD_WARNING;
  125. }
  126. DEFUN (no_debug_rip_events,
  127. no_debug_rip_events_cmd,
  128. "no debug rip events",
  129. NO_STR
  130. DEBUG_STR
  131. RIP_STR
  132. "RIP events\n")
  133. {
  134. rip_debug_event = 0;
  135. return CMD_SUCCESS;
  136. }
  137. DEFUN (no_debug_rip_packet,
  138. no_debug_rip_packet_cmd,
  139. "no debug rip packet",
  140. NO_STR
  141. DEBUG_STR
  142. RIP_STR
  143. "RIP packet\n")
  144. {
  145. rip_debug_packet = 0;
  146. return CMD_SUCCESS;
  147. }
  148. DEFUN (no_debug_rip_packet_direct,
  149. no_debug_rip_packet_direct_cmd,
  150. "no debug rip packet (recv|send)",
  151. NO_STR
  152. DEBUG_STR
  153. RIP_STR
  154. "RIP packet\n"
  155. "RIP option set for receive packet\n"
  156. "RIP option set for send packet\n")
  157. {
  158. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  159. {
  160. if (IS_RIP_DEBUG_RECV)
  161. rip_debug_packet &= ~RIP_DEBUG_SEND;
  162. else
  163. rip_debug_packet = 0;
  164. }
  165. else if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  166. {
  167. if (IS_RIP_DEBUG_SEND)
  168. rip_debug_packet &= ~RIP_DEBUG_RECV;
  169. else
  170. rip_debug_packet = 0;
  171. }
  172. return CMD_SUCCESS;
  173. }
  174. DEFUN (no_debug_rip_zebra,
  175. no_debug_rip_zebra_cmd,
  176. "no debug rip zebra",
  177. NO_STR
  178. DEBUG_STR
  179. RIP_STR
  180. "RIP and ZEBRA communication\n")
  181. {
  182. rip_debug_zebra = 0;
  183. return CMD_WARNING;
  184. }
  185. /* Debug node. */
  186. static struct cmd_node debug_node =
  187. {
  188. DEBUG_NODE,
  189. "", /* Debug node has no interface. */
  190. 1
  191. };
  192. static int
  193. config_write_debug (struct vty *vty)
  194. {
  195. int write = 0;
  196. if (IS_RIP_DEBUG_EVENT)
  197. {
  198. vty_out (vty, "debug rip events%s", VTY_NEWLINE);
  199. write++;
  200. }
  201. if (IS_RIP_DEBUG_PACKET)
  202. {
  203. if (IS_RIP_DEBUG_SEND && IS_RIP_DEBUG_RECV)
  204. {
  205. vty_out (vty, "debug rip packet%s",
  206. VTY_NEWLINE);
  207. write++;
  208. }
  209. else
  210. {
  211. if (IS_RIP_DEBUG_SEND)
  212. vty_out (vty, "debug rip packet send%s",
  213. VTY_NEWLINE);
  214. else
  215. vty_out (vty, "debug rip packet recv%s",
  216. VTY_NEWLINE);
  217. write++;
  218. }
  219. }
  220. if (IS_RIP_DEBUG_ZEBRA)
  221. {
  222. vty_out (vty, "debug rip zebra%s", VTY_NEWLINE);
  223. write++;
  224. }
  225. return write;
  226. }
  227. void
  228. rip_debug_reset (void)
  229. {
  230. rip_debug_event = 0;
  231. rip_debug_packet = 0;
  232. rip_debug_zebra = 0;
  233. }
  234. void
  235. rip_debug_init (void)
  236. {
  237. rip_debug_event = 0;
  238. rip_debug_packet = 0;
  239. rip_debug_zebra = 0;
  240. install_node (&debug_node, config_write_debug);
  241. install_element (ENABLE_NODE, &show_debugging_rip_cmd);
  242. install_element (ENABLE_NODE, &debug_rip_events_cmd);
  243. install_element (ENABLE_NODE, &debug_rip_packet_cmd);
  244. install_element (ENABLE_NODE, &debug_rip_packet_direct_cmd);
  245. install_element (ENABLE_NODE, &debug_rip_packet_detail_cmd);
  246. install_element (ENABLE_NODE, &debug_rip_zebra_cmd);
  247. install_element (ENABLE_NODE, &no_debug_rip_events_cmd);
  248. install_element (ENABLE_NODE, &no_debug_rip_packet_cmd);
  249. install_element (ENABLE_NODE, &no_debug_rip_packet_direct_cmd);
  250. install_element (ENABLE_NODE, &no_debug_rip_zebra_cmd);
  251. install_element (CONFIG_NODE, &debug_rip_events_cmd);
  252. install_element (CONFIG_NODE, &debug_rip_packet_cmd);
  253. install_element (CONFIG_NODE, &debug_rip_packet_direct_cmd);
  254. install_element (CONFIG_NODE, &debug_rip_packet_detail_cmd);
  255. install_element (CONFIG_NODE, &debug_rip_zebra_cmd);
  256. install_element (CONFIG_NODE, &no_debug_rip_events_cmd);
  257. install_element (CONFIG_NODE, &no_debug_rip_packet_cmd);
  258. install_element (CONFIG_NODE, &no_debug_rip_packet_direct_cmd);
  259. install_element (CONFIG_NODE, &no_debug_rip_zebra_cmd);
  260. }