ripng_debug.c 7.9 KB

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