From: Vincent Bernat Date: Sun, 23 Dec 2012 15:26:38 +0000 (+0100) Subject: netlink: fix bogus alignment warnings X-Git-Tag: 0.7.0~45 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2fafbd309cac8e7d66892d92b26900fe0f34d32e;p=thirdparty%2Flldpd.git netlink: fix bogus alignment warnings 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 --- diff --git a/include/linux/if_addr.h b/include/linux/if_addr.h index 58b39f47..60b2d8c3 100644 --- a/include/linux/if_addr.h +++ b/include/linux/if_addr.h @@ -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 diff --git a/include/linux/if_link.h b/include/linux/if_link.h index 46f03db3..e4e6e71a 100644 --- a/include/linux/if_link.h +++ b/include/linux/if_link.h @@ -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 { diff --git a/include/linux/netlink.h b/include/linux/netlink.h index 830923b7..ada78670 100644 --- a/include/linux/netlink.h +++ b/include/linux/netlink.h @@ -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)) diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index d5b7fddf..69b90706 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -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 diff --git a/src/daemon/netlink.c b/src/daemon/netlink.c index 9c3f8bce..898ee1c8 100644 --- a/src/daemon/netlink.c +++ b/src/daemon/netlink.c @@ -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) {