ripng_debug.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * RIPng debug output routines
  3. * Copyright (C) 1998 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 Free
  19. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  20. * 02111-1307, USA.
  21. */
  22. #include <zebra.h>
  23. #include "command.h"
  24. #include "ripngd/ripng_debug.h"
  25. /* For debug statement. */
  26. unsigned long ripng_debug_event = 0;
  27. unsigned long ripng_debug_packet = 0;
  28. unsigned long ripng_debug_zebra = 0;
  29. DEFUN (show_debugging_ripng,
  30. show_debugging_ripng_cmd,
  31. "show debugging ripng",
  32. SHOW_STR
  33. DEBUG_STR
  34. "RIPng configuration\n")
  35. {
  36. vty_out (vty, "RIPng debugging status:%s", VTY_NEWLINE);
  37. if (IS_RIPNG_DEBUG_EVENT)
  38. vty_out (vty, " RIPng event debugging is on%s", VTY_NEWLINE);
  39. if (IS_RIPNG_DEBUG_PACKET)
  40. {
  41. if (IS_RIPNG_DEBUG_SEND && IS_RIPNG_DEBUG_RECV)
  42. {
  43. vty_out (vty, " RIPng packet debugging is on%s",
  44. VTY_NEWLINE);
  45. }
  46. else
  47. {
  48. if (IS_RIPNG_DEBUG_SEND)
  49. vty_out (vty, " RIPng packet send debugging is on%s",
  50. VTY_NEWLINE);
  51. else
  52. vty_out (vty, " RIPng packet receive debugging is on%s",
  53. VTY_NEWLINE);
  54. }
  55. }
  56. if (IS_RIPNG_DEBUG_ZEBRA)
  57. vty_out (vty, " RIPng zebra debugging is on%s", VTY_NEWLINE);
  58. return CMD_SUCCESS;
  59. }
  60. DEFUN (debug_ripng_events,
  61. debug_ripng_events_cmd,
  62. "debug ripng events",
  63. DEBUG_STR
  64. "RIPng configuration\n"
  65. "Debug option set for ripng events\n")
  66. {
  67. ripng_debug_event = RIPNG_DEBUG_EVENT;
  68. return CMD_WARNING;
  69. }
  70. DEFUN (debug_ripng_packet,
  71. debug_ripng_packet_cmd,
  72. "debug ripng packet",
  73. DEBUG_STR
  74. "RIPng configuration\n"
  75. "Debug option set for ripng packet\n")
  76. {
  77. ripng_debug_packet = RIPNG_DEBUG_PACKET;
  78. ripng_debug_packet |= RIPNG_DEBUG_SEND;
  79. ripng_debug_packet |= RIPNG_DEBUG_RECV;
  80. return CMD_SUCCESS;
  81. }
  82. DEFUN (debug_ripng_packet_direct,
  83. debug_ripng_packet_direct_cmd,
  84. "debug ripng packet (recv|send)",
  85. DEBUG_STR
  86. "RIPng configuration\n"
  87. "Debug option set for ripng packet\n"
  88. "Debug option set for receive packet\n"
  89. "Debug option set for send packet\n")
  90. {
  91. ripng_debug_packet |= RIPNG_DEBUG_PACKET;
  92. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  93. ripng_debug_packet |= RIPNG_DEBUG_SEND;
  94. if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  95. ripng_debug_packet |= RIPNG_DEBUG_RECV;
  96. return CMD_SUCCESS;
  97. }
  98. /* N.B. the "detail" modifier is a no-op. we leave this command
  99. for legacy compatibility. */
  100. DEFUN_DEPRECATED (debug_ripng_packet_detail,
  101. debug_ripng_packet_detail_cmd,
  102. "debug ripng packet (recv|send) detail",
  103. DEBUG_STR
  104. "RIPng configuration\n"
  105. "Debug option set for ripng packet\n"
  106. "Debug option set for receive packet\n"
  107. "Debug option set for send packet\n"
  108. "Debug option set detaied information\n")
  109. {
  110. ripng_debug_packet |= RIPNG_DEBUG_PACKET;
  111. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  112. ripng_debug_packet |= RIPNG_DEBUG_SEND;
  113. if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  114. ripng_debug_packet |= RIPNG_DEBUG_RECV;
  115. return CMD_SUCCESS;
  116. }
  117. DEFUN (debug_ripng_zebra,
  118. debug_ripng_zebra_cmd,
  119. "debug ripng zebra",
  120. DEBUG_STR
  121. "RIPng configuration\n"
  122. "Debug option set for ripng and zebra communication\n")
  123. {
  124. ripng_debug_zebra = RIPNG_DEBUG_ZEBRA;
  125. return CMD_WARNING;
  126. }
  127. DEFUN (no_debug_ripng_events,
  128. no_debug_ripng_events_cmd,
  129. "no debug ripng events",
  130. NO_STR
  131. DEBUG_STR
  132. "RIPng configuration\n"
  133. "Debug option set for ripng events\n")
  134. {
  135. ripng_debug_event = 0;
  136. return CMD_SUCCESS;
  137. }
  138. DEFUN (no_debug_ripng_packet,
  139. no_debug_ripng_packet_cmd,
  140. "no debug ripng packet",
  141. NO_STR
  142. DEBUG_STR
  143. "RIPng configuration\n"
  144. "Debug option set for ripng packet\n")
  145. {
  146. ripng_debug_packet = 0;
  147. return CMD_SUCCESS;
  148. }
  149. DEFUN (no_debug_ripng_packet_direct,
  150. no_debug_ripng_packet_direct_cmd,
  151. "no debug ripng packet (recv|send)",
  152. NO_STR
  153. DEBUG_STR
  154. "RIPng configuration\n"
  155. "Debug option set for ripng packet\n"
  156. "Debug option set for receive packet\n"
  157. "Debug option set for send packet\n")
  158. {
  159. if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
  160. {
  161. if (IS_RIPNG_DEBUG_RECV)
  162. ripng_debug_packet &= ~RIPNG_DEBUG_SEND;
  163. else
  164. ripng_debug_packet = 0;
  165. }
  166. else if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
  167. {
  168. if (IS_RIPNG_DEBUG_SEND)
  169. ripng_debug_packet &= ~RIPNG_DEBUG_RECV;
  170. else
  171. ripng_debug_packet = 0;
  172. }
  173. return CMD_SUCCESS;
  174. }
  175. DEFUN (no_debug_ripng_zebra,
  176. no_debug_ripng_zebra_cmd,
  177. "no debug ripng zebra",
  178. NO_STR
  179. DEBUG_STR
  180. "RIPng configuration\n"
  181. "Debug option set for ripng and zebra communication\n")
  182. {
  183. ripng_debug_zebra = 0;
  184. return CMD_WARNING;
  185. }
  186. /* Debug node. */
  187. static struct cmd_node debug_node =
  188. {
  189. DEBUG_NODE,
  190. "", /* Debug node has no interface. */
  191. 1 /* VTYSH */
  192. };
  193. static int
  194. config_write_debug (struct vty *vty)
  195. {
  196. int write = 0;
  197. if (IS_RIPNG_DEBUG_EVENT)
  198. {
  199. vty_out (vty, "debug ripng events%s", VTY_NEWLINE);
  200. write++;
  201. }
  202. if (IS_RIPNG_DEBUG_PACKET)
  203. {
  204. if (IS_RIPNG_DEBUG_SEND && IS_RIPNG_DEBUG_RECV)
  205. {
  206. vty_out (vty, "debug ripng packet%s",
  207. VTY_NEWLINE);
  208. write++;
  209. }
  210. else
  211. {
  212. if (IS_RIPNG_DEBUG_SEND)
  213. vty_out (vty, "debug ripng packet send%s",
  214. VTY_NEWLINE);
  215. else
  216. vty_out (vty, "debug ripng packet recv%s",
  217. VTY_NEWLINE);
  218. write++;
  219. }
  220. }
  221. if (IS_RIPNG_DEBUG_ZEBRA)
  222. {
  223. vty_out (vty, "debug ripng zebra%s", VTY_NEWLINE);
  224. write++;
  225. }
  226. return write;
  227. }
  228. void
  229. ripng_debug_reset ()
  230. {
  231. ripng_debug_event = 0;
  232. ripng_debug_packet = 0;
  233. ripng_debug_zebra = 0;
  234. }
  235. void
  236. ripng_debug_init ()
  237. {
  238. ripng_debug_event = 0;
  239. ripng_debug_packet = 0;
  240. ripng_debug_zebra = 0;
  241. install_node (&debug_node, config_write_debug);
  242. install_element (VIEW_NODE, &show_debugging_ripng_cmd);
  243. install_element (ENABLE_NODE, &debug_ripng_events_cmd);
  244. install_element (ENABLE_NODE, &debug_ripng_packet_cmd);
  245. install_element (ENABLE_NODE, &debug_ripng_packet_direct_cmd);
  246. install_element (ENABLE_NODE, &debug_ripng_packet_detail_cmd);
  247. install_element (ENABLE_NODE, &debug_ripng_zebra_cmd);
  248. install_element (ENABLE_NODE, &no_debug_ripng_events_cmd);
  249. install_element (ENABLE_NODE, &no_debug_ripng_packet_cmd);
  250. install_element (ENABLE_NODE, &no_debug_ripng_packet_direct_cmd);
  251. install_element (ENABLE_NODE, &no_debug_ripng_zebra_cmd);
  252. install_element (CONFIG_NODE, &debug_ripng_events_cmd);
  253. install_element (CONFIG_NODE, &debug_ripng_packet_cmd);
  254. install_element (CONFIG_NODE, &debug_ripng_packet_direct_cmd);
  255. install_element (CONFIG_NODE, &debug_ripng_packet_detail_cmd);
  256. install_element (CONFIG_NODE, &debug_ripng_zebra_cmd);
  257. install_element (CONFIG_NODE, &no_debug_ripng_events_cmd);
  258. install_element (CONFIG_NODE, &no_debug_ripng_packet_cmd);
  259. install_element (CONFIG_NODE, &no_debug_ripng_packet_direct_cmd);
  260. install_element (CONFIG_NODE, &no_debug_ripng_zebra_cmd);
  261. }