bgp_debug.c 26 KB

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