]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: display hostname capabilities as advertised and received
authorMitesh Kanjariya <mitesh@marvel-07.cumulusnetworks.com>
Mon, 7 Aug 2017 20:54:57 +0000 (13:54 -0700)
committerMitesh Kanjariya <mitesh@marvel-07.cumulusnetworks.com>
Thu, 17 Aug 2017 08:46:16 +0000 (01:46 -0700)
Ticket: CM-17250
Review: CCR-6567
Testing: Manual

Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com>
bgpd/bgp_vty.c
bgpd/bgpd.c

index de30311e0100d53080015a5b278c650bc083f241..cabbade525f9159d1836de180158e3713c181981 100644 (file)
@@ -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,
index f48ba6af245c033eaecb1b8690f71c4dace1d63e..c58e4e70cd726721a9afdd884785b8bdfaab1715 100644 (file)
@@ -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);