最近在移植iptables,linux下强大的防火墙配置工具,被一个bug死死的卡了一周。。。
开始我是在虚拟机上编译的iptables(这里用的是mipsel-linux 交叉编译工具),拷到龙芯目标板上运行,一直报错: "target error" 。
后来我在代码里跟进去发现错误的原因是iptables查表的时候,使用的是copy_to_user(), 把内核空间的数据拷贝到用户空间,数据的定位都是通过offset,并使用了一堆算法。想通过代码解决这个问题感觉好难。
我在网上搜了下这个错误的原因,都说是下面这个结构体的对齐问题。1.4.0版本之前出现这个问题,都是通过改这个结构体解决的。
/* this is a dummy structure to find out the alignment requirement for a struct
* containing all the fundamental data types that are used in ipt_entry,
* ip6t_entry and arpt_entry. This sucks, and it is a hack. It will be my
* personal pleasure to remove it -HW
*/
struct _xt_align {
__u8 u8;
__u16 u16;
__u32 u32;
__u64 u64;
};
#define XT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) \
& ~(__alignof__(struct _xt_align)-1))
不同平台边界对齐的大小是不一样的&