Fix most compiler warnings in default GCC build.

Fix lots of warnings. Some const and type-pun breaks strict-aliasing
warnings left but much reduced.

* bgp_advertise.h: (struct bgp_advertise_fifo) is functionally identical to
  (struct fifo), so just use that.  Makes it clearer the beginning of
  (struct bgp_advertise) is compatible with with (struct fifo), which seems
  to be enough for gcc.
  Add a BGP_ADV_FIFO_HEAD macro to contain the right cast to try shut up
  type-punning breaks strict aliasing warnings.
* bgp_packet.c: Use BGP_ADV_FIFO_HEAD.
  (bgp_route_refresh_receive) fix an interesting logic error in
  (!ok || (ret != BLAH)) where ret is only well-defined if ok.
* bgp_vty.c: Peer commands should use bgp_vty_return to set their return.
* jhash.{c,h}: Can take const on * args without adding issues & fix warnings.
* libospf.h: LSA sequence numbers use the unsigned range of values, and
  constants need to be set to unsigned, or it causes warnings in ospf6d.
* md5.h: signedness of caddr_t is implementation specific, change to an
  explicit (uint_8 *), fix sign/unsigned comparison warnings.
* vty.c: (vty_log_fixed) const on level is well-intentioned, but not going
  to fly given iov_base.
* workqueue.c: ALL_LIST_ELEMENTS_RO tests for null pointer, which is always
  true for address of static variable.  Correct but pointless warning in
  this case, but use a 2nd pointer to shut it up.
* ospf6_route.h: Add a comment about the use of (struct prefix) to stuff 2
  different 32 bit IDs into in (struct ospf6_route), and the resulting
  type-pun strict-alias breakage warnings this causes.  Need to use 2
  different fields to fix that warning?

general:

* remove unused variables, other than a few cases where they serve a
  sufficiently useful documentary purpose (e.g.  for code that needs
  fixing), or they're required dummies.  In those cases, try mark them as
  unused.
* Remove dead code that can't be reached.
* Quite a few 'no ...' forms of vty commands take arguments, but do not
  check the argument matches the command being negated.  E.g., should
  'distance X <prefix>' succeed if previously 'distance Y <prefix>' was set?
  Or should it be required that the distance match the previously configured
  distance for the prefix?
  Ultimately, probably better to be strict about this.  However, changing
  from slack to strict might expose problems in command aliases and tools.
* Fix uninitialised use of variables.
* Fix sign/unsigned comparison warnings by making signedness of types consistent.
* Mark functions as static where their use is restricted to the same compilation
  unit.
* Add required headers
* Move constants defined in headers into code.
* remove dead, unused functions that have no debug purpose.
diff --git a/lib/command.c b/lib/command.c
index 1087ceb..d1af7fa 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -1411,7 +1411,7 @@
   const char *word;
   int keyword_argc;
   const char **keyword_argv;
-  enum matcher_rv rv;
+  enum matcher_rv rv = MATCHER_NO_MATCH;
 
   keyword_mask = 0;
   while (1)
@@ -1642,7 +1642,7 @@
 {
   struct cmd_matcher matcher;
   unsigned int token_index;
-  enum matcher_rv rv;
+  enum matcher_rv rv = MATCHER_NO_MATCH;
 
   cmd_matcher_init(&matcher, cmd_element, filter,
                    vline, index, match_type, match);
diff --git a/lib/if.c b/lib/if.c
index 18e2fb3..3a1f9b4 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -309,8 +309,6 @@
 if_lookup_prefix (struct prefix *prefix)
 {
   struct listnode *node;
-  struct prefix addr;
-  int bestlen = 0;
   struct listnode *cnode;
   struct interface *ifp;
   struct connected *c;
@@ -453,7 +451,7 @@
 if_dump (const struct interface *ifp)
 {
   struct listnode *node;
-  struct connected *c;
+  struct connected *c __attribute__((unused));
 
   for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, c))
     zlog_info ("Interface %s index %d metric %d mtu %d "
diff --git a/lib/jhash.c b/lib/jhash.c
index 071fed6..6154c34 100644
--- a/lib/jhash.c
+++ b/lib/jhash.c
@@ -42,10 +42,10 @@
  * the input key.
  */
 u_int32_t
-jhash (void *key, u_int32_t length, u_int32_t initval)
+jhash (const void *key, u_int32_t length, u_int32_t initval)
 {
   u_int32_t a, b, c, len;
-  u_int8_t *k = key;
+  const u_int8_t *k = key;
 
   len = length;
   a = b = JHASH_GOLDEN_RATIO;
@@ -105,7 +105,7 @@
  * The length parameter here is the number of u_int32_ts in the key.
  */
 u_int32_t
-jhash2 (u_int32_t * k, u_int32_t length, u_int32_t initval)
+jhash2 (const u_int32_t *k, u_int32_t length, u_int32_t initval)
 {
   u_int32_t a, b, c, len;
 
diff --git a/lib/jhash.h b/lib/jhash.h
index 44dd1b5..985ac94 100644
--- a/lib/jhash.h
+++ b/lib/jhash.h
@@ -24,12 +24,12 @@
  * of bytes.  No alignment or length assumptions are made about
  * the input key.
  */
-extern u_int32_t jhash(void *key, u_int32_t length, u_int32_t initval);
+extern u_int32_t jhash(const void *key, u_int32_t length, u_int32_t initval);
 
 /* A special optimized version that handles 1 or more of u_int32_ts.
  * The length parameter here is the number of u_int32_ts in the key.
  */
-extern u_int32_t jhash2(u_int32_t *k, u_int32_t length, u_int32_t initval);
+extern u_int32_t jhash2(const u_int32_t *k, u_int32_t length, u_int32_t initval);
 
 /* A special ultra-optimized versions that knows they are hashing exactly
  * 3, 2 or 1 word(s).
diff --git a/lib/libospf.h b/lib/libospf.h
index 856c76d..2796209 100644
--- a/lib/libospf.h
+++ b/lib/libospf.h
@@ -47,8 +47,8 @@
 #define OSPF_LSA_MAXAGE_DIFF                   900
 #define OSPF_LS_INFINITY                  0xffffff
 #define OSPF_DEFAULT_DESTINATION        0x00000000      /* 0.0.0.0 */
-#define OSPF_INITIAL_SEQUENCE_NUMBER    0x80000001
-#define OSPF_MAX_SEQUENCE_NUMBER        0x7fffffff
+#define OSPF_INITIAL_SEQUENCE_NUMBER    0x80000001U
+#define OSPF_MAX_SEQUENCE_NUMBER        0x7fffffffU
 
 /* OSPF Interface Types */
 #define OSPF_IFTYPE_NONE		0
diff --git a/lib/md5.c b/lib/md5.c
index 2fc36e1..ce459bb 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -306,7 +306,7 @@
 int             text_len;		/* length of data stream */
 unsigned char*  key;			/* pointer to authentication key */
 int             key_len;		/* length of authentication key */
-caddr_t         digest;		/* caller digest to be filled in */
+uint8_t *       digest;			/* caller digest to be filled in */
 
 {
     MD5_CTX context;
diff --git a/lib/md5.h b/lib/md5.h
index a03bf22..4e5ffbd 100644
--- a/lib/md5.h
+++ b/lib/md5.h
@@ -84,6 +84,6 @@
 
 /* From RFC 2104 */
 void hmac_md5(unsigned char* text, int text_len, unsigned char* key,
-              int key_len, caddr_t digest);
+              int key_len, uint8_t *digest);
 
 #endif /* ! _LIBZEBRA_MD5_H_*/
diff --git a/lib/table.c b/lib/table.c
index 220e9b8..bd7023c 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -626,11 +626,8 @@
 			       struct prefix *p)
 {
   struct route_node *node, *tmp_node;
-  u_char prefixlen;
   int cmp;
 
-  prefixlen = p->prefixlen;
-
   node = table->top;
 
   while (node)
diff --git a/lib/vty.c b/lib/vty.c
index 488f8d5..3f08b9e 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -2458,7 +2458,7 @@
 
 /* Async-signal-safe version of vty_log for fixed strings. */
 void
-vty_log_fixed (const char *buf, size_t len)
+vty_log_fixed (char *buf, size_t len)
 {
   unsigned int i;
   struct iovec iov[2];
@@ -2467,7 +2467,7 @@
   if (!vtyvec)
     return;
   
-  iov[0].iov_base = (void *)buf;
+  iov[0].iov_base = buf;
   iov[0].iov_len = len;
   iov[1].iov_base = (void *)"\r\n";
   iov[1].iov_len = 2;
diff --git a/lib/vty.h b/lib/vty.h
index 1798585..4d6048c 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -242,6 +242,6 @@
 
 /* Send a fixed-size message to all vty terminal monitors; this should be
    an async-signal-safe function. */
-extern void vty_log_fixed (const char *buf, size_t len);
+extern void vty_log_fixed (char *buf, size_t len);
 
 #endif /* _ZEBRA_VTY_H */
diff --git a/lib/workqueue.c b/lib/workqueue.c
index 61643bf..e09d009 100644
--- a/lib/workqueue.c
+++ b/lib/workqueue.c
@@ -30,7 +30,11 @@
 #include "log.h"
 
 /* master list of work_queues */
-static struct list work_queues;
+static struct list _work_queues;
+/* pointer primarily to avoid an otherwise harmless warning on
+ * ALL_LIST_ELEMENTS_RO 
+ */
+static struct list *work_queues = &_work_queues;
 
 #define WORK_QUEUE_MIN_GRANULARITY 1
 
@@ -78,7 +82,7 @@
   
   new->items->del = (void (*)(void *)) work_queue_item_free;  
   
-  listnode_add (&work_queues, new);
+  listnode_add (work_queues, new);
   
   new->cycles.granularity = WORK_QUEUE_MIN_GRANULARITY;
 
@@ -96,7 +100,7 @@
   
   /* list_delete frees items via callback */
   list_delete (wq->items);
-  listnode_delete (&work_queues, wq);
+  listnode_delete (work_queues, wq);
   
   XFREE (MTYPE_WORK_QUEUE_NAME, wq->name);
   XFREE (MTYPE_WORK_QUEUE, wq);
@@ -187,7 +191,7 @@
            "Name", 
            VTY_NEWLINE);
  
-  for (ALL_LIST_ELEMENTS_RO ((&work_queues), node, wq))
+  for (ALL_LIST_ELEMENTS_RO (work_queues, node, wq))
     {
       vty_out (vty,"%c %8d %5d %8ld %7d %6d %6u %s%s",
                (CHECK_FLAG (wq->flags, WQ_UNPLUGGED) ? ' ' : 'P'),