]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Add option hostname for each protocol
authorJana Babovakova <babovakova.jana@gmail.com>
Wed, 12 Feb 2025 16:06:39 +0000 (17:06 +0100)
committerJana Babovakova <babovakova.jana@gmail.com>
Tue, 25 Feb 2025 14:45:06 +0000 (15:45 +0100)
conf/conf.h
doc/bird.sgml
nest/config.Y
nest/protocol.h
proto/bgp/bgp.c
proto/bgp/bgp.h
proto/bgp/packets.c

index dd2966520578289de2a3081d8c71d3474b1a7a2b..921ebb69daa291a56b4f4f4ac98a899236f8eff6 100644 (file)
@@ -34,6 +34,7 @@ struct config {
   struct iface_patt *router_id_from;   /* Configured list of router ID iface patterns */
 
   u32 router_id;                       /* Our Router ID */
+  const char *hostname;                        /* Hostname */
   u32 proto_default_debug;             /* Default protocol debug mask */
   u32 proto_default_mrtdump;           /* Default protocol mrtdump mask */
   u32 channel_default_debug;           /* Default channel debug mask */
@@ -43,7 +44,6 @@ struct config {
   struct timeformat tf_log;            /* Time format for the logfile */
   struct timeformat tf_base;           /* Time format for other purposes */
   u32 gr_wait;                         /* Graceful restart wait timeout (sec) */
-  const char *hostname;                        /* Hostname */
 
   int cli_debug;                       /* Tracing of CLI connections and commands */
   int latency_debug;                   /* I/O loop tracks duration of each event */
index d400b3491c1a9109e6d0a5776610d3421c5e09f9..d408cace2964817a361337a5f8e4241f932a7580 100644 (file)
@@ -836,6 +836,10 @@ agreement").
        This option can be used to override global router id for a given
        protocol. Default: uses global router id.
 
+       <tag><label id="proto-hostname">hostname "<m/name/"</tag>
+       This option can be used to override global hostname for a given
+       protocol. Default: uses global hostname.
+
        <tag><label id="proto-description">description "<m/text/"</tag>
        This is an optional description of the protocol. It is displayed as a
        part of the output of 'show protocols all' command.
index 47fef3d7951466f417a9c0969a2f62d307121df7..4e5095bdc79f08ac5da73f40368b22f8982b87fe 100644 (file)
@@ -302,6 +302,7 @@ proto_item:
  | DEBUG debug_mask { this_proto->debug = $2; }
  | MRTDUMP mrtdump_mask { this_proto->mrtdump = $2; }
  | ROUTER ID idval { this_proto->router_id = $3; }
+ | HOSTNAME text { this_proto->hostname = $2; }
  | DESCRIPTION text { this_proto->dsc = $2; }
  | VRF text { this_proto->vrf = if_get_by_name($2); this_proto->vrf_set = 1; }
  | VRF DEFAULT { this_proto->vrf = NULL; this_proto->vrf_set = 1; }
index d577820eec7a4569928525a2c77e0bbef274085a..32f2c2e8ab88a35f9935438b3d75cfcee7b2167e 100644 (file)
@@ -127,6 +127,7 @@ struct proto_config {
   u8 vrf_set;                          /* Related VRF instance (below) is defined */
   u32 debug, mrtdump;                  /* Debugging bitfields, both use D_* constants */
   u32 router_id;                       /* Protocol specific router ID */
+  const char *hostname;                        /* Protocol specific hostname */
 
   list channels;                       /* List of channel configs (struct channel_config) */
   struct iface *vrf;                   /* Related VRF instance, NULL if global */
@@ -311,6 +312,12 @@ proto_get_router_id(struct proto_config *pc)
   return pc->router_id ? pc->router_id : pc->global->router_id;
 }
 
+static inline const char*
+proto_get_hostname(struct proto_config *pc)
+{
+  return pc->hostname ? pc->hostname : pc->global->hostname;
+}
+
 
 extern pool *proto_pool;
 extern list proto_list;
index 405be13f183ef08ac939e87d2ddabfa2b25ca94c..e6e01e7ba06a697b5b21afb708649ac548b399e9 100644 (file)
@@ -1599,6 +1599,8 @@ bgp_start(struct proto *P)
   p->startup_timer = tm_new_init(p->p.pool, bgp_startup_timeout, p, 0, 0);
   p->gr_timer = tm_new_init(p->p.pool, bgp_graceful_restart_timeout, p, 0, 0);
 
+  p->hostname = proto_get_hostname(P->cf);
+
   p->local_id = proto_get_router_id(P->cf);
   if (p->rr_client)
     p->rr_cluster_id = p->cf->rr_cluster_id ? p->cf->rr_cluster_id : p->local_id;
@@ -2215,6 +2217,9 @@ bgp_reconfigure(struct proto *P, struct proto_config *CF)
   if (proto_get_router_id(CF) != p->local_id)
     return 0;
 
+  if (proto_get_hostname(CF) != p->hostname)
+    return 0;
+
   int same = !memcmp(((byte *) old) + sizeof(struct proto_config),
                     ((byte *) new) + sizeof(struct proto_config),
                     // password item is last and must be checked separately
index bd6fe2de4b9033288a7a9485eac0f9bb821bb1ec..1585f6800554971018b7f361de20f01a96e3c8ba 100644 (file)
@@ -330,6 +330,7 @@ struct bgp_conn {
 struct bgp_proto {
   struct proto p;
   const struct bgp_config *cf;         /* Shortcut to BGP configuration */
+  const char *hostname;      /* Hostname for this BGP protocol */
   ip_addr local_ip, remote_ip;
   u32 local_as, remote_as;
   u32 public_as;                       /* Externally visible ASN (local_as or confederation id) */
index b5e0a30c814c9d6e49a8101c6c4b14f61229ea4f..bfb8c672e8d44b296d829112ce0ce4215564d8a9 100644 (file)
@@ -281,11 +281,11 @@ bgp_prepare_capabilities(struct bgp_conn *conn)
   if (p->cf->llgr_mode)
     caps->llgr_aware = 1;
 
-  if (p->cf->enable_hostname && config->hostname)
+  if (p->cf->enable_hostname && p->hostname)
   {
-    size_t length = strlen(config->hostname);
+    size_t length = strlen(p->hostname);
     char *hostname = mb_allocz(p->p.pool, length+1);
-    memcpy(hostname, config->hostname, length+1);
+    memcpy(hostname, p->hostname, length+1);
     caps->hostname = hostname;
   }