* [PATCH] iproute2: rtnl_wilddump_request: fix alignment for embedded platforms
@ 2012-08-22 7:38 Lutz Jaenicke
2012-08-30 15:01 ` [PATCH] rtnl_wilddump_request: fix alignment issue " Lutz Jaenicke
0 siblings, 1 reply; 4+ messages in thread
From: Lutz Jaenicke @ 2012-08-22 7:38 UTC (permalink / raw)
To: netdev; +Cc: Lutz Jaenicke
Platforms have different alignment requirements which need to be
fulfilled by the compiler. If the structure elements are already
4 byte (NLMGS_ALIGNTO) aligned by the compiler adding an explicit
padding element (align_rta) is not allowed.
Use __attribute__ ((aligned (NLMSG_ALIGNTO))) in order to achieve
the required alignment.
Experienced on ARM (xscale) with symptom
netlink: 12 bytes leftover after parsing attributes
Signed-off-by: Lutz Jaenicke <ljaenicke@innominate.com>
---
lib/libnetlink.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 8e8c8b9..05701ef 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -94,10 +94,9 @@ int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
struct {
struct nlmsghdr nlh;
struct rtgenmsg g;
- __u16 align_rta; /* attribute has to be 32bit aligned */
struct rtattr ext_req;
__u32 ext_filter_mask;
- } req;
+ } req __attribute__ ((aligned (NLMSG_ALIGNTO)));
memset(&req, 0, sizeof(req));
req.nlh.nlmsg_len = sizeof(req);
--
1.7.2.5
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH] rtnl_wilddump_request: fix alignment issue for embedded platforms
2012-08-22 7:38 [PATCH] iproute2: rtnl_wilddump_request: fix alignment for embedded platforms Lutz Jaenicke
@ 2012-08-30 15:01 ` Lutz Jaenicke
2012-08-30 15:51 ` David Laight
0 siblings, 1 reply; 4+ messages in thread
From: Lutz Jaenicke @ 2012-08-30 15:01 UTC (permalink / raw)
To: netdev
Platforms have different alignment requirements which need to be
fulfilled by the compiler. If the structure elements are already
4 byte (NLMGS_ALIGNTO) aligned by the compiler adding an explicit
padding element (align_rta) is not allowed.
Use __attribute__ ((aligned (NLMSG_ALIGNTO))) in order to achieve
the required alignment.
Experienced on ARM (xscale) with symptom
netlink: 12 bytes leftover after parsing attributes
Tested on:
ARM (32bit Big Endian)
PowerPC (32bit Big Endian)
x86_64 (64bit Little Endian)
Each with different aligment requirments.
Signed-off-by: Lutz Jaenicke <ljaenicke@innominate.com>
---
lib/libnetlink.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 8e8c8b9..09b4277 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -94,8 +94,8 @@ int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
struct {
struct nlmsghdr nlh;
struct rtgenmsg g;
- __u16 align_rta; /* attribute has to be 32bit aligned */
- struct rtattr ext_req;
+ /* attribute has to be NLMSG aligned */
+ struct rtattr ext_req __attribute__ ((aligned(NLMSG_ALIGNTO)));
__u32 ext_filter_mask;
} req;
--
1.7.2.5
^ permalink raw reply related [flat|nested] 4+ messages in thread* RE: [PATCH] rtnl_wilddump_request: fix alignment issue for embedded platforms
2012-08-30 15:01 ` [PATCH] rtnl_wilddump_request: fix alignment issue " Lutz Jaenicke
@ 2012-08-30 15:51 ` David Laight
2012-08-30 16:09 ` Lutz Jaenicke
0 siblings, 1 reply; 4+ messages in thread
From: David Laight @ 2012-08-30 15:51 UTC (permalink / raw)
To: Lutz Jaenicke, netdev
> + /* attribute has to be NLMSG aligned */
> + struct rtattr ext_req
__attribute__((aligned(NLMSG_ALIGNTO)));
Would it be better to apply the attribute to the definition
of 'struct rtattr' itself ?
David
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rtnl_wilddump_request: fix alignment issue for embedded platforms
2012-08-30 15:51 ` David Laight
@ 2012-08-30 16:09 ` Lutz Jaenicke
0 siblings, 0 replies; 4+ messages in thread
From: Lutz Jaenicke @ 2012-08-30 16:09 UTC (permalink / raw)
To: David Laight; +Cc: netdev
On Thu, Aug 30, 2012 at 04:51:49PM +0100, David Laight wrote:
> > + /* attribute has to be NLMSG aligned */
> > + struct rtattr ext_req
> __attribute__((aligned(NLMSG_ALIGNTO)));
>
> Would it be better to apply the attribute to the definition
> of 'struct rtattr' itself ?
'struct rtattr' is defined in a kernel header and I am not really sure
what kind of side effects it would have.
The problem I intend to solve with my page is rather caused by the use case:
The request is sent as a single structure, the processing is however
performed step by step: first the nlmsg is parsed, then the pointer
is moved on to the parsing of the content. This pointer is hoever not
oriented at the structure element but by using size information which
is then adjust by NLMSG_ALIGN() etc. Consequently one should actually
use the same method in sending (generate the header first, then addattr_()
which enforces protocol conform alignment). This is the way all other
instances in iproute2 generate their messages btw.
I hence consider my proposed patch to be the least intrusive solution.
Best regards,
Lutz
--
Dr.-Ing. Lutz Jänicke
CTO
Innominate Security Technologies AG /protecting industrial networks/
tel: +49.30.921028-200
fax: +49.30.921028-020
Rudower Chaussee 13
D-12489 Berlin, Germany
www.innominate.com
Register Court: AG Charlottenburg, HR B 81603
Management Board: Dirk Seewald
Chairman of the Supervisory Board: Christoph Leifer
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-08-30 16:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-22 7:38 [PATCH] iproute2: rtnl_wilddump_request: fix alignment for embedded platforms Lutz Jaenicke
2012-08-30 15:01 ` [PATCH] rtnl_wilddump_request: fix alignment issue " Lutz Jaenicke
2012-08-30 15:51 ` David Laight
2012-08-30 16:09 ` Lutz Jaenicke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox