From: Pavel TvrdĂ­k Date: Mon, 3 Aug 2015 11:06:55 +0000 (+0200) Subject: MRT Table Dump: Bugfix creating filename from fmt X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d2d8293b7cc1564b134250ff9dacd910afbea79;p=thirdparty%2Fbird.git MRT Table Dump: Bugfix creating filename from fmt - At *BSD systems a command 'date +%f' returns only 'f' without percent - Small fixes for *BSD systems --- diff --git a/nest/mrtdump.c b/nest/mrtdump.c index 787cbf983..515a7c4dc 100644 --- a/nest/mrtdump.c +++ b/nest/mrtdump.c @@ -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); diff --git a/nest/mrtdump.h b/nest/mrtdump.h index eef1f6772..d3b134932 100644 --- a/nest/mrtdump.h +++ b/nest/mrtdump.h @@ -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 diff --git a/nest/rt-table.c b/nest/rt-table.c index e38c3ddb7..4420613d8 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -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, ×tamp_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, ×tamp_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); } } }