Skip to contentSkip to conversation

libnetfilter-conntrack byte alignment

PATCH Applied Fabian Hugelshofer 2 participants 3 messages Jun 3, 2008 – Jun 18, 2008 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 libnetfilter-conntrack byte alignment

Aligns buffers to maximum alignment of architecture to make the cast of char pointers to struct pointers more portable.

src/conntrack/api.c +1 -1
diff -ruN libnetfilter_conntrack-0.0.89.orig/src/conntrack/api.c libnetfilter_conntrack-0.0.89/src/conntrack/api.c
@@ -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);
src/expect/api.c +1 -1
diff -ruN libnetfilter_conntrack-0.0.89.orig/src/expect/api.c libnetfilter_conntrack-0.0.89/src/expect/api.c
@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw

Use union of char buffer and message header to ensure proper byte alignment.

src/conntrack/api.c +12 -8
index b1347dc..58efd32 100644
@@ -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);
 }
 
 
src/expect/api.c +6 -4
index eefc294..ab804ca 100644
@@ -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);
 }
 
 /**
#2 lore raw
Quoted 2 lines · Fabian Hugelshofer

Use union of char buffer and message header to ensure proper byte alignment.

Also applied. Thanks.

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers