bgp_debug.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  1. /* BGP-4, BGP-4+ packet debug routine
  2. Copyright (C) 1996, 97, 99 Kunihiro Ishiguro
  3. This file is part of GNU Zebra.
  4. GNU Zebra is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. GNU Zebra is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Zebra; see the file COPYING. If not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. 02111-1307, USA. */
  16. #include <zebra.h>
  17. #include <lib/version.h>
  18. #include "prefix.h"
  19. #include "linklist.h"
  20. #include "stream.h"
  21. #include "command.h"
  22. #include "str.h"
  23. #include "log.h"
  24. #include "sockunion.h"
  25. #include "filter.h"
  26. #include "memory.h"
  27. #include "bgpd/bgpd.h"
  28. #include "bgpd/bgp_aspath.h"
  29. #include "bgpd/bgp_route.h"
  30. #include "bgpd/bgp_attr.h"
  31. #include "bgpd/bgp_debug.h"
  32. #include "bgpd/bgp_community.h"
  33. unsigned long conf_bgp_debug_as4;
  34. unsigned long conf_bgp_debug_fsm;
  35. unsigned long conf_bgp_debug_events;
  36. unsigned long conf_bgp_debug_packet;
  37. unsigned long conf_bgp_debug_filter;
  38. unsigned long conf_bgp_debug_keepalive;
  39. unsigned long conf_bgp_debug_update;
  40. unsigned long conf_bgp_debug_normal;
  41. unsigned long conf_bgp_debug_zebra;
  42. unsigned long conf_bgp_debug_allow_martians;
  43. unsigned long conf_bgp_debug_nht;
  44. unsigned long term_bgp_debug_as4;
  45. unsigned long term_bgp_debug_fsm;
  46. unsigned long term_bgp_debug_events;
  47. unsigned long term_bgp_debug_packet;
  48. unsigned long term_bgp_debug_filter;
  49. unsigned long term_bgp_debug_keepalive;
  50. unsigned long term_bgp_debug_update;
  51. unsigned long term_bgp_debug_normal;
  52. unsigned long term_bgp_debug_zebra;
  53. unsigned long term_bgp_debug_allow_martians;
  54. unsigned long term_bgp_debug_nht;
  55. /* messages for BGP-4 status */
  56. const struct message bgp_status_msg[] =
  57. {
  58. { Idle, "Idle" },
  59. { Connect, "Connect" },
  60. { Active, "Active" },
  61. { OpenSent, "OpenSent" },
  62. { OpenConfirm, "OpenConfirm" },
  63. { Established, "Established" },
  64. { Clearing, "Clearing" },
  65. { Deleted, "Deleted" },
  66. };
  67. #define BGP_DEBUG_MSG_MAX(msg) const int msg ## _max = array_size (msg)
  68. BGP_DEBUG_MSG_MAX (bgp_status_msg);
  69. /* BGP message type string. */
  70. const char *bgp_type_str[] =
  71. {
  72. NULL,
  73. "OPEN",
  74. "UPDATE",
  75. "NOTIFICATION",
  76. "KEEPALIVE",
  77. "ROUTE-REFRESH",
  78. "CAPABILITY",
  79. NULL,
  80. };
  81. /* message for BGP-4 Notify */
  82. static const struct message bgp_notify_msg[] =
  83. {
  84. { BGP_NOTIFY_HEADER_ERR, "Message Header Error"},
  85. { BGP_NOTIFY_OPEN_ERR, "OPEN Message Error"},
  86. { BGP_NOTIFY_UPDATE_ERR, "UPDATE Message Error"},
  87. { BGP_NOTIFY_HOLD_ERR, "Hold Timer Expired"},
  88. { BGP_NOTIFY_FSM_ERR, "Finite State Machine Error"},
  89. { BGP_NOTIFY_CEASE, "Cease"},
  90. { BGP_NOTIFY_CAPABILITY_ERR, "CAPABILITY Message Error"},
  91. };
  92. BGP_DEBUG_MSG_MAX (bgp_notify_msg);
  93. static const struct message bgp_notify_head_msg[] =
  94. {
  95. { BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"},
  96. { BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length"},
  97. { BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"},
  98. };
  99. BGP_DEBUG_MSG_MAX (bgp_notify_head_msg);
  100. static const struct message bgp_notify_open_msg[] =
  101. {
  102. { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
  103. { BGP_NOTIFY_OPEN_UNSUP_VERSION, "/Unsupported Version Number" },
  104. { BGP_NOTIFY_OPEN_BAD_PEER_AS, "/Bad Peer AS"},
  105. { BGP_NOTIFY_OPEN_BAD_BGP_IDENT, "/Bad BGP Identifier"},
  106. { BGP_NOTIFY_OPEN_UNSUP_PARAM, "/Unsupported Optional Parameter"},
  107. { BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure"},
  108. { BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"},
  109. { BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability"},
  110. };
  111. BGP_DEBUG_MSG_MAX (bgp_notify_open_msg);
  112. static const struct message bgp_notify_update_msg[] =
  113. {
  114. { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
  115. { BGP_NOTIFY_UPDATE_MAL_ATTR, "/Malformed Attribute List"},
  116. { BGP_NOTIFY_UPDATE_UNREC_ATTR, "/Unrecognized Well-known Attribute"},
  117. { BGP_NOTIFY_UPDATE_MISS_ATTR, "/Missing Well-known Attribute"},
  118. { BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR, "/Attribute Flags Error"},
  119. { BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, "/Attribute Length Error"},
  120. { BGP_NOTIFY_UPDATE_INVAL_ORIGIN, "/Invalid ORIGIN Attribute"},
  121. { BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP, "/AS Routing Loop"},
  122. { BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, "/Invalid NEXT_HOP Attribute"},
  123. { BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"},
  124. { BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"},
  125. { BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH"},
  126. };
  127. BGP_DEBUG_MSG_MAX (bgp_notify_update_msg);
  128. static const struct message bgp_notify_cease_msg[] =
  129. {
  130. { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
  131. { BGP_NOTIFY_CEASE_MAX_PREFIX, "/Maximum Number of Prefixes Reached"},
  132. { BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, "/Administratively Shutdown"},
  133. { BGP_NOTIFY_CEASE_PEER_UNCONFIG, "/Peer Unconfigured"},
  134. { BGP_NOTIFY_CEASE_ADMIN_RESET, "/Administratively Reset"},
  135. { BGP_NOTIFY_CEASE_CONNECT_REJECT, "/Connection Rejected"},
  136. { BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"},
  137. { BGP_NOTIFY_CEASE_COLLISION_RESOLUTION, "/Connection collision resolution"},
  138. { BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resource"},
  139. };
  140. BGP_DEBUG_MSG_MAX (bgp_notify_cease_msg);
  141. static const struct message bgp_notify_capability_msg[] =
  142. {
  143. { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
  144. { BGP_NOTIFY_CAPABILITY_INVALID_ACTION, "/Invalid Action Value" },
  145. { BGP_NOTIFY_CAPABILITY_INVALID_LENGTH, "/Invalid Capability Length"},
  146. { BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value"},
  147. };
  148. BGP_DEBUG_MSG_MAX (bgp_notify_capability_msg);
  149. /* Origin strings. */
  150. const char *bgp_origin_str[] = {"i","e","?"};
  151. const char *bgp_origin_long_str[] = {"IGP","EGP","incomplete"};
  152. /* Dump attribute. */
  153. int
  154. bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size)
  155. {
  156. if (! attr)
  157. return 0;
  158. if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP)))
  159. snprintf (buf, size, "nexthop %s", inet_ntoa (attr->nexthop));
  160. if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGIN)))
  161. snprintf (buf + strlen (buf), size - strlen (buf), ", origin %s",
  162. bgp_origin_str[attr->origin]);
  163. if (attr->extra)
  164. {
  165. char addrbuf[BUFSIZ];
  166. /* Add MP case. */
  167. if (attr->extra->mp_nexthop_len == 16
  168. || attr->extra->mp_nexthop_len == 32)
  169. snprintf (buf + strlen (buf), size - strlen (buf), ", mp_nexthop %s",
  170. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
  171. addrbuf, BUFSIZ));
  172. if (attr->extra->mp_nexthop_len == 32)
  173. snprintf (buf + strlen (buf), size - strlen (buf), "(%s)",
  174. inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
  175. addrbuf, BUFSIZ));
  176. }
  177. if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)))
  178. snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %u",
  179. attr->local_pref);
  180. if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
  181. snprintf (buf + strlen (buf), size - strlen (buf), ", metric %u",
  182. attr->med);
  183. if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES)))
  184. snprintf (buf + strlen (buf), size - strlen (buf), ", community %s",
  185. community_str (attr->community));
  186. if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE)))
  187. snprintf (buf + strlen (buf), size - strlen (buf), ", atomic-aggregate");
  188. if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
  189. snprintf (buf + strlen (buf), size - strlen (buf), ", aggregated by %u %s",
  190. attr->extra->aggregator_as,
  191. inet_ntoa (attr->extra->aggregator_addr));
  192. if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)))
  193. snprintf (buf + strlen (buf), size - strlen (buf), ", originator %s",
  194. inet_ntoa (attr->extra->originator_id));
  195. if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST)))
  196. {
  197. int i;
  198. snprintf (buf + strlen (buf), size - strlen (buf), ", clusterlist");
  199. for (i = 0; i < attr->extra->cluster->length / 4; i++)
  200. snprintf (buf + strlen (buf), size - strlen (buf), " %s",
  201. inet_ntoa (attr->extra->cluster->list[i]));
  202. }
  203. if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH)))
  204. snprintf (buf + strlen (buf), size - strlen (buf), ", path %s",
  205. aspath_print (attr->aspath));
  206. if (strlen (buf) > 1)
  207. return 1;
  208. else
  209. return 0;
  210. }
  211. /* dump notify packet */
  212. void
  213. bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
  214. const char *direct)
  215. {
  216. const char *subcode_str;
  217. const char *code_str;
  218. subcode_str = "";
  219. code_str = LOOKUP_DEF (bgp_notify_msg, bgp_notify->code,
  220. "Unrecognized Error Code");
  221. switch (bgp_notify->code)
  222. {
  223. case BGP_NOTIFY_HEADER_ERR:
  224. subcode_str = LOOKUP_DEF (bgp_notify_head_msg, bgp_notify->subcode,
  225. "Unrecognized Error Subcode");
  226. break;
  227. case BGP_NOTIFY_OPEN_ERR:
  228. subcode_str = LOOKUP_DEF (bgp_notify_open_msg, bgp_notify->subcode,
  229. "Unrecognized Error Subcode");
  230. break;
  231. case BGP_NOTIFY_UPDATE_ERR:
  232. subcode_str = LOOKUP_DEF (bgp_notify_update_msg, bgp_notify->subcode,
  233. "Unrecognized Error Subcode");
  234. break;
  235. case BGP_NOTIFY_HOLD_ERR:
  236. break;
  237. case BGP_NOTIFY_FSM_ERR:
  238. break;
  239. case BGP_NOTIFY_CEASE:
  240. subcode_str = LOOKUP_DEF (bgp_notify_cease_msg, bgp_notify->subcode,
  241. "Unrecognized Error Subcode");
  242. break;
  243. case BGP_NOTIFY_CAPABILITY_ERR:
  244. subcode_str = LOOKUP_DEF (bgp_notify_capability_msg, bgp_notify->subcode,
  245. "Unrecognized Error Subcode");
  246. break;
  247. }
  248. if (bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES))
  249. zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
  250. strcmp (direct, "received") == 0 ? "received from" : "sent to",
  251. peer->host, bgp_notify->code, bgp_notify->subcode,
  252. code_str, subcode_str, bgp_notify->length,
  253. bgp_notify->data ? bgp_notify->data : "");
  254. else if (BGP_DEBUG (normal, NORMAL))
  255. plog_debug (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s",
  256. peer ? peer->host : "",
  257. direct, bgp_notify->code, bgp_notify->subcode,
  258. code_str, subcode_str, bgp_notify->length,
  259. bgp_notify->data ? bgp_notify->data : "");
  260. }
  261. /* Debug option setting interface. */
  262. unsigned long bgp_debug_option = 0;
  263. int
  264. debug (unsigned int option)
  265. {
  266. return bgp_debug_option & option;
  267. }
  268. DEFUN (debug_bgp_as4,
  269. debug_bgp_as4_cmd,
  270. "debug bgp as4",
  271. DEBUG_STR
  272. BGP_STR
  273. "BGP AS4 actions\n")
  274. {
  275. if (vty->node == CONFIG_NODE)
  276. DEBUG_ON (as4, AS4);
  277. else
  278. {
  279. TERM_DEBUG_ON (as4, AS4);
  280. vty_out (vty, "BGP as4 debugging is on%s", VTY_NEWLINE);
  281. }
  282. return CMD_SUCCESS;
  283. }
  284. DEFUN (no_debug_bgp_as4,
  285. no_debug_bgp_as4_cmd,
  286. "no debug bgp as4",
  287. NO_STR
  288. DEBUG_STR
  289. BGP_STR
  290. "BGP AS4 actions\n")
  291. {
  292. if (vty->node == CONFIG_NODE)
  293. DEBUG_OFF (as4, AS4);
  294. else
  295. {
  296. TERM_DEBUG_OFF (as4, AS4);
  297. vty_out (vty, "BGP as4 debugging is off%s", VTY_NEWLINE);
  298. }
  299. return CMD_SUCCESS;
  300. }
  301. ALIAS (no_debug_bgp_as4,
  302. undebug_bgp_as4_cmd,
  303. "undebug bgp as4",
  304. UNDEBUG_STR
  305. BGP_STR
  306. "BGP AS4 actions\n")
  307. DEFUN (debug_bgp_as4_segment,
  308. debug_bgp_as4_segment_cmd,
  309. "debug bgp as4 segment",
  310. DEBUG_STR
  311. BGP_STR
  312. "BGP AS4 actions\n"
  313. "BGP AS4 aspath segment handling\n")
  314. {
  315. if (vty->node == CONFIG_NODE)
  316. DEBUG_ON (as4, AS4_SEGMENT);
  317. else
  318. {
  319. TERM_DEBUG_ON (as4, AS4_SEGMENT);
  320. vty_out (vty, "BGP as4 segment debugging is on%s", VTY_NEWLINE);
  321. }
  322. return CMD_SUCCESS;
  323. }
  324. DEFUN (no_debug_bgp_as4_segment,
  325. no_debug_bgp_as4_segment_cmd,
  326. "no debug bgp as4 segment",
  327. NO_STR
  328. DEBUG_STR
  329. BGP_STR
  330. "BGP AS4 actions\n"
  331. "BGP AS4 aspath segment handling\n")
  332. {
  333. if (vty->node == CONFIG_NODE)
  334. DEBUG_OFF (as4, AS4_SEGMENT);
  335. else
  336. {
  337. TERM_DEBUG_OFF (as4, AS4_SEGMENT);
  338. vty_out (vty, "BGP as4 segment debugging is off%s", VTY_NEWLINE);
  339. }
  340. return CMD_SUCCESS;
  341. }
  342. ALIAS (no_debug_bgp_as4_segment,
  343. undebug_bgp_as4_segment_cmd,
  344. "undebug bgp as4 segment",
  345. UNDEBUG_STR
  346. BGP_STR
  347. "BGP AS4 actions\n"
  348. "BGP AS4 aspath segment handling\n")
  349. DEFUN (debug_bgp_fsm,
  350. debug_bgp_fsm_cmd,
  351. "debug bgp fsm",
  352. DEBUG_STR
  353. BGP_STR
  354. "BGP Finite State Machine\n")
  355. {
  356. if (vty->node == CONFIG_NODE)
  357. DEBUG_ON (fsm, FSM);
  358. else
  359. {
  360. TERM_DEBUG_ON (fsm, FSM);
  361. vty_out (vty, "BGP fsm debugging is on%s", VTY_NEWLINE);
  362. }
  363. return CMD_SUCCESS;
  364. }
  365. DEFUN (no_debug_bgp_fsm,
  366. no_debug_bgp_fsm_cmd,
  367. "no debug bgp fsm",
  368. NO_STR
  369. DEBUG_STR
  370. BGP_STR
  371. "Finite State Machine\n")
  372. {
  373. if (vty->node == CONFIG_NODE)
  374. DEBUG_OFF (fsm, FSM);
  375. else
  376. {
  377. TERM_DEBUG_OFF (fsm, FSM);
  378. vty_out (vty, "BGP fsm debugging is off%s", VTY_NEWLINE);
  379. }
  380. return CMD_SUCCESS;
  381. }
  382. ALIAS (no_debug_bgp_fsm,
  383. undebug_bgp_fsm_cmd,
  384. "undebug bgp fsm",
  385. UNDEBUG_STR
  386. BGP_STR
  387. "Finite State Machine\n")
  388. DEFUN (debug_bgp_events,
  389. debug_bgp_events_cmd,
  390. "debug bgp events",
  391. DEBUG_STR
  392. BGP_STR
  393. "BGP events\n")
  394. {
  395. if (vty->node == CONFIG_NODE)
  396. DEBUG_ON (events, EVENTS);
  397. else
  398. {
  399. TERM_DEBUG_ON (events, EVENTS);
  400. vty_out (vty, "BGP events debugging is on%s", VTY_NEWLINE);
  401. }
  402. return CMD_SUCCESS;
  403. }
  404. DEFUN (no_debug_bgp_events,
  405. no_debug_bgp_events_cmd,
  406. "no debug bgp events",
  407. NO_STR
  408. DEBUG_STR
  409. BGP_STR
  410. "BGP events\n")
  411. {
  412. if (vty->node == CONFIG_NODE)
  413. DEBUG_OFF (events, EVENTS);
  414. else
  415. {
  416. TERM_DEBUG_OFF (events, EVENTS);
  417. vty_out (vty, "BGP events debugging is off%s", VTY_NEWLINE);
  418. }
  419. return CMD_SUCCESS;
  420. }
  421. ALIAS (no_debug_bgp_events,
  422. undebug_bgp_events_cmd,
  423. "undebug bgp events",
  424. UNDEBUG_STR
  425. BGP_STR
  426. "BGP events\n")
  427. DEFUN (debug_bgp_nht,
  428. debug_bgp_nht_cmd,
  429. "debug bgp nht",
  430. DEBUG_STR
  431. BGP_STR
  432. "BGP nexthop tracking events\n")
  433. {
  434. if (vty->node == CONFIG_NODE)
  435. DEBUG_ON (nht, NHT);
  436. else
  437. {
  438. TERM_DEBUG_ON (nht, NHT);
  439. vty_out (vty, "BGP nexthop tracking debugging is on%s", VTY_NEWLINE);
  440. }
  441. return CMD_SUCCESS;
  442. }
  443. DEFUN (no_debug_bgp_nht,
  444. no_debug_bgp_nht_cmd,
  445. "no debug bgp nht",
  446. NO_STR
  447. DEBUG_STR
  448. BGP_STR
  449. "BGP nexthop tracking events\n")
  450. {
  451. if (vty->node == CONFIG_NODE)
  452. DEBUG_OFF (nht, NHT);
  453. else
  454. {
  455. TERM_DEBUG_OFF (nht, NHT);
  456. vty_out (vty, "BGP nexthop tracking debugging is off%s", VTY_NEWLINE);
  457. }
  458. return CMD_SUCCESS;
  459. }
  460. ALIAS (no_debug_bgp_nht,
  461. undebug_bgp_nht_cmd,
  462. "undebug bgp nht",
  463. UNDEBUG_STR
  464. BGP_STR
  465. "BGP next-hop tracking updates\n")
  466. DEFUN (debug_bgp_filter,
  467. debug_bgp_filter_cmd,
  468. "debug bgp filters",
  469. DEBUG_STR
  470. BGP_STR
  471. "BGP filters\n")
  472. {
  473. if (vty->node == CONFIG_NODE)
  474. DEBUG_ON (filter, FILTER);
  475. else
  476. {
  477. TERM_DEBUG_ON (filter, FILTER);
  478. vty_out (vty, "BGP filters debugging is on%s", VTY_NEWLINE);
  479. }
  480. return CMD_SUCCESS;
  481. }
  482. DEFUN (no_debug_bgp_filter,
  483. no_debug_bgp_filter_cmd,
  484. "no debug bgp filters",
  485. NO_STR
  486. DEBUG_STR
  487. BGP_STR
  488. "BGP filters\n")
  489. {
  490. if (vty->node == CONFIG_NODE)
  491. DEBUG_OFF (filter, FILTER);
  492. else
  493. {
  494. TERM_DEBUG_OFF (filter, FILTER);
  495. vty_out (vty, "BGP filters debugging is off%s", VTY_NEWLINE);
  496. }
  497. return CMD_SUCCESS;
  498. }
  499. ALIAS (no_debug_bgp_filter,
  500. undebug_bgp_filter_cmd,
  501. "undebug bgp filters",
  502. UNDEBUG_STR
  503. BGP_STR
  504. "BGP filters\n")
  505. DEFUN (debug_bgp_keepalive,
  506. debug_bgp_keepalive_cmd,
  507. "debug bgp keepalives",
  508. DEBUG_STR
  509. BGP_STR
  510. "BGP keepalives\n")
  511. {
  512. if (vty->node == CONFIG_NODE)
  513. DEBUG_ON (keepalive, KEEPALIVE);
  514. else
  515. {
  516. TERM_DEBUG_ON (keepalive, KEEPALIVE);
  517. vty_out (vty, "BGP keepalives debugging is on%s", VTY_NEWLINE);
  518. }
  519. return CMD_SUCCESS;
  520. }
  521. DEFUN (no_debug_bgp_keepalive,
  522. no_debug_bgp_keepalive_cmd,
  523. "no debug bgp keepalives",
  524. NO_STR
  525. DEBUG_STR
  526. BGP_STR
  527. "BGP keepalives\n")
  528. {
  529. if (vty->node == CONFIG_NODE)
  530. DEBUG_OFF (keepalive, KEEPALIVE);
  531. else
  532. {
  533. TERM_DEBUG_OFF (keepalive, KEEPALIVE);
  534. vty_out (vty, "BGP keepalives debugging is off%s", VTY_NEWLINE);
  535. }
  536. return CMD_SUCCESS;
  537. }
  538. ALIAS (no_debug_bgp_keepalive,
  539. undebug_bgp_keepalive_cmd,
  540. "undebug bgp keepalives",
  541. UNDEBUG_STR
  542. BGP_STR
  543. "BGP keepalives\n")
  544. DEFUN (debug_bgp_update,
  545. debug_bgp_update_cmd,
  546. "debug bgp updates",
  547. DEBUG_STR
  548. BGP_STR
  549. "BGP updates\n")
  550. {
  551. if (vty->node == CONFIG_NODE)
  552. {
  553. DEBUG_ON (update, UPDATE_IN);
  554. DEBUG_ON (update, UPDATE_OUT);
  555. }
  556. else
  557. {
  558. TERM_DEBUG_ON (update, UPDATE_IN);
  559. TERM_DEBUG_ON (update, UPDATE_OUT);
  560. vty_out (vty, "BGP updates debugging is on%s", VTY_NEWLINE);
  561. }
  562. return CMD_SUCCESS;
  563. }
  564. DEFUN (debug_bgp_update_direct,
  565. debug_bgp_update_direct_cmd,
  566. "debug bgp updates (in|out)",
  567. DEBUG_STR
  568. BGP_STR
  569. "BGP updates\n"
  570. "Inbound updates\n"
  571. "Outbound updates\n")
  572. {
  573. if (vty->node == CONFIG_NODE)
  574. {
  575. if (strncmp ("i", argv[0], 1) == 0)
  576. {
  577. DEBUG_OFF (update, UPDATE_OUT);
  578. DEBUG_ON (update, UPDATE_IN);
  579. }
  580. else
  581. {
  582. DEBUG_OFF (update, UPDATE_IN);
  583. DEBUG_ON (update, UPDATE_OUT);
  584. }
  585. }
  586. else
  587. {
  588. if (strncmp ("i", argv[0], 1) == 0)
  589. {
  590. TERM_DEBUG_OFF (update, UPDATE_OUT);
  591. TERM_DEBUG_ON (update, UPDATE_IN);
  592. vty_out (vty, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
  593. }
  594. else
  595. {
  596. TERM_DEBUG_OFF (update, UPDATE_IN);
  597. TERM_DEBUG_ON (update, UPDATE_OUT);
  598. vty_out (vty, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
  599. }
  600. }
  601. return CMD_SUCCESS;
  602. }
  603. DEFUN (no_debug_bgp_update,
  604. no_debug_bgp_update_cmd,
  605. "no debug bgp updates",
  606. NO_STR
  607. DEBUG_STR
  608. BGP_STR
  609. "BGP updates\n")
  610. {
  611. if (vty->node == CONFIG_NODE)
  612. {
  613. DEBUG_OFF (update, UPDATE_IN);
  614. DEBUG_OFF (update, UPDATE_OUT);
  615. }
  616. else
  617. {
  618. TERM_DEBUG_OFF (update, UPDATE_IN);
  619. TERM_DEBUG_OFF (update, UPDATE_OUT);
  620. vty_out (vty, "BGP updates debugging is off%s", VTY_NEWLINE);
  621. }
  622. return CMD_SUCCESS;
  623. }
  624. ALIAS (no_debug_bgp_update,
  625. undebug_bgp_update_cmd,
  626. "undebug bgp updates",
  627. UNDEBUG_STR
  628. BGP_STR
  629. "BGP updates\n")
  630. DEFUN (debug_bgp_normal,
  631. debug_bgp_normal_cmd,
  632. "debug bgp",
  633. DEBUG_STR
  634. BGP_STR)
  635. {
  636. if (vty->node == CONFIG_NODE)
  637. DEBUG_ON (normal, NORMAL);
  638. else
  639. {
  640. TERM_DEBUG_ON (normal, NORMAL);
  641. vty_out (vty, "BGP debugging is on%s", VTY_NEWLINE);
  642. }
  643. return CMD_SUCCESS;
  644. }
  645. DEFUN (no_debug_bgp_normal,
  646. no_debug_bgp_normal_cmd,
  647. "no debug bgp",
  648. NO_STR
  649. DEBUG_STR
  650. BGP_STR)
  651. {
  652. if (vty->node == CONFIG_NODE)
  653. DEBUG_OFF (normal, NORMAL);
  654. else
  655. {
  656. TERM_DEBUG_OFF (normal, NORMAL);
  657. vty_out (vty, "BGP debugging is off%s", VTY_NEWLINE);
  658. }
  659. return CMD_SUCCESS;
  660. }
  661. ALIAS (no_debug_bgp_normal,
  662. undebug_bgp_normal_cmd,
  663. "undebug bgp",
  664. UNDEBUG_STR
  665. BGP_STR)
  666. DEFUN (debug_bgp_zebra,
  667. debug_bgp_zebra_cmd,
  668. "debug bgp zebra",
  669. DEBUG_STR
  670. BGP_STR
  671. "BGP Zebra messages\n")
  672. {
  673. if (vty->node == CONFIG_NODE)
  674. DEBUG_ON (zebra, ZEBRA);
  675. else
  676. {
  677. TERM_DEBUG_ON (zebra, ZEBRA);
  678. vty_out (vty, "BGP zebra debugging is on%s", VTY_NEWLINE);
  679. }
  680. return CMD_SUCCESS;
  681. }
  682. DEFUN (no_debug_bgp_zebra,
  683. no_debug_bgp_zebra_cmd,
  684. "no debug bgp zebra",
  685. NO_STR
  686. DEBUG_STR
  687. BGP_STR
  688. "BGP Zebra messages\n")
  689. {
  690. if (vty->node == CONFIG_NODE)
  691. DEBUG_OFF (zebra, ZEBRA);
  692. else
  693. {
  694. TERM_DEBUG_OFF (zebra, ZEBRA);
  695. vty_out (vty, "BGP zebra debugging is off%s", VTY_NEWLINE);
  696. }
  697. return CMD_SUCCESS;
  698. }
  699. ALIAS (no_debug_bgp_zebra,
  700. undebug_bgp_zebra_cmd,
  701. "undebug bgp zebra",
  702. UNDEBUG_STR
  703. BGP_STR
  704. "BGP Zebra messages\n")
  705. DEFUN (debug_bgp_allow_martians,
  706. debug_bgp_allow_martians_cmd,
  707. "debug bgp allow-martians",
  708. DEBUG_STR
  709. BGP_STR
  710. "BGP allow martian next hops\n")
  711. {
  712. if (vty->node == CONFIG_NODE)
  713. DEBUG_ON (allow_martians, ALLOW_MARTIANS);
  714. else
  715. {
  716. TERM_DEBUG_ON (allow_martians, ALLOW_MARTIANS);
  717. vty_out (vty, "BGP allow_martian next hop debugging is on%s", VTY_NEWLINE);
  718. }
  719. return CMD_SUCCESS;
  720. }
  721. DEFUN (no_debug_bgp_allow_martians,
  722. no_debug_bgp_allow_martians_cmd,
  723. "no debug bgp allow-martians",
  724. NO_STR
  725. DEBUG_STR
  726. BGP_STR
  727. "BGP allow martian next hops\n")
  728. {
  729. if (vty->node == CONFIG_NODE)
  730. DEBUG_OFF (allow_martians, ALLOW_MARTIANS);
  731. else
  732. {
  733. TERM_DEBUG_OFF (allow_martians, ALLOW_MARTIANS);
  734. vty_out (vty, "BGP allow martian next hop debugging is off%s", VTY_NEWLINE);
  735. }
  736. return CMD_SUCCESS;
  737. }
  738. ALIAS (no_debug_bgp_allow_martians,
  739. undebug_bgp_allow_martians_cmd,
  740. "undebug bgp allow-martians",
  741. UNDEBUG_STR
  742. BGP_STR
  743. "BGP allow martian next hops\n")
  744. DEFUN (no_debug_bgp_all,
  745. no_debug_bgp_all_cmd,
  746. "no debug all bgp",
  747. NO_STR
  748. DEBUG_STR
  749. "Enable all debugging\n"
  750. BGP_STR)
  751. {
  752. TERM_DEBUG_OFF (normal, NORMAL);
  753. TERM_DEBUG_OFF (events, EVENTS);
  754. TERM_DEBUG_OFF (keepalive, KEEPALIVE);
  755. TERM_DEBUG_OFF (update, UPDATE_IN);
  756. TERM_DEBUG_OFF (update, UPDATE_OUT);
  757. TERM_DEBUG_OFF (as4, AS4);
  758. TERM_DEBUG_OFF (as4, AS4_SEGMENT);
  759. TERM_DEBUG_OFF (fsm, FSM);
  760. TERM_DEBUG_OFF (filter, FILTER);
  761. TERM_DEBUG_OFF (zebra, ZEBRA);
  762. TERM_DEBUG_OFF (allow_martians, ALLOW_MARTIANS);
  763. vty_out (vty, "All possible debugging has been turned off%s", VTY_NEWLINE);
  764. return CMD_SUCCESS;
  765. }
  766. ALIAS (no_debug_bgp_all,
  767. undebug_bgp_all_cmd,
  768. "undebug all bgp",
  769. UNDEBUG_STR
  770. "Enable all debugging\n"
  771. BGP_STR)
  772. DEFUN (show_debugging_bgp,
  773. show_debugging_bgp_cmd,
  774. "show debugging bgp",
  775. SHOW_STR
  776. DEBUG_STR
  777. BGP_STR)
  778. {
  779. vty_out (vty, "BGP debugging status:%s", VTY_NEWLINE);
  780. if (BGP_DEBUG (normal, NORMAL))
  781. vty_out (vty, " BGP debugging is on%s", VTY_NEWLINE);
  782. if (BGP_DEBUG (events, EVENTS))
  783. vty_out (vty, " BGP events debugging is on%s", VTY_NEWLINE);
  784. if (BGP_DEBUG (keepalive, KEEPALIVE))
  785. vty_out (vty, " BGP keepalives debugging is on%s", VTY_NEWLINE);
  786. if (BGP_DEBUG (update, UPDATE_IN) && BGP_DEBUG (update, UPDATE_OUT))
  787. vty_out (vty, " BGP updates debugging is on%s", VTY_NEWLINE);
  788. else if (BGP_DEBUG (update, UPDATE_IN))
  789. vty_out (vty, " BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
  790. else if (BGP_DEBUG (update, UPDATE_OUT))
  791. vty_out (vty, " BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
  792. if (BGP_DEBUG (fsm, FSM))
  793. vty_out (vty, " BGP fsm debugging is on%s", VTY_NEWLINE);
  794. if (BGP_DEBUG (filter, FILTER))
  795. vty_out (vty, " BGP filter debugging is on%s", VTY_NEWLINE);
  796. if (BGP_DEBUG (zebra, ZEBRA))
  797. vty_out (vty, " BGP zebra debugging is on%s", VTY_NEWLINE);
  798. if (BGP_DEBUG (as4, AS4))
  799. vty_out (vty, " BGP as4 debugging is on%s", VTY_NEWLINE);
  800. if (BGP_DEBUG (as4, AS4_SEGMENT))
  801. vty_out (vty, " BGP as4 aspath segment debugging is on%s", VTY_NEWLINE);
  802. if (BGP_DEBUG (allow_martians, ALLOW_MARTIANS))
  803. vty_out (vty, " BGP allow martian next hop debugging is on%s", VTY_NEWLINE);
  804. if (BGP_DEBUG (nht, NHT))
  805. vty_out (vty, " BGP next-hop tracking debugging is on%s", VTY_NEWLINE);
  806. vty_out (vty, "%s", VTY_NEWLINE);
  807. return CMD_SUCCESS;
  808. }
  809. static int
  810. bgp_config_write_debug (struct vty *vty)
  811. {
  812. int write = 0;
  813. if (CONF_BGP_DEBUG (normal, NORMAL))
  814. {
  815. vty_out (vty, "debug bgp%s", VTY_NEWLINE);
  816. write++;
  817. }
  818. if (CONF_BGP_DEBUG (as4, AS4))
  819. {
  820. vty_out (vty, "debug bgp as4%s", VTY_NEWLINE);
  821. write++;
  822. }
  823. if (CONF_BGP_DEBUG (as4, AS4_SEGMENT))
  824. {
  825. vty_out (vty, "debug bgp as4 segment%s", VTY_NEWLINE);
  826. write++;
  827. }
  828. if (CONF_BGP_DEBUG (events, EVENTS))
  829. {
  830. vty_out (vty, "debug bgp events%s", VTY_NEWLINE);
  831. write++;
  832. }
  833. if (CONF_BGP_DEBUG (keepalive, KEEPALIVE))
  834. {
  835. vty_out (vty, "debug bgp keepalives%s", VTY_NEWLINE);
  836. write++;
  837. }
  838. if (CONF_BGP_DEBUG (update, UPDATE_IN) && CONF_BGP_DEBUG (update, UPDATE_OUT))
  839. {
  840. vty_out (vty, "debug bgp updates%s", VTY_NEWLINE);
  841. write++;
  842. }
  843. else if (CONF_BGP_DEBUG (update, UPDATE_IN))
  844. {
  845. vty_out (vty, "debug bgp updates in%s", VTY_NEWLINE);
  846. write++;
  847. }
  848. else if (CONF_BGP_DEBUG (update, UPDATE_OUT))
  849. {
  850. vty_out (vty, "debug bgp updates out%s", VTY_NEWLINE);
  851. write++;
  852. }
  853. if (CONF_BGP_DEBUG (fsm, FSM))
  854. {
  855. vty_out (vty, "debug bgp fsm%s", VTY_NEWLINE);
  856. write++;
  857. }
  858. if (CONF_BGP_DEBUG (filter, FILTER))
  859. {
  860. vty_out (vty, "debug bgp filters%s", VTY_NEWLINE);
  861. write++;
  862. }
  863. if (CONF_BGP_DEBUG (zebra, ZEBRA))
  864. {
  865. vty_out (vty, "debug bgp zebra%s", VTY_NEWLINE);
  866. write++;
  867. }
  868. if (CONF_BGP_DEBUG (allow_martians, ALLOW_MARTIANS))
  869. {
  870. vty_out (vty, "debug bgp allow-martians%s", VTY_NEWLINE);
  871. write++;
  872. }
  873. if (CONF_BGP_DEBUG (nht, NHT))
  874. {
  875. vty_out (vty, "debug bgp nht%s", VTY_NEWLINE);
  876. write++;
  877. }
  878. return write;
  879. }
  880. static struct cmd_node debug_node =
  881. {
  882. DEBUG_NODE,
  883. "",
  884. 1
  885. };
  886. void
  887. bgp_debug_init (void)
  888. {
  889. install_node (&debug_node, bgp_config_write_debug);
  890. install_element (ENABLE_NODE, &show_debugging_bgp_cmd);
  891. install_element (ENABLE_NODE, &debug_bgp_as4_cmd);
  892. install_element (CONFIG_NODE, &debug_bgp_as4_cmd);
  893. install_element (ENABLE_NODE, &debug_bgp_as4_segment_cmd);
  894. install_element (CONFIG_NODE, &debug_bgp_as4_segment_cmd);
  895. install_element (ENABLE_NODE, &debug_bgp_fsm_cmd);
  896. install_element (CONFIG_NODE, &debug_bgp_fsm_cmd);
  897. install_element (ENABLE_NODE, &debug_bgp_events_cmd);
  898. install_element (CONFIG_NODE, &debug_bgp_events_cmd);
  899. install_element (ENABLE_NODE, &debug_bgp_nht_cmd);
  900. install_element (CONFIG_NODE, &debug_bgp_nht_cmd);
  901. install_element (ENABLE_NODE, &debug_bgp_filter_cmd);
  902. install_element (CONFIG_NODE, &debug_bgp_filter_cmd);
  903. install_element (ENABLE_NODE, &debug_bgp_keepalive_cmd);
  904. install_element (CONFIG_NODE, &debug_bgp_keepalive_cmd);
  905. install_element (ENABLE_NODE, &debug_bgp_update_cmd);
  906. install_element (CONFIG_NODE, &debug_bgp_update_cmd);
  907. install_element (ENABLE_NODE, &debug_bgp_update_direct_cmd);
  908. install_element (CONFIG_NODE, &debug_bgp_update_direct_cmd);
  909. install_element (ENABLE_NODE, &debug_bgp_normal_cmd);
  910. install_element (CONFIG_NODE, &debug_bgp_normal_cmd);
  911. install_element (ENABLE_NODE, &debug_bgp_zebra_cmd);
  912. install_element (CONFIG_NODE, &debug_bgp_zebra_cmd);
  913. install_element (ENABLE_NODE, &debug_bgp_allow_martians_cmd);
  914. install_element (CONFIG_NODE, &debug_bgp_allow_martians_cmd);
  915. install_element (ENABLE_NODE, &no_debug_bgp_as4_cmd);
  916. install_element (ENABLE_NODE, &undebug_bgp_as4_cmd);
  917. install_element (CONFIG_NODE, &no_debug_bgp_as4_cmd);
  918. install_element (ENABLE_NODE, &no_debug_bgp_as4_segment_cmd);
  919. install_element (ENABLE_NODE, &undebug_bgp_as4_segment_cmd);
  920. install_element (CONFIG_NODE, &no_debug_bgp_as4_segment_cmd);
  921. install_element (ENABLE_NODE, &no_debug_bgp_fsm_cmd);
  922. install_element (ENABLE_NODE, &undebug_bgp_fsm_cmd);
  923. install_element (CONFIG_NODE, &no_debug_bgp_fsm_cmd);
  924. install_element (ENABLE_NODE, &no_debug_bgp_events_cmd);
  925. install_element (ENABLE_NODE, &undebug_bgp_events_cmd);
  926. install_element (CONFIG_NODE, &no_debug_bgp_events_cmd);
  927. install_element (ENABLE_NODE, &no_debug_bgp_nht_cmd);
  928. install_element (ENABLE_NODE, &undebug_bgp_nht_cmd);
  929. install_element (CONFIG_NODE, &no_debug_bgp_nht_cmd);
  930. install_element (ENABLE_NODE, &no_debug_bgp_filter_cmd);
  931. install_element (ENABLE_NODE, &undebug_bgp_filter_cmd);
  932. install_element (CONFIG_NODE, &no_debug_bgp_filter_cmd);
  933. install_element (ENABLE_NODE, &no_debug_bgp_keepalive_cmd);
  934. install_element (ENABLE_NODE, &undebug_bgp_keepalive_cmd);
  935. install_element (CONFIG_NODE, &no_debug_bgp_keepalive_cmd);
  936. install_element (ENABLE_NODE, &no_debug_bgp_update_cmd);
  937. install_element (ENABLE_NODE, &undebug_bgp_update_cmd);
  938. install_element (CONFIG_NODE, &no_debug_bgp_update_cmd);
  939. install_element (ENABLE_NODE, &no_debug_bgp_normal_cmd);
  940. install_element (ENABLE_NODE, &undebug_bgp_normal_cmd);
  941. install_element (CONFIG_NODE, &no_debug_bgp_normal_cmd);
  942. install_element (ENABLE_NODE, &no_debug_bgp_zebra_cmd);
  943. install_element (ENABLE_NODE, &undebug_bgp_zebra_cmd);
  944. install_element (CONFIG_NODE, &no_debug_bgp_zebra_cmd);
  945. install_element (ENABLE_NODE, &no_debug_bgp_allow_martians_cmd);
  946. install_element (ENABLE_NODE, &undebug_bgp_allow_martians_cmd);
  947. install_element (CONFIG_NODE, &no_debug_bgp_allow_martians_cmd);
  948. install_element (ENABLE_NODE, &no_debug_bgp_all_cmd);
  949. install_element (ENABLE_NODE, &undebug_bgp_all_cmd);
  950. }