]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
MRT Table Dump: Bugfix creating filename from fmt
authorPavel Tvrdík <pawel.tvrdik@gmail.cz>
Mon, 3 Aug 2015 11:06:55 +0000 (13:06 +0200)
committerPavel Tvrdík <pawel.tvrdik@gmail.cz>
Mon, 3 Aug 2015 11:12:32 +0000 (13:12 +0200)
- At *BSD systems a command 'date +%f' returns only 'f' without percent
- Small fixes for *BSD systems

nest/mrtdump.c
nest/mrtdump.h
nest/rt-table.c

index 787cbf983f1dc5ab81e33dd1329adb369a02daee..515a7c4dca60b17e4c299413da903ba86514e948 100644 (file)
@@ -170,8 +170,9 @@ mrt_peer_index_table_add_peer(struct mrt_peer_index_table *state, u32 peer_bgp_i
   struct mrt_buffer *msg = &state->msg;
 
   u8 peer_type = MRT_PEER_TYPE_32BIT_ASN;
-  if (sizeof(peer_ip_addr) > sizeof(ip4_addr))
+#ifdef IPV6
     peer_type |= MRT_PEER_TYPE_IPV6;
+#endif
 
   mrt_buffer_put_var_autosize(msg, peer_type);
   mrt_buffer_put_var_autosize(msg, peer_bgp_id);
index eef1f6772a942342ffedb09ba3462c0306ae8942..d3b134932b0878c45658a124cb6273e57f08a025 100644 (file)
@@ -16,9 +16,9 @@
 #include "nest/route.h"
 #include "lib/event.h"
 
-#define MRT_HDR_LENGTH         12         /* MRT Timestamp + MRT Type + MRT Subtype + MRT Load Length */
-#define MRT_PEER_TYPE_32BIT_ASN        0b00000010 /* MRT Table Dump: Peer Index Table: Peer Type: Use 32bit ASN */
-#define MRT_PEER_TYPE_IPV6     0b00000001 /* MRT Table Dump: Peer Index Table: Peer Type: Use IPv6 IP Address */
+#define MRT_HDR_LENGTH         12      /* MRT Timestamp + MRT Type + MRT Subtype + MRT Load Length */
+#define MRT_PEER_TYPE_32BIT_ASN        2       /* MRT Table Dump: Peer Index Table: Peer Type: Use 32bit ASN */
+#define MRT_PEER_TYPE_IPV6     1       /* MRT Table Dump: Peer Index Table: Peer Type: Use IPv6 IP Address */
 
 #ifdef PATH_MAX
 #define BIRD_PATH_MAX PATH_MAX
index e38c3ddb76c928d0adc7897e3448c9572d7e306d..4420613d8be87042ea52516c2d952b710b9a6764 100644 (file)
@@ -2858,7 +2858,7 @@ mrt_str_replace(const char *orig, const char *rep, const char *with)
    *   ins points to the next occurrence of rep in orig
    *   orig points to the remainder of orig after "end of rep"
    */
-  tmp = result = mb_alloc(&root_pool, strlen(orig) + (len_with - len_rep) * num_of_replacements + 1);
+  tmp = result = mb_alloc(rt_table_pool, strlen(orig) + (len_with - len_rep) * num_of_replacements + 1);
 
   if (!result)
     return NULL;
@@ -2890,17 +2890,17 @@ mrt_table_dump_get_realpath(const char *filename)
 void
 mrt_table_dump_init_file_descriptor(struct mrt_table_dump_ctx *state)
 {
-  struct timeformat timestamp_fmt = {
-      .fmt1 = mrt_table_dump_config_get_filename_fmt(state),
-  };
-
-  char timestamp[TM_DATETIME_BUFFER_SIZE];
-  tm_format_datetime(timestamp, &timestamp_fmt, now);
   char *tablename = state->config.table_cf->name;
-  char *filename = mrt_str_replace(timestamp, "%f", tablename);
+  char *filename_fmt = mrt_str_replace(mrt_table_dump_config_get_filename_fmt(state), "%f", tablename);
 
-  if (filename)
+  if (filename_fmt)
   {
+    struct timeformat timestamp_fmt = {
+       .fmt1 = filename_fmt,
+    };
+
+    char filename[TM_DATETIME_BUFFER_SIZE];
+    tm_format_datetime(filename, &timestamp_fmt, now);
     state->rfile = tracked_fopen(rt_table_pool, filename, "a");
 
     const char *filename_fullpath = mrt_table_dump_get_realpath(filename);
@@ -2923,14 +2923,14 @@ mrt_table_dump_init_file_descriptor(struct mrt_table_dump_ctx *state)
        cli_msg(13, "Dump of table %s is saving into file \"%s\"", tablename, state->file_path);
       }
     }
-    mb_free(filename);
+    mb_free(filename_fmt);
   }
   else
   {
-    log(L_ERR "Parsing MRT dump filename format \"%s\" for table %s failed", timestamp_fmt.fmt1, tablename);
+    log(L_ERR "Parsing MRT dump filename filename_fmt \"%s\" for table %s failed", mrt_table_dump_config_get_filename_fmt(state), tablename);
     if (state->config.c.cli)
     {
-      cli_msg(13, "Parsing filename format \"%s\" for table %s failed", timestamp_fmt.fmt1, tablename);
+      cli_msg(13, "Parsing filename filename_fmt \"%s\" for table %s failed", mrt_table_dump_config_get_filename_fmt(state), tablename);
     }
   }
 }