diff options
author | Vincent Bernat <vincent@bernat.ch> | 2021-02-10 16:53:57 +0100 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2021-02-10 16:53:57 +0100 |
commit | 714238716ef36f1dfc5721055e2ec4affd42ebfa (patch) | |
tree | 50564bd78326443e2376f2095251b6b1c0871afc /proto/bgp/packets.c | |
parent | 00b85905b9f5081eb2fce0ed79542085278e9f42 (diff) |
BGP: Add support for BGP hostname capability
This is an implementation of draft-walton-bgp-hostname-capability-02.
It is implemented since quite some time for FRR and in datacenter, this
gives a nice output to avoid using IP addresses.
It is disabled by default. The hostname is retrieved from uname(2) and
can be overriden with "hostname" option. The domain name is never set
nor displayed.
Minor changes by committer.
Diffstat (limited to 'proto/bgp/packets.c')
-rw-r--r-- | proto/bgp/packets.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index 78fdd1e0..b16ee242 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -252,6 +252,14 @@ bgp_prepare_capabilities(struct bgp_conn *conn) if (p->cf->llgr_mode) caps->llgr_aware = 1; + if (p->cf->enable_hostname && config->hostname) + { + size_t length = strlen(config->hostname); + char *hostname = mb_allocz(p->p.pool, length+1); + memcpy(hostname, config->hostname, length+1); + caps->hostname = hostname; + } + /* Allocate and fill per-AF fields */ WALK_LIST(c, p->p.channels) { @@ -412,6 +420,24 @@ bgp_write_capabilities(struct bgp_conn *conn, byte *buf) data[-1] = buf - data; } + if (caps->hostname) + { + *buf++ = 73; /* Capability 73: Hostname */ + *buf++ = 0; /* Capability data length */ + data = buf; + + /* Hostname */ + size_t length = strlen(caps->hostname); + *buf++ = length; + memcpy(buf, caps->hostname, length); + buf += length; + + /* Domain, not implemented */ + *buf++ = 0; + + data[-1] = buf - data; + } + caps->length = buf - buf_head; return buf; @@ -573,6 +599,21 @@ bgp_read_capabilities(struct bgp_conn *conn, byte *pos, int len) } break; + case 73: /* Hostname, RFC draft */ + if ((cl < 2) || (cl < 2 + pos[2])) + goto err; + + int length = pos[2]; + char *hostname = mb_allocz(p->p.pool, length+1); + memcpy(hostname, pos + 3, length); + hostname[length] = 0; + + for (i = 0; i < length; i++) + if (hostname[i] < ' ') + hostname[i] = ' '; + + caps->hostname = hostname; + /* We can safely ignore all other capabilities */ } |