summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bgpd/bgp_fsm.c18
-rw-r--r--bgpd/bgpd.c1
-rw-r--r--tests/topotests/bgp_dont_capability_negotiate/r1/bgpd.conf6
-rw-r--r--tests/topotests/bgp_dont_capability_negotiate/r2/bgpd.conf2
-rw-r--r--tests/topotests/bgp_dont_capability_negotiate/test_bgp_dont_capability_negotiate.py97
5 files changed, 102 insertions, 22 deletions
diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c
index c57e148ef8..9624adfbe2 100644
--- a/bgpd/bgp_fsm.c
+++ b/bgpd/bgp_fsm.c
@@ -279,22 +279,20 @@ static struct peer *peer_xfer_conn(struct peer *from_peer)
}
}
+ if (peer->hostname) {
+ XFREE(MTYPE_BGP_PEER_HOST, peer->hostname);
+ peer->hostname = NULL;
+ }
if (from_peer->hostname != NULL) {
- if (peer->hostname) {
- XFREE(MTYPE_BGP_PEER_HOST, peer->hostname);
- peer->hostname = NULL;
- }
-
peer->hostname = from_peer->hostname;
from_peer->hostname = NULL;
}
+ if (peer->domainname) {
+ XFREE(MTYPE_BGP_PEER_HOST, peer->domainname);
+ peer->domainname = NULL;
+ }
if (from_peer->domainname != NULL) {
- if (peer->domainname) {
- XFREE(MTYPE_BGP_PEER_HOST, peer->domainname);
- peer->domainname = NULL;
- }
-
peer->domainname = from_peer->domainname;
from_peer->domainname = NULL;
}
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 1fd394a849..39010e76f9 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -1156,6 +1156,7 @@ static void peer_free(struct peer *peer)
XFREE(MTYPE_PEER_DESC, peer->desc);
XFREE(MTYPE_BGP_PEER_HOST, peer->host);
+ XFREE(MTYPE_BGP_PEER_HOST, peer->hostname);
XFREE(MTYPE_BGP_PEER_HOST, peer->domainname);
XFREE(MTYPE_BGP_PEER_IFNAME, peer->ifname);
diff --git a/tests/topotests/bgp_dont_capability_negotiate/r1/bgpd.conf b/tests/topotests/bgp_dont_capability_negotiate/r1/bgpd.conf
index b429efe076..e2ff1df965 100644
--- a/tests/topotests/bgp_dont_capability_negotiate/r1/bgpd.conf
+++ b/tests/topotests/bgp_dont_capability_negotiate/r1/bgpd.conf
@@ -1,6 +1,12 @@
!
+debug bgp neighbor
+!
router bgp 65001
no bgp ebgp-requires-policy
+ bgp default show-hostname
+ bgp default show-nexthop-hostname
neighbor 192.168.1.2 remote-as external
+ neighbor 192.168.1.2 timers 1 3
+ neighbor 192.168.1.2 timers connect 1
neighbor 192.168.1.2 dont-capability-negotiate
!
diff --git a/tests/topotests/bgp_dont_capability_negotiate/r2/bgpd.conf b/tests/topotests/bgp_dont_capability_negotiate/r2/bgpd.conf
index 4af2cd6a80..06e1e54b6f 100644
--- a/tests/topotests/bgp_dont_capability_negotiate/r2/bgpd.conf
+++ b/tests/topotests/bgp_dont_capability_negotiate/r2/bgpd.conf
@@ -1,6 +1,8 @@
router bgp 65002
no bgp ebgp-requires-policy
neighbor 192.168.1.1 remote-as external
+ neighbor 192.168.1.1 timers 1 3
+ neighbor 192.168.1.1 timers connect 1
address-family ipv4 unicast
redistribute connected
exit-address-family
diff --git a/tests/topotests/bgp_dont_capability_negotiate/test_bgp_dont_capability_negotiate.py b/tests/topotests/bgp_dont_capability_negotiate/test_bgp_dont_capability_negotiate.py
index 272fdd334a..211472e57d 100644
--- a/tests/topotests/bgp_dont_capability_negotiate/test_bgp_dont_capability_negotiate.py
+++ b/tests/topotests/bgp_dont_capability_negotiate/test_bgp_dont_capability_negotiate.py
@@ -37,6 +37,7 @@ sys.path.append(os.path.join(CWD, "../"))
# pylint: disable=C0413
from lib import topotest
from lib.topogen import Topogen, TopoRouter, get_topogen
+from lib.common_config import step
pytestmark = [pytest.mark.bgpd]
@@ -64,32 +65,104 @@ def teardown_module(mod):
tgen.stop_topology()
+def bgp_converge(router):
+ output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast summary json"))
+ expected = {
+ "peers": {
+ "192.168.1.2": {
+ "pfxRcd": 2,
+ "pfxSnt": 2,
+ "state": "Established",
+ "peerState": "OK",
+ }
+ }
+ }
+ return topotest.json_cmp(output, expected)
+
+
def test_bgp_dont_capability_negotiate():
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
- router = tgen.gears["r1"]
+ r1 = tgen.gears["r1"]
+
+ test_func = functools.partial(bgp_converge, r1)
+ _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
+ assert result is None, "Can't converge with dont-capability-negotiate"
+
+
+def test_bgp_check_fqdn():
+ tgen = get_topogen()
- def _bgp_converge(router):
- output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast summary json"))
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ r1 = tgen.gears["r1"]
+ r2 = tgen.gears["r2"]
+
+ def _bgp_check_fqdn(fqdn=None):
+ output = json.loads(r1.vtysh_cmd("show bgp ipv4 unicast 172.16.16.1/32 json"))
expected = {
- "peers": {
- "192.168.1.2": {
- "pfxRcd": 2,
- "pfxSnt": 2,
- "state": "Established",
- "peerState": "OK",
+ "paths": [
+ {
+ "nexthops": [
+ {
+ "hostname": fqdn,
+ }
+ ],
+ "peer": {
+ "hostname": fqdn,
+ },
}
- }
+ ]
}
return topotest.json_cmp(output, expected)
- test_func = functools.partial(_bgp_converge, router)
- success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
+ step("Enable all capabilities")
+ r1.vtysh_cmd(
+ """
+ configure terminal
+ router bgp
+ address-family ipv4 unicast
+ no neighbor 192.168.1.2 dont-capability-negotiate
+ end
+ clear bgp 192.168.1.2
+ """
+ )
+
+ step("Wait to converge")
+ test_func = functools.partial(bgp_converge, r1)
+ _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
+ assert result is None, "Can't converge with dont-capability-negotiate"
+
+ test_func = functools.partial(_bgp_check_fqdn, "r2")
+ _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
+ assert result is None, "FQDN capability enabled, but r1 can't see it"
+
+ step("Disable sending any capabilities from r2")
+ r2.vtysh_cmd(
+ """
+ configure terminal
+ router bgp
+ address-family ipv4 unicast
+ neighbor 192.168.1.1 dont-capability-negotiate
+ end
+ clear bgp 192.168.1.1
+ """
+ )
+
+ step("Wait to converge")
+ test_func = functools.partial(bgp_converge, r1)
+ _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
assert result is None, "Can't converge with dont-capability-negotiate"
+ step("Make sure FQDN capability is reset")
+ test_func = functools.partial(_bgp_check_fqdn)
+ _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
+ assert result is None, "FQDN capability disabled, but we still have a hostname"
+
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]