[hipl-commit] [trunk] Rev 3720: Minimized and cleaned up a compilation fix for __u32 and __u64.

  • From: Miika Komu <miika@xxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Sat, 27 Feb 2010 14:26:16 +0200

Committer: Miika Komu <miika@xxxxxx>
Date: Sat Feb 27 14:26:13 2010 +0200
Revision: 3720
Revision-id: miika@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: trunk

Log:
  Minimized and cleaned up a compilation fix for __u32 and __u64.
  
  While compiling binaries on Fedora 10, compiler was warning on
  <linux/rtnetlink.h> that it was missing __u32 or __u64. There was an
  old hack in the code spread to multiple places that used to fix this
  issue but not anymore. I moved the hack to a single file (nlink.h),
  cleaned it up and made sure that other code was just including nlink.h
  instead of the troublesome <linux/rtnetlink.h>.
  
  I also went through the HIPL code and replaced all __u32 and __u64
  occurrences with uint32_t and uint64_t. Contants beginning with
  underscores should not be used.
  
  I tested successfully the compilation with default options on the
  following platforms using off-dir compilation:
  
  * Ubuntu 8.10, i386
  * Ubuntu 8.10, amd64
  * F10-x86_64
  * F12-x86_64
  * CentOS-5.4 i386
  * CentOS-5.4 x86_64
  * F10-i386
  * f12-i386
  * fc11-x86_64
  * fc11-i386
  
  I hope somebody would have time to test OpenWRT and Maemo compilation again?

Modified:
  M  agent/agent.c
  M  agent/connhipd.c
  M  firewall/helpers.c
  M  firewall/rule_management.c
  M  firewall/savah_gateway.h
  M  hipd/hit_to_ip.c
  M  hipd/hit_to_ip.h
  M  hipd/init.c
  M  hipd/netdev.c
  M  hipd/netdev.h
  M  lib/core/kerncompat.h
  M  lib/tool/nlink.c
  M  lib/tool/nlink.h
  M  lib/tool/xfrmapi.c
  M  lib/tool/xfrmapi.h

=== modified file 'agent/agent.c'
--- agent/agent.c       2010-02-12 14:38:34 +0000
+++ agent/agent.c       2010-02-27 12:26:13 +0000
@@ -32,11 +32,6 @@
 #include <unistd.h>
 #include <time.h>
 
-#ifndef __u32
-/* Fedore Core 3/4 and Enterprise linux 4 is broken. */
-#  include <linux/types.h>
-#endif
-
 #include "agent.h"
 #include "tools.h"
 #include "gui_interface.h"

=== modified file 'agent/connhipd.c'
--- agent/connhipd.c    2010-02-11 17:21:17 +0000
+++ agent/connhipd.c    2010-02-27 12:26:13 +0000
@@ -19,11 +19,6 @@
 #include <string.h>
 #include <fcntl.h>
 
-#ifndef __u32
-/* Fedore Core 3/4 and Enterprise linux 4 is broken. */
-#  include <linux/types.h>
-#endif
-
 #include "connhipd.h"
 #include "agent.h"
 #include "tools.h"

=== modified file 'firewall/helpers.c'
--- firewall/helpers.c  2010-02-12 14:39:22 +0000
+++ firewall/helpers.c  2010-02-27 12:26:13 +0000
@@ -10,7 +10,7 @@
  * @todo the actual utility of this file seems questionable (should be removed)
  */
 
-#include <linux/types.h>
+//#include <linux/types.h>
 #include <limits.h>
 
 #include "helpers.h"

=== modified file 'firewall/rule_management.c'
--- firewall/rule_management.c  2010-02-16 21:54:14 +0000
+++ firewall/rule_management.c  2010-02-27 12:26:13 +0000
@@ -17,7 +17,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <netinet/in.h>
-#include <linux/types.h>
+//#include <linux/types.h>
 #include <linux/netfilter.h>
 #include <libipq.h>
 

=== modified file 'firewall/savah_gateway.h'
--- firewall/savah_gateway.h    2010-02-17 13:08:39 +0000
+++ firewall/savah_gateway.h    2010-02-27 12:26:13 +0000
@@ -3,7 +3,7 @@
 
 #include <stdio.h>
 #include <netinet/in.h>
-#include <linux/types.h>
+//#include <linux/types.h>
 #include <openssl/sha.h>
 #include <openssl/md5.h>
 #include <openssl/des.h>

=== modified file 'hipd/hit_to_ip.c'
--- hipd/hit_to_ip.c    2010-02-17 14:11:29 +0000
+++ hipd/hit_to_ip.c    2010-02-27 12:26:13 +0000
@@ -14,23 +14,16 @@
 /* required for s6_addr32 */
 #define _BSD_SOURCE
 
-#include "maintenance.h"
-#include "lib/conf/hipconf.h"
 #include <netinet/in.h>
 #include <string.h>
-
 #include <sys/socket.h>
-#ifndef __u32
-/* Fedore Core 3/4 and Enterprise linux 4 is broken. */
-#  include <linux/types.h>
-#endif
-//#include <netinet/ip6.h>
 
+#include "hit_to_ip.h"
 #include "lib/core/list.h"
 #include "lib/core/debug.h"
 #include "lib/core/utils.h"
-
-#include "hit_to_ip.h"
+#include "maintenance.h"
+#include "lib/conf/hipconf.h"
 
 //  value to return by the function
 #define ERR -1

=== modified file 'hipd/hit_to_ip.h'
--- hipd/hit_to_ip.h    2010-02-17 13:08:39 +0000
+++ hipd/hit_to_ip.h    2010-02-27 12:26:13 +0000
@@ -12,6 +12,10 @@
 #ifndef HIP_HIPD_HIT_TO_IP_H
 #define HIP_HIPD_HIT_TO_IP_H
 
+#include <netinet/in.h>
+#include <sys/types.h>
+#include "lib/core/protodefs.h"
+
 int hip_hit_to_ip(hip_hit_t *hit, struct in6_addr *retval);
 
 void hip_set_hit_to_ip_status(const int status);

=== modified file 'hipd/init.c'
--- hipd/init.c 2010-02-23 14:10:06 +0000
+++ hipd/init.c 2010-02-27 12:26:13 +0000
@@ -46,9 +46,9 @@
 #ifndef ANDROID_CHANGES
 
 /** ICMPV6_FILTER related stuff */
-#define BIT_CLEAR(nr, addr) do { ((__u32 *) (addr))[(nr) >> 5] &= ~(1U << 
((nr) & 31)); } while (0)
-#define BIT_SET(nr, addr) do { ((__u32 *) (addr))[(nr) >> 5] |= (1U << ((nr) & 
31)); } while (0)
-#define BIT_TEST(nr, addr) do { (__u32 *) (addr))[(nr) >> 5] & (1U << ((nr) & 
31)); } while (0)
+#define BIT_CLEAR(nr, addr) do { ((uint32_t *) (addr))[(nr) >> 5] &= ~(1U << 
((nr) & 31)); } while (0)
+#define BIT_SET(nr, addr) do { ((uint32_t *) (addr))[(nr) >> 5] |= (1U << 
((nr) & 31)); } while (0)
+#define BIT_TEST(nr, addr) do { (uint32_t *) (addr))[(nr) >> 5] & (1U << ((nr) 
& 31)); } while (0)
 
 #ifndef ICMP6_FILTER_WILLPASS
 #define ICMP6_FILTER_WILLPASS(type, filterp) \

=== modified file 'hipd/netdev.c'
--- hipd/netdev.c       2010-02-16 14:10:36 +0000
+++ hipd/netdev.c       2010-02-27 12:26:13 +0000
@@ -26,6 +26,7 @@
 #endif /* HAVE_CONFIG_H */
 
 #include <netinet/in.h>
+#include "lib/tool/nlink.h"
 #include "netdev.h"
 #include "maintenance.h"
 #include "lib/dht/libhipdht.h"

=== modified file 'hipd/netdev.h'
--- hipd/netdev.h       2010-02-17 13:08:39 +0000
+++ hipd/netdev.h       2010-02-27 12:26:13 +0000
@@ -6,12 +6,6 @@
 #define HIP_HIPD_NETDEV_H
 
 #include <sys/socket.h>
-#ifndef __u32
-/* Fedore Core 3/4 and Enterprise linux 4 is broken. */
-#  include <linux/types.h>
-#endif
-#include <linux/netlink.h>      /* get_my_addresses() support   */
-#include <linux/rtnetlink.h>    /* get_my_addresses() support   */
 #include <netinet/ip6.h>
 #include <openssl/rand.h>
 #ifdef HAVE_CONFIG_H

=== modified file 'lib/core/kerncompat.h'
--- lib/core/kerncompat.h       2010-02-17 13:08:39 +0000
+++ lib/core/kerncompat.h       2010-02-27 12:26:13 +0000
@@ -39,7 +39,7 @@
   #define hton64(i) (i)
   #define ntoh64(i) (i)
 #else
-  #define hton64(i) (((__u64) (htonl((i) & 0xffffffff)) << 32) | htonl(((i) >> 
32) & 0xffffffff ))
+  #define hton64(i) (((uint64_t) (htonl((i) & 0xffffffff)) << 32) | htonl(((i) 
>> 32) & 0xffffffff ))
   #define ntoh64 hton64
 #endif
 

=== modified file 'lib/tool/nlink.c'
--- lib/tool/nlink.c    2010-02-15 16:22:35 +0000
+++ lib/tool/nlink.c    2010-02-27 12:26:13 +0000
@@ -54,8 +54,8 @@
     __u8  family;
     __u8  bytelen;
     __s16 bitlen;
-    __u32 flags;
-    __u32 data[4];
+    uint32_t flags;
+    uint32_t data[4];
 } inet_prefix;
 
 int lsi_total = 0;
@@ -637,7 +637,7 @@
  * @param data the attribute
  * @return zero on success and negative on error
  */
-static int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data)
+static int addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data)
 {
     int len = RTA_LENGTH(4);
     struct rtattr *rta;
@@ -1356,7 +1356,7 @@
  * @param mask mask for the flags
  * @return zero on success and negative on error
  */
-static int do_chflags(const char *dev, __u32 flags, __u32 mask)
+static int do_chflags(const char *dev, uint32_t flags, uint32_t mask)
 {
     struct ifreq ifr;
     int fd;
@@ -1398,8 +1398,8 @@
 int set_up_device(char *dev, int up)
 {
     int err     = -1, total_add;
-    __u32 mask  = 0;
-    __u32 flags = 0;
+    uint32_t mask  = 0;
+    uint32_t flags = 0;
     char label[4];
     char *res   = NULL;
     int size_dev;

=== modified file 'lib/tool/nlink.h'
--- lib/tool/nlink.h    2010-02-17 13:08:39 +0000
+++ lib/tool/nlink.h    2010-02-27 12:26:13 +0000
@@ -5,13 +5,19 @@
 #include <stdint.h>
 #include <net/if.h>
 #include <netinet/in.h>
+#include <linux/netlink.h>
+/* CentOS 5.4 and some other legacy systems are broken. Including
+   linux/rtnetlink.h complains that __u32 or __64 is undefine */
+#ifndef __u32
+#define __u32 uint32_t
+#define __u64 uint64_t
+#endif /* __u32 */
+#include <linux/xfrm.h>
+#include <linux/rtnetlink.h>
 
 #include "lib/core/builder.h"
 #include "lib/core/debug.h"
-#include <linux/xfrm.h>
 
-/* Keep this one as the last to avoid some weird compilation problems */
-#include <linux/netlink.h>
 
 struct pseudo_hdr {
     u32 s_addr;
@@ -54,8 +60,8 @@
     int                fd;
     struct sockaddr_nl local;
     struct sockaddr_nl peer;
-    __u32              seq;
-    __u32              dump;
+    uint32_t           seq;
+    uint32_t           dump;
 };
 
 /* Workaround: in6_pktinfo does not compile on Fedora and Ubuntu anymore.

=== modified file 'lib/tool/xfrmapi.c'
--- lib/tool/xfrmapi.c  2010-02-16 17:00:19 +0000
+++ lib/tool/xfrmapi.c  2010-02-27 12:26:13 +0000
@@ -20,6 +20,8 @@
   #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
+#include "lib/tool/nlink.h"
+
 #include "xfrmapi.h"
 
 #ifndef CONFIG_HIP_PFKEY
@@ -124,9 +126,9 @@
         tmpl->id.proto = proto;
     }
 
-    tmpl->aalgos   = (~(__u32) 0);
-    tmpl->ealgos   = (~(__u32) 0);
-    tmpl->calgos   = (~(__u32) 0);
+    tmpl->aalgos   = (~(uint32_t) 0);
+    tmpl->ealgos   = (~(uint32_t) 0);
+    tmpl->calgos   = (~(uint32_t) 0);
     tmpl->optional = 0;     /* required */
     tmpls_len     += sizeof(*tmpl);
     if (tmpl_saddr && tmpl_daddr) {
@@ -276,7 +278,7 @@
                                  const struct in6_addr *daddr,
                                  const struct in6_addr *src_id,
                                  const struct in6_addr *dst_id,
-                                 const __u32 spi, const int ealg,
+                                 const uint32_t spi, const int ealg,
                                  const struct hip_crypto_key *enckey,
                                  const int enckey_len,
                                  const int aalg,
@@ -386,7 +388,7 @@
  * @return 0 on success or negative on error
  */
 static int hip_xfrm_state_delete(struct rtnl_handle *rth,
-                                 const struct in6_addr *peer_addr, __u32 spi,
+                                 const struct in6_addr *peer_addr, uint32_t 
spi,
                                  const int preferred_family,
                                  const int sport, const int dport)
 {

=== modified file 'lib/tool/xfrmapi.h'
--- lib/tool/xfrmapi.h  2010-02-17 13:08:39 +0000
+++ lib/tool/xfrmapi.h  2010-02-27 12:26:13 +0000
@@ -8,12 +8,6 @@
 
 #include <time.h>
 #include <netdb.h>
-#ifndef __u32
-/* Fedore Core 3/4 and Enterprise linux 4 is broken. */
-#  include <linux/types.h>
-#endif
-#include <linux/netlink.h>
-#include <linux/rtnetlink.h>
 #include <errno.h>
 
 #include "hipd/netdev.h"

Other related posts:

  • » [hipl-commit] [trunk] Rev 3720: Minimized and cleaned up a compilation fix for __u32 and __u64. - Miika Komu