]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
netlink: fix bogus alignment warnings
authorVincent Bernat <bernat@luffy.cx>
Sun, 23 Dec 2012 15:26:38 +0000 (16:26 +0100)
committerVincent Bernat <bernat@luffy.cx>
Sun, 23 Dec 2012 22:11:07 +0000 (23:11 +0100)
The fix is stolen from XORP: we insert an intermediate cast to
`(void*)` to avoid the warning. Netlink stuff is already taking care
of the alignment issue, the compiler just doesn't know. This means
that the headers we copied from the kernel should be modified with:

     sed -i -e 's/\*)(((char\*/*)(void*)(((char*/g' \
            -e 's/(void\*)(void\*)/(void*)/g' include/**/*.h

include/linux/if_addr.h
include/linux/if_link.h
include/linux/netlink.h
include/linux/rtnetlink.h
src/daemon/netlink.c

index 58b39f47ae673f6e50a7e6a5530ada442f80d170..60b2d8c3338264b318d1ea8090c7f4fbbaf0d832 100644 (file)
@@ -53,7 +53,7 @@ struct ifa_cacheinfo {
 };
 
 /* backwards compatibility for userspace */
-#define IFA_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
+#define IFA_RTA(r)  ((struct rtattr*)(void*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
 #define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
 
 #endif
index 46f03db3a4d137c037818d50ea8b4de10b4a2aaa..e4e6e71a4e987490a51b01cd3889e2882c27678c 100644 (file)
@@ -149,7 +149,7 @@ enum {
 #define IFLA_MAX (__IFLA_MAX - 1)
 
 /* backwards compatibility for userspace */
-#define IFLA_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
+#define IFLA_RTA(r)  ((struct rtattr*)(void*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
 #define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
 
 enum {
index 830923b7e53a33fd4558dc3a95579d881f69aa43..ada786704db2a27aac28625e7347d1eff0c4a814 100644 (file)
@@ -82,7 +82,7 @@ struct nlmsghdr {
 #define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
 #define NLMSG_DATA(nlh)  ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
 #define NLMSG_NEXT(nlh,len)     ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
-                                 (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
+                                 (struct nlmsghdr*)(void*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
 #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
                           (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
                           (nlh)->nlmsg_len <= (len))
index d5b7fddf38359c4cff87a53df096d1ada5018769..69b90706d5cf8833c1e5ef0c4a0136376d0c66b2 100644 (file)
@@ -147,7 +147,7 @@ struct rtattr {
                         (rta)->rta_len >= sizeof(struct rtattr) && \
                         (rta)->rta_len <= (len))
 #define RTA_NEXT(rta,attrlen)  ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
-                                (struct rtattr*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
+                                (struct rtattr*)(void*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
 #define RTA_LENGTH(len)        (RTA_ALIGN(sizeof(struct rtattr)) + (len))
 #define RTA_SPACE(len) RTA_ALIGN(RTA_LENGTH(len))
 #define RTA_DATA(rta)   ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
@@ -288,7 +288,7 @@ enum rtattr_type_t {
 
 #define RTA_MAX (__RTA_MAX - 1)
 
-#define RTM_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
+#define RTM_RTA(r)  ((struct rtattr*)(void*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
 #define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg))
 
 /* RTM_MULTIPATH --- array of struct rtnexthop.
@@ -319,10 +319,10 @@ struct rtnexthop {
 #define RTNH_ALIGN(len) ( ((len)+RTNH_ALIGNTO-1) & ~(RTNH_ALIGNTO-1) )
 #define RTNH_OK(rtnh,len) ((rtnh)->rtnh_len >= sizeof(struct rtnexthop) && \
                           ((int)(rtnh)->rtnh_len) <= (len))
-#define RTNH_NEXT(rtnh)        ((struct rtnexthop*)(((char*)(rtnh)) + RTNH_ALIGN((rtnh)->rtnh_len)))
+#define RTNH_NEXT(rtnh)        ((struct rtnexthop*)(void*)(((char*)(rtnh)) + RTNH_ALIGN((rtnh)->rtnh_len)))
 #define RTNH_LENGTH(len) (RTNH_ALIGN(sizeof(struct rtnexthop)) + (len))
 #define RTNH_SPACE(len)        RTNH_ALIGN(RTNH_LENGTH(len))
-#define RTNH_DATA(rtnh)   ((struct rtattr*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
+#define RTNH_DATA(rtnh)   ((struct rtattr*)(void*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
 
 /* RTM_CACHEINFO */
 
@@ -489,7 +489,7 @@ enum {
 
 #define TCA_MAX (__TCA_MAX - 1)
 
-#define TCA_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
+#define TCA_RTA(r)  ((struct rtattr*)(void*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
 #define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
 
 /********************************************************************
@@ -595,7 +595,7 @@ struct tcamsg {
        unsigned char   tca__pad1;
        unsigned short  tca__pad2;
 };
-#define TA_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcamsg))))
+#define TA_RTA(r)  ((struct rtattr*)(void*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcamsg))))
 #define TA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcamsg))
 #define TCA_ACT_TAB 1 /* attr type must be >=1 */      
 #define TCAA_MAX 1
index 9c3f8bce941e87b02c2ab9907011b40e1f2742ff..898ee1c823b6a358713d5c7aa627641943d5db83 100644 (file)
@@ -174,18 +174,18 @@ static int
 netlink_parse_link(struct nlmsghdr *msg,
     struct netlink_interface *iff)
 {
-    struct ifinfomsg *iface;
+    struct ifinfomsg *ifi;
     struct rtattr *attribute;
     int len;
-    iface = NLMSG_DATA(msg);
+    ifi = NLMSG_DATA(msg);
     len = msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
 
-    iff->index = iface->ifi_index;
-    iff->type  = iface->ifi_type;
-    iff->flags = iface->ifi_flags;
+    iff->index = ifi->ifi_index;
+    iff->type  = ifi->ifi_type;
+    iff->flags = ifi->ifi_flags;
     iff->link  = -1;
 
-    for (attribute = IFLA_RTA(iface);
+    for (attribute = IFLA_RTA(ifi);
          RTA_OK(attribute, len);
          attribute = RTA_NEXT(attribute, len)) {
         switch(attribute->rta_type) {
@@ -306,7 +306,7 @@ netlink_recv(int s,
   struct netlink_interface_list *ifs,
   struct netlink_address_list *ifas)
 {
-    char reply[NETLINK_BUFFER];
+    char reply[NETLINK_BUFFER] __attribute__ ((aligned));
     int  end = 0;
 
     struct netlink_interface *iff;
@@ -333,7 +333,7 @@ netlink_recv(int s,
             return -1;
         }
         if (!len) return 0;
-        for (msg = (struct nlmsghdr*)reply;
+        for (msg = (struct nlmsghdr*)(void*)reply;
              NLMSG_OK(msg, len);
              msg = NLMSG_NEXT(msg, len)) {
             switch (msg->nlmsg_type) {