summaryrefslogtreecommitdiff
path: root/proto/bgp/packets.c
diff options
context:
space:
mode:
Diffstat (limited to 'proto/bgp/packets.c')
-rw-r--r--proto/bgp/packets.c41
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 */
}