You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

835 lines
27 KiB

  1. From c6a5994609deec62c8aefa1fa15c517e32575ca3 Mon Sep 17 00:00:00 2001
  2. From: Donatas Abraitis <donatas.abraitis@gmail.com>
  3. Date: Wed, 6 May 2020 17:45:31 +0300
  4. Subject: [PATCH 1/4] tests: Remove bgp_show_ip_bgp_fqdn test
  5. Not really relevant for now.
  6. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
  7. ---
  8. .../bgp_show_ip_bgp_fqdn/__init__.py | 0
  9. .../bgp_show_ip_bgp_fqdn/r1/bgpd.conf | 5 -
  10. .../bgp_show_ip_bgp_fqdn/r1/zebra.conf | 9 --
  11. .../bgp_show_ip_bgp_fqdn/r2/bgpd.conf | 5 -
  12. .../bgp_show_ip_bgp_fqdn/r2/zebra.conf | 12 --
  13. .../bgp_show_ip_bgp_fqdn/r3/bgpd.conf | 3 -
  14. .../bgp_show_ip_bgp_fqdn/r3/zebra.conf | 6 -
  15. .../test_bgp_show_ip_bgp_fqdn.py | 133 ------------------
  16. 8 files changed, 173 deletions(-)
  17. delete mode 100644 tests/topotests/bgp_show_ip_bgp_fqdn/__init__.py
  18. delete mode 100644 tests/topotests/bgp_show_ip_bgp_fqdn/r1/bgpd.conf
  19. delete mode 100644 tests/topotests/bgp_show_ip_bgp_fqdn/r1/zebra.conf
  20. delete mode 100644 tests/topotests/bgp_show_ip_bgp_fqdn/r2/bgpd.conf
  21. delete mode 100644 tests/topotests/bgp_show_ip_bgp_fqdn/r2/zebra.conf
  22. delete mode 100644 tests/topotests/bgp_show_ip_bgp_fqdn/r3/bgpd.conf
  23. delete mode 100644 tests/topotests/bgp_show_ip_bgp_fqdn/r3/zebra.conf
  24. delete mode 100644 tests/topotests/bgp_show_ip_bgp_fqdn/test_bgp_show_ip_bgp_fqdn.py
  25. diff --git a/tests/topotests/bgp_show_ip_bgp_fqdn/__init__.py b/tests/topotests/bgp_show_ip_bgp_fqdn/__init__.py
  26. deleted file mode 100644
  27. index e69de29bb2..0000000000
  28. diff --git a/tests/topotests/bgp_show_ip_bgp_fqdn/r1/bgpd.conf b/tests/topotests/bgp_show_ip_bgp_fqdn/r1/bgpd.conf
  29. deleted file mode 100644
  30. index f0df56e947..0000000000
  31. --- a/tests/topotests/bgp_show_ip_bgp_fqdn/r1/bgpd.conf
  32. +++ /dev/null
  33. @@ -1,5 +0,0 @@
  34. -router bgp 65000
  35. - no bgp ebgp-requires-policy
  36. - neighbor 192.168.255.2 remote-as 65001
  37. - address-family ipv4 unicast
  38. - redistribute connected
  39. diff --git a/tests/topotests/bgp_show_ip_bgp_fqdn/r1/zebra.conf b/tests/topotests/bgp_show_ip_bgp_fqdn/r1/zebra.conf
  40. deleted file mode 100644
  41. index 0a283c06d5..0000000000
  42. --- a/tests/topotests/bgp_show_ip_bgp_fqdn/r1/zebra.conf
  43. +++ /dev/null
  44. @@ -1,9 +0,0 @@
  45. -!
  46. -interface lo
  47. - ip address 172.16.255.254/32
  48. -!
  49. -interface r1-eth0
  50. - ip address 192.168.255.1/24
  51. -!
  52. -ip forwarding
  53. -!
  54. diff --git a/tests/topotests/bgp_show_ip_bgp_fqdn/r2/bgpd.conf b/tests/topotests/bgp_show_ip_bgp_fqdn/r2/bgpd.conf
  55. deleted file mode 100644
  56. index 422a7345f9..0000000000
  57. --- a/tests/topotests/bgp_show_ip_bgp_fqdn/r2/bgpd.conf
  58. +++ /dev/null
  59. @@ -1,5 +0,0 @@
  60. -router bgp 65001
  61. - no bgp ebgp-requires-policy
  62. - bgp default show-hostname
  63. - neighbor 192.168.255.1 remote-as 65000
  64. - neighbor 192.168.254.1 remote-as 65001
  65. diff --git a/tests/topotests/bgp_show_ip_bgp_fqdn/r2/zebra.conf b/tests/topotests/bgp_show_ip_bgp_fqdn/r2/zebra.conf
  66. deleted file mode 100644
  67. index e9e2e4391f..0000000000
  68. --- a/tests/topotests/bgp_show_ip_bgp_fqdn/r2/zebra.conf
  69. +++ /dev/null
  70. @@ -1,12 +0,0 @@
  71. -!
  72. -interface lo
  73. - ip address 172.16.255.253/32
  74. -!
  75. -interface r2-eth0
  76. - ip address 192.168.255.2/24
  77. -!
  78. -interface r2-eth1
  79. - ip address 192.168.254.2/24
  80. -!
  81. -ip forwarding
  82. -!
  83. diff --git a/tests/topotests/bgp_show_ip_bgp_fqdn/r3/bgpd.conf b/tests/topotests/bgp_show_ip_bgp_fqdn/r3/bgpd.conf
  84. deleted file mode 100644
  85. index 8fcf6a736d..0000000000
  86. --- a/tests/topotests/bgp_show_ip_bgp_fqdn/r3/bgpd.conf
  87. +++ /dev/null
  88. @@ -1,3 +0,0 @@
  89. -router bgp 65001
  90. - bgp default show-hostname
  91. - neighbor 192.168.254.2 remote-as 65001
  92. diff --git a/tests/topotests/bgp_show_ip_bgp_fqdn/r3/zebra.conf b/tests/topotests/bgp_show_ip_bgp_fqdn/r3/zebra.conf
  93. deleted file mode 100644
  94. index a8b8bc38c5..0000000000
  95. --- a/tests/topotests/bgp_show_ip_bgp_fqdn/r3/zebra.conf
  96. +++ /dev/null
  97. @@ -1,6 +0,0 @@
  98. -!
  99. -interface r3-eth0
  100. - ip address 192.168.254.1/24
  101. -!
  102. -ip forwarding
  103. -!
  104. diff --git a/tests/topotests/bgp_show_ip_bgp_fqdn/test_bgp_show_ip_bgp_fqdn.py b/tests/topotests/bgp_show_ip_bgp_fqdn/test_bgp_show_ip_bgp_fqdn.py
  105. deleted file mode 100644
  106. index e8ad180935..0000000000
  107. --- a/tests/topotests/bgp_show_ip_bgp_fqdn/test_bgp_show_ip_bgp_fqdn.py
  108. +++ /dev/null
  109. @@ -1,133 +0,0 @@
  110. -#!/usr/bin/env python
  111. -
  112. -#
  113. -# test_bgp_show_ip_bgp_fqdn.py
  114. -# Part of NetDEF Topology Tests
  115. -#
  116. -# Copyright (c) 2019 by
  117. -# Donatas Abraitis <donatas.abraitis@gmail.com>
  118. -#
  119. -# Permission to use, copy, modify, and/or distribute this software
  120. -# for any purpose with or without fee is hereby granted, provided
  121. -# that the above copyright notice and this permission notice appear
  122. -# in all copies.
  123. -#
  124. -# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
  125. -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  126. -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
  127. -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
  128. -# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  129. -# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  130. -# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  131. -# OF THIS SOFTWARE.
  132. -#
  133. -
  134. -"""
  135. -test_bgp_show_ip_bgp_fqdn.py:
  136. -Test if FQND is visible in `show [ip] bgp` output if
  137. -`bgp default show-hostname` is toggled.
  138. -
  139. -Topology:
  140. -r1 <-- eBGP --> r2 <-- iBGP --> r3
  141. -
  142. -1. Check if both hostname and ip are added to JSON output
  143. -for 172.16.255.254/32 on r2.
  144. -2. Check if only ip is added to JSON output for 172.16.255.254/32 on r3.
  145. -"""
  146. -
  147. -import os
  148. -import sys
  149. -import json
  150. -import time
  151. -import pytest
  152. -import functools
  153. -
  154. -CWD = os.path.dirname(os.path.realpath(__file__))
  155. -sys.path.append(os.path.join(CWD, "../"))
  156. -
  157. -# pylint: disable=C0413
  158. -from lib import topotest
  159. -from lib.topogen import Topogen, TopoRouter, get_topogen
  160. -from lib.topolog import logger
  161. -from mininet.topo import Topo
  162. -
  163. -
  164. -class TemplateTopo(Topo):
  165. - def build(self, *_args, **_opts):
  166. - tgen = get_topogen(self)
  167. -
  168. - for routern in range(1, 4):
  169. - tgen.add_router("r{}".format(routern))
  170. -
  171. - switch = tgen.add_switch("s1")
  172. - switch.add_link(tgen.gears["r1"])
  173. - switch.add_link(tgen.gears["r2"])
  174. -
  175. - switch = tgen.add_switch("s2")
  176. - switch.add_link(tgen.gears["r2"])
  177. - switch.add_link(tgen.gears["r3"])
  178. -
  179. -
  180. -def setup_module(mod):
  181. - tgen = Topogen(TemplateTopo, mod.__name__)
  182. - tgen.start_topology()
  183. -
  184. - router_list = tgen.routers()
  185. -
  186. - for i, (rname, router) in enumerate(router_list.iteritems(), 1):
  187. - router.load_config(
  188. - TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
  189. - )
  190. - router.load_config(
  191. - TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
  192. - )
  193. -
  194. - tgen.start_router()
  195. -
  196. -
  197. -def teardown_module(mod):
  198. - tgen = get_topogen()
  199. - tgen.stop_topology()
  200. -
  201. -
  202. -def test_bgp_show_ip_bgp_hostname():
  203. - tgen = get_topogen()
  204. -
  205. - if tgen.routers_have_failure():
  206. - pytest.skip(tgen.errors)
  207. -
  208. - def _bgp_converge(router):
  209. - output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.254/32 json"))
  210. - expected = {"prefix": "172.16.255.254/32"}
  211. - return topotest.json_cmp(output, expected)
  212. -
  213. - def _bgp_show_nexthop_hostname_and_ip(router):
  214. - output = json.loads(router.vtysh_cmd("show ip bgp json"))
  215. - for nh in output["routes"]["172.16.255.254/32"][0]["nexthops"]:
  216. - if "hostname" in nh and "ip" in nh:
  217. - return True
  218. - return False
  219. -
  220. - def _bgp_show_nexthop_ip_only(router):
  221. - output = json.loads(router.vtysh_cmd("show ip bgp json"))
  222. - for nh in output["routes"]["172.16.255.254/32"][0]["nexthops"]:
  223. - if "ip" in nh and not "hostname" in nh:
  224. - return True
  225. - return False
  226. -
  227. - test_func = functools.partial(_bgp_converge, tgen.gears["r2"])
  228. - success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
  229. -
  230. - test_func = functools.partial(_bgp_converge, tgen.gears["r3"])
  231. - success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
  232. -
  233. - assert result is None, 'Failed bgp convergence in "{}"'.format(tgen.gears["r2"])
  234. - assert _bgp_show_nexthop_hostname_and_ip(tgen.gears["r2"]) == True
  235. -
  236. - assert result is None, 'Failed bgp convergence in "{}"'.format(tgen.gears["r3"])
  237. - assert _bgp_show_nexthop_ip_only(tgen.gears["r3"]) == True
  238. -
  239. -
  240. -if __name__ == "__main__":
  241. - args = ["-s"] + sys.argv[1:]
  242. - sys.exit(pytest.main(args))
  243. From e7cc3d21452bd771a97bc46ab5a1e4853c46f944 Mon Sep 17 00:00:00 2001
  244. From: Donatas Abraitis <donatas.abraitis@gmail.com>
  245. Date: Wed, 6 May 2020 17:46:10 +0300
  246. Subject: [PATCH 2/4] bgpd: Show the real next-hop address in addition to
  247. hostname in `show bgp`
  248. It's hard to cope with cases when next-hop is changed/unchanged or
  249. peers are non-direct.
  250. It would be better to show the hostname and nexthop IP address (both)
  251. under `show bgp` to quickly identify the source and the real next-hop
  252. of the route.
  253. If `bgp default show-nexthop-hostname` is toggled the output looks like:
  254. ```
  255. spine1-debian-9# show bgp
  256. BGP table version is 1, local router ID is 2.2.2.2, vrf id 0
  257. Default local pref 100, local AS 65002
  258. Status codes: s suppressed, d damped, h history, * valid, > best, = multipath,
  259. i internal, r RIB-failure, S Stale, R Removed
  260. Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
  261. Origin codes: i - IGP, e - EGP, ? - incomplete
  262. Network Next Hop Metric LocPrf Weight Path
  263. * 2a02:4780::/64 fe80::a00:27ff:fe09:f8a3(exit1-debian-9)
  264. 0 0 65001 ?
  265. spine1-debian-9# show ip bgp
  266. BGP table version is 5, local router ID is 2.2.2.2, vrf id 0
  267. Default local pref 100, local AS 65002
  268. Status codes: s suppressed, d damped, h history, * valid, > best, = multipath,
  269. i internal, r RIB-failure, S Stale, R Removed
  270. Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
  271. Origin codes: i - IGP, e - EGP, ? - incomplete
  272. Network Next Hop Metric LocPrf Weight Path
  273. *> 10.255.255.0/24 192.168.0.1(exit1-debian-9)
  274. 0 0 65001 ?
  275. ```
  276. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
  277. ---
  278. bgpd/bgp_route.c | 161 ++++++++++++++++++++++++++++++-----------------
  279. bgpd/bgp_vty.c | 45 +++++++++++++
  280. bgpd/bgpd.h | 1 +
  281. 3 files changed, 149 insertions(+), 58 deletions(-)
  282. diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
  283. index 7bfefde482..f033f525e5 100644
  284. --- a/bgpd/bgp_route.c
  285. +++ b/bgpd/bgp_route.c
  286. @@ -7559,8 +7559,7 @@ static char *bgp_nexthop_hostname(struct peer *peer,
  287. struct bgp_nexthop_cache *bnc)
  288. {
  289. if (peer->hostname
  290. - && CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHOW_HOSTNAME) && bnc
  291. - && CHECK_FLAG(bnc->flags, BGP_NEXTHOP_CONNECTED))
  292. + && CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME))
  293. return peer->hostname;
  294. return NULL;
  295. }
  296. @@ -7570,6 +7569,7 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
  297. struct bgp_path_info *path, int display, safi_t safi,
  298. json_object *json_paths)
  299. {
  300. + int len;
  301. struct attr *attr = path->attr;
  302. json_object *json_path = NULL;
  303. json_object *json_nexthops = NULL;
  304. @@ -7681,10 +7681,19 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
  305. : "ipv6");
  306. json_object_boolean_true_add(json_nexthop_global,
  307. "used");
  308. - } else
  309. - vty_out(vty, "%s%s",
  310. - nexthop_hostname ? nexthop_hostname : nexthop,
  311. - vrf_id_str);
  312. + } else {
  313. + if (nexthop_hostname)
  314. + len = vty_out(vty, "%s(%s)%s", nexthop,
  315. + nexthop_hostname, vrf_id_str);
  316. + else
  317. + len = vty_out(vty, "%s%s", nexthop, vrf_id_str);
  318. +
  319. + len = 16 - len;
  320. + if (len < 1)
  321. + vty_out(vty, "\n%*s", 36, " ");
  322. + else
  323. + vty_out(vty, "%*s", len, " ");
  324. + }
  325. } else if (safi == SAFI_EVPN) {
  326. if (json_paths) {
  327. json_nexthop_global = json_object_new_object();
  328. @@ -7701,11 +7710,20 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
  329. "ipv4");
  330. json_object_boolean_true_add(json_nexthop_global,
  331. "used");
  332. - } else
  333. - vty_out(vty, "%-16s%s",
  334. - nexthop_hostname ? nexthop_hostname
  335. - : inet_ntoa(attr->nexthop),
  336. - vrf_id_str);
  337. + } else {
  338. + if (nexthop_hostname)
  339. + len = vty_out(vty, "%pI4(%s)%s", &attr->nexthop,
  340. + nexthop_hostname, vrf_id_str);
  341. + else
  342. + len = vty_out(vty, "%pI4%s", &attr->nexthop,
  343. + vrf_id_str);
  344. +
  345. + len = 16 - len;
  346. + if (len < 1)
  347. + vty_out(vty, "\n%*s", 36, " ");
  348. + else
  349. + vty_out(vty, "%*s", len, " ");
  350. + }
  351. } else if (safi == SAFI_FLOWSPEC) {
  352. if (attr->nexthop.s_addr != INADDR_ANY) {
  353. if (json_paths) {
  354. @@ -7726,10 +7744,21 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
  355. json_nexthop_global,
  356. "used");
  357. } else {
  358. - vty_out(vty, "%-16s",
  359. - nexthop_hostname
  360. - ? nexthop_hostname
  361. - : inet_ntoa(attr->nexthop));
  362. + if (nexthop_hostname)
  363. + len = vty_out(vty, "%pI4(%s)%s",
  364. + &attr->nexthop,
  365. + nexthop_hostname,
  366. + vrf_id_str);
  367. + else
  368. + len = vty_out(vty, "%pI4%s",
  369. + &attr->nexthop,
  370. + vrf_id_str);
  371. +
  372. + len = 16 - len;
  373. + if (len < 1)
  374. + vty_out(vty, "\n%*s", 36, " ");
  375. + else
  376. + vty_out(vty, "%*s", len, " ");
  377. }
  378. }
  379. } else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
  380. @@ -7749,19 +7778,23 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
  381. json_object_boolean_true_add(json_nexthop_global,
  382. "used");
  383. } else {
  384. - char buf[BUFSIZ];
  385. + if (nexthop_hostname)
  386. + len = vty_out(vty, "%pI4(%s)%s", &attr->nexthop,
  387. + nexthop_hostname, vrf_id_str);
  388. + else
  389. + len = vty_out(vty, "%pI4%s", &attr->nexthop,
  390. + vrf_id_str);
  391. - snprintf(buf, sizeof(buf), "%s%s",
  392. - nexthop_hostname ? nexthop_hostname
  393. - : inet_ntoa(attr->nexthop),
  394. - vrf_id_str);
  395. - vty_out(vty, "%-16s", buf);
  396. + len = 16 - len;
  397. + if (len < 1)
  398. + vty_out(vty, "\n%*s", 36, " ");
  399. + else
  400. + vty_out(vty, "%*s", len, " ");
  401. }
  402. }
  403. /* IPv6 Next Hop */
  404. else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
  405. - int len;
  406. char buf[BUFSIZ];
  407. if (json_paths) {
  408. @@ -7835,15 +7868,18 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
  409. else
  410. vty_out(vty, "%*s", len, " ");
  411. } else {
  412. - len = vty_out(
  413. - vty, "%s%s",
  414. - nexthop_hostname
  415. - ? nexthop_hostname
  416. - : inet_ntop(
  417. - AF_INET6,
  418. - &attr->mp_nexthop_local,
  419. - buf, BUFSIZ),
  420. - vrf_id_str);
  421. + if (nexthop_hostname)
  422. + len = vty_out(
  423. + vty, "%pI6(%s)%s",
  424. + &attr->mp_nexthop_local,
  425. + nexthop_hostname,
  426. + vrf_id_str);
  427. + else
  428. + len = vty_out(
  429. + vty, "%pI6%s",
  430. + &attr->mp_nexthop_local,
  431. + vrf_id_str);
  432. +
  433. len = 16 - len;
  434. if (len < 1)
  435. @@ -7852,15 +7888,16 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
  436. vty_out(vty, "%*s", len, " ");
  437. }
  438. } else {
  439. - len = vty_out(
  440. - vty, "%s%s",
  441. - nexthop_hostname
  442. - ? nexthop_hostname
  443. - : inet_ntop(
  444. - AF_INET6,
  445. - &attr->mp_nexthop_global,
  446. - buf, BUFSIZ),
  447. - vrf_id_str);
  448. + if (nexthop_hostname)
  449. + len = vty_out(vty, "%pI6(%s)%s",
  450. + &attr->mp_nexthop_global,
  451. + nexthop_hostname,
  452. + vrf_id_str);
  453. + else
  454. + len = vty_out(vty, "%pI6%s",
  455. + &attr->mp_nexthop_global,
  456. + vrf_id_str);
  457. +
  458. len = 16 - len;
  459. if (len < 1)
  460. @@ -7986,6 +8023,7 @@ void route_vty_out_tmp(struct vty *vty, const struct prefix *p,
  461. {
  462. json_object *json_status = NULL;
  463. json_object *json_net = NULL;
  464. + int len;
  465. char buff[BUFSIZ];
  466. /* Route status display. */
  467. @@ -8079,7 +8117,6 @@ void route_vty_out_tmp(struct vty *vty, const struct prefix *p,
  468. inet_ntoa(attr->nexthop));
  469. } else if (p->family == AF_INET6
  470. || BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
  471. - int len;
  472. char buf[BUFSIZ];
  473. len = vty_out(
  474. @@ -8823,12 +8860,15 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
  475. json_object_string_add(
  476. json_nexthop_global, "hostname",
  477. nexthop_hostname);
  478. - } else
  479. - vty_out(vty, " %s",
  480. - nexthop_hostname
  481. - ? nexthop_hostname
  482. - : inet_ntoa(
  483. - attr->mp_nexthop_global_in));
  484. + } else {
  485. + if (nexthop_hostname)
  486. + vty_out(vty, " %pI4(%s)",
  487. + &attr->mp_nexthop_global_in,
  488. + nexthop_hostname);
  489. + else
  490. + vty_out(vty, " %pI4",
  491. + &attr->mp_nexthop_global_in);
  492. + }
  493. } else {
  494. if (json_paths) {
  495. json_object_string_add(
  496. @@ -8839,11 +8879,15 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
  497. json_object_string_add(
  498. json_nexthop_global, "hostname",
  499. nexthop_hostname);
  500. - } else
  501. - vty_out(vty, " %s",
  502. - nexthop_hostname
  503. - ? nexthop_hostname
  504. - : inet_ntoa(attr->nexthop));
  505. + } else {
  506. + if (nexthop_hostname)
  507. + vty_out(vty, " %pI4(%s)",
  508. + &attr->nexthop,
  509. + nexthop_hostname);
  510. + else
  511. + vty_out(vty, " %pI4",
  512. + &attr->nexthop);
  513. + }
  514. }
  515. if (json_paths)
  516. @@ -8866,12 +8910,13 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
  517. json_object_string_add(json_nexthop_global, "scope",
  518. "global");
  519. } else {
  520. - vty_out(vty, " %s",
  521. - nexthop_hostname
  522. - ? nexthop_hostname
  523. - : inet_ntop(AF_INET6,
  524. - &attr->mp_nexthop_global,
  525. - buf, INET6_ADDRSTRLEN));
  526. + if (nexthop_hostname)
  527. + vty_out(vty, " %pI6(%s)",
  528. + &attr->mp_nexthop_global,
  529. + nexthop_hostname);
  530. + else
  531. + vty_out(vty, " %pI6",
  532. + &attr->mp_nexthop_global);
  533. }
  534. }
  535. diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
  536. index 78521457fd..7f00ff3fbe 100644
  537. --- a/bgpd/bgp_vty.c
  538. +++ b/bgpd/bgp_vty.c
  539. @@ -84,6 +84,10 @@ FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
  540. { .val_bool = true, .match_profile = "datacenter", },
  541. { .val_bool = false },
  542. )
  543. +FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
  544. + { .val_bool = true, .match_profile = "datacenter", },
  545. + { .val_bool = false },
  546. +)
  547. FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
  548. { .val_bool = true, .match_profile = "datacenter", },
  549. { .val_bool = false },
  550. @@ -422,6 +426,8 @@ int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
  551. SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
  552. if (DFLT_BGP_SHOW_HOSTNAME)
  553. SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
  554. + if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
  555. + SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
  556. if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
  557. SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
  558. if (DFLT_BGP_DETERMINISTIC_MED)
  559. @@ -3100,6 +3106,32 @@ DEFUN (no_bgp_default_show_hostname,
  560. return CMD_SUCCESS;
  561. }
  562. +/* Display hostname in certain command outputs */
  563. +DEFUN (bgp_default_show_nexthop_hostname,
  564. + bgp_default_show_nexthop_hostname_cmd,
  565. + "bgp default show-nexthop-hostname",
  566. + "BGP specific commands\n"
  567. + "Configure BGP defaults\n"
  568. + "Show hostname for nexthop in certain command outputs\n")
  569. +{
  570. + VTY_DECLVAR_CONTEXT(bgp, bgp);
  571. + SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
  572. + return CMD_SUCCESS;
  573. +}
  574. +
  575. +DEFUN (no_bgp_default_show_nexthop_hostname,
  576. + no_bgp_default_show_nexthop_hostname_cmd,
  577. + "no bgp default show-nexthop-hostname",
  578. + NO_STR
  579. + "BGP specific commands\n"
  580. + "Configure BGP defaults\n"
  581. + "Show hostname for nexthop in certain command outputs\n")
  582. +{
  583. + VTY_DECLVAR_CONTEXT(bgp, bgp);
  584. + UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
  585. + return CMD_SUCCESS;
  586. +}
  587. +
  588. /* "bgp network import-check" configuration. */
  589. DEFUN (bgp_network_import_check,
  590. bgp_network_import_check_cmd,
  591. @@ -15190,6 +15222,15 @@ int bgp_config_write(struct vty *vty)
  592. ? ""
  593. : "no ");
  594. + /* BGP default show-nexthop-hostname */
  595. + if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
  596. + != SAVE_BGP_SHOW_HOSTNAME)
  597. + vty_out(vty, " %sbgp default show-nexthop-hostname\n",
  598. + CHECK_FLAG(bgp->flags,
  599. + BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
  600. + ? ""
  601. + : "no ");
  602. +
  603. /* BGP default subgroup-pkt-queue-max. */
  604. if (bgp->default_subgroup_pkt_queue_max
  605. != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
  606. @@ -15815,6 +15856,10 @@ void bgp_vty_init(void)
  607. install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
  608. install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
  609. + /* bgp default show-nexthop-hostname */
  610. + install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
  611. + install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
  612. +
  613. /* "bgp default subgroup-pkt-queue-max" commands. */
  614. install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
  615. install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
  616. diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
  617. index 4a5772a53b..4efc068dea 100644
  618. --- a/bgpd/bgpd.h
  619. +++ b/bgpd/bgpd.h
  620. @@ -447,6 +447,7 @@ struct bgp {
  621. #define BGP_FLAG_SELECT_DEFER_DISABLE (1 << 23)
  622. #define BGP_FLAG_GR_DISABLE_EOR (1 << 24)
  623. #define BGP_FLAG_EBGP_REQUIRES_POLICY (1 << 25)
  624. +#define BGP_FLAG_SHOW_NEXTHOP_HOSTNAME (1 << 26)
  625. enum global_mode GLOBAL_GR_FSM[BGP_GLOBAL_GR_MODE]
  626. [BGP_GLOBAL_GR_EVENT_CMD];
  627. From 104dfe5258cbeb0443fa4d6577794a1e5a5dafd3 Mon Sep 17 00:00:00 2001
  628. From: Donatas Abraitis <donatas.abraitis@gmail.com>
  629. Date: Wed, 6 May 2020 17:50:04 +0300
  630. Subject: [PATCH 3/4] bgpd: Add "hostname" in JSON output for `show bgp` family
  631. outputs
  632. This adds hostname regardless if `bgp default show-hostname` enabled or not.
  633. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
  634. ---
  635. bgpd/bgp_route.c | 40 ++++++++++++++++++++--------------------
  636. 1 file changed, 20 insertions(+), 20 deletions(-)
  637. diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
  638. index f033f525e5..5f645fa871 100644
  639. --- a/bgpd/bgp_route.c
  640. +++ b/bgpd/bgp_route.c
  641. @@ -7671,10 +7671,10 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
  642. json_object_string_add(json_nexthop_global, "ip",
  643. nexthop);
  644. - if (nexthop_hostname)
  645. + if (path->peer->hostname)
  646. json_object_string_add(json_nexthop_global,
  647. "hostname",
  648. - nexthop_hostname);
  649. + path->peer->hostname);
  650. json_object_string_add(json_nexthop_global, "afi",
  651. (af == AF_INET) ? "ipv4"
  652. @@ -7701,10 +7701,10 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
  653. json_object_string_add(json_nexthop_global, "ip",
  654. inet_ntoa(attr->nexthop));
  655. - if (nexthop_hostname)
  656. + if (path->peer->hostname)
  657. json_object_string_add(json_nexthop_global,
  658. "hostname",
  659. - nexthop_hostname);
  660. + path->peer->hostname);
  661. json_object_string_add(json_nexthop_global, "afi",
  662. "ipv4");
  663. @@ -7735,10 +7735,10 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
  664. json_nexthop_global, "ip",
  665. inet_ntoa(attr->nexthop));
  666. - if (nexthop_hostname)
  667. + if (path->peer->hostname)
  668. json_object_string_add(
  669. json_nexthop_global, "hostname",
  670. - nexthop_hostname);
  671. + path->peer->hostname);
  672. json_object_boolean_true_add(
  673. json_nexthop_global,
  674. @@ -7768,10 +7768,10 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
  675. json_object_string_add(json_nexthop_global, "ip",
  676. inet_ntoa(attr->nexthop));
  677. - if (nexthop_hostname)
  678. + if (path->peer->hostname)
  679. json_object_string_add(json_nexthop_global,
  680. "hostname",
  681. - nexthop_hostname);
  682. + path->peer->hostname);
  683. json_object_string_add(json_nexthop_global, "afi",
  684. "ipv4");
  685. @@ -7804,10 +7804,10 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
  686. inet_ntop(AF_INET6, &attr->mp_nexthop_global,
  687. buf, BUFSIZ));
  688. - if (nexthop_hostname)
  689. + if (path->peer->hostname)
  690. json_object_string_add(json_nexthop_global,
  691. "hostname",
  692. - nexthop_hostname);
  693. + path->peer->hostname);
  694. json_object_string_add(json_nexthop_global, "afi",
  695. "ipv6");
  696. @@ -7826,10 +7826,10 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
  697. &attr->mp_nexthop_local, buf,
  698. BUFSIZ));
  699. - if (nexthop_hostname)
  700. + if (path->peer->hostname)
  701. json_object_string_add(
  702. json_nexthop_ll, "hostname",
  703. - nexthop_hostname);
  704. + path->peer->hostname);
  705. json_object_string_add(json_nexthop_ll, "afi",
  706. "ipv6");
  707. @@ -8856,10 +8856,10 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
  708. json_nexthop_global, "ip",
  709. inet_ntoa(attr->mp_nexthop_global_in));
  710. - if (nexthop_hostname)
  711. + if (path->peer->hostname)
  712. json_object_string_add(
  713. json_nexthop_global, "hostname",
  714. - nexthop_hostname);
  715. + path->peer->hostname);
  716. } else {
  717. if (nexthop_hostname)
  718. vty_out(vty, " %pI4(%s)",
  719. @@ -8875,10 +8875,10 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
  720. json_nexthop_global, "ip",
  721. inet_ntoa(attr->nexthop));
  722. - if (nexthop_hostname)
  723. + if (path->peer->hostname)
  724. json_object_string_add(
  725. json_nexthop_global, "hostname",
  726. - nexthop_hostname);
  727. + path->peer->hostname);
  728. } else {
  729. if (nexthop_hostname)
  730. vty_out(vty, " %pI4(%s)",
  731. @@ -8900,10 +8900,10 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
  732. inet_ntop(AF_INET6, &attr->mp_nexthop_global,
  733. buf, INET6_ADDRSTRLEN));
  734. - if (nexthop_hostname)
  735. + if (path->peer->hostname)
  736. json_object_string_add(json_nexthop_global,
  737. "hostname",
  738. - nexthop_hostname);
  739. + path->peer->hostname);
  740. json_object_string_add(json_nexthop_global, "afi",
  741. "ipv6");
  742. @@ -9094,10 +9094,10 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
  743. inet_ntop(AF_INET6, &attr->mp_nexthop_local,
  744. buf, INET6_ADDRSTRLEN));
  745. - if (nexthop_hostname)
  746. + if (path->peer->hostname)
  747. json_object_string_add(json_nexthop_ll,
  748. "hostname",
  749. - nexthop_hostname);
  750. + path->peer->hostname);
  751. json_object_string_add(json_nexthop_ll, "afi", "ipv6");
  752. json_object_string_add(json_nexthop_ll, "scope",
  753. From 8df39282ea64e2a65a7910012627f78d080833b1 Mon Sep 17 00:00:00 2001
  754. From: Donatas Abraitis <donatas.abraitis@gmail.com>
  755. Date: Wed, 24 Jun 2020 17:26:27 +0300
  756. Subject: [PATCH 4/4] doc: Add some words about `bgp default
  757. show-[nexthop]-hostname`
  758. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
  759. ---
  760. doc/user/bgp.rst | 13 +++++++++++++
  761. 1 file changed, 13 insertions(+)
  762. diff --git a/doc/user/bgp.rst b/doc/user/bgp.rst
  763. index 36227db604..a6c29724b0 100644
  764. --- a/doc/user/bgp.rst
  765. +++ b/doc/user/bgp.rst
  766. @@ -1366,6 +1366,19 @@ Configuring Peers
  767. on by default or not. This command defaults to on and is not displayed.
  768. The `no bgp default ipv4-unicast` form of the command is displayed.
  769. +.. index:: [no] bgp default show-hostname
  770. +.. clicmd:: [no] bgp default show-hostname
  771. +
  772. + This command shows the hostname of the peer in certain BGP commands
  773. + outputs. It's easier to troubleshoot if you have a number of BGP peers.
  774. +
  775. +.. index:: [no] bgp default show-nexthop-hostname
  776. +.. clicmd:: [no] bgp default show-nexthop-hostname
  777. +
  778. + This command shows the hostname of the next-hop in certain BGP commands
  779. + outputs. It's easier to troubleshoot if you have a number of BGP peers
  780. + and a number of routes to check.
  781. +
  782. .. index:: [no] neighbor PEER advertisement-interval (0-600)
  783. .. clicmd:: [no] neighbor PEER advertisement-interval (0-600)