netlink: Fix RTM_SETLINK padding at the end of the message
authorJouni Malinen <j@w1.fi>
Sun, 12 Oct 2014 16:07:17 +0000 (19:07 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 12 Oct 2014 16:27:16 +0000 (19:27 +0300)
While the kernel seems to have accepted the message to set linkmode and
operstate without the final attribute getting padded to 32-bit length,
it is better to get this cleaned up to match expected format. The double
NLMSG_ALIGN() followed by RTA_LENGTH() did not make much sense here.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/drivers/netlink.c
src/drivers/priv_netlink.h

index 2fa20b1..0e960f4 100644 (file)
@@ -199,8 +199,7 @@ int netlink_send_oper_ifla(struct netlink_data *netlink, int ifindex,
                rta->rta_type = IFLA_LINKMODE;
                rta->rta_len = RTA_LENGTH(sizeof(char));
                *((char *) RTA_DATA(rta)) = linkmode;
-               req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) +
-                       RTA_LENGTH(sizeof(char));
+               req.hdr.nlmsg_len += RTA_SPACE(sizeof(char));
        }
        if (operstate != -1) {
                rta = aliasing_hide_typecast(
@@ -209,8 +208,7 @@ int netlink_send_oper_ifla(struct netlink_data *netlink, int ifindex,
                rta->rta_type = IFLA_OPERSTATE;
                rta->rta_len = RTA_LENGTH(sizeof(char));
                *((char *) RTA_DATA(rta)) = operstate;
-               req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) +
-                       RTA_LENGTH(sizeof(char));
+               req.hdr.nlmsg_len += RTA_SPACE(sizeof(char));
        }
 
        wpa_printf(MSG_DEBUG, "netlink: Operstate: ifindex=%d linkmode=%d (%s), operstate=%d (%s)",
index 6232088..d3f091c 100644 (file)
@@ -68,6 +68,7 @@
 ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
 (struct rtattr *) (((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)))
 #define RTA_PAYLOAD(rta) ((int) ((rta)->rta_len) - RTA_LENGTH(0))