ospf_dump.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749
  1. /*
  2. * OSPFd dump routine.
  3. * Copyright (C) 1999, 2000 Toshiaki Takada
  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 "linklist.h"
  24. #include "thread.h"
  25. #include "prefix.h"
  26. #include "command.h"
  27. #include "stream.h"
  28. #include "log.h"
  29. #include "sockopt.h"
  30. #include "ospfd/ospfd.h"
  31. #include "ospfd/ospf_interface.h"
  32. #include "ospfd/ospf_ism.h"
  33. #include "ospfd/ospf_asbr.h"
  34. #include "ospfd/ospf_lsa.h"
  35. #include "ospfd/ospf_lsdb.h"
  36. #include "ospfd/ospf_neighbor.h"
  37. #include "ospfd/ospf_nsm.h"
  38. #include "ospfd/ospf_dump.h"
  39. #include "ospfd/ospf_packet.h"
  40. #include "ospfd/ospf_network.h"
  41. const struct message ospf_ism_state_msg[] =
  42. {
  43. { ISM_DependUpon, "DependUpon" },
  44. { ISM_Down, "Down" },
  45. { ISM_Loopback, "Loopback" },
  46. { ISM_Waiting, "Waiting" },
  47. { ISM_PointToPoint, "Point-To-Point" },
  48. { ISM_DROther, "DROther" },
  49. { ISM_Backup, "Backup" },
  50. { ISM_DR, "DR" },
  51. };
  52. const int ospf_ism_state_msg_max = OSPF_ISM_STATE_MAX;
  53. const struct message ospf_nsm_state_msg[] =
  54. {
  55. { NSM_DependUpon, "DependUpon" },
  56. { NSM_Deleted, "Deleted" },
  57. { NSM_Down, "Down" },
  58. { NSM_Attempt, "Attempt" },
  59. { NSM_Init, "Init" },
  60. { NSM_TwoWay, "2-Way" },
  61. { NSM_ExStart, "ExStart" },
  62. { NSM_Exchange, "Exchange" },
  63. { NSM_Loading, "Loading" },
  64. { NSM_Full, "Full" },
  65. };
  66. const int ospf_nsm_state_msg_max = OSPF_NSM_STATE_MAX;
  67. const struct message ospf_lsa_type_msg[] =
  68. {
  69. { OSPF_UNKNOWN_LSA, "unknown" },
  70. { OSPF_ROUTER_LSA, "router-LSA" },
  71. { OSPF_NETWORK_LSA, "network-LSA" },
  72. { OSPF_SUMMARY_LSA, "summary-LSA" },
  73. { OSPF_ASBR_SUMMARY_LSA, "summary-LSA" },
  74. { OSPF_AS_EXTERNAL_LSA, "AS-external-LSA" },
  75. { OSPF_GROUP_MEMBER_LSA, "GROUP MEMBER LSA" },
  76. { OSPF_AS_NSSA_LSA, "NSSA-LSA" },
  77. { 8, "Type-8 LSA" },
  78. { OSPF_OPAQUE_LINK_LSA, "Link-Local Opaque-LSA" },
  79. { OSPF_OPAQUE_AREA_LSA, "Area-Local Opaque-LSA" },
  80. { OSPF_OPAQUE_AS_LSA, "AS-external Opaque-LSA" },
  81. };
  82. const int ospf_lsa_type_msg_max = OSPF_MAX_LSA;
  83. const struct message ospf_link_state_id_type_msg[] =
  84. {
  85. { OSPF_UNKNOWN_LSA, "(unknown)" },
  86. { OSPF_ROUTER_LSA, "" },
  87. { OSPF_NETWORK_LSA, "(address of Designated Router)" },
  88. { OSPF_SUMMARY_LSA, "(summary Network Number)" },
  89. { OSPF_ASBR_SUMMARY_LSA, "(AS Boundary Router address)" },
  90. { OSPF_AS_EXTERNAL_LSA, "(External Network Number)" },
  91. { OSPF_GROUP_MEMBER_LSA, "(Group membership information)" },
  92. { OSPF_AS_NSSA_LSA, "(External Network Number for NSSA)" },
  93. { 8, "(Type-8 LSID)" },
  94. { OSPF_OPAQUE_LINK_LSA, "(Link-Local Opaque-Type/ID)" },
  95. { OSPF_OPAQUE_AREA_LSA, "(Area-Local Opaque-Type/ID)" },
  96. { OSPF_OPAQUE_AS_LSA, "(AS-external Opaque-Type/ID)" },
  97. };
  98. const int ospf_link_state_id_type_msg_max = OSPF_MAX_LSA;
  99. const struct message ospf_network_type_msg[] =
  100. {
  101. { OSPF_IFTYPE_NONE, "NONE" },
  102. { OSPF_IFTYPE_POINTOPOINT, "Point-to-Point" },
  103. { OSPF_IFTYPE_BROADCAST, "Broadcast" },
  104. { OSPF_IFTYPE_NBMA, "NBMA" },
  105. { OSPF_IFTYPE_POINTOMULTIPOINT, "Point-to-MultiPoint" },
  106. { OSPF_IFTYPE_VIRTUALLINK, "Virtual-Link" },
  107. };
  108. const int ospf_network_type_msg_max = OSPF_IFTYPE_MAX;
  109. /* AuType */
  110. const struct message ospf_auth_type_str[] =
  111. {
  112. { OSPF_AUTH_NULL, "Null" },
  113. { OSPF_AUTH_SIMPLE, "Simple" },
  114. { OSPF_AUTH_CRYPTOGRAPHIC, "Cryptographic" },
  115. };
  116. const size_t ospf_auth_type_str_max = sizeof (ospf_auth_type_str) /
  117. sizeof (ospf_auth_type_str[0]);
  118. /* Configuration debug option variables. */
  119. unsigned long conf_debug_ospf_packet[5] = {0, 0, 0, 0, 0};
  120. unsigned long conf_debug_ospf_event = 0;
  121. unsigned long conf_debug_ospf_ism = 0;
  122. unsigned long conf_debug_ospf_nsm = 0;
  123. unsigned long conf_debug_ospf_lsa = 0;
  124. unsigned long conf_debug_ospf_zebra = 0;
  125. unsigned long conf_debug_ospf_nssa = 0;
  126. unsigned long conf_debug_ospf_te = 0;
  127. /* Enable debug option variables -- valid only session. */
  128. unsigned long term_debug_ospf_packet[5] = {0, 0, 0, 0, 0};
  129. unsigned long term_debug_ospf_event = 0;
  130. unsigned long term_debug_ospf_ism = 0;
  131. unsigned long term_debug_ospf_nsm = 0;
  132. unsigned long term_debug_ospf_lsa = 0;
  133. unsigned long term_debug_ospf_zebra = 0;
  134. unsigned long term_debug_ospf_nssa = 0;
  135. unsigned long term_debug_ospf_te = 0;
  136. const char *
  137. ospf_redist_string(u_int route_type)
  138. {
  139. return (route_type == ZEBRA_ROUTE_MAX) ?
  140. "Default" : zebra_route_string(route_type);
  141. }
  142. #define OSPF_AREA_STRING_MAXLEN 16
  143. const char *
  144. ospf_area_name_string (struct ospf_area *area)
  145. {
  146. static char buf[OSPF_AREA_STRING_MAXLEN] = "";
  147. u_int32_t area_id;
  148. if (!area)
  149. return "-";
  150. area_id = ntohl (area->area_id.s_addr);
  151. snprintf (buf, OSPF_AREA_STRING_MAXLEN, "%d.%d.%d.%d",
  152. (area_id >> 24) & 0xff, (area_id >> 16) & 0xff,
  153. (area_id >> 8) & 0xff, area_id & 0xff);
  154. return buf;
  155. }
  156. #define OSPF_AREA_DESC_STRING_MAXLEN 23
  157. const char *
  158. ospf_area_desc_string (struct ospf_area *area)
  159. {
  160. static char buf[OSPF_AREA_DESC_STRING_MAXLEN] = "";
  161. u_char type;
  162. if (!area)
  163. return "(incomplete)";
  164. type = area->external_routing;
  165. switch (type)
  166. {
  167. case OSPF_AREA_NSSA:
  168. snprintf (buf, OSPF_AREA_DESC_STRING_MAXLEN, "%s [NSSA]",
  169. ospf_area_name_string (area));
  170. break;
  171. case OSPF_AREA_STUB:
  172. snprintf (buf, OSPF_AREA_DESC_STRING_MAXLEN, "%s [Stub]",
  173. ospf_area_name_string (area));
  174. break;
  175. default:
  176. return ospf_area_name_string (area);
  177. }
  178. return buf;
  179. }
  180. #define OSPF_IF_STRING_MAXLEN 40
  181. const char *
  182. ospf_if_name_string (struct ospf_interface *oi)
  183. {
  184. static char buf[OSPF_IF_STRING_MAXLEN] = "";
  185. u_int32_t ifaddr;
  186. if (!oi)
  187. return "inactive";
  188. if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
  189. return oi->ifp->name;
  190. ifaddr = ntohl (oi->address->u.prefix4.s_addr);
  191. snprintf (buf, OSPF_IF_STRING_MAXLEN,
  192. "%s:%d.%d.%d.%d", oi->ifp->name,
  193. (ifaddr >> 24) & 0xff, (ifaddr >> 16) & 0xff,
  194. (ifaddr >> 8) & 0xff, ifaddr & 0xff);
  195. return buf;
  196. }
  197. void
  198. ospf_nbr_state_message (struct ospf_neighbor *nbr, char *buf, size_t size)
  199. {
  200. int state;
  201. struct ospf_interface *oi = nbr->oi;
  202. if (IPV4_ADDR_SAME (&DR (oi), &nbr->address.u.prefix4))
  203. state = ISM_DR;
  204. else if (IPV4_ADDR_SAME (&BDR (oi), &nbr->address.u.prefix4))
  205. state = ISM_Backup;
  206. else
  207. state = ISM_DROther;
  208. memset (buf, 0, size);
  209. snprintf (buf, size, "%s/%s",
  210. LOOKUP (ospf_nsm_state_msg, nbr->state),
  211. LOOKUP (ospf_ism_state_msg, state));
  212. }
  213. const char *
  214. ospf_timeval_dump (struct timeval *t, char *buf, size_t size)
  215. {
  216. /* Making formatted timer strings. */
  217. #define MINUTE_IN_SECONDS 60
  218. #define HOUR_IN_SECONDS (60*MINUTE_IN_SECONDS)
  219. #define DAY_IN_SECONDS (24*HOUR_IN_SECONDS)
  220. #define WEEK_IN_SECONDS (7*DAY_IN_SECONDS)
  221. unsigned long w, d, h, m, s, ms, us;
  222. if (!t)
  223. return "inactive";
  224. w = d = h = m = s = ms = us = 0;
  225. memset (buf, 0, size);
  226. us = t->tv_usec;
  227. if (us >= 1000)
  228. {
  229. ms = us / 1000;
  230. us %= 1000;
  231. }
  232. if (ms >= 1000)
  233. {
  234. t->tv_sec += ms / 1000;
  235. ms %= 1000;
  236. }
  237. if (t->tv_sec > WEEK_IN_SECONDS)
  238. {
  239. w = t->tv_sec / WEEK_IN_SECONDS;
  240. t->tv_sec -= w * WEEK_IN_SECONDS;
  241. }
  242. if (t->tv_sec > DAY_IN_SECONDS)
  243. {
  244. d = t->tv_sec / DAY_IN_SECONDS;
  245. t->tv_sec -= d * DAY_IN_SECONDS;
  246. }
  247. if (t->tv_sec >= HOUR_IN_SECONDS)
  248. {
  249. h = t->tv_sec / HOUR_IN_SECONDS;
  250. t->tv_sec -= h * HOUR_IN_SECONDS;
  251. }
  252. if (t->tv_sec >= MINUTE_IN_SECONDS)
  253. {
  254. m = t->tv_sec / MINUTE_IN_SECONDS;
  255. t->tv_sec -= m * MINUTE_IN_SECONDS;
  256. }
  257. if (w > 99)
  258. snprintf (buf, size, "%ldw%1ldd", w, d);
  259. else if (w)
  260. snprintf (buf, size, "%ldw%1ldd%02ldh", w, d, h);
  261. else if (d)
  262. snprintf (buf, size, "%1ldd%02ldh%02ldm", d, h, m);
  263. else if (h)
  264. snprintf (buf, size, "%ldh%02ldm%02lds", h, m, (long)t->tv_sec);
  265. else if (m)
  266. snprintf (buf, size, "%ldm%02lds", m, (long)t->tv_sec);
  267. else if (ms)
  268. snprintf (buf, size, "%ld.%03lds", (long)t->tv_sec, ms);
  269. else
  270. snprintf (buf, size, "%ld usecs", (long)t->tv_usec);
  271. return buf;
  272. }
  273. const char *
  274. ospf_timer_dump (struct thread *t, char *buf, size_t size)
  275. {
  276. struct timeval result;
  277. if (!t)
  278. return "inactive";
  279. result = tv_sub (t->u.sands, recent_relative_time());
  280. return ospf_timeval_dump (&result, buf, size);
  281. }
  282. #define OSPF_OPTION_STR_MAXLEN 24
  283. char *
  284. ospf_options_dump (u_char options)
  285. {
  286. static char buf[OSPF_OPTION_STR_MAXLEN];
  287. snprintf (buf, OSPF_OPTION_STR_MAXLEN, "*|%s|%s|%s|%s|%s|%s|%s",
  288. (options & OSPF_OPTION_O) ? "O" : "-",
  289. (options & OSPF_OPTION_DC) ? "DC" : "-",
  290. (options & OSPF_OPTION_EA) ? "EA" : "-",
  291. (options & OSPF_OPTION_NP) ? "N/P" : "-",
  292. (options & OSPF_OPTION_MC) ? "MC" : "-",
  293. (options & OSPF_OPTION_E) ? "E" : "-",
  294. (options & OSPF_OPTION_MT) ? "M/T" : "-");
  295. return buf;
  296. }
  297. static void
  298. ospf_packet_hello_dump (struct stream *s, u_int16_t length)
  299. {
  300. struct ospf_hello *hello;
  301. int i;
  302. hello = (struct ospf_hello *) STREAM_PNT (s);
  303. zlog_debug ("Hello");
  304. zlog_debug (" NetworkMask %s", inet_ntoa (hello->network_mask));
  305. zlog_debug (" HelloInterval %d", ntohs (hello->hello_interval));
  306. zlog_debug (" Options %d (%s)", hello->options,
  307. ospf_options_dump (hello->options));
  308. zlog_debug (" RtrPriority %d", hello->priority);
  309. zlog_debug (" RtrDeadInterval %ld", (u_long)ntohl (hello->dead_interval));
  310. zlog_debug (" DRouter %s", inet_ntoa (hello->d_router));
  311. zlog_debug (" BDRouter %s", inet_ntoa (hello->bd_router));
  312. length -= OSPF_HEADER_SIZE + OSPF_HELLO_MIN_SIZE;
  313. zlog_debug (" # Neighbors %d", length / 4);
  314. for (i = 0; length > 0; i++, length -= sizeof (struct in_addr))
  315. zlog_debug (" Neighbor %s", inet_ntoa (hello->neighbors[i]));
  316. }
  317. static char *
  318. ospf_dd_flags_dump (u_char flags, char *buf, size_t size)
  319. {
  320. memset (buf, 0, size);
  321. snprintf (buf, size, "%s|%s|%s",
  322. (flags & OSPF_DD_FLAG_I) ? "I" : "-",
  323. (flags & OSPF_DD_FLAG_M) ? "M" : "-",
  324. (flags & OSPF_DD_FLAG_MS) ? "MS" : "-");
  325. return buf;
  326. }
  327. void
  328. ospf_lsa_header_dump (struct lsa_header *lsah)
  329. {
  330. const char *lsah_type = LOOKUP (ospf_lsa_type_msg, lsah->type);
  331. zlog_debug (" LSA Header");
  332. zlog_debug (" LS age %d", ntohs (lsah->ls_age));
  333. zlog_debug (" Options %d (%s)", lsah->options,
  334. ospf_options_dump (lsah->options));
  335. zlog_debug (" LS type %d (%s)", lsah->type,
  336. (lsah->type ? lsah_type : "unknown type"));
  337. zlog_debug (" Link State ID %s", inet_ntoa (lsah->id));
  338. zlog_debug (" Advertising Router %s", inet_ntoa (lsah->adv_router));
  339. zlog_debug (" LS sequence number 0x%lx", (u_long)ntohl (lsah->ls_seqnum));
  340. zlog_debug (" LS checksum 0x%x", ntohs (lsah->checksum));
  341. zlog_debug (" length %d", ntohs (lsah->length));
  342. }
  343. static char *
  344. ospf_router_lsa_flags_dump (u_char flags, char *buf, size_t size)
  345. {
  346. memset (buf, 0, size);
  347. snprintf (buf, size, "%s|%s|%s",
  348. (flags & ROUTER_LSA_VIRTUAL) ? "V" : "-",
  349. (flags & ROUTER_LSA_EXTERNAL) ? "E" : "-",
  350. (flags & ROUTER_LSA_BORDER) ? "B" : "-");
  351. return buf;
  352. }
  353. static void
  354. ospf_router_lsa_dump (struct stream *s, u_int16_t length)
  355. {
  356. char buf[BUFSIZ];
  357. struct router_lsa *rl;
  358. int i, len;
  359. rl = (struct router_lsa *) STREAM_PNT (s);
  360. zlog_debug (" Router-LSA");
  361. zlog_debug (" flags %s",
  362. ospf_router_lsa_flags_dump (rl->flags, buf, BUFSIZ));
  363. zlog_debug (" # links %d", ntohs (rl->links));
  364. len = ntohs (rl->header.length) - OSPF_LSA_HEADER_SIZE - 4;
  365. for (i = 0; len > 0; i++)
  366. {
  367. zlog_debug (" Link ID %s", inet_ntoa (rl->link[i].link_id));
  368. zlog_debug (" Link Data %s", inet_ntoa (rl->link[i].link_data));
  369. zlog_debug (" Type %d", (u_char) rl->link[i].type);
  370. zlog_debug (" TOS %d", (u_char) rl->link[i].tos);
  371. zlog_debug (" metric %d", ntohs (rl->link[i].metric));
  372. len -= 12;
  373. }
  374. }
  375. static void
  376. ospf_network_lsa_dump (struct stream *s, u_int16_t length)
  377. {
  378. struct network_lsa *nl;
  379. int i, cnt;
  380. nl = (struct network_lsa *) STREAM_PNT (s);
  381. cnt = (ntohs (nl->header.length) - (OSPF_LSA_HEADER_SIZE + 4)) / 4;
  382. zlog_debug (" Network-LSA");
  383. /*
  384. zlog_debug ("LSA total size %d", ntohs (nl->header.length));
  385. zlog_debug ("Network-LSA size %d",
  386. ntohs (nl->header.length) - OSPF_LSA_HEADER_SIZE);
  387. */
  388. zlog_debug (" Network Mask %s", inet_ntoa (nl->mask));
  389. zlog_debug (" # Attached Routers %d", cnt);
  390. for (i = 0; i < cnt; i++)
  391. zlog_debug (" Attached Router %s", inet_ntoa (nl->routers[i]));
  392. }
  393. static void
  394. ospf_summary_lsa_dump (struct stream *s, u_int16_t length)
  395. {
  396. struct summary_lsa *sl;
  397. int size;
  398. int i;
  399. sl = (struct summary_lsa *) STREAM_PNT (s);
  400. zlog_debug (" Summary-LSA");
  401. zlog_debug (" Network Mask %s", inet_ntoa (sl->mask));
  402. size = ntohs (sl->header.length) - OSPF_LSA_HEADER_SIZE - 4;
  403. for (i = 0; size > 0; size -= 4, i++)
  404. zlog_debug (" TOS=%d metric %d", sl->tos,
  405. GET_METRIC (sl->metric));
  406. }
  407. static void
  408. ospf_as_external_lsa_dump (struct stream *s, u_int16_t length)
  409. {
  410. struct as_external_lsa *al;
  411. int size;
  412. int i;
  413. al = (struct as_external_lsa *) STREAM_PNT (s);
  414. zlog_debug (" %s", ospf_lsa_type_msg[al->header.type].str);
  415. zlog_debug (" Network Mask %s", inet_ntoa (al->mask));
  416. size = ntohs (al->header.length) - OSPF_LSA_HEADER_SIZE -4;
  417. for (i = 0; size > 0; size -= 12, i++)
  418. {
  419. zlog_debug (" bit %s TOS=%d metric %d",
  420. IS_EXTERNAL_METRIC (al->e[i].tos) ? "E" : "-",
  421. al->e[i].tos & 0x7f, GET_METRIC (al->e[i].metric));
  422. zlog_debug (" Forwarding address %s", inet_ntoa (al->e[i].fwd_addr));
  423. zlog_debug (" External Route Tag %u", al->e[i].route_tag);
  424. }
  425. }
  426. static void
  427. ospf_lsa_header_list_dump (struct stream *s, u_int16_t length)
  428. {
  429. struct lsa_header *lsa;
  430. zlog_debug (" # LSA Headers %d", length / OSPF_LSA_HEADER_SIZE);
  431. /* LSA Headers. */
  432. while (length > 0)
  433. {
  434. lsa = (struct lsa_header *) STREAM_PNT (s);
  435. ospf_lsa_header_dump (lsa);
  436. stream_forward_getp (s, OSPF_LSA_HEADER_SIZE);
  437. length -= OSPF_LSA_HEADER_SIZE;
  438. }
  439. }
  440. static void
  441. ospf_packet_db_desc_dump (struct stream *s, u_int16_t length)
  442. {
  443. struct ospf_db_desc *dd;
  444. char dd_flags[8];
  445. u_int32_t gp;
  446. gp = stream_get_getp (s);
  447. dd = (struct ospf_db_desc *) STREAM_PNT (s);
  448. zlog_debug ("Database Description");
  449. zlog_debug (" Interface MTU %d", ntohs (dd->mtu));
  450. zlog_debug (" Options %d (%s)", dd->options,
  451. ospf_options_dump (dd->options));
  452. zlog_debug (" Flags %d (%s)", dd->flags,
  453. ospf_dd_flags_dump (dd->flags, dd_flags, sizeof dd_flags));
  454. zlog_debug (" Sequence Number 0x%08lx", (u_long)ntohl (dd->dd_seqnum));
  455. length -= OSPF_HEADER_SIZE + OSPF_DB_DESC_MIN_SIZE;
  456. stream_forward_getp (s, OSPF_DB_DESC_MIN_SIZE);
  457. ospf_lsa_header_list_dump (s, length);
  458. stream_set_getp (s, gp);
  459. }
  460. static void
  461. ospf_packet_ls_req_dump (struct stream *s, u_int16_t length)
  462. {
  463. u_int32_t sp;
  464. u_int32_t ls_type;
  465. struct in_addr ls_id;
  466. struct in_addr adv_router;
  467. sp = stream_get_getp (s);
  468. length -= OSPF_HEADER_SIZE;
  469. zlog_debug ("Link State Request");
  470. zlog_debug (" # Requests %d", length / 12);
  471. for (; length > 0; length -= 12)
  472. {
  473. ls_type = stream_getl (s);
  474. ls_id.s_addr = stream_get_ipv4 (s);
  475. adv_router.s_addr = stream_get_ipv4 (s);
  476. zlog_debug (" LS type %d", ls_type);
  477. zlog_debug (" Link State ID %s", inet_ntoa (ls_id));
  478. zlog_debug (" Advertising Router %s",
  479. inet_ntoa (adv_router));
  480. }
  481. stream_set_getp (s, sp);
  482. }
  483. static void
  484. ospf_packet_ls_upd_dump (struct stream *s, u_int16_t length)
  485. {
  486. u_int32_t sp;
  487. struct lsa_header *lsa;
  488. int lsa_len;
  489. u_int32_t count;
  490. length -= OSPF_HEADER_SIZE;
  491. sp = stream_get_getp (s);
  492. count = stream_getl (s);
  493. length -= 4;
  494. zlog_debug ("Link State Update");
  495. zlog_debug (" # LSAs %d", count);
  496. while (length > 0 && count > 0)
  497. {
  498. if (length < OSPF_HEADER_SIZE || length % 4 != 0)
  499. {
  500. zlog_debug (" Remaining %d bytes; Incorrect length.", length);
  501. break;
  502. }
  503. lsa = (struct lsa_header *) STREAM_PNT (s);
  504. lsa_len = ntohs (lsa->length);
  505. ospf_lsa_header_dump (lsa);
  506. switch (lsa->type)
  507. {
  508. case OSPF_ROUTER_LSA:
  509. ospf_router_lsa_dump (s, length);
  510. break;
  511. case OSPF_NETWORK_LSA:
  512. ospf_network_lsa_dump (s, length);
  513. break;
  514. case OSPF_SUMMARY_LSA:
  515. case OSPF_ASBR_SUMMARY_LSA:
  516. ospf_summary_lsa_dump (s, length);
  517. break;
  518. case OSPF_AS_EXTERNAL_LSA:
  519. ospf_as_external_lsa_dump (s, length);
  520. break;
  521. case OSPF_AS_NSSA_LSA:
  522. ospf_as_external_lsa_dump (s, length);
  523. break;
  524. case OSPF_OPAQUE_LINK_LSA:
  525. case OSPF_OPAQUE_AREA_LSA:
  526. case OSPF_OPAQUE_AS_LSA:
  527. ospf_opaque_lsa_dump (s, length);
  528. break;
  529. default:
  530. break;
  531. }
  532. stream_forward_getp (s, lsa_len);
  533. length -= lsa_len;
  534. count--;
  535. }
  536. stream_set_getp (s, sp);
  537. }
  538. static void
  539. ospf_packet_ls_ack_dump (struct stream *s, u_int16_t length)
  540. {
  541. u_int32_t sp;
  542. length -= OSPF_HEADER_SIZE;
  543. sp = stream_get_getp (s);
  544. zlog_debug ("Link State Acknowledgment");
  545. ospf_lsa_header_list_dump (s, length);
  546. stream_set_getp (s, sp);
  547. }
  548. /* Expects header to be in host order */
  549. void
  550. ospf_ip_header_dump (struct ip *iph)
  551. {
  552. /* IP Header dump. */
  553. zlog_debug ("ip_v %d", iph->ip_v);
  554. zlog_debug ("ip_hl %d", iph->ip_hl);
  555. zlog_debug ("ip_tos %d", iph->ip_tos);
  556. zlog_debug ("ip_len %d", iph->ip_len);
  557. zlog_debug ("ip_id %u", (u_int32_t) iph->ip_id);
  558. zlog_debug ("ip_off %u", (u_int32_t) iph->ip_off);
  559. zlog_debug ("ip_ttl %d", iph->ip_ttl);
  560. zlog_debug ("ip_p %d", iph->ip_p);
  561. zlog_debug ("ip_sum 0x%x", (u_int32_t) iph->ip_sum);
  562. zlog_debug ("ip_src %s", inet_ntoa (iph->ip_src));
  563. zlog_debug ("ip_dst %s", inet_ntoa (iph->ip_dst));
  564. }
  565. static void
  566. ospf_header_dump (struct ospf_header *ospfh)
  567. {
  568. char buf[9];
  569. u_int16_t auth_type = ntohs (ospfh->auth_type);
  570. zlog_debug ("Header");
  571. zlog_debug (" Version %d", ospfh->version);
  572. zlog_debug (" Type %d (%s)", ospfh->type,
  573. LOOKUP (ospf_packet_type_str, ospfh->type));
  574. zlog_debug (" Packet Len %d", ntohs (ospfh->length));
  575. zlog_debug (" Router ID %s", inet_ntoa (ospfh->router_id));
  576. zlog_debug (" Area ID %s", inet_ntoa (ospfh->area_id));
  577. zlog_debug (" Checksum 0x%x", ntohs (ospfh->checksum));
  578. zlog_debug (" AuType %s", LOOKUP (ospf_auth_type_str, auth_type));
  579. switch (auth_type)
  580. {
  581. case OSPF_AUTH_NULL:
  582. break;
  583. case OSPF_AUTH_SIMPLE:
  584. memset (buf, 0, 9);
  585. strncpy (buf, (char *) ospfh->u.auth_data, 8);
  586. zlog_debug (" Simple Password %s", buf);
  587. break;
  588. case OSPF_AUTH_CRYPTOGRAPHIC:
  589. zlog_debug (" Cryptographic Authentication");
  590. zlog_debug (" Key ID %d", ospfh->u.crypt.key_id);
  591. zlog_debug (" Auth Data Len %d", ospfh->u.crypt.auth_data_len);
  592. zlog_debug (" Sequence number %ld",
  593. (u_long)ntohl (ospfh->u.crypt.crypt_seqnum));
  594. break;
  595. default:
  596. zlog_debug ("* This is not supported authentication type");
  597. break;
  598. }
  599. }
  600. void
  601. ospf_packet_dump (struct stream *s)
  602. {
  603. struct ospf_header *ospfh;
  604. unsigned long gp;
  605. /* Preserve pointer. */
  606. gp = stream_get_getp (s);
  607. /* OSPF Header dump. */
  608. ospfh = (struct ospf_header *) STREAM_PNT (s);
  609. /* Until detail flag is set, return. */
  610. if (!(term_debug_ospf_packet[ospfh->type - 1] & OSPF_DEBUG_DETAIL))
  611. return;
  612. /* Show OSPF header detail. */
  613. ospf_header_dump (ospfh);
  614. stream_forward_getp (s, OSPF_HEADER_SIZE);
  615. switch (ospfh->type)
  616. {
  617. case OSPF_MSG_HELLO:
  618. ospf_packet_hello_dump (s, ntohs (ospfh->length));
  619. break;
  620. case OSPF_MSG_DB_DESC:
  621. ospf_packet_db_desc_dump (s, ntohs (ospfh->length));
  622. break;
  623. case OSPF_MSG_LS_REQ:
  624. ospf_packet_ls_req_dump (s, ntohs (ospfh->length));
  625. break;
  626. case OSPF_MSG_LS_UPD:
  627. ospf_packet_ls_upd_dump (s, ntohs (ospfh->length));
  628. break;
  629. case OSPF_MSG_LS_ACK:
  630. ospf_packet_ls_ack_dump (s, ntohs (ospfh->length));
  631. break;
  632. default:
  633. break;
  634. }
  635. stream_set_getp (s, gp);
  636. }
  637. /*
  638. [no] debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all)
  639. [send|recv [detail]]
  640. */
  641. DEFUN (debug_ospf_packet,
  642. debug_ospf_packet_all_cmd,
  643. "debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all)",
  644. DEBUG_STR
  645. OSPF_STR
  646. "OSPF packets\n"
  647. "OSPF Hello\n"
  648. "OSPF Database Description\n"
  649. "OSPF Link State Request\n"
  650. "OSPF Link State Update\n"
  651. "OSPF Link State Acknowledgment\n"
  652. "OSPF all packets\n")
  653. {
  654. int type = 0;
  655. int flag = 0;
  656. int i;
  657. assert (argc > 0);
  658. /* Check packet type. */
  659. if (strncmp (argv[0], "h", 1) == 0)
  660. type = OSPF_DEBUG_HELLO;
  661. else if (strncmp (argv[0], "d", 1) == 0)
  662. type = OSPF_DEBUG_DB_DESC;
  663. else if (strncmp (argv[0], "ls-r", 4) == 0)
  664. type = OSPF_DEBUG_LS_REQ;
  665. else if (strncmp (argv[0], "ls-u", 4) == 0)
  666. type = OSPF_DEBUG_LS_UPD;
  667. else if (strncmp (argv[0], "ls-a", 4) == 0)
  668. type = OSPF_DEBUG_LS_ACK;
  669. else if (strncmp (argv[0], "a", 1) == 0)
  670. type = OSPF_DEBUG_ALL;
  671. /* Default, both send and recv. */
  672. if (argc == 1)
  673. flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV;
  674. /* send or recv. */
  675. if (argc >= 2)
  676. {
  677. if (strncmp (argv[1], "s", 1) == 0)
  678. flag = OSPF_DEBUG_SEND;
  679. else if (strncmp (argv[1], "r", 1) == 0)
  680. flag = OSPF_DEBUG_RECV;
  681. else if (strncmp (argv[1], "d", 1) == 0)
  682. flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV | OSPF_DEBUG_DETAIL;
  683. }
  684. /* detail. */
  685. if (argc == 3)
  686. if (strncmp (argv[2], "d", 1) == 0)
  687. flag |= OSPF_DEBUG_DETAIL;
  688. for (i = 0; i < 5; i++)
  689. if (type & (0x01 << i))
  690. {
  691. if (vty->node == CONFIG_NODE)
  692. DEBUG_PACKET_ON (i, flag);
  693. else
  694. TERM_DEBUG_PACKET_ON (i, flag);
  695. }
  696. return CMD_SUCCESS;
  697. }
  698. ALIAS (debug_ospf_packet,
  699. debug_ospf_packet_send_recv_cmd,
  700. "debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv|detail)",
  701. "Debugging functions\n"
  702. "OSPF information\n"
  703. "OSPF packets\n"
  704. "OSPF Hello\n"
  705. "OSPF Database Description\n"
  706. "OSPF Link State Request\n"
  707. "OSPF Link State Update\n"
  708. "OSPF Link State Acknowledgment\n"
  709. "OSPF all packets\n"
  710. "Packet sent\n"
  711. "Packet received\n"
  712. "Detail information\n")
  713. ALIAS (debug_ospf_packet,
  714. debug_ospf_packet_send_recv_detail_cmd,
  715. "debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv) (detail|)",
  716. "Debugging functions\n"
  717. "OSPF information\n"
  718. "OSPF packets\n"
  719. "OSPF Hello\n"
  720. "OSPF Database Description\n"
  721. "OSPF Link State Request\n"
  722. "OSPF Link State Update\n"
  723. "OSPF Link State Acknowledgment\n"
  724. "OSPF all packets\n"
  725. "Packet sent\n"
  726. "Packet received\n"
  727. "Detail Information\n")
  728. DEFUN (no_debug_ospf_packet,
  729. no_debug_ospf_packet_all_cmd,
  730. "no debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all)",
  731. NO_STR
  732. DEBUG_STR
  733. OSPF_STR
  734. "OSPF packets\n"
  735. "OSPF Hello\n"
  736. "OSPF Database Description\n"
  737. "OSPF Link State Request\n"
  738. "OSPF Link State Update\n"
  739. "OSPF Link State Acknowledgment\n"
  740. "OSPF all packets\n")
  741. {
  742. int type = 0;
  743. int flag = 0;
  744. int i;
  745. assert (argc > 0);
  746. /* Check packet type. */
  747. if (strncmp (argv[0], "h", 1) == 0)
  748. type = OSPF_DEBUG_HELLO;
  749. else if (strncmp (argv[0], "d", 1) == 0)
  750. type = OSPF_DEBUG_DB_DESC;
  751. else if (strncmp (argv[0], "ls-r", 4) == 0)
  752. type = OSPF_DEBUG_LS_REQ;
  753. else if (strncmp (argv[0], "ls-u", 4) == 0)
  754. type = OSPF_DEBUG_LS_UPD;
  755. else if (strncmp (argv[0], "ls-a", 4) == 0)
  756. type = OSPF_DEBUG_LS_ACK;
  757. else if (strncmp (argv[0], "a", 1) == 0)
  758. type = OSPF_DEBUG_ALL;
  759. /* Default, both send and recv. */
  760. if (argc == 1)
  761. flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV | OSPF_DEBUG_DETAIL ;
  762. /* send or recv. */
  763. if (argc == 2)
  764. {
  765. if (strncmp (argv[1], "s", 1) == 0)
  766. flag = OSPF_DEBUG_SEND | OSPF_DEBUG_DETAIL;
  767. else if (strncmp (argv[1], "r", 1) == 0)
  768. flag = OSPF_DEBUG_RECV | OSPF_DEBUG_DETAIL;
  769. else if (strncmp (argv[1], "d", 1) == 0)
  770. flag = OSPF_DEBUG_SEND | OSPF_DEBUG_RECV | OSPF_DEBUG_DETAIL;
  771. }
  772. /* detail. */
  773. if (argc == 3)
  774. if (strncmp (argv[2], "d", 1) == 0)
  775. flag = OSPF_DEBUG_DETAIL;
  776. for (i = 0; i < 5; i++)
  777. if (type & (0x01 << i))
  778. {
  779. if (vty->node == CONFIG_NODE)
  780. DEBUG_PACKET_OFF (i, flag);
  781. else
  782. TERM_DEBUG_PACKET_OFF (i, flag);
  783. }
  784. #ifdef DEBUG
  785. /*
  786. for (i = 0; i < 5; i++)
  787. zlog_debug ("flag[%d] = %d", i, ospf_debug_packet[i]);
  788. */
  789. #endif /* DEBUG */
  790. return CMD_SUCCESS;
  791. }
  792. ALIAS (no_debug_ospf_packet,
  793. no_debug_ospf_packet_send_recv_cmd,
  794. "no debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv|detail)",
  795. NO_STR
  796. "Debugging functions\n"
  797. "OSPF information\n"
  798. "OSPF packets\n"
  799. "OSPF Hello\n"
  800. "OSPF Database Description\n"
  801. "OSPF Link State Request\n"
  802. "OSPF Link State Update\n"
  803. "OSPF Link State Acknowledgment\n"
  804. "OSPF all packets\n"
  805. "Packet sent\n"
  806. "Packet received\n"
  807. "Detail Information\n")
  808. ALIAS (no_debug_ospf_packet,
  809. no_debug_ospf_packet_send_recv_detail_cmd,
  810. "no debug ospf packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv) (detail|)",
  811. NO_STR
  812. "Debugging functions\n"
  813. "OSPF information\n"
  814. "OSPF packets\n"
  815. "OSPF Hello\n"
  816. "OSPF Database Description\n"
  817. "OSPF Link State Request\n"
  818. "OSPF Link State Update\n"
  819. "OSPF Link State Acknowledgment\n"
  820. "OSPF all packets\n"
  821. "Packet sent\n"
  822. "Packet received\n"
  823. "Detail Information\n")
  824. DEFUN (debug_ospf_ism,
  825. debug_ospf_ism_cmd,
  826. "debug ospf ism",
  827. DEBUG_STR
  828. OSPF_STR
  829. "OSPF Interface State Machine\n")
  830. {
  831. if (vty->node == CONFIG_NODE)
  832. {
  833. if (argc == 0)
  834. DEBUG_ON (ism, ISM);
  835. else if (argc == 1)
  836. {
  837. if (strncmp (argv[0], "s", 1) == 0)
  838. DEBUG_ON (ism, ISM_STATUS);
  839. else if (strncmp (argv[0], "e", 1) == 0)
  840. DEBUG_ON (ism, ISM_EVENTS);
  841. else if (strncmp (argv[0], "t", 1) == 0)
  842. DEBUG_ON (ism, ISM_TIMERS);
  843. }
  844. return CMD_SUCCESS;
  845. }
  846. /* ENABLE_NODE. */
  847. if (argc == 0)
  848. TERM_DEBUG_ON (ism, ISM);
  849. else if (argc == 1)
  850. {
  851. if (strncmp (argv[0], "s", 1) == 0)
  852. TERM_DEBUG_ON (ism, ISM_STATUS);
  853. else if (strncmp (argv[0], "e", 1) == 0)
  854. TERM_DEBUG_ON (ism, ISM_EVENTS);
  855. else if (strncmp (argv[0], "t", 1) == 0)
  856. TERM_DEBUG_ON (ism, ISM_TIMERS);
  857. }
  858. return CMD_SUCCESS;
  859. }
  860. ALIAS (debug_ospf_ism,
  861. debug_ospf_ism_sub_cmd,
  862. "debug ospf ism (status|events|timers)",
  863. DEBUG_STR
  864. OSPF_STR
  865. "OSPF Interface State Machine\n"
  866. "ISM Status Information\n"
  867. "ISM Event Information\n"
  868. "ISM TImer Information\n")
  869. DEFUN (no_debug_ospf_ism,
  870. no_debug_ospf_ism_cmd,
  871. "no debug ospf ism",
  872. NO_STR
  873. DEBUG_STR
  874. OSPF_STR
  875. "OSPF Interface State Machine")
  876. {
  877. if (vty->node == CONFIG_NODE)
  878. {
  879. if (argc == 0)
  880. DEBUG_OFF (ism, ISM);
  881. else if (argc == 1)
  882. {
  883. if (strncmp (argv[0], "s", 1) == 0)
  884. DEBUG_OFF (ism, ISM_STATUS);
  885. else if (strncmp (argv[0], "e", 1) == 0)
  886. DEBUG_OFF (ism, ISM_EVENTS);
  887. else if (strncmp (argv[0], "t", 1) == 0)
  888. DEBUG_OFF (ism, ISM_TIMERS);
  889. }
  890. return CMD_SUCCESS;
  891. }
  892. /* ENABLE_NODE. */
  893. if (argc == 0)
  894. TERM_DEBUG_OFF (ism, ISM);
  895. else if (argc == 1)
  896. {
  897. if (strncmp (argv[0], "s", 1) == 0)
  898. TERM_DEBUG_OFF (ism, ISM_STATUS);
  899. else if (strncmp (argv[0], "e", 1) == 0)
  900. TERM_DEBUG_OFF (ism, ISM_EVENTS);
  901. else if (strncmp (argv[0], "t", 1) == 0)
  902. TERM_DEBUG_OFF (ism, ISM_TIMERS);
  903. }
  904. return CMD_SUCCESS;
  905. }
  906. ALIAS (no_debug_ospf_ism,
  907. no_debug_ospf_ism_sub_cmd,
  908. "no debug ospf ism (status|events|timers)",
  909. NO_STR
  910. "Debugging functions\n"
  911. "OSPF information\n"
  912. "OSPF Interface State Machine\n"
  913. "ISM Status Information\n"
  914. "ISM Event Information\n"
  915. "ISM Timer Information\n")
  916. DEFUN (debug_ospf_nsm,
  917. debug_ospf_nsm_cmd,
  918. "debug ospf nsm",
  919. DEBUG_STR
  920. OSPF_STR
  921. "OSPF Neighbor State Machine\n")
  922. {
  923. if (vty->node == CONFIG_NODE)
  924. {
  925. if (argc == 0)
  926. DEBUG_ON (nsm, NSM);
  927. else if (argc == 1)
  928. {
  929. if (strncmp (argv[0], "s", 1) == 0)
  930. DEBUG_ON (nsm, NSM_STATUS);
  931. else if (strncmp (argv[0], "e", 1) == 0)
  932. DEBUG_ON (nsm, NSM_EVENTS);
  933. else if (strncmp (argv[0], "t", 1) == 0)
  934. DEBUG_ON (nsm, NSM_TIMERS);
  935. }
  936. return CMD_SUCCESS;
  937. }
  938. /* ENABLE_NODE. */
  939. if (argc == 0)
  940. TERM_DEBUG_ON (nsm, NSM);
  941. else if (argc == 1)
  942. {
  943. if (strncmp (argv[0], "s", 1) == 0)
  944. TERM_DEBUG_ON (nsm, NSM_STATUS);
  945. else if (strncmp (argv[0], "e", 1) == 0)
  946. TERM_DEBUG_ON (nsm, NSM_EVENTS);
  947. else if (strncmp (argv[0], "t", 1) == 0)
  948. TERM_DEBUG_ON (nsm, NSM_TIMERS);
  949. }
  950. return CMD_SUCCESS;
  951. }
  952. ALIAS (debug_ospf_nsm,
  953. debug_ospf_nsm_sub_cmd,
  954. "debug ospf nsm (status|events|timers)",
  955. DEBUG_STR
  956. OSPF_STR
  957. "OSPF Neighbor State Machine\n"
  958. "NSM Status Information\n"
  959. "NSM Event Information\n"
  960. "NSM Timer Information\n")
  961. DEFUN (no_debug_ospf_nsm,
  962. no_debug_ospf_nsm_cmd,
  963. "no debug ospf nsm",
  964. NO_STR
  965. DEBUG_STR
  966. OSPF_STR
  967. "OSPF Neighbor State Machine")
  968. {
  969. if (vty->node == CONFIG_NODE)
  970. {
  971. if (argc == 0)
  972. DEBUG_OFF (nsm, NSM);
  973. else if (argc == 1)
  974. {
  975. if (strncmp (argv[0], "s", 1) == 0)
  976. DEBUG_OFF (nsm, NSM_STATUS);
  977. else if (strncmp (argv[0], "e", 1) == 0)
  978. DEBUG_OFF (nsm, NSM_EVENTS);
  979. else if (strncmp (argv[0], "t", 1) == 0)
  980. DEBUG_OFF (nsm, NSM_TIMERS);
  981. }
  982. return CMD_SUCCESS;
  983. }
  984. /* ENABLE_NODE. */
  985. if (argc == 0)
  986. TERM_DEBUG_OFF (nsm, NSM);
  987. else if (argc == 1)
  988. {
  989. if (strncmp (argv[0], "s", 1) == 0)
  990. TERM_DEBUG_OFF (nsm, NSM_STATUS);
  991. else if (strncmp (argv[0], "e", 1) == 0)
  992. TERM_DEBUG_OFF (nsm, NSM_EVENTS);
  993. else if (strncmp (argv[0], "t", 1) == 0)
  994. TERM_DEBUG_OFF (nsm, NSM_TIMERS);
  995. }
  996. return CMD_SUCCESS;
  997. }
  998. ALIAS (no_debug_ospf_nsm,
  999. no_debug_ospf_nsm_sub_cmd,
  1000. "no debug ospf nsm (status|events|timers)",
  1001. NO_STR
  1002. "Debugging functions\n"
  1003. "OSPF information\n"
  1004. "OSPF Interface State Machine\n"
  1005. "NSM Status Information\n"
  1006. "NSM Event Information\n"
  1007. "NSM Timer Information\n")
  1008. DEFUN (debug_ospf_lsa,
  1009. debug_ospf_lsa_cmd,
  1010. "debug ospf lsa",
  1011. DEBUG_STR
  1012. OSPF_STR
  1013. "OSPF Link State Advertisement\n")
  1014. {
  1015. if (vty->node == CONFIG_NODE)
  1016. {
  1017. if (argc == 0)
  1018. DEBUG_ON (lsa, LSA);
  1019. else if (argc == 1)
  1020. {
  1021. if (strncmp (argv[0], "g", 1) == 0)
  1022. DEBUG_ON (lsa, LSA_GENERATE);
  1023. else if (strncmp (argv[0], "f", 1) == 0)
  1024. DEBUG_ON (lsa, LSA_FLOODING);
  1025. else if (strncmp (argv[0], "i", 1) == 0)
  1026. DEBUG_ON (lsa, LSA_INSTALL);
  1027. else if (strncmp (argv[0], "r", 1) == 0)
  1028. DEBUG_ON (lsa, LSA_REFRESH);
  1029. }
  1030. return CMD_SUCCESS;
  1031. }
  1032. /* ENABLE_NODE. */
  1033. if (argc == 0)
  1034. TERM_DEBUG_ON (lsa, LSA);
  1035. else if (argc == 1)
  1036. {
  1037. if (strncmp (argv[0], "g", 1) == 0)
  1038. TERM_DEBUG_ON (lsa, LSA_GENERATE);
  1039. else if (strncmp (argv[0], "f", 1) == 0)
  1040. TERM_DEBUG_ON (lsa, LSA_FLOODING);
  1041. else if (strncmp (argv[0], "i", 1) == 0)
  1042. TERM_DEBUG_ON (lsa, LSA_INSTALL);
  1043. else if (strncmp (argv[0], "r", 1) == 0)
  1044. TERM_DEBUG_ON (lsa, LSA_REFRESH);
  1045. }
  1046. return CMD_SUCCESS;
  1047. }
  1048. ALIAS (debug_ospf_lsa,
  1049. debug_ospf_lsa_sub_cmd,
  1050. "debug ospf lsa (generate|flooding|install|refresh)",
  1051. DEBUG_STR
  1052. OSPF_STR
  1053. "OSPF Link State Advertisement\n"
  1054. "LSA Generation\n"
  1055. "LSA Flooding\n"
  1056. "LSA Install/Delete\n"
  1057. "LSA Refresh\n")
  1058. DEFUN (no_debug_ospf_lsa,
  1059. no_debug_ospf_lsa_cmd,
  1060. "no debug ospf lsa",
  1061. NO_STR
  1062. DEBUG_STR
  1063. OSPF_STR
  1064. "OSPF Link State Advertisement\n")
  1065. {
  1066. if (vty->node == CONFIG_NODE)
  1067. {
  1068. if (argc == 0)
  1069. DEBUG_OFF (lsa, LSA);
  1070. else if (argc == 1)
  1071. {
  1072. if (strncmp (argv[0], "g", 1) == 0)
  1073. DEBUG_OFF (lsa, LSA_GENERATE);
  1074. else if (strncmp (argv[0], "f", 1) == 0)
  1075. DEBUG_OFF (lsa, LSA_FLOODING);
  1076. else if (strncmp (argv[0], "i", 1) == 0)
  1077. DEBUG_OFF (lsa, LSA_INSTALL);
  1078. else if (strncmp (argv[0], "r", 1) == 0)
  1079. DEBUG_OFF (lsa, LSA_REFRESH);
  1080. }
  1081. return CMD_SUCCESS;
  1082. }
  1083. /* ENABLE_NODE. */
  1084. if (argc == 0)
  1085. TERM_DEBUG_OFF (lsa, LSA);
  1086. else if (argc == 1)
  1087. {
  1088. if (strncmp (argv[0], "g", 1) == 0)
  1089. TERM_DEBUG_OFF (lsa, LSA_GENERATE);
  1090. else if (strncmp (argv[0], "f", 1) == 0)
  1091. TERM_DEBUG_OFF (lsa, LSA_FLOODING);
  1092. else if (strncmp (argv[0], "i", 1) == 0)
  1093. TERM_DEBUG_OFF (lsa, LSA_INSTALL);
  1094. else if (strncmp (argv[0], "r", 1) == 0)
  1095. TERM_DEBUG_OFF (lsa, LSA_REFRESH);
  1096. }
  1097. return CMD_SUCCESS;
  1098. }
  1099. ALIAS (no_debug_ospf_lsa,
  1100. no_debug_ospf_lsa_sub_cmd,
  1101. "no debug ospf lsa (generate|flooding|install|refresh)",
  1102. NO_STR
  1103. DEBUG_STR
  1104. OSPF_STR
  1105. "OSPF Link State Advertisement\n"
  1106. "LSA Generation\n"
  1107. "LSA Flooding\n"
  1108. "LSA Install/Delete\n"
  1109. "LSA Refres\n")
  1110. DEFUN (debug_ospf_zebra,
  1111. debug_ospf_zebra_cmd,
  1112. "debug ospf zebra",
  1113. DEBUG_STR
  1114. OSPF_STR
  1115. "OSPF Zebra information\n")
  1116. {
  1117. if (vty->node == CONFIG_NODE)
  1118. {
  1119. if (argc == 0)
  1120. DEBUG_ON (zebra, ZEBRA);
  1121. else if (argc == 1)
  1122. {
  1123. if (strncmp (argv[0], "i", 1) == 0)
  1124. DEBUG_ON (zebra, ZEBRA_INTERFACE);
  1125. else if (strncmp (argv[0], "r", 1) == 0)
  1126. DEBUG_ON (zebra, ZEBRA_REDISTRIBUTE);
  1127. }
  1128. return CMD_SUCCESS;
  1129. }
  1130. /* ENABLE_NODE. */
  1131. if (argc == 0)
  1132. TERM_DEBUG_ON (zebra, ZEBRA);
  1133. else if (argc == 1)
  1134. {
  1135. if (strncmp (argv[0], "i", 1) == 0)
  1136. TERM_DEBUG_ON (zebra, ZEBRA_INTERFACE);
  1137. else if (strncmp (argv[0], "r", 1) == 0)
  1138. TERM_DEBUG_ON (zebra, ZEBRA_REDISTRIBUTE);
  1139. }
  1140. return CMD_SUCCESS;
  1141. }
  1142. ALIAS (debug_ospf_zebra,
  1143. debug_ospf_zebra_sub_cmd,
  1144. "debug ospf zebra (interface|redistribute)",
  1145. DEBUG_STR
  1146. OSPF_STR
  1147. "OSPF Zebra information\n"
  1148. "Zebra interface\n"
  1149. "Zebra redistribute\n")
  1150. DEFUN (no_debug_ospf_zebra,
  1151. no_debug_ospf_zebra_cmd,
  1152. "no debug ospf zebra",
  1153. NO_STR
  1154. DEBUG_STR
  1155. OSPF_STR
  1156. "OSPF Zebra information\n")
  1157. {
  1158. if (vty->node == CONFIG_NODE)
  1159. {
  1160. if (argc == 0)
  1161. DEBUG_OFF (zebra, ZEBRA);
  1162. else if (argc == 1)
  1163. {
  1164. if (strncmp (argv[0], "i", 1) == 0)
  1165. DEBUG_OFF (zebra, ZEBRA_INTERFACE);
  1166. else if (strncmp (argv[0], "r", 1) == 0)
  1167. DEBUG_OFF (zebra, ZEBRA_REDISTRIBUTE);
  1168. }
  1169. return CMD_SUCCESS;
  1170. }
  1171. /* ENABLE_NODE. */
  1172. if (argc == 0)
  1173. TERM_DEBUG_OFF (zebra, ZEBRA);
  1174. else if (argc == 1)
  1175. {
  1176. if (strncmp (argv[0], "i", 1) == 0)
  1177. TERM_DEBUG_OFF (zebra, ZEBRA_INTERFACE);
  1178. else if (strncmp (argv[0], "r", 1) == 0)
  1179. TERM_DEBUG_OFF (zebra, ZEBRA_REDISTRIBUTE);
  1180. }
  1181. return CMD_SUCCESS;
  1182. }
  1183. ALIAS (no_debug_ospf_zebra,
  1184. no_debug_ospf_zebra_sub_cmd,
  1185. "no debug ospf zebra (interface|redistribute)",
  1186. NO_STR
  1187. DEBUG_STR
  1188. OSPF_STR
  1189. "OSPF Zebra information\n"
  1190. "Zebra interface\n"
  1191. "Zebra redistribute\n")
  1192. DEFUN (debug_ospf_event,
  1193. debug_ospf_event_cmd,
  1194. "debug ospf event",
  1195. DEBUG_STR
  1196. OSPF_STR
  1197. "OSPF event information\n")
  1198. {
  1199. if (vty->node == CONFIG_NODE)
  1200. CONF_DEBUG_ON (event, EVENT);
  1201. TERM_DEBUG_ON (event, EVENT);
  1202. return CMD_SUCCESS;
  1203. }
  1204. DEFUN (no_debug_ospf_event,
  1205. no_debug_ospf_event_cmd,
  1206. "no debug ospf event",
  1207. NO_STR
  1208. DEBUG_STR
  1209. OSPF_STR
  1210. "OSPF event information\n")
  1211. {
  1212. if (vty->node == CONFIG_NODE)
  1213. CONF_DEBUG_OFF (event, EVENT);
  1214. TERM_DEBUG_OFF (event, EVENT);
  1215. return CMD_SUCCESS;
  1216. }
  1217. DEFUN (debug_ospf_nssa,
  1218. debug_ospf_nssa_cmd,
  1219. "debug ospf nssa",
  1220. DEBUG_STR
  1221. OSPF_STR
  1222. "OSPF nssa information\n")
  1223. {
  1224. if (vty->node == CONFIG_NODE)
  1225. CONF_DEBUG_ON (nssa, NSSA);
  1226. TERM_DEBUG_ON (nssa, NSSA);
  1227. return CMD_SUCCESS;
  1228. }
  1229. DEFUN (no_debug_ospf_nssa,
  1230. no_debug_ospf_nssa_cmd,
  1231. "no debug ospf nssa",
  1232. NO_STR
  1233. DEBUG_STR
  1234. OSPF_STR
  1235. "OSPF nssa information\n")
  1236. {
  1237. if (vty->node == CONFIG_NODE)
  1238. CONF_DEBUG_OFF (nssa, NSSA);
  1239. TERM_DEBUG_OFF (nssa, NSSA);
  1240. return CMD_SUCCESS;
  1241. }
  1242. DEFUN (debug_ospf_te,
  1243. debug_ospf_te_cmd,
  1244. "debug ospf te",
  1245. DEBUG_STR
  1246. OSPF_STR
  1247. "OSPF-TE information\n")
  1248. {
  1249. if (vty->node == CONFIG_NODE)
  1250. CONF_DEBUG_ON (te, TE);
  1251. TERM_DEBUG_ON (te, TE);
  1252. return CMD_SUCCESS;
  1253. }
  1254. DEFUN (no_debug_ospf_te,
  1255. no_debug_ospf_te_cmd,
  1256. "no debug ospf te",
  1257. NO_STR
  1258. DEBUG_STR
  1259. OSPF_STR
  1260. "OSPF-TE information\n")
  1261. {
  1262. if (vty->node == CONFIG_NODE)
  1263. CONF_DEBUG_OFF (te, TE);
  1264. TERM_DEBUG_OFF (te, TE);
  1265. return CMD_SUCCESS;
  1266. }
  1267. DEFUN (show_debugging_ospf,
  1268. show_debugging_ospf_cmd,
  1269. "show debugging ospf",
  1270. SHOW_STR
  1271. DEBUG_STR
  1272. OSPF_STR)
  1273. {
  1274. int i;
  1275. vty_out (vty, "OSPF debugging status:%s", VTY_NEWLINE);
  1276. /* Show debug status for events. */
  1277. if (IS_DEBUG_OSPF(event,EVENT))
  1278. vty_out (vty, " OSPF event debugging is on%s", VTY_NEWLINE);
  1279. /* Show debug status for ISM. */
  1280. if (IS_DEBUG_OSPF (ism, ISM) == OSPF_DEBUG_ISM)
  1281. vty_out (vty, " OSPF ISM debugging is on%s", VTY_NEWLINE);
  1282. else
  1283. {
  1284. if (IS_DEBUG_OSPF (ism, ISM_STATUS))
  1285. vty_out (vty, " OSPF ISM status debugging is on%s", VTY_NEWLINE);
  1286. if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
  1287. vty_out (vty, " OSPF ISM event debugging is on%s", VTY_NEWLINE);
  1288. if (IS_DEBUG_OSPF (ism, ISM_TIMERS))
  1289. vty_out (vty, " OSPF ISM timer debugging is on%s", VTY_NEWLINE);
  1290. }
  1291. /* Show debug status for NSM. */
  1292. if (IS_DEBUG_OSPF (nsm, NSM) == OSPF_DEBUG_NSM)
  1293. vty_out (vty, " OSPF NSM debugging is on%s", VTY_NEWLINE);
  1294. else
  1295. {
  1296. if (IS_DEBUG_OSPF (nsm, NSM_STATUS))
  1297. vty_out (vty, " OSPF NSM status debugging is on%s", VTY_NEWLINE);
  1298. if (IS_DEBUG_OSPF (nsm, NSM_EVENTS))
  1299. vty_out (vty, " OSPF NSM event debugging is on%s", VTY_NEWLINE);
  1300. if (IS_DEBUG_OSPF (nsm, NSM_TIMERS))
  1301. vty_out (vty, " OSPF NSM timer debugging is on%s", VTY_NEWLINE);
  1302. }
  1303. /* Show debug status for OSPF Packets. */
  1304. for (i = 0; i < 5; i++)
  1305. if (IS_DEBUG_OSPF_PACKET (i, SEND) && IS_DEBUG_OSPF_PACKET (i, RECV))
  1306. {
  1307. vty_out (vty, " OSPF packet %s%s debugging is on%s",
  1308. LOOKUP (ospf_packet_type_str, i + 1),
  1309. IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
  1310. VTY_NEWLINE);
  1311. }
  1312. else
  1313. {
  1314. if (IS_DEBUG_OSPF_PACKET (i, SEND))
  1315. vty_out (vty, " OSPF packet %s send%s debugging is on%s",
  1316. LOOKUP (ospf_packet_type_str, i + 1),
  1317. IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
  1318. VTY_NEWLINE);
  1319. if (IS_DEBUG_OSPF_PACKET (i, RECV))
  1320. vty_out (vty, " OSPF packet %s receive%s debugging is on%s",
  1321. LOOKUP (ospf_packet_type_str, i + 1),
  1322. IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
  1323. VTY_NEWLINE);
  1324. }
  1325. /* Show debug status for OSPF LSAs. */
  1326. if (IS_DEBUG_OSPF (lsa, LSA) == OSPF_DEBUG_LSA)
  1327. vty_out (vty, " OSPF LSA debugging is on%s", VTY_NEWLINE);
  1328. else
  1329. {
  1330. if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
  1331. vty_out (vty, " OSPF LSA generation debugging is on%s", VTY_NEWLINE);
  1332. if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
  1333. vty_out (vty, " OSPF LSA flooding debugging is on%s", VTY_NEWLINE);
  1334. if (IS_DEBUG_OSPF (lsa, LSA_INSTALL))
  1335. vty_out (vty, " OSPF LSA install debugging is on%s", VTY_NEWLINE);
  1336. if (IS_DEBUG_OSPF (lsa, LSA_REFRESH))
  1337. vty_out (vty, " OSPF LSA refresh debugging is on%s", VTY_NEWLINE);
  1338. }
  1339. /* Show debug status for Zebra. */
  1340. if (IS_DEBUG_OSPF (zebra, ZEBRA) == OSPF_DEBUG_ZEBRA)
  1341. vty_out (vty, " OSPF Zebra debugging is on%s", VTY_NEWLINE);
  1342. else
  1343. {
  1344. if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
  1345. vty_out (vty, " OSPF Zebra interface debugging is on%s", VTY_NEWLINE);
  1346. if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
  1347. vty_out (vty, " OSPF Zebra redistribute debugging is on%s", VTY_NEWLINE);
  1348. }
  1349. /* Show debug status for NSSA. */
  1350. if (IS_DEBUG_OSPF (nssa, NSSA) == OSPF_DEBUG_NSSA)
  1351. vty_out (vty, " OSPF NSSA debugging is on%s", VTY_NEWLINE);
  1352. return CMD_SUCCESS;
  1353. }
  1354. /* Debug node. */
  1355. static struct cmd_node debug_node =
  1356. {
  1357. DEBUG_NODE,
  1358. "",
  1359. 1 /* VTYSH */
  1360. };
  1361. static int
  1362. config_write_debug (struct vty *vty)
  1363. {
  1364. int write = 0;
  1365. int i, r;
  1366. const char *type_str[] = {"hello", "dd", "ls-request", "ls-update", "ls-ack"};
  1367. const char *detail_str[] = {"", " send", " recv", "", " detail",
  1368. " send detail", " recv detail", " detail"};
  1369. /* debug ospf ism (status|events|timers). */
  1370. if (IS_CONF_DEBUG_OSPF (ism, ISM) == OSPF_DEBUG_ISM)
  1371. vty_out (vty, "debug ospf ism%s", VTY_NEWLINE);
  1372. else
  1373. {
  1374. if (IS_CONF_DEBUG_OSPF (ism, ISM_STATUS))
  1375. vty_out (vty, "debug ospf ism status%s", VTY_NEWLINE);
  1376. if (IS_CONF_DEBUG_OSPF (ism, ISM_EVENTS))
  1377. vty_out (vty, "debug ospf ism event%s", VTY_NEWLINE);
  1378. if (IS_CONF_DEBUG_OSPF (ism, ISM_TIMERS))
  1379. vty_out (vty, "debug ospf ism timer%s", VTY_NEWLINE);
  1380. }
  1381. /* debug ospf nsm (status|events|timers). */
  1382. if (IS_CONF_DEBUG_OSPF (nsm, NSM) == OSPF_DEBUG_NSM)
  1383. vty_out (vty, "debug ospf nsm%s", VTY_NEWLINE);
  1384. else
  1385. {
  1386. if (IS_CONF_DEBUG_OSPF (nsm, NSM_STATUS))
  1387. vty_out (vty, "debug ospf nsm status%s", VTY_NEWLINE);
  1388. if (IS_CONF_DEBUG_OSPF (nsm, NSM_EVENTS))
  1389. vty_out (vty, "debug ospf nsm event%s", VTY_NEWLINE);
  1390. if (IS_CONF_DEBUG_OSPF (nsm, NSM_TIMERS))
  1391. vty_out (vty, "debug ospf nsm timer%s", VTY_NEWLINE);
  1392. }
  1393. /* debug ospf lsa (generate|flooding|install|refresh). */
  1394. if (IS_CONF_DEBUG_OSPF (lsa, LSA) == OSPF_DEBUG_LSA)
  1395. vty_out (vty, "debug ospf lsa%s", VTY_NEWLINE);
  1396. else
  1397. {
  1398. if (IS_CONF_DEBUG_OSPF (lsa, LSA_GENERATE))
  1399. vty_out (vty, "debug ospf lsa generate%s", VTY_NEWLINE);
  1400. if (IS_CONF_DEBUG_OSPF (lsa, LSA_FLOODING))
  1401. vty_out (vty, "debug ospf lsa flooding%s", VTY_NEWLINE);
  1402. if (IS_CONF_DEBUG_OSPF (lsa, LSA_INSTALL))
  1403. vty_out (vty, "debug ospf lsa install%s", VTY_NEWLINE);
  1404. if (IS_CONF_DEBUG_OSPF (lsa, LSA_REFRESH))
  1405. vty_out (vty, "debug ospf lsa refresh%s", VTY_NEWLINE);
  1406. write = 1;
  1407. }
  1408. /* debug ospf zebra (interface|redistribute). */
  1409. if (IS_CONF_DEBUG_OSPF (zebra, ZEBRA) == OSPF_DEBUG_ZEBRA)
  1410. vty_out (vty, "debug ospf zebra%s", VTY_NEWLINE);
  1411. else
  1412. {
  1413. if (IS_CONF_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
  1414. vty_out (vty, "debug ospf zebra interface%s", VTY_NEWLINE);
  1415. if (IS_CONF_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
  1416. vty_out (vty, "debug ospf zebra redistribute%s", VTY_NEWLINE);
  1417. write = 1;
  1418. }
  1419. /* debug ospf event. */
  1420. if (IS_CONF_DEBUG_OSPF (event, EVENT) == OSPF_DEBUG_EVENT)
  1421. {
  1422. vty_out (vty, "debug ospf event%s", VTY_NEWLINE);
  1423. write = 1;
  1424. }
  1425. /* debug ospf nssa. */
  1426. if (IS_CONF_DEBUG_OSPF (nssa, NSSA) == OSPF_DEBUG_NSSA)
  1427. {
  1428. vty_out (vty, "debug ospf nssa%s", VTY_NEWLINE);
  1429. write = 1;
  1430. }
  1431. /* debug ospf packet all detail. */
  1432. r = OSPF_DEBUG_SEND_RECV|OSPF_DEBUG_DETAIL;
  1433. for (i = 0; i < 5; i++)
  1434. r &= conf_debug_ospf_packet[i] & (OSPF_DEBUG_SEND_RECV|OSPF_DEBUG_DETAIL);
  1435. if (r == (OSPF_DEBUG_SEND_RECV|OSPF_DEBUG_DETAIL))
  1436. {
  1437. vty_out (vty, "debug ospf packet all detail%s", VTY_NEWLINE);
  1438. return 1;
  1439. }
  1440. /* debug ospf packet all. */
  1441. r = OSPF_DEBUG_SEND_RECV;
  1442. for (i = 0; i < 5; i++)
  1443. r &= conf_debug_ospf_packet[i] & OSPF_DEBUG_SEND_RECV;
  1444. if (r == OSPF_DEBUG_SEND_RECV)
  1445. {
  1446. vty_out (vty, "debug ospf packet all%s", VTY_NEWLINE);
  1447. for (i = 0; i < 5; i++)
  1448. if (conf_debug_ospf_packet[i] & OSPF_DEBUG_DETAIL)
  1449. vty_out (vty, "debug ospf packet %s detail%s",
  1450. type_str[i],
  1451. VTY_NEWLINE);
  1452. return 1;
  1453. }
  1454. /* debug ospf packet (hello|dd|ls-request|ls-update|ls-ack)
  1455. (send|recv) (detail). */
  1456. for (i = 0; i < 5; i++)
  1457. {
  1458. if (conf_debug_ospf_packet[i] == 0)
  1459. continue;
  1460. vty_out (vty, "debug ospf packet %s%s%s",
  1461. type_str[i], detail_str[conf_debug_ospf_packet[i]],
  1462. VTY_NEWLINE);
  1463. write = 1;
  1464. }
  1465. return write;
  1466. }
  1467. /* Initialize debug commands. */
  1468. void
  1469. debug_init ()
  1470. {
  1471. install_node (&debug_node, config_write_debug);
  1472. install_element (ENABLE_NODE, &show_debugging_ospf_cmd);
  1473. install_element (ENABLE_NODE, &debug_ospf_packet_send_recv_detail_cmd);
  1474. install_element (ENABLE_NODE, &debug_ospf_packet_send_recv_cmd);
  1475. install_element (ENABLE_NODE, &debug_ospf_packet_all_cmd);
  1476. install_element (ENABLE_NODE, &debug_ospf_ism_sub_cmd);
  1477. install_element (ENABLE_NODE, &debug_ospf_ism_cmd);
  1478. install_element (ENABLE_NODE, &debug_ospf_nsm_sub_cmd);
  1479. install_element (ENABLE_NODE, &debug_ospf_nsm_cmd);
  1480. install_element (ENABLE_NODE, &debug_ospf_lsa_sub_cmd);
  1481. install_element (ENABLE_NODE, &debug_ospf_lsa_cmd);
  1482. install_element (ENABLE_NODE, &debug_ospf_zebra_sub_cmd);
  1483. install_element (ENABLE_NODE, &debug_ospf_zebra_cmd);
  1484. install_element (ENABLE_NODE, &debug_ospf_event_cmd);
  1485. install_element (ENABLE_NODE, &debug_ospf_nssa_cmd);
  1486. install_element (ENABLE_NODE, &debug_ospf_te_cmd);
  1487. install_element (ENABLE_NODE, &no_debug_ospf_packet_send_recv_detail_cmd);
  1488. install_element (ENABLE_NODE, &no_debug_ospf_packet_send_recv_cmd);
  1489. install_element (ENABLE_NODE, &no_debug_ospf_packet_all_cmd);
  1490. install_element (ENABLE_NODE, &no_debug_ospf_ism_sub_cmd);
  1491. install_element (ENABLE_NODE, &no_debug_ospf_ism_cmd);
  1492. install_element (ENABLE_NODE, &no_debug_ospf_nsm_sub_cmd);
  1493. install_element (ENABLE_NODE, &no_debug_ospf_nsm_cmd);
  1494. install_element (ENABLE_NODE, &no_debug_ospf_lsa_sub_cmd);
  1495. install_element (ENABLE_NODE, &no_debug_ospf_lsa_cmd);
  1496. install_element (ENABLE_NODE, &no_debug_ospf_zebra_sub_cmd);
  1497. install_element (ENABLE_NODE, &no_debug_ospf_zebra_cmd);
  1498. install_element (ENABLE_NODE, &no_debug_ospf_event_cmd);
  1499. install_element (ENABLE_NODE, &no_debug_ospf_nssa_cmd);
  1500. install_element (ENABLE_NODE, &no_debug_ospf_te_cmd);
  1501. install_element (CONFIG_NODE, &debug_ospf_packet_send_recv_detail_cmd);
  1502. install_element (CONFIG_NODE, &debug_ospf_packet_send_recv_cmd);
  1503. install_element (CONFIG_NODE, &debug_ospf_packet_all_cmd);
  1504. install_element (CONFIG_NODE, &debug_ospf_ism_sub_cmd);
  1505. install_element (CONFIG_NODE, &debug_ospf_ism_cmd);
  1506. install_element (CONFIG_NODE, &debug_ospf_nsm_sub_cmd);
  1507. install_element (CONFIG_NODE, &debug_ospf_nsm_cmd);
  1508. install_element (CONFIG_NODE, &debug_ospf_lsa_sub_cmd);
  1509. install_element (CONFIG_NODE, &debug_ospf_lsa_cmd);
  1510. install_element (CONFIG_NODE, &debug_ospf_zebra_sub_cmd);
  1511. install_element (CONFIG_NODE, &debug_ospf_zebra_cmd);
  1512. install_element (CONFIG_NODE, &debug_ospf_event_cmd);
  1513. install_element (CONFIG_NODE, &debug_ospf_nssa_cmd);
  1514. install_element (CONFIG_NODE, &debug_ospf_te_cmd);
  1515. install_element (CONFIG_NODE, &no_debug_ospf_packet_send_recv_detail_cmd);
  1516. install_element (CONFIG_NODE, &no_debug_ospf_packet_send_recv_cmd);
  1517. install_element (CONFIG_NODE, &no_debug_ospf_packet_all_cmd);
  1518. install_element (CONFIG_NODE, &no_debug_ospf_ism_sub_cmd);
  1519. install_element (CONFIG_NODE, &no_debug_ospf_ism_cmd);
  1520. install_element (CONFIG_NODE, &no_debug_ospf_nsm_sub_cmd);
  1521. install_element (CONFIG_NODE, &no_debug_ospf_nsm_cmd);
  1522. install_element (CONFIG_NODE, &no_debug_ospf_lsa_sub_cmd);
  1523. install_element (CONFIG_NODE, &no_debug_ospf_lsa_cmd);
  1524. install_element (CONFIG_NODE, &no_debug_ospf_zebra_sub_cmd);
  1525. install_element (CONFIG_NODE, &no_debug_ospf_zebra_cmd);
  1526. install_element (CONFIG_NODE, &no_debug_ospf_event_cmd);
  1527. install_element (CONFIG_NODE, &no_debug_ospf_nssa_cmd);
  1528. install_element (CONFIG_NODE, &no_debug_ospf_te_cmd);
  1529. }