summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_aspath.c
diff options
context:
space:
mode:
Diffstat (limited to 'bgpd/bgp_aspath.c')
-rw-r--r--bgpd/bgp_aspath.c45
1 files changed, 21 insertions, 24 deletions
diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c
index d0d621c2..c7c40094 100644
--- a/bgpd/bgp_aspath.c
+++ b/bgpd/bgp_aspath.c
@@ -86,7 +86,7 @@ struct assegment_header
};
/* Hash for aspath. This is the top level structure of AS path. */
-struct hash *ashash;
+static struct hash *ashash;
/* Stream for SNMP. See aspath_snmp_pathseg */
static struct stream *snmp_stream;
@@ -322,11 +322,7 @@ assegment_normalise (struct assegment *head)
static struct aspath *
aspath_new (void)
{
- struct aspath *aspath;
-
- aspath = XMALLOC (MTYPE_AS_PATH, sizeof (struct aspath));
- memset (aspath, 0, sizeof (struct aspath));
- return aspath;
+ return XCALLOC (MTYPE_AS_PATH, sizeof (struct aspath));
}
/* Free AS path structure. */
@@ -486,6 +482,7 @@ aspath_has_as4 (struct aspath *aspath)
return 0;
}
+#ifdef unused
/* Return number of as numbers in in path */
unsigned int
aspath_count_numas (struct aspath *aspath)
@@ -501,20 +498,20 @@ aspath_count_numas (struct aspath *aspath)
}
return num;
}
+#endif
-static void
-aspath_make_str_big_enough (int len,
- char **str_buf,
- int *str_size,
- int count_to_be_added)
+/* Expand aspath string */
+static char *
+aspath_expand (char *buf, size_t *size, size_t len, size_t growth)
{
-#define TERMINATOR 1
- while (len + count_to_be_added + TERMINATOR > *str_size)
- {
- *str_size *= 2;
- *str_buf = XREALLOC (MTYPE_AS_STR, *str_buf, *str_size);
- }
-#undef TERMINATOR
+ len += growth + 1; /* space for null terminator */
+ if (len <= *size)
+ return buf;
+
+ while (len > *size)
+ *size += *size / 2;
+
+ return XREALLOC(MTYPE_AS_STR, buf, *size);
}
/* Convert aspath structure to string expression. */
@@ -522,7 +519,7 @@ static char *
aspath_make_str_count (struct aspath *as)
{
struct assegment *seg;
- int str_size;
+ size_t str_size;
int len = 0;
char *str_buf;
@@ -562,7 +559,7 @@ aspath_make_str_count (struct aspath *as)
if (seg->type != AS_SEQUENCE)
{
- aspath_make_str_big_enough (len, &str_buf, &str_size, 1); /* %c */
+ str_buf = aspath_expand(str_buf, &str_size, len, 1); /* %c */
len += snprintf (str_buf + len, str_size - len,
"%c",
aspath_delimiter_char (seg->type, AS_SEG_START));
@@ -573,10 +570,8 @@ aspath_make_str_count (struct aspath *as)
{
#define APPROX_DIG_CNT(x) (x < 100000U ? 5 : 10)
/* %u + %c + %c + " " (last two are below loop) */
- aspath_make_str_big_enough (len,
- &str_buf,
- &str_size,
- APPROX_DIG_CNT(seg->as[i]) + 1 + 1 + 1);
+ str_buf = aspath_expand(str_buf, &str_size, len,
+ APPROX_DIG_CNT(seg->as[i]) + 3);
len += snprintf (str_buf + len, str_size - len, "%u", seg->as[i]);
@@ -1776,6 +1771,7 @@ aspath_init (void)
ashash = hash_create_size (32767, aspath_key_make, aspath_cmp);
}
+#ifdef unused
void
aspath_finish (void)
{
@@ -1784,6 +1780,7 @@ aspath_finish (void)
if (snmp_stream)
stream_free (snmp_stream);
}
+#endif
/* return and as path value */
const char *