]> git.puffer.fish Git - matthieu/frr.git/commitdiff
Fix most compiler warnings in default GCC build.
authorPaul Jakma <paul@opensourcerouting.org>
Fri, 19 Sep 2014 13:42:23 +0000 (14:42 +0100)
committerDaniel Walton <dwalton@cumulusnetworks.com>
Thu, 26 May 2016 18:57:39 +0000 (18:57 +0000)
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.

(cherry picked from commit 7aa9dcef80b2ce50ecaa77653d87c8b84e009c49)

Conflicts:
bgpd/bgp_advertise.h
bgpd/bgp_mplsvpn.c
bgpd/bgp_nexthop.c
bgpd/bgp_packet.c
bgpd/bgp_route.c
bgpd/bgp_routemap.c
bgpd/bgp_vty.c
lib/command.c
lib/if.c
lib/jhash.c
lib/workqueue.c
ospf6d/ospf6_lsa.c
ospf6d/ospf6_neighbor.h
ospf6d/ospf6_spf.c
ospf6d/ospf6_top.c
ospfd/ospf_api.c
zebra/router-id.c
zebra/rt_netlink.c
zebra/rt_netlink.h

17 files changed:
bgpd/bgp_mplsvpn.c
bgpd/bgp_packet.c
bgpd/bgp_route.c
bgpd/bgp_routemap.c
bgpd/bgp_vty.c
bgpd/bgpd.c
bgpd/bgpd.h
lib/if.c
lib/jhash.c
lib/vty.c
lib/workqueue.c
ospf6d/ospf6_abr.h
ospf6d/ospf6_network.c
ospf6d/ospf6_network.h
ospf6d/ospf6_route.h
ospf6d/ospf6_spf.c
zebra/router-id.c

index 31ec6947a1f6ccc2155421e5f03f741be9738611..2510e2e040b7e95a28547356a814ac2a64373824 100644 (file)
@@ -130,6 +130,15 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
           pnt += BGP_ADDPATH_ID_LEN;
         }
 
+      if (prefixlen < 88)
+       {
+         zlog_err ("prefix length is less than 88: %d", prefixlen);
+         return -1;
+       }
+
+      /* XXX: Not doing anything with the label */
+      decode_label (pnt);
+
       /* Fetch prefix length. */
       prefixlen = *pnt++;
       p.family = afi2family (packet->afi);
index 08082161fa81a03b820e2c3a85b09ef7e4243ae3..025cfbaeebb2a9582bc6c5c55ff5bbe65072c1b0 100644 (file)
@@ -1862,8 +1862,8 @@ bgp_route_refresh_receive (struct peer *peer, bgp_size_t size)
          if (orf_type == ORF_TYPE_PREFIX
              || orf_type == ORF_TYPE_PREFIX_OLD)
            {
-             u_char *p_pnt = stream_pnt (s);
-             u_char *p_end = stream_pnt (s) + orf_len;
+             uint8_t *p_pnt = stream_pnt (s);
+             uint8_t *p_end = stream_pnt (s) + orf_len;
              struct orf_prefix orfp;
              u_char common = 0;
              u_int32_t seq;
@@ -1956,7 +1956,7 @@ bgp_route_refresh_receive (struct peer *peer, bgp_size_t size)
                                   (common & ORF_COMMON_PART_DENY ? 0 : 1 ),
                                   (common & ORF_COMMON_PART_REMOVE ? 0 : 1));
 
-                 if (!ok || (ret != CMD_SUCCESS))
+                 if (!ok || (ok && ret != CMD_SUCCESS))
                    {
                      zlog_info ("%s Received misformatted prefixlist ORF."
                                 " Remove All pfxlist", peer->host);
index 581d9db89d7911c52ada18b54fb0c882621729ea..74969e0ec70d365a09738ce8600fe85d39572b5d 100644 (file)
@@ -13399,6 +13399,7 @@ bgp_distance_unset (struct vty *vty, const char *distance_str,
                     const char *ip_str, const char *access_list_str)
 {
   int ret;
+  int distance;
   struct prefix_ipv4 p;
   struct bgp_node *rn;
   struct bgp_distance *bdistance;
@@ -13418,6 +13419,13 @@ bgp_distance_unset (struct vty *vty, const char *distance_str,
     }
 
   bdistance = rn->info;
+  distance = atoi(distance_str);
+
+  if (bdistance->distance != distance)
+    {
+       vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
+       return CMD_WARNING;
+    }
 
   if (bdistance->access_list)
     XFREE(MTYPE_AS_LIST, bdistance->access_list);
index ad154389ea90fba737f81dc72bfdc6be97de67da..ab22a455d2f23cc5b45ae5d2fd8154f1bbb1f2a5 100644 (file)
@@ -2100,6 +2100,7 @@ static route_map_result_t
 route_match_ipv6_next_hop (void *rule, struct prefix *prefix, 
                           route_map_object_t type, void *object)
 {
+  struct in6_addr *addr = rule;
   struct bgp_info *bgp_info;
 
   if (type == RMAP_BGP)
@@ -2109,7 +2110,7 @@ route_match_ipv6_next_hop (void *rule, struct prefix *prefix,
       if (!bgp_info->attr->extra)
         return RMAP_NOMATCH;
       
-      if (IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_global, rule))
+      if (IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_global, addr))
        return RMAP_MATCH;
 
       if (bgp_info->attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL &&
index ad04308f06fc8d4d13aee180d53b192ce4ede99c..825f5954c235cbfac7e2266b5d5240e31aecd3f4 100644 (file)
@@ -4662,6 +4662,7 @@ static int
 peer_weight_set_vty (struct vty *vty, const char *ip_str, 
                      const char *weight_str)
 {
+  int ret;
   struct peer *peer;
   unsigned long weight;
 
@@ -4671,23 +4672,22 @@ peer_weight_set_vty (struct vty *vty, const char *ip_str,
 
   VTY_GET_INTEGER_RANGE("weight", weight, weight_str, 0, 65535);
 
-  peer_weight_set (peer, weight);
-
-  return CMD_SUCCESS;
+  ret = peer_weight_set (peer, weight);
+  return bgp_vty_return (vty, ret);
 }
 
 static int
 peer_weight_unset_vty (struct vty *vty, const char *ip_str)
 {
+  int ret;
   struct peer *peer;
 
   peer = peer_and_group_lookup_vty (vty, ip_str);
   if (! peer)
     return CMD_WARNING;
 
-  peer_weight_unset (peer);
-
-  return CMD_SUCCESS;
+  ret = peer_weight_unset (peer);
+  return bgp_vty_return (vty, ret);
 }
 
 DEFUN (neighbor_weight,
index 61bed4fc535b8f27af2ef90ef1fb7446fba21517..36ab3e5fa7cfc4ab15b824a3565c025568451ab4 100644 (file)
@@ -4421,7 +4421,7 @@ peer_port_unset (struct peer *peer)
 }
 
 /* neighbor weight. */
-void
+int
 peer_weight_set (struct peer *peer, u_int16_t weight)
 {
   struct peer_group *group;
@@ -4431,7 +4431,7 @@ peer_weight_set (struct peer *peer, u_int16_t weight)
   peer->weight = weight;
 
   if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
-    return;
+    return 0;
 
   /* peer-group member updates. */
   group = peer->group;
@@ -4439,9 +4439,10 @@ peer_weight_set (struct peer *peer, u_int16_t weight)
     {
       peer->weight = group->conf->weight;
     }
+  return 1;
 }
 
-void
+int
 peer_weight_unset (struct peer *peer)
 {
   struct peer_group *group;
@@ -4456,7 +4457,7 @@ peer_weight_unset (struct peer *peer)
   UNSET_FLAG (peer->config, PEER_CONFIG_WEIGHT);
 
   if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
-    return;
+    return 0;
 
   /* peer-group member updates. */
   group = peer->group;
@@ -4464,7 +4465,7 @@ peer_weight_unset (struct peer *peer)
     {
       peer->weight = 0;
     }
-  return;
+  return 1;
 }
 
 int
index 20f23e73cbfdcccca4e70333e70c4181d1d4b807..1e7a00628fd11d8dc8099b1c647fd3e10112856d 100644 (file)
@@ -1268,8 +1268,8 @@ extern int peer_default_originate_unset (struct peer *, afi_t, safi_t);
 extern int peer_port_set (struct peer *, u_int16_t);
 extern int peer_port_unset (struct peer *);
 
-extern void peer_weight_set (struct peer *, u_int16_t);
-extern void peer_weight_unset (struct peer *);
+extern int peer_weight_set (struct peer *, u_int16_t);
+extern int peer_weight_unset (struct peer *);
 
 extern int peer_timers_set (struct peer *, u_int32_t, u_int32_t);
 extern int peer_timers_unset (struct peer *);
index d49b5acad73a0e8d49095233616a4587fb42fd6b..97edf1769a24d0b19ad89ac44c1e2c87b62f9612 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -638,16 +638,14 @@ if_flag_dump (unsigned long flag)
 static void
 if_dump (const struct interface *ifp)
 {
+  struct listnode *node;
+  struct connected *c __attribute__((unused));
+
+  for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, c))
     zlog_info ("Interface %s vrf %u index %d metric %d mtu %d "
-#ifdef HAVE_IPV6
-               "mtu6 %d "
-#endif /* HAVE_IPV6 */
-               "%s",
+               "mtu6 %d %s",
                ifp->name, ifp->vrf_id, ifp->ifindex, ifp->metric, ifp->mtu,
-#ifdef HAVE_IPV6
-               ifp->mtu6,
-#endif /* HAVE_IPV6 */
-               if_flag_dump (ifp->flags));
+               ifp->mtu6, if_flag_dump (ifp->flags));
 }
 
 /* Interface printing for all interface. */
index decd066cd7befe4591ff112e556f04270d7fdfde..6154c34630face49976fc93fc6af771954c7fce3 100644 (file)
@@ -105,7 +105,7 @@ jhash (const void *key, u_int32_t length, u_int32_t initval)
  * The length parameter here is the number of u_int32_ts in the key.
  */
 u_int32_t
-jhash2 (const 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;
 
index 146a20fb0ff3d6c05d72195c1469c6111e592fe1..a38a7523ca90d9a66b3129cd458ab83f5ab7c0e2 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -2486,7 +2486,7 @@ vty_log_fixed (char *buf, size_t len)
   if (!vtyvec)
     return;
   
-  iov[0].iov_base = (void *)buf;
+  iov[0].iov_base = buf;
   iov[0].iov_len = len;
   iov[1].iov_base = crlf;
   iov[1].iov_len = 2;
index 6fad237e1169c9a541010e754bbe7df9a77d2810..a45a6fc09748c1567e2ae697843c1fe7c0823cf3 100644 (file)
@@ -31,7 +31,7 @@
 
 /* master list of work_queues */
 static struct list _work_queues;
-/* pointer primarly to avid an otherwise harmless warning on
+/* pointer primarily to avoid an otherwise harmless warning on
  * ALL_LIST_ELEMENTS_RO
  */
 static struct list *work_queues = &_work_queues;
index bfd609c25558320e988139e75e3a4b379bd28475..5bc2469e10c23bee63ac712cc7d79d3effe16dbf 100644 (file)
@@ -24,6 +24,8 @@
 
 /* for struct ospf6_route */
 #include "ospf6_route.h"
+/* for struct ospf6_prefix */
+#include "ospf6_proto.h"
 
 /* Debug option */
 extern unsigned char conf_debug_ospf6_abr;
index 0d53d3ee7f34fd8124e647eca6d003135f774092..7b1cf919327815f7dde41274d35995519531c6bc 100644 (file)
@@ -37,18 +37,8 @@ int  ospf6_sock;
 struct in6_addr allspfrouters6;
 struct in6_addr alldrouters6;
 
-/* setsockopt ReUseAddr to on */
-void
-ospf6_set_reuseaddr (void)
-{
-  u_int on = 0;
-  if (setsockopt (ospf6_sock, SOL_SOCKET, SO_REUSEADDR, &on,
-                  sizeof (u_int)) < 0)
-    zlog_warn ("Network: set SO_REUSEADDR failed: %s", safe_strerror (errno));
-}
-
 /* setsockopt MulticastLoop to off */
-void
+static void
 ospf6_reset_mcastloop (void)
 {
   u_int off = 0;
@@ -58,7 +48,7 @@ ospf6_reset_mcastloop (void)
                safe_strerror (errno));
 }
 
-void
+static void
 ospf6_set_pktinfo (void)
 {
   setsockopt_ipv6_pktinfo (ospf6_sock, 1);
@@ -72,7 +62,7 @@ ospf6_set_transport_class (void)
 #endif
 }
 
-void
+static void
 ospf6_set_checksum (void)
 {
   int offset = 12;
index 7208845d2cf1b2b0e5692b84e6d7c64fc4450464..2aeafe50416620dbf21b0be24265dee14e8d189e 100644 (file)
@@ -28,12 +28,6 @@ extern int ospf6_sock;
 extern struct in6_addr allspfrouters6;
 extern struct in6_addr alldrouters6;
 
-/* Function Prototypes */
-extern void ospf6_set_reuseaddr (void);
-extern void ospf6_reset_mcastloop (void);
-extern void ospf6_set_pktinfo (void);
-extern void ospf6_set_checksum (void);
-
 extern int ospf6_serv_sock (void);
 extern int ospf6_sso (u_int ifindex, struct in6_addr *group, int option);
 
index e5bfc5ed041b467e2e5c4c57577ae3f66a5bab1f..b3be66c28e29ab8d2ed3965100b4217b175c49c7 100644 (file)
@@ -130,6 +130,10 @@ struct ospf6_route
   /* Destination Type */
   u_char type;
 
+  /* XXX: It would likely be better to use separate struct in_addr's
+   * for the advertising router-ID and prefix IDs, instead of stuffing them
+   * into one. See also XXX below.
+   */
   /* Destination ID */
   struct prefix prefix;
 
@@ -247,6 +251,7 @@ extern const char *ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX];
 
 #define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST))
 
+/* XXX: This gives GCC heartburn aboutbreaking aliasing rules. */
 #define ospf6_linkstate_prefix_adv_router(x) \
   ((x)->u.prefix4.s_addr)
 #define ospf6_linkstate_prefix_id(x) \
index 52b60f1e698d0c63e26c71a72b43efca7bddda5f..fda3bb5fb87b23890d543cbcaf687b5548803b7a 100644 (file)
@@ -42,6 +42,7 @@
 #include "ospf6_intra.h"
 #include "ospf6_interface.h"
 #include "ospf6d.h"
+#include "ospf6_abr.h"
 
 unsigned char conf_debug_ospf6_spf = 0;
 
index a1d7cb9dabaa2968467f7b5ee9734f8d8bb0888a..58c1c031cf3292cc9eb6ab5d4e378ba322ab42b2 100644 (file)
@@ -43,6 +43,9 @@
 #include "zebra/router-id.h"
 #include "zebra/redistribute.h"
 
+/* master zebra server structure */
+extern struct zebra_t zebrad;
+
 static struct connected *
 router_id_find_node (struct list *l, struct connected *ifc)
 {