* [PATCH 3/3] libnetfilter-conntrack byte alignment
@ 2008-06-03 10:21 Fabian Hugelshofer
2008-06-16 20:32 ` Fabian Hugelshofer
0 siblings, 1 reply; 3+ messages in thread
From: Fabian Hugelshofer @ 2008-06-03 10:21 UTC (permalink / raw)
To: netfilter-devel
Aligns buffers to maximum alignment of architecture to make the cast of
char pointers to struct pointers more portable.
Signed-off-by: Fabian Hugelshofer <hugelshofer2006@gmx.ch>
diff -ruN libnetfilter_conntrack-0.0.89.orig/src/conntrack/api.c libnetfilter_conntrack-0.0.89/src/conntrack/api.c
--- libnetfilter_conntrack-0.0.89.orig/src/conntrack/api.c 2008-06-02 19:35:12.000000000 +0100
+++ libnetfilter_conntrack-0.0.89/src/conntrack/api.c 2008-06-02 19:38:07.000000000 +0100
@@ -561,7 +561,7 @@
const void *data)
{
size_t size = 4096; /* enough for now */
- char buffer[4096];
+ char buffer[4096] __attribute__ ((aligned));
struct nfnlhdr *req = (struct nfnlhdr *) buffer;
assert(h != NULL);
diff -ruN libnetfilter_conntrack-0.0.89.orig/src/expect/api.c libnetfilter_conntrack-0.0.89/src/expect/api.c
--- libnetfilter_conntrack-0.0.89.orig/src/expect/api.c 2008-06-02 19:35:12.000000000 +0100
+++ libnetfilter_conntrack-0.0.89/src/expect/api.c 2008-06-02 19:39:59.000000000 +0100
@@ -507,7 +507,7 @@
const void *data)
{
size_t size = 4096; /* enough for now */
- char buffer[4096];
+ char buffer[4096] __attribute__ ((aligned));
struct nfnlhdr *req = (struct nfnlhdr *) buffer;
assert(h != NULL);
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH 3/3] libnetfilter-conntrack byte alignment 2008-06-03 10:21 [PATCH 3/3] libnetfilter-conntrack byte alignment Fabian Hugelshofer @ 2008-06-16 20:32 ` Fabian Hugelshofer 2008-06-18 12:40 ` Pablo Neira Ayuso 0 siblings, 1 reply; 3+ messages in thread From: Fabian Hugelshofer @ 2008-06-16 20:32 UTC (permalink / raw) To: netfilter-devel; +Cc: pablo Use union of char buffer and message header to ensure proper byte alignment. Signed-off-by: Fabian Hugelshofer <hugelshofer2006@gmx.ch> diff --git a/src/conntrack/api.c b/src/conntrack/api.c index b1347dc..58efd32 100644 --- a/src/conntrack/api.c +++ b/src/conntrack/api.c @@ -563,16 +563,18 @@ int nfct_query(struct nfct_handle *h, const void *data) { size_t size = 4096; /* enough for now */ - char buffer[4096]; - struct nfnlhdr *req = (struct nfnlhdr *) buffer; + union { + char buffer[size]; + struct nfnlhdr req; + } u; assert(h != NULL); assert(data != NULL); - if (nfct_build_query(h->nfnlssh_ct, qt, data, req, size) == -1) + if (nfct_build_query(h->nfnlssh_ct, qt, data, &u.req, size) == -1) return -1; - return nfnl_query(h->nfnlh, &req->nlh); + return nfnl_query(h->nfnlh, &u.req.nlh); } /** @@ -593,16 +595,18 @@ int nfct_send(struct nfct_handle *h, const void *data) { size_t size = 4096; /* enough for now */ - char buffer[4096]; - struct nfnlhdr *req = (struct nfnlhdr *) buffer; + union { + char buffer[size]; + struct nfnlhdr req; + } u; assert(h != NULL); assert(data != NULL); - if (nfct_build_query(h->nfnlssh_ct, qt, data, req, size) == -1) + if (nfct_build_query(h->nfnlssh_ct, qt, data, &u.req, size) == -1) return -1; - return nfnl_send(h->nfnlh, &req->nlh); + return nfnl_send(h->nfnlh, &u.req.nlh); } diff --git a/src/expect/api.c b/src/expect/api.c index eefc294..ab804ca 100644 --- a/src/expect/api.c +++ b/src/expect/api.c @@ -507,16 +507,18 @@ int nfexp_query(struct nfct_handle *h, const void *data) { size_t size = 4096; /* enough for now */ - char buffer[4096]; - struct nfnlhdr *req = (struct nfnlhdr *) buffer; + union { + char buffer[size]; + struct nfnlhdr req; + } u; assert(h != NULL); assert(data != NULL); - if (nfexp_build_query(h->nfnlssh_exp, qt, data, req, size) == -1) + if (nfexp_build_query(h->nfnlssh_exp, qt, data, &u.req, size) == -1) return -1; - return nfnl_query(h->nfnlh, &req->nlh); + return nfnl_query(h->nfnlh, &u.req.nlh); } /** ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 3/3] libnetfilter-conntrack byte alignment 2008-06-16 20:32 ` Fabian Hugelshofer @ 2008-06-18 12:40 ` Pablo Neira Ayuso 0 siblings, 0 replies; 3+ messages in thread From: Pablo Neira Ayuso @ 2008-06-18 12:40 UTC (permalink / raw) To: Fabian Hugelshofer; +Cc: netfilter-devel Fabian Hugelshofer wrote: > Use union of char buffer and message header to ensure proper byte > alignment. Also applied. Thanks. -- "Los honestos son inadaptados sociales" -- Les Luthiers ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-06-18 12:40 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-06-03 10:21 [PATCH 3/3] libnetfilter-conntrack byte alignment Fabian Hugelshofer 2008-06-16 20:32 ` Fabian Hugelshofer 2008-06-18 12:40 ` Pablo Neira Ayuso
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.