fix alignment issues
authorFabian Hugelshofer <hugelshofer2006@gmx.ch>
Mon, 23 Jun 2008 14:16:58 +0000 (16:16 +0200)
committerr.kubiak <r.kubiak@samsung.com>
Mon, 16 Nov 2015 13:12:05 +0000 (14:12 +0100)
src/libnetfilter_queue.c
utils/nfqnl_test.c

index ef638d6860c39f31ba9d49673fd8a9dd053e5652..d319b7bf91a27a00802292a3cd6b3145373b1667 100644 (file)
@@ -97,19 +97,21 @@ static struct nfq_q_handle *find_qh(struct nfq_handle *h, u_int16_t id)
 __build_send_cfg_msg(struct nfq_handle *h, u_int8_t command,
                u_int16_t queuenum, u_int16_t pf)
 {
-       char buf[NFNL_HEADER_LEN
-               +NFA_LENGTH(sizeof(struct nfqnl_msg_config_cmd))];
+       union {
+               char buf[NFNL_HEADER_LEN
+                       +NFA_LENGTH(sizeof(struct nfqnl_msg_config_cmd))];
+               struct nlmsghdr nmh;
+       } u;
        struct nfqnl_msg_config_cmd cmd;
-       struct nlmsghdr *nmh = (struct nlmsghdr *) buf;
 
-       nfnl_fill_hdr(h->nfnlssh, nmh, 0, AF_UNSPEC, queuenum,
+       nfnl_fill_hdr(h->nfnlssh, &u.nmh, 0, AF_UNSPEC, queuenum,
                        NFQNL_MSG_CONFIG, NLM_F_REQUEST|NLM_F_ACK);
 
        cmd.command = command;
        cmd.pf = htons(pf);
-       nfnl_addattr_l(nmh, sizeof(buf), NFQA_CFG_CMD, &cmd, sizeof(cmd));
+       nfnl_addattr_l(&u.nmh, sizeof(u), NFQA_CFG_CMD, &cmd, sizeof(cmd));
 
-       return nfnl_talk(h->nfnlh, nmh, 0, 0, NULL, NULL, NULL);
+       return nfnl_talk(h->nfnlh, &u.nmh, 0, 0, NULL, NULL, NULL);
 }
 
 static int __nfq_rcv_pkt(struct nlmsghdr *nlh, struct nfattr *nfa[],
@@ -272,37 +274,41 @@ int nfq_handle_packet(struct nfq_handle *h, char *buf, int len)
 int nfq_set_mode(struct nfq_q_handle *qh,
                u_int8_t mode, u_int32_t range)
 {
-       char buf[NFNL_HEADER_LEN
-               +NFA_LENGTH(sizeof(struct nfqnl_msg_config_params))];
+       union {
+               char buf[NFNL_HEADER_LEN
+                       +NFA_LENGTH(sizeof(struct nfqnl_msg_config_params))];
+               struct nlmsghdr nmh;
+       } u;
        struct nfqnl_msg_config_params params;
-       struct nlmsghdr *nmh = (struct nlmsghdr *) buf;
 
-       nfnl_fill_hdr(qh->h->nfnlssh, nmh, 0, AF_UNSPEC, qh->id,
+       nfnl_fill_hdr(qh->h->nfnlssh, &u.nmh, 0, AF_UNSPEC, qh->id,
                        NFQNL_MSG_CONFIG, NLM_F_REQUEST|NLM_F_ACK);
 
        params.copy_range = htonl(range);
        params.copy_mode = mode;
-       nfnl_addattr_l(nmh, sizeof(buf), NFQA_CFG_PARAMS, &params,
+       nfnl_addattr_l(&u.nmh, sizeof(u), NFQA_CFG_PARAMS, &params,
                        sizeof(params));
 
-       return nfnl_talk(qh->h->nfnlh, nmh, 0, 0, NULL, NULL, NULL);
+       return nfnl_talk(qh->h->nfnlh, &u.nmh, 0, 0, NULL, NULL, NULL);
 }
 
 int nfq_set_queue_maxlen(struct nfq_q_handle *qh,
                                u_int32_t queuelen)
 {
-       char buf[NFNL_HEADER_LEN
-               +NFA_LENGTH(sizeof(struct nfqnl_msg_config_params))];
+       union {
+               char buf[NFNL_HEADER_LEN
+                       +NFA_LENGTH(sizeof(struct nfqnl_msg_config_params))];
+               struct nlmsghdr nmh;
+       } u;
        u_int32_t queue_maxlen = htonl(queuelen);
-       struct nlmsghdr *nmh = (struct nlmsghdr *) buf;
 
-       nfnl_fill_hdr(qh->h->nfnlssh, nmh, 0, AF_UNSPEC, qh->id,
+       nfnl_fill_hdr(qh->h->nfnlssh, &u.nmh, 0, AF_UNSPEC, qh->id,
                        NFQNL_MSG_CONFIG, NLM_F_REQUEST|NLM_F_ACK);
 
-       nfnl_addattr_l(nmh, sizeof(buf), NFQA_CFG_QUEUE_MAXLEN, &queue_maxlen,
+       nfnl_addattr_l(&u.nmh, sizeof(u), NFQA_CFG_QUEUE_MAXLEN, &queue_maxlen,
                        sizeof(queue_maxlen));
 
-       return nfnl_talk(qh->h->nfnlh, nmh, 0, 0, NULL, NULL, NULL);
+       return nfnl_talk(qh->h->nfnlh, &u.nmh, 0, 0, NULL, NULL, NULL);
 }
 
 static int __set_verdict(struct nfq_q_handle *qh, u_int32_t id,
@@ -310,10 +316,12 @@ static int __set_verdict(struct nfq_q_handle *qh, u_int32_t id,
                u_int32_t data_len, unsigned char *data)
 {
        struct nfqnl_msg_verdict_hdr vh;
-       char buf[NFNL_HEADER_LEN
-               +NFA_LENGTH(sizeof(mark))
-               +NFA_LENGTH(sizeof(vh))];
-       struct nlmsghdr *nmh = (struct nlmsghdr *) buf;
+       union {
+               char buf[NFNL_HEADER_LEN
+                       +NFA_LENGTH(sizeof(mark))
+                       +NFA_LENGTH(sizeof(vh))];
+               struct nlmsghdr nmh;
+       } u;
 
        struct iovec iov[3];
        int nvecs;
@@ -327,17 +335,17 @@ static int __set_verdict(struct nfq_q_handle *qh, u_int32_t id,
        vh.verdict = htonl(verdict);
        vh.id = htonl(id);
 
-       nfnl_fill_hdr(qh->h->nfnlssh, nmh, 0, AF_UNSPEC, qh->id,
+       nfnl_fill_hdr(qh->h->nfnlssh, &u.nmh, 0, AF_UNSPEC, qh->id,
                        NFQNL_MSG_VERDICT, NLM_F_REQUEST);
 
        /* add verdict header */
-       nfnl_addattr_l(nmh, sizeof(buf), NFQA_VERDICT_HDR, &vh, sizeof(vh));
+       nfnl_addattr_l(&u.nmh, sizeof(u), NFQA_VERDICT_HDR, &vh, sizeof(vh));
 
        if (set_mark)
-               nfnl_addattr32(nmh, sizeof(buf), NFQA_MARK, mark);
+               nfnl_addattr32(&u.nmh, sizeof(u), NFQA_MARK, mark);
 
-       iov[0].iov_base = nmh;
-       iov[0].iov_len = NLMSG_TAIL(nmh) - (void *)nmh;
+       iov[0].iov_base = &u.nmh;
+       iov[0].iov_len = NLMSG_TAIL(&u.nmh) - (void *)&u.nmh;
        nvecs = 1;
 
        if (data_len) {
@@ -348,7 +356,7 @@ static int __set_verdict(struct nfq_q_handle *qh, u_int32_t id,
                 * header.  The size of the attribute is given in the
                 * nfa_len field and is set in the nfnl_build_nfa_iovec()
                 * function. */
-               nmh->nlmsg_len += data_attr.nfa_len;
+               u.nmh.nlmsg_len += data_attr.nfa_len;
        }
 
        return nfnl_sendiov(qh->h->nfnlh, iov, nvecs, 0);
index be729746009e4e2bdd7670a419dbc982209e946a..7e4edab8be4660d8c942df8da4790d2b11b875a7 100644 (file)
@@ -61,7 +61,7 @@ int main(int argc, char **argv)
        struct nfnl_handle *nh;
        int fd;
        int rv;
-       char buf[4096];
+       char buf[4096] __attribute__ ((aligned));
 
        printf("opening library handle\n");
        h = nfq_open();