summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitesh Kanjariya <mitesh@marvel-07.cumulusnetworks.com>2017-08-07 13:54:57 -0700
committerMitesh Kanjariya <mitesh@marvel-07.cumulusnetworks.com>2017-08-17 01:46:16 -0700
commitd77114b704bf6dd9a767e31f75af44dd5259cdcc (patch)
tree818ef1fc564db1c667ea11ad8c018370775e71b0
parentc6462ff4b3134fb986310852d8001d8f9917a621 (diff)
bgpd: display hostname capabilities as advertised and received
Ticket: CM-17250 Review: CCR-6567 Testing: Manual Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com>
-rw-r--r--bgpd/bgp_vty.c84
-rw-r--r--bgpd/bgpd.c21
2 files changed, 85 insertions, 20 deletions
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index de30311e01..cabbade525 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -8651,6 +8651,46 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
json_cap, "multiprotocolExtensions",
json_multi);
+ /* Hostname capabilities */
+ json_object *json_hname = NULL;
+
+ json_hname = json_object_new_object();
+
+ if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
+ json_object_string_add(
+ json_hname,
+ "advHostName",
+ bgp->peer_self->hostname ?
+ bgp->peer_self->hostname
+ : "n/a");
+ json_object_string_add(
+ json_hname,
+ "advDomainName",
+ bgp->peer_self->domainname ?
+ bgp->peer_self->domainname
+ : "n/a");
+ }
+
+
+ if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
+ json_object_string_add(
+ json_hname,
+ "rcvHostName",
+ p->hostname ?
+ p->hostname :
+ "n/a");
+ json_object_string_add(
+ json_hname,
+ "rcvDomainName",
+ p->domainname ?
+ p->domainname :
+ "n/a");
+ }
+
+ json_object_object_add(json_cap,
+ "hostName",
+ json_hname);
+
/* Gracefull Restart */
if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
|| CHECK_FLAG(p->cap,
@@ -8984,25 +9024,35 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
}
/* Hostname capability */
- if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)
- || CHECK_FLAG(p->cap,
- PEER_CAP_HOSTNAME_RCV)) {
- vty_out(vty,
- " Hostname Capability:");
- if (CHECK_FLAG(p->cap,
- PEER_CAP_HOSTNAME_ADV))
- vty_out(vty, " advertised");
- if (CHECK_FLAG(p->cap,
- PEER_CAP_HOSTNAME_RCV))
- vty_out(vty, " %sreceived",
- CHECK_FLAG(
- p->cap,
- PEER_CAP_HOSTNAME_ADV)
- ? "and "
- : "");
- vty_out(vty, "\n");
+ vty_out(vty,
+ " Hostname Capability:");
+
+ if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
+ vty_out(vty, " advertised (name: %s, "
+ "domain name: %s)",
+ bgp->peer_self->hostname ?
+ bgp->peer_self->hostname
+ : "n/a",
+ bgp->peer_self->domainname ?
+ bgp->peer_self->domainname
+ : "n/a");
+ } else {
+ vty_out(vty, " not advertised");
}
+ if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
+ vty_out(vty, " received (name: %s, "
+ "domain name: %s)",
+ p->hostname ?
+ p->hostname : "n/a",
+ p->domainname ?
+ p->domainname : "n/a");
+ } else {
+ vty_out(vty, " not received");
+ }
+
+ vty_out(vty, "\n");
+
/* Gracefull Restart */
if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
|| CHECK_FLAG(p->cap,
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index f48ba6af24..c58e4e70cd 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -2735,9 +2735,12 @@ static int bgp_startup_timer_expire(struct thread *thread)
static struct bgp *bgp_create(as_t *as, const char *name,
enum bgp_instance_type inst_type)
{
- struct bgp *bgp;
- afi_t afi;
- safi_t safi;
+ struct bgp *bgp;
+ afi_t afi;
+ safi_t safi;
+ struct utsname names;
+
+ uname(&names);
if ((bgp = XCALLOC(MTYPE_BGP, sizeof(struct bgp))) == NULL)
return NULL;
@@ -2762,6 +2765,18 @@ static struct bgp *bgp_create(as_t *as, const char *name,
XFREE(MTYPE_BGP_PEER_HOST, bgp->peer_self->host);
bgp->peer_self->host =
XSTRDUP(MTYPE_BGP_PEER_HOST, "Static announcement");
+ if (bgp->peer_self->hostname != NULL) {
+ XFREE(MTYPE_BGP_PEER_HOST, bgp->peer_self->hostname);
+ bgp->peer_self->hostname = NULL;
+ }
+
+ if (bgp->peer_self->domainname != NULL) {
+ XFREE(MTYPE_BGP_PEER_HOST, bgp->peer_self->domainname);
+ bgp->peer_self->domainname = NULL;
+ }
+ bgp->peer_self->hostname = XSTRDUP(MTYPE_BGP_PEER_HOST, names.nodename);
+ bgp->peer_self->domainname = XSTRDUP(MTYPE_BGP_PEER_HOST,
+ names.domainname);
bgp->peer = list_new();
bgp->peer->cmp = (int (*)(void *, void *))peer_cmp;
bgp->peerhash = hash_create(peer_hash_key_make, peer_hash_same, NULL);