summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/command.c10
-rw-r--r--lib/distribute.c11
-rw-r--r--lib/filter.c4
-rw-r--r--lib/hash.c7
-rw-r--r--lib/hash.h6
-rw-r--r--lib/if_rmap.c11
-rw-r--r--lib/keychain.c14
-rw-r--r--lib/linklist.c12
-rw-r--r--lib/log.c4
-rw-r--r--lib/log.h47
-rw-r--r--lib/memory.c2
-rw-r--r--lib/plist.c4
-rw-r--r--lib/routemap.c2
-rw-r--r--lib/smux.c2
-rw-r--r--lib/sockopt.h1
-rw-r--r--lib/sockunion.c3
-rw-r--r--lib/thread.c6
-rw-r--r--lib/vty.h7
-rw-r--r--lib/zassert.h14
-rw-r--r--lib/zclient.c3
20 files changed, 85 insertions, 85 deletions
diff --git a/lib/command.c b/lib/command.c
index 270bf0d3..a9085eb7 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -41,31 +41,31 @@ vector cmdvec = NULL;
struct host host;
/* Standard command node structures. */
-struct cmd_node auth_node =
+static struct cmd_node auth_node =
{
AUTH_NODE,
"Password: ",
};
-struct cmd_node view_node =
+static struct cmd_node view_node =
{
VIEW_NODE,
"%s> ",
};
-struct cmd_node auth_enable_node =
+static struct cmd_node auth_enable_node =
{
AUTH_ENABLE_NODE,
"Password: ",
};
-struct cmd_node enable_node =
+static struct cmd_node enable_node =
{
ENABLE_NODE,
"%s# ",
};
-struct cmd_node config_node =
+static struct cmd_node config_node =
{
CONFIG_NODE,
"%s(config)# ",
diff --git a/lib/distribute.c b/lib/distribute.c
index 3d616211..242a225c 100644
--- a/lib/distribute.c
+++ b/lib/distribute.c
@@ -38,12 +38,7 @@ void (*distribute_delete_hook) (struct distribute *);
static struct distribute *
distribute_new (void)
{
- struct distribute *new;
-
- new = XMALLOC (MTYPE_DISTRIBUTE, sizeof (struct distribute));
- memset (new, 0, sizeof (struct distribute));
-
- return new;
+ return XCALLOC (MTYPE_DISTRIBUTE, sizeof (struct distribute));
}
/* Free distribute object. */
@@ -134,7 +129,7 @@ distribute_hash_make (struct distribute *dist)
/* If two distribute-list have same value then return 1 else return
0. This function is used by hash package. */
static int
-distribute_cmp (struct distribute *dist1, struct distribute *dist2)
+distribute_cmp (const struct distribute *dist1, const struct distribute *dist2)
{
if (dist1->ifname && dist2->ifname)
if (strcmp (dist1->ifname, dist2->ifname) == 0)
@@ -769,7 +764,7 @@ void
distribute_list_init (int node)
{
disthash = hash_create ((unsigned int (*) (void *)) distribute_hash_make,
- (int (*) (void *, void *)) distribute_cmp);
+ (int (*) (const void *, const void *)) distribute_cmp);
if(node==RIP_NODE) {
install_element (RIP_NODE, &distribute_list_all_cmd);
diff --git a/lib/filter.c b/lib/filter.c
index 069919bb..1509cc31 100644
--- a/lib/filter.c
+++ b/lib/filter.c
@@ -1857,7 +1857,7 @@ config_write_access (struct vty *vty, afi_t afi)
}
/* Access-list node. */
-struct cmd_node access_node =
+static struct cmd_node access_node =
{
ACCESS_NODE,
"", /* Access list has no interface. */
@@ -1953,7 +1953,7 @@ access_list_init_ipv4 (void)
}
#ifdef HAVE_IPV6
-struct cmd_node access_ipv6_node =
+static struct cmd_node access_ipv6_node =
{
ACCESS_IPV6_NODE,
"",
diff --git a/lib/hash.c b/lib/hash.c
index 76bf802a..f705e5dd 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -27,14 +27,13 @@
/* Allocate a new hash. */
struct hash *
hash_create_size (unsigned int size, unsigned int (*hash_key) (void *),
- int (*hash_cmp) (void *, void *))
+ int (*hash_cmp) (const void *, const void *))
{
struct hash *hash;
hash = XMALLOC (MTYPE_HASH, sizeof (struct hash));
- hash->index = XMALLOC (MTYPE_HASH_INDEX,
+ hash->index = XCALLOC (MTYPE_HASH_INDEX,
sizeof (struct hash_backet *) * size);
- memset (hash->index, 0, sizeof (struct hash_backet *) * size);
hash->size = size;
hash->hash_key = hash_key;
hash->hash_cmp = hash_cmp;
@@ -46,7 +45,7 @@ hash_create_size (unsigned int size, unsigned int (*hash_key) (void *),
/* Allocate a new hash with default hash size. */
struct hash *
hash_create (unsigned int (*hash_key) (void *),
- int (*hash_cmp) (void *, void *))
+ int (*hash_cmp) (const void *, const void *))
{
return hash_create_size (HASHTABSIZE, hash_key, hash_cmp);
}
diff --git a/lib/hash.h b/lib/hash.h
index a6e3d59a..f4b1c23e 100644
--- a/lib/hash.h
+++ b/lib/hash.h
@@ -48,16 +48,16 @@ struct hash
unsigned int (*hash_key) (void *);
/* Data compare function. */
- int (*hash_cmp) (void *, void *);
+ int (*hash_cmp) (const void *, const void *);
/* Backet alloc. */
unsigned long count;
};
extern struct hash *hash_create (unsigned int (*) (void *),
- int (*) (void *, void *));
+ int (*) (const void *, const void *));
extern struct hash *hash_create_size (unsigned int, unsigned int (*) (void *),
- int (*) (void *, void *));
+ int (*) (const void *, const void *));
extern void *hash_get (struct hash *, void *, void * (*) (void *));
extern void *hash_alloc_intern (void *);
diff --git a/lib/if_rmap.c b/lib/if_rmap.c
index e6f753c2..ddc62fd5 100644
--- a/lib/if_rmap.c
+++ b/lib/if_rmap.c
@@ -120,13 +120,12 @@ if_rmap_hash_make (void *data)
}
static int
-if_rmap_hash_cmp (void *arg1, void* arg2)
+if_rmap_hash_cmp (const void *arg1, const void* arg2)
{
- struct if_rmap *if_rmap1 = arg1;
- struct if_rmap *if_rmap2 = arg2;
- if (strcmp (if_rmap1->ifname, if_rmap2->ifname) == 0)
- return 1;
- return 0;
+ const struct if_rmap *if_rmap1 = arg1;
+ const struct if_rmap *if_rmap2 = arg2;
+
+ return strcmp (if_rmap1->ifname, if_rmap2->ifname) == 0;
}
static struct if_rmap *
diff --git a/lib/keychain.c b/lib/keychain.c
index 10928b11..6719cebf 100644
--- a/lib/keychain.c
+++ b/lib/keychain.c
@@ -31,10 +31,7 @@ struct list *keychain_list;
static struct keychain *
keychain_new (void)
{
- struct keychain *new;
- new = XMALLOC (MTYPE_KEYCHAIN, sizeof (struct keychain));
- memset (new, 0, sizeof (struct keychain));
- return new;
+ return XCALLOC (MTYPE_KEYCHAIN, sizeof (struct keychain));
}
static void
@@ -46,10 +43,7 @@ keychain_free (struct keychain *keychain)
static struct key *
key_new (void)
{
- struct key *new;
- new = XMALLOC (MTYPE_KEY, sizeof (struct key));
- memset (new, 0, sizeof (struct key));
- return new;
+ return XCALLOC (MTYPE_KEY, sizeof (struct key));
}
static void
@@ -854,14 +848,14 @@ DEFUN (send_lifetime_duration_month_day,
argv[3], argv[4]);
}
-struct cmd_node keychain_node =
+static struct cmd_node keychain_node =
{
KEYCHAIN_NODE,
"%s(config-keychain)# ",
1
};
-struct cmd_node keychain_key_node =
+static struct cmd_node keychain_key_node =
{
KEYCHAIN_KEY_NODE,
"%s(config-keychain-key)# ",
diff --git a/lib/linklist.c b/lib/linklist.c
index a16e9e18..485a80be 100644
--- a/lib/linklist.c
+++ b/lib/linklist.c
@@ -28,11 +28,7 @@
struct list *
list_new (void)
{
- struct list *new;
-
- new = XMALLOC (MTYPE_LINK_LIST, sizeof (struct list));
- memset (new, 0, sizeof (struct list));
- return new;
+ return XCALLOC (MTYPE_LINK_LIST, sizeof (struct list));
}
/* Free list. */
@@ -46,11 +42,7 @@ list_free (struct list *l)
static struct listnode *
listnode_new (void)
{
- struct listnode *node;
-
- node = XMALLOC (MTYPE_LINK_NODE, sizeof (struct listnode));
- memset (node, 0, sizeof (struct listnode));
- return node;
+ return XCALLOC (MTYPE_LINK_NODE, sizeof (struct listnode));
}
/* Free listnode. */
diff --git a/lib/log.c b/lib/log.c
index df630099..09ddfb29 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -740,9 +740,9 @@ zlog_rotate (struct zlog *zl)
/* Message lookup function. */
const char *
-lookup (struct message *mes, int key)
+lookup (const struct message *mes, int key)
{
- struct message *pnt;
+ const struct message *pnt;
for (pnt = mes; pnt->key != 0; pnt++)
if (pnt->key == key)
diff --git a/lib/log.h b/lib/log.h
index 691368c0..5411fa6b 100644
--- a/lib/log.h
+++ b/lib/log.h
@@ -105,27 +105,48 @@ extern void closezlog (struct zlog *zl);
/* GCC have printf type attribute check. */
#ifdef __GNUC__
-#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
+#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((format (printf, a, b)))
#else
#define PRINTF_ATTRIBUTE(a,b)
#endif /* __GNUC__ */
+#if !(__GNUC__ == 4)
+/* Mark functions as cold. gcc will assume any path leading to a call
+ to them will be unlikely. This means a lot of paths leading up
+ to log messages are easily marked as not likely.
+*/
+#define COLD_ATTRIBUTE __attribute__((__cold__))
+#else
+#define COLD_ATTRIBUTE
+#endif
+
/* Generic function for zlog. */
-extern void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
+extern void zlog (struct zlog *zl, int priority, const char *format, ...)
+ PRINTF_ATTRIBUTE(3, 4);
/* Handy zlog functions. */
-extern void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
-extern void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
-extern void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
-extern void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
-extern void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
+extern void zlog_err (const char *format, ...)
+ PRINTF_ATTRIBUTE(1, 2) COLD_ATTRIBUTE;
+extern void zlog_warn (const char *format, ...)
+ PRINTF_ATTRIBUTE(1, 2) COLD_ATTRIBUTE;
+extern void zlog_info (const char *format, ...)
+ PRINTF_ATTRIBUTE(1, 2) COLD_ATTRIBUTE;
+extern void zlog_notice (const char *format, ...)
+ PRINTF_ATTRIBUTE(1, 2) COLD_ATTRIBUTE;
+extern void zlog_debug (const char *format, ...)
+ PRINTF_ATTRIBUTE(1, 2) COLD_ATTRIBUTE;
/* For bgpd's peer oriented log. */
-extern void plog_err (struct zlog *, const char *format, ...);
-extern void plog_warn (struct zlog *, const char *format, ...);
-extern void plog_info (struct zlog *, const char *format, ...);
-extern void plog_notice (struct zlog *, const char *format, ...);
-extern void plog_debug (struct zlog *, const char *format, ...);
+extern void plog_err (struct zlog *, const char *format, ...)
+ PRINTF_ATTRIBUTE(2, 3) COLD_ATTRIBUTE;
+extern void plog_warn (struct zlog *, const char *format, ...)
+ PRINTF_ATTRIBUTE(2, 3) COLD_ATTRIBUTE;
+extern void plog_info (struct zlog *, const char *format, ...)
+ PRINTF_ATTRIBUTE(2, 3) COLD_ATTRIBUTE;
+extern void plog_notice (struct zlog *, const char *format, ...)
+ PRINTF_ATTRIBUTE(2, 3) COLD_ATTRIBUTE;
+extern void plog_debug (struct zlog *, const char *format, ...)
+ PRINTF_ATTRIBUTE(2, 3) COLD_ATTRIBUTE;
/* Set logging level for the given destination. If the log_level
argument is ZLOG_DISABLED, then the destination is disabled.
@@ -144,7 +165,7 @@ extern int zlog_rotate (struct zlog *);
/* For hackey massage lookup and check */
#define LOOKUP(x, y) mes_lookup(x, x ## _max, y, "(no item found)")
-extern const char *lookup (struct message *, int);
+extern const char *lookup (const struct message *, int);
extern const char *mes_lookup (struct message *meslist,
int max, int index,
const char *no_item);
diff --git a/lib/memory.c b/lib/memory.c
index 9ed5e100..28b3d896 100644
--- a/lib/memory.c
+++ b/lib/memory.c
@@ -33,7 +33,7 @@ static void alloc_inc (int);
static void alloc_dec (int);
static void log_memstats(int log_priority);
-static struct message mstr [] =
+static const struct message mstr [] =
{
{ MTYPE_THREAD, "thread" },
{ MTYPE_THREAD_MASTER, "thread_master" },
diff --git a/lib/plist.c b/lib/plist.c
index 6caece0e..e46dae0b 100644
--- a/lib/plist.c
+++ b/lib/plist.c
@@ -2623,7 +2623,7 @@ prefix_list_reset_orf (void)
/* Prefix-list node. */
-struct cmd_node prefix_node =
+static struct cmd_node prefix_node =
{
PREFIX_NODE,
"", /* Prefix list has no interface. */
@@ -2732,7 +2732,7 @@ prefix_list_init_ipv4 (void)
#ifdef HAVE_IPV6
/* Prefix-list node. */
-struct cmd_node prefix_ipv6_node =
+static struct cmd_node prefix_ipv6_node =
{
PREFIX_IPV6_NODE,
"", /* Prefix list has no interface. */
diff --git a/lib/routemap.c b/lib/routemap.c
index 58ed09a7..5f7a3182 100644
--- a/lib/routemap.c
+++ b/lib/routemap.c
@@ -1280,7 +1280,7 @@ route_map_config_write (struct vty *vty)
}
/* Route map node structure. */
-struct cmd_node rmap_node =
+static struct cmd_node rmap_node =
{
RMAP_NODE,
"%s(config-route-map)# ",
diff --git a/lib/smux.c b/lib/smux.c
index 8572df54..630c1a98 100644
--- a/lib/smux.c
+++ b/lib/smux.c
@@ -71,7 +71,7 @@ int debug_smux = 0;
int fail = 0;
/* SMUX node. */
-struct cmd_node smux_node =
+static struct cmd_node smux_node =
{
SMUX_NODE,
"" /* SMUX has no interface. */
diff --git a/lib/sockopt.h b/lib/sockopt.h
index 95382792..cb05c6fb 100644
--- a/lib/sockopt.h
+++ b/lib/sockopt.h
@@ -89,6 +89,7 @@ extern int setsockopt_multicast_ipv4(int sock, int optname,
unsigned int ifindex
/* optional: if non-zero, may be used
instead of if_addr */);
+extern int setsockopt_ipv4_tos(int sock, int tos);
/* Ask for, and get, ifindex, by whatever method is supported. */
extern int setsockopt_ifindex (int, int, int);
diff --git a/lib/sockunion.c b/lib/sockunion.c
index cfd3bf9a..1ae092bd 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -180,8 +180,7 @@ sockunion_str2su (const char *str)
int ret;
union sockunion *su;
- su = XMALLOC (MTYPE_SOCKUNION, sizeof (union sockunion));
- memset (su, 0, sizeof (union sockunion));
+ su = XCALLOC (MTYPE_SOCKUNION, sizeof (union sockunion));
ret = inet_pton (AF_INET, str, &su->sin.sin_addr);
if (ret > 0) /* Valid IPv4 address format. */
diff --git a/lib/thread.c b/lib/thread.c
index 095dff4e..260e8c8e 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -223,8 +223,8 @@ cpu_record_hash_key (struct cpu_thread_history *a)
}
static int
-cpu_record_hash_cmp (struct cpu_thread_history *a,
- struct cpu_thread_history *b)
+cpu_record_hash_cmp (const struct cpu_thread_history *a,
+ const struct cpu_thread_history *b)
{
return a->func == b->func;
}
@@ -410,7 +410,7 @@ thread_master_create ()
if (cpu_record == NULL)
cpu_record
= hash_create_size (1011, (unsigned int (*) (void *))cpu_record_hash_key,
- (int (*) (void *, void *))cpu_record_hash_cmp);
+ (int (*) (const void *, const void *))cpu_record_hash_cmp);
return (struct thread_master *) XCALLOC (MTYPE_THREAD_MASTER,
sizeof (struct thread_master));
diff --git a/lib/vty.h b/lib/vty.h
index 65ae6201..31cbd498 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -141,13 +141,6 @@ struct vty
#define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP)
#endif
-/* GCC have printf type attribute check. */
-#ifdef __GNUC__
-#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
-#else
-#define PRINTF_ATTRIBUTE(a,b)
-#endif /* __GNUC__ */
-
/* Utility macros to convert VTY argument to unsigned long or integer. */
#define VTY_GET_LONG(NAME,V,STR) \
do { \
diff --git a/lib/zassert.h b/lib/zassert.h
index 79126760..123aee16 100644
--- a/lib/zassert.h
+++ b/lib/zassert.h
@@ -17,9 +17,17 @@ extern void _zlog_assert_failed (const char *assertion, const char *file,
#define __ASSERT_FUNCTION NULL
#endif
-#define zassert(EX) ((void)((EX) ? 0 : \
- (_zlog_assert_failed(#EX, __FILE__, __LINE__, \
- __ASSERT_FUNCTION), 0)))
+#ifdef __GNUC__
+#define UNLIKELY(EX) __builtin_expect(!!(EX), 0)
+#define LIKELY(EX) __builtin_expect(!!(EX), 1)
+#else
+#define UNLIKELY(EX) (EX)
+#define LIKELY(EX) (EX)
+#endif
+
+#define zassert(EX) ((void)(UNLIKELY(EX) ? 0 : \
+ (_zlog_assert_failed(#EX, __FILE__, __LINE__, \
+ __ASSERT_FUNCTION), 0)))
#undef assert
#define assert(EX) zassert(EX)
diff --git a/lib/zclient.c b/lib/zclient.c
index 10e6b5fd..4a716a66 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -49,8 +49,7 @@ struct zclient *
zclient_new ()
{
struct zclient *zclient;
- zclient = XMALLOC (MTYPE_ZCLIENT, sizeof (struct zclient));
- memset (zclient, 0, sizeof (struct zclient));
+ zclient = XCALLOC (MTYPE_ZCLIENT, sizeof (struct zclient));
zclient->ibuf = stream_new (ZEBRA_MAX_PACKET_SIZ);
zclient->obuf = stream_new (ZEBRA_MAX_PACKET_SIZ);