当前位置:   article > 正文

strongswan编译、配置_arm 设备上移植 strongswan

arm 设备上移植 strongswan

strongswan编译

下载strongswan源码后,在命令行执行

./configure -h

会打印出来编译时的配置选项,比较重要有:

--prefix=PREFIX,PREFIX为编译完成后的可执行文件、库文件以及配置文件等的安装目录、运行目录。该目录会被硬编码到可执行文件中,ipsec启动时,会在该目录下找配置文件。如果做移植,务必保证该目录和开发板上的运行目录路径相同,避免ipsec找不到配置文件。再直白点儿说,--prefix=/home/strongswan,在宿主机make && make install后,把strongswan这个文件夹整体复制到开发板的/home目录下才行。

--bindir=DIR,可执行文件的路径,make && make install后,可执行文件被放在这里,优先级高于--prefix选项,直白点儿说,同时设置了--prefix和--bindir,除可执行文件外,其他安装文件依然被放置到--prefix指定的位置。

--sbindir、--libexecdir、--sysconfdir都是类似的。如果不做移植,一般会设置为--prefix=/usr/local --sysconfdir=/etc

--host=HOST,如果不做移植,可以不用设置,否则该选项一般可以设置为交叉编译器的名称去掉-gcc

--with-lib-prefix这个选项在做移植的时候有用,告诉编译器去哪里找strongswan依赖的其他库的头文件和库文件,比如openssl

--disable-xxxx,--enable-xxxx,顾名思义,失能或使能strongswan的某些特性,看自己情况使用吧。如果缺少了某些特性,后面strongswan加载配置文件时,可能会不认识某些配置项,那时再回来重新编译一下就可以了,建议:--enable-openssl --enable-dhcp --enable-mediation --enable-swanctl

CC=(交叉)编译器路径

CFLAGS=编译开关等

设置完这些,make  && make install(make出错一般是找不到某些依赖库,安装或移植一下即可)

strongswan配置

包括2部分:通用配置和网络拓扑配置。通用配置主要是配置文件路径、日志信息等等。网络拓扑配置需要参考官方给出来的例子。在StrongSwan的官网上,我们可以在左侧找到TestScenarios,这里有许多场景,我们需要进去之后点开strongSWan test suits,最笨的办法就是一个一个打开,找到我们的网络拓扑。

配置日志文件(在etc/strongswan.conf,以下为官方配置,可以在官网找到)

  1. charon {
  2. # two defined file loggers
  3. filelog {
  4. charon {
  5. # path to the log file, specify this as section name in versions prior to 5.7.0
  6. path = /var/log/charon.log
  7. # add a timestamp prefix
  8. time_format = %b %e %T
  9. # prepend connection name, simplifies grepping
  10. ike_name = yes
  11. # overwrite existing files
  12. append = no
  13. # increase default loglevel for all daemon subsystems
  14. default = 2
  15. # flush each line to disk
  16. flush_line = yes
  17. }
  18. stderr {
  19. # more detailed loglevel for a specific subsystem, overriding the
  20. # default loglevel.
  21. ike = 2
  22. knl = 3
  23. }
  24. }
  25. }

日志等级参考:

  • -1: Absolutely silent
  • 0: Very basic auditing logs, (e.g. SA up/SA down)
  • 1: Generic control flow with errors, a good default to see whats going on
  • 2: More detailed debugging control flow
  • 3: Including RAW data dumps in hex
  • 4: Also include sensitive material in dumps, e.g. keys

日志文件用来排查建立隧道时出现的问题,是调试strongswan的有效手段:

查看日志信息:tail -f /var/log/charon.log       

和官方提供的日志信息比较:官方日志为:deamon.log

去高频问题页面搜索相关问题:https://wiki.strongswan.org/projects/strongswan/wiki/FAQ

百度、google等等

配置网络拓扑

大的方向上,有2种配置方案,二选一,官方是这说的:

Used by swanctl and the preferred vici plugin(建议使用)

Used by starter and the deprecated stroke plugin(不建议使用)

建议采用swanctl那种,需要把我们的配置文件放在etc/swanctl/conf.d下,文件名格式为xxxx.conf。比较蛋疼的是,strongswan官网提供的最完整测试case,用的是第二种,即配置ipsec.conf。建议的做法是先使用官网提供的一个转换工具(https://gitlab.com/Thermi/ipsec2swanctl)把ipsec.conf转换成swanctl可以识别的格式,然后参考官方给出的转换表格(https://wiki.strongswan.org/projects/strongswan/wiki/Fromipsecconf),针对性的修改其中的某些项。转换工具是python写的。用法为:

sduo python3 ipsec2swanctl.py --ipsecconf ./ipsec.conf -o swanctl.xxxx.conf -w

当然,官方也给出了一些swanctl可用的配置,可以直接使用(https://wiki.strongswan.org/projects/strongswan/wiki/ConfigurationExamples

启动strongswan

sudo ipsec start

sudo swanctl --load-all        加载所有的配置,即加载etc/swanctl/conf.d下的名为xxxx.conf的配置文件

常用的一些命令:

sudo ipsec stop

sudo swanctl  --list-conns

sudo ipsec statusall

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/739239
推荐阅读
相关标签
  

闽ICP备14008679号