bgp_debug.c 29 KB

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