2008年2月20日 星期三

Cross compiling openswan-2.5.16 on ARM

  1. download openswan-2.5.16, gmp-4.2.2, decompress.
  2. build gmp-4.2.2,小蛋糕一塊~
    ./configure --host=arm-linux CC=arm-linux-gcc CXX=arm-linux-uclibc-g++ --prefix=${INSTALL_PATH}
    make
    make install
  3. build好的ipsec.ko會無法insert,因為沒定義bzero? openswan會出這種包嗎? 總覺得會是我耍笨....
    ipsec: Unknown symbol bzero
    insmod: cannot insert `ipsec.ko': Unknown symbol in module (-1): No such file or directory
    所以要define bzero
    Index: linux/include/openswan.h
    ===================================================================
    --- linux/include/openswan.h (revision 72)
    +++ linux/include/openswan.h (revision 73)
    @@ -36,6 +34,7 @@
    /* things that need to come from one place or the other, depending */
    #if defined(linux)
    #if defined(__KERNEL__)
    +#define bzero(_a,_b) memset(_a,0,_b)
    #include <linux/types.h>
    #include <linux/socket.h>
    #include <linux/in.h>
  4. 雖然設定完成,但是ipsec.ko還是會被install到/lib/下而不是${DESTDIR}/lib下
    Index: Makefile
    ===================================================================
    --- Makefile (revision 69)
    +++ Makefile (revision 73)
    @@ -424,6 +424,7 @@
    exit 93 ; \
    fi ; \
    set -x ; \
    + OSMODLIB=${DESTDIR}$$OSMODLIB;\
    mkdir -p $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
    cp $(MODBUILDDIR)/ipsec.o $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
    if [ -f /sbin/depmod ] ; then depmod -a ; fi; \
    @@ -493,6 +494,7 @@
    exit 93 ; \
    fi ; \
    set -x ; \
    + OSMODLIB=${DESTDIR}$$OSMODLIB;\
    mkdir -p $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
    cp $(MOD26BUILDDIR)/ipsec.ko $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
    if [ -f /sbin/depmod ] ; then depmod -a ; fi; \
  5. kernel config CONFIG_NET_KEY 要拿掉 (For KLIPS)
  6. build openswan-2.5.16
    make DESTDIR=${INSTALL_PATH} KERNELSRC=${KERNELDIR} USERCOMPILE=-I${INSTALL_PATH}/include/ ARCH=arm OSDEP=linux USE_NETKEY=no CC="arm-linux-gcc -L${INSTALL_PATH}/lib " LD=arm-linux-ld RANLIB=arm-linux-ranlib AR=arm-linux-ar AS=arm-linux-as STRIP=arm-linux-strip programs module minstall install
===========
我用的kernel是2.6.16卻沒辦法build NETKEY
openswan-2.5.16/programs/pluto/linux26/rtnetlink.h:5:27: linux/if_link.h: No such file or directory
openswan-2.5.16/programs/pluto/linux26/rtnetlink.h:6:27: linux/if_addr.h: No such file or directory
openswan-2.5.16/programs/pluto/linux26/rtnetlink.h:7:29: linux/neighbour.h: No such file or directory
make[4]: *** [kernel_netlink.o] Error 1
稍微去LXR找了一下,if_link.h和if_addr.h和在2.6.19之後才出現,neighbour.h在2.6.19是放在include/net/下面........
這.......openswan並沒有說2.6.19以後才能用NETKEY啊,2.6應該都可以的呀,像這裡
只好用KLIPS了
USE_NETKEY=no
0802122
我稍微改了一下後就可以過了,但是還沒測過
Index: programs/pluto/linux26/rtnetlink.h
===================================================================
--- programs/pluto/linux26/rtnetlink.h (revision 75)
+++ programs/pluto/linux26/rtnetlink.h (revision 76)
@@ -2,9 +2,10 @@
#define __LINUX_RTNETLINK_H

#include <linux/netlink.h>
-#include <linux/if_link.h>
-#include <linux/if_addr.h>
-#include <linux/neighbour.h>
+//#include <linux/if_link.h>
+//#include <linux/if_addr.h>
+//#include <linux/neighbour.h>
+#include <net/neighbour.h>

===========
doc/src/crosscompile.html建議用LD_LIBRARY_PATH指定library的位置,但是結果會是
make: error while loading shared libraries: rootfs/target/lib/libpthread.so.0: ELF file OS ABI invalid
所以也沒有用,而且人家都說不要用了說....
3.3.1. LD_LIBRARY_PATH
Why LD_LIBRARY_PATH is bad

===========
0802122
今天打算要上NAT-T patch時又發現另一個問題,那就是它竟然對.svn檔案patch??
openswan-2.5.16 # make nattpatch

if [ -f /usr/src/linux/Makefile ]; then \
make nattpatch2.6; \
else echo "Cannot determine Linux kernel version. Perhaps you need to set KERNELSRC? (eg: export KERNELSRC=/usr/src/linux-`uname -r`/)"; exit 1; \
fi;
make[1]: Entering directory `/home/mac/star/str8100-lsdk/apps-pool/openswan-2.5.16'
packaging/utils/nattpatch 2.6
--- /dev/null 2008-02-02 20:09:24.144292949 +0000
+++ nat-t/.svn/entries 2008-02-21 14:47:42.133786674 +0000
@@ -0,0 +1,22 @@
(......................................................)
最後發現,是因為我把openswan加到subversion裡面,可是packaging/utils/nattpatch:
find nat-t -type f -print | grep -v CVS | egrep -v 'linux/Makefile' | sort
會包括svn檔案,改一下讓他也拿掉.svn
Index: packaging/utils/nattpatch
===================================================================
--- packaging/utils/nattpatch (revision 73)
+++ packaging/utils/nattpatch (working copy)
@@ -29,7 +29,7 @@
LC_ALL=C export LC_ALL


-find nat-t -type f -print | grep -v CVS | egrep -v 'linux/Makefile' | sort | while read file
+find nat-t -type f -print | grep -v CVS | egrep -v 'linux/Makefile' | grep -v "\.svn" | sort | while read file
do
base=`basename $file`
pname=`echo $file | sed -e 's,\.fs._.$,,' -e 's,\.os._.$,,'`

32 則留言:

匿名 提到...

你试过了吗?怎么我生成的ipsec,ko及其它组件下载到ARM板上后不能用呢?

mkl 提到...

應該是可以用的
你是怎麼個不能用法呢?

匿名 提到...

把ipsec.ko及install安装生成的包下载到板上,然后执行ipsec verify,结果提示找不到ipsec这个命令!

匿名 提到...

在板上insmod ipsec.ko的时候出现下面的提示,不知道对不对!
klips_info:ipsec_init: KLIPS startup, Openswan KLIPS IPsec stack version: 2.6.16
NET: Registered protocol family 15
klips_info:ipsec_alg_init: KLIPS alg v=0.8.1-0 (EALG_MAX=255, AALG_MAX=251)
klips_info:ipsec_alg_init: calling ipsec_alg_static_init()
ipsec_aes_init(alg_type=15 alg_id=12 name=aes): ret=0
ipsec_3des_init(alg_type=15 alg_id=3 name=3des): ret=0

mkl 提到...

ipsec 預設是安裝在 /usr/local/sbin下的
我剛剛還跑了一次,確定是好的喔

匿名 提到...

是吗?你是怎么用的?我在交叉编译的时候指定了安装路径为/tool,然后在/tool下会生成/etc /usr /var(/include /info /lib 是安装gmp时生成的),然后将/etc /usr /var里的文件全都下载到ARM板上对应的目录里去,接着执行ipsec verify 或都是其它的命令,就会出现错误提示,可是它提示的不存在的文件是已经放在那个位置的,我列出来你看一下!

# /usr/local/sbin/ipsec
Usage: ipsec command argument ...
Use --help for list of commands, or see ipsec(8) manual page
or the Openswan documentation for names of the common ones.
Most have their own manual pages, e.g. ipsec_auto(8).
See ...
# /usr/local/sbin/ipsec verify
/usr/local/sbin/ipsec: /usr/local/libexec/ipsec/verify: bad interpreter: No such file or directory
/usr/local/sbin/ipsec: /usr/local/libexec/ipsec/verify: No such file or directory
# /usr/local/sbin/ipsec look
/usr/local/sbin/ipsec: unknown IPsec command `look' (`ipsec --help' for list)
# /usr/local/sbin/ipsec --help
Usage: ipsec command argument ...
where command is one of:
/usr/local/sbin/ipsec: egrep: command not found

Most of these have their own manual pages, e.g. ipsec_auto(8).
See also 。。。 or the ipsec(8) manual page.
# ipsec
sh: ipsec: command not found

mkl 提到...

那是因為verify是perl的scrip
你要跑的話要裝perl

我沒有裝,所以也有同樣的狀況

匿名 提到...

这样的啊,那有没有什么方法可以用来检验我的ipsec移植到板上后是否是可以运行的?我刚刚发现/tool/var/run/pluto是一个空的文件夹,它应该是有一个pluto.ctl,你的有吗?我的没有这个文件哦!

匿名 提到...

我想问一下,你在板上是怎么运行IPSEC的?我现在似乎还缺少很多设置,比如我在运行ipsec setup start时又会出现ipsec_setup: modprobe: module af_key not found.
ipsec_setup: modprobe: failed to load module af_key这样的错误提示,其它的命令执行起来也会有一些错误提示,比如前面说的:/var/run/pluto/pluto.ctl文件一存在等,所以现在不知道该怎么配置!

mkl 提到...

直接建個tunnel起來跑,然後抓個packet就知道它是不是跑ipsec囉...

我想你是沒有enable正確的kernel config
參考http://mkl-note.blogspot.com/2008/03/openswan.htmlfor the required kernel config和psk config, script...
不過openswan 2.5.16沒有install /etc/ipsec.d/examples/no_oe.conf
我是用舊(2.4.11)的啦,我想直接把config裡的那個include拿掉應該也可以吧

或者你先在pc上試,試好的config直接拿來用也可以

/var/run/pluto是放pluto runtime的資料
如果你的pluto跑起來才會有東西在裡面
如果已經有東西在裡面了,最好把它刪掉
/var/run/pluto # ls -al
drwx------ 2 root root 1024 Jan 1 00:43 .
drwxrwxrwx 3 root root 1024 Oct 15 2008 ..
-rw-r--r-- 1 root root 107 Jan 1 00:43 ipsec.info
-rw-r--r-- 1 root root 3 Jan 1 00:43 ipsec_setup.pid
srwx------ 1 root root 0 Jan 1 00:43 pluto.ctl
-r--r--r-- 1 root root 4 Jan 1 00:43 pluto.pid
/var/run/pluto #

匿名 提到...

谢谢你了,我一会就重新编译内核试试!按你的意思,如果将那些选项选上,就不会出现modprobe: module af_key not found.这样的问题了,真的非常感谢!

匿名 提到...

你好,今天看了你的文档在第五步有一个
“kernel config CONFIG_NET_KEY 要拿掉 (For KLIPS)”是什么意思?是是在内核编译的时候要把这个选项掉?这个选项是在什么位置的呢?我在执行ipsec setup start 的时候出现了:unknown IPsec command ‘_startnetkey’是不是因为这个选项的关系呢?谢谢!

匿名 提到...

你在这里的第五点说“kernel config CONFIG_NET_KEY 要拿掉 (For KLIPS)”,可是在《openswan 雜記》里又说
要把PF_KEY sockets选上,这是什么意思?有点矛盾哦!
Networking Options --->
(M) PF_KEY sockets

mkl 提到...

netkey和klips是兩個不同的ipsec stack
runtime只能同時存在一套
這裡我是把netkey build成module
到runtime時可選擇要insert哪一個來跑
一個存在時另一個是沒辦法insert進去的

netkey的選項是
(M) IP: AH transformations
(M) IP: ESP transformations
PF_KEY是ipsec用的socket interface

匿名 提到...

那我按你的文档编译之后,运行ipsec --version提示是Linux2.6.19(netkey),可是我现在想要用klips,那内核该怎么选呢?还有,我出现的unknown IPsec command ‘_startnetkey’是不是也是与这个有关?是不是只要把
Networking Options --->
(M) PF_KEY sockets
选项去掉就可以了呢?谢谢!

mkl 提到...

如果你照我的設定(build成module),只要在runtime時先insert klips的module就行了(應該叫ipsec.ko),要不就都不要選

你的問題我沒遇過
你可以拿掉試試看,應該跟PF_KEY沒關係,而且你跑netkey的話反而是需要的

我跑klips的module
/ # lsmod
Module Size Used by Not tainted
xfrm_user 16516 2 - Live 0xbf024000
xfrm4_tunnel 3044 0 - Live 0xbf022000
ipcomp 6056 0 - Live 0xbf01f000
esp4 5920 0 - Live 0xbf01c000
ah4 4992 0 - Live 0xbf019000
af_key 33968 0 - Live 0xbf000000

netkey的module
/ # lsmod
Module Size Used by Not tainted
ipsec 372764 0 - Live 0xbf000000

我有試著用/usr/local/sbin/ipsec setup start, 也沒有問題....

mkl 提到...

不好意思
我剛剛是用2.4.11沒問題
但是用了2.5.16也有相同的問題

我用netkey啟動方式會有問題(先insert ah4 esp4 af_key),用klips啟動就沒問題(先insert ipsec)

我想是因為我的build參數下了USE_NETKEY=false的關係
USE_NETKEY=true我目前也沒build成功

我現在是用2.4.11,兩個stack都可以用

匿名 提到...

这样啊,这种问题还真是让人没有头绪,呵呵,不过很感谢你,我也改用2.4.11试试先,有不明白的再向你请教!

匿名 提到...

你好!想问一下,你在IPSEC起来以后用IFCONFIG能看到IPSEC0这个设备吗?

mkl 提到...

klips會有ipsec0
netkey則沒有

匿名 提到...

咦,那奇怪我的没有!我在启动IPSEC的时候执行了/etc/rc.d/init.d/ipsec start ,然后提示说:
netstat: -r (display routing table) is not compiled in.
然后就结束了,我用IFCONFIG看也没有看到IPSEC0。
想向你请教一下!

mkl 提到...

只要有insert ipsec.ko就會有ipsec0等等的device出現
你的沒有應該是根本還沒insert?
至於那個netstat訊息我沒看過,是不是busybox沒加入netstat的某個feature?

試試看netstat -r, 我的如下
/ # netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0
172.200.0.0 * 255.255.0.0 U 0 0 0 eth1
172.200.0.0 * 255.255.0.0 U 0 0 0 ipsec0
default 172.200.6.3 0.0.0.0 UG 0 0 0 eth1
/ #

匿名 提到...

你好!我现在已经能在ARM板上用ipsec version看到
# ipsec version
Linux Openswan 2.6.16 (klips)
See `ipsec --copyright' for copyright information.
但是在ipsec pluto时有如下提示:including NAT-Traversal patch (Version 0.6c) [disabled],所以我也准备打NAT-T补丁,可是我参照了一些网上的做法,步骤如下:
cd openswan-2.4.11
export KERNELSRC=...
make nattpatch > /openswan-2.4.11/openswan-2.4.11.kernel-2.6-natt.patch.gz
cd $KERNELSRC
cat /openswan-2.4.11/openswan-2.4.11.kernel-2.6-natt.patch.gz | patch -p1 -s
make (已经改过交叉编译器的!)
可是总是出现这样的错误提示:
net/ipv4/udp.c:963: error: redefinition of 'xfrm4_rcv_encap_func'
net/ipv4/udp.c:929: error: previous definition of 'xfrm4_rcv_encap_func' was here
net/ipv4/udp.c:972: error: redefinition of 'udp4_register_esp_rcvencap'
net/ipv4/udp.c:934: error: previous definition of 'udp4_register_esp_rcvencap' was here
net/ipv4/udp.c:987: error: redefinition of 'udp4_unregister_esp_rcvencap'
net/ipv4/udp.c:949: error: previous definition of 'udp4_unregister_esp_rcvencap' was here
net/ipv4/udp.c:999: error: redefinition of 'xfrm4_rcv_encap_func'
net/ipv4/udp.c:963: error: previous definition of 'xfrm4_rcv_encap_func' was here
net/ipv4/udp.c:999: error: redefinition of 'xfrm4_rcv_encap_func'
net/ipv4/udp.c:963: error: previous definition of 'xfrm4_rcv_encap_func' was here
net/ipv4/udp.c:1002: error: redefinition of 'udp4_register_esp_rcvencap'
net/ipv4/udp.c:972: error: previous definition of 'udp4_register_esp_rcvencap' was here
net/ipv4/udp.c:1002: error: redefinition of 'udp4_register_esp_rcvencap'
net/ipv4/udp.c:972: error: previous definition of 'udp4_register_esp_rcvencap' was here
net/ipv4/udp.c:1012: error: redefinition of 'udp4_unregister_esp_rcvencap'
net/ipv4/udp.c:987: error: previous definition of 'udp4_unregister_esp_rcvencap' was here
net/ipv4/udp.c:1012: error: redefinition of 'udp4_unregister_esp_rcvencap'
net/ipv4/udp.c:987: error: previous definition of 'udp4_unregister_esp_rcvencap' was here
make[3]: *** [net/ipv4/udp.o] Error 1
make[2]: *** [net/ipv4] Error 2
make[1]: *** [net] Error 2

想问问你也是这样打补丁的吗?我怎么会出现这样的问题呢!

mkl 提到...

natt並不是一定得上
因為沒用到,所以我並沒有上

可能得看code才能確定發生什麼事

匿名 提到...

您好~
請問您在安裝gmp時,
INSTALL_PATH是cross compile的路徑?
或者是openswan欲安裝的目標路徑呢?

謝謝

匿名 提到...

您好~
我還有一個問題想請教您,
我依照您這篇文章所教學的成功安裝gmp之後,在我要編譯openswan時,卻出現以下訊息:
${略}/lib/libgmp.so: could not read symbols: File in wrong format could not read symbols: File in wrong format

我使用gmp-4.2.4和openswan-2.6.18
煩請您能邦我解惑,感激不盡!!

mkl 提到...

確定gmp與openswan都是用cross compiler build的
用file再確定一下..

然後再看一下openswan用的gmp不是系統(pc)上的, 而是剛剛build好的gmp

匿名 提到...

您好,
我在確認編譯過程都是經由cross compiler之後,
我用file檢查gmp.so得到以下訊息:
libgmp.so: symbolic link to `libgmp.so.3.4.4
再用file檢查libgmp.so.3.4.4得到以下訊息:
libgmp.so.3.4.4: ELF 32-bit MSB shared object, MIPS, N32 MIPS32 rel2 version 1 (SYSV), not stripped

請問是configure時沒設定cross comiiler的strip嗎? 但後來我自行加入了cross的strip但編出來的libgmp.so.3.4.4依然not stripped,
可否再提示我一個方向解決,感激不盡!!

mkl 提到...

去openswan下找個.o file看看
跟有沒有strip應該沒差
沒strip過只是size比較大

Gazineu 提到...

Hi, does you know where can I get the str8100-lsdk package? I have a device to play with and had searched almost everywhere for it. Thanks in advance. dgazineu [at@] gmail [dot.] com

mkl 提到...

I'm sorry that I don't know anywhere that you could get the lsdk. I wish I could help, but I'm not the one who could make such release.

maybe it doesn't help, but following site provide patches for str9104 of his own hack...
http://tinyhack.com/

匿名 提到...

你好,我最近也做这方面的内容,我借鉴着你的文章做的,内核是2.6.12的,由于KILPS我编译不出来,就是用NETKEY的,但是在执行ipsec setup start时,显示ipsec_setup: sh: 0: unknown operand
ipsec_setup: Starting Openswan IPsec ...
ipsec_setup: sh: 1000: unknown operand
ipsec_setup: No KLIPS support found while requested, desperately falling back to
netkey
ipsec_setup: modprobe: cannot parse modules.dep
ipsec_setup: Even NETKEY support is not there, aborting
我在配置内核的时候,照你的说法,应该把 Networking Options --->
(M) PF_KEY sockets
(M) IP: AH transformations (M) IP: ESP transformations (M) IP: IPComp transformations (M) IP: tunnel transformations (M) IPsec user configuration interfaceCryptographic options ---> <*> MD5 digest algorithm
<*> SHA1 digest algorithm
<*> DES and Triple DES EDE cipher algorithms
<*> AES cipher algorithms
都选上了,结果还是显示no kernel code presently loaded,请问这是什么原因呢?