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