首页 技术 正文
技术 2022年11月16日
0 收藏 818 点赞 3,571 浏览 1998 个字

前言

我们知道,strongswan是基于插件式管理的。不同的插件有不同的配置文件,在这下面,

我们以netlink的插件为例:etc/strongswan.d/charon/kernel-netlink.conf

在这个文件里,提供了不同的针对插件的配置项。接下来我们将讲解,如何开发这些配置项。

配置文件结构

在开始之前,先了解一下strongswan的配置文件组织结构,

strongswan的所有配置项都是层级结构组织的,如:charon.plugins.kernel-netlink.force_receive_buffer_size

树状结构,它们拥有共同的父节点,charon。

在配置文件里面,可以include其他的配置文件。

strongswan的所有配置文件,也都是树型引用的,它们拥有同一个共同的父节点,也就是所有配置文件的入口:etc/strongswan.conf

所有的plugin的配置文件,都在目录etc/strongswan.d/charon/下,并以插件的名字命令,形如kernel-netlink.conf

配置文件的读取和使用

做了简单的代码分析,如 [dev][ipsec] strongswan plugin加载优先级原理 中提到的,

charon程序的一开始,便进行了所有配置文件的加载。在library_init()函数里。

[ipsec][strongswan] strongswan源码分析–(五)plugin的配置文件的添加方法与管理架构解析

配置文件的生成

作为开发者,我们将通过netlink plugin,来学习如何正确的为plugin设置配置文件。

在strongswan的代码里,所有的配置文件管理,都在这个目录下

strongswan.git/conf

plugin在它的子目录里,strongswan.git/conf/plugins

配置文件是自动生成的,通过模块,和脚本的辅助。

两个模版文件:

default.conf, default.opt

配置文件的生成过程,在Makefile中:Makefile.am

大该的过程如下:

1. 读取configure阶段开启的所以plugin列表。

2. 在plugins目前下读取每一个plugin的自定义配置项,如kernel-netlink.opt

3. 如果没有默认配置项的,将使用默认的配置项配置文件:default.opt

4. 将自定义配置项中的配置,通过配置文件魔板整合生成对应plugin的配置文件 如:kernel-netlink.conf

这个配置文件在代码仓库中是没有的,而是在编译安装过程中生成的。

5. 为其他plugin重复以上步骤。

几段关键的代码:

1. 指定所有配置文件作为target的宏

# we only install snippets for enabled plugins
plugins_install_tmp = $(charon_plugins:%=plugins/%.tmp)
plugins_install_src = $(charon_plugins:%=plugins/%.conf)

2。整合魔板与定制内容的target

.opt.conf:
$(AM_V_GEN) \
case "$<" in \
*plugins/*) \
sed \
-e "s:\@PLUGIN_NAME\@:`basename $< .opt`:" \
$(srcdir)/default.opt | cat - $< | \
$(PYTHON) $(srcdir)/format-options.py -f conf -r charon.plugins > $(srcdir)/$@ \
;; \
*) \
$(PYTHON) $(srcdir)/format-options.py -f conf -r charon.plugins $< > $(srcdir)/$@ \
;; \
esac# we need another implicit rule to generate files from the generic template only
# if the rules above did not catch it. this requires an intermediate step that
# generates a copy of the generic config template.
$(plugins_install_tmp):
@mkdir -p $(builddir)/plugins
@cp $(srcdir)/default.conf $(builddir)/$@.tmp.conf:
$(AM_V_GEN) \
sed \
-e "s:\@PLUGIN_NAME\@:`basename $< .tmp`:" \
$(builddir)/$< > $(builddir)/$@

举例:

假设我们现在要自开发一个plugin,classic-tong并为其指定以下配置项,只需要在目录

plugins下,添加一个文件,classic-tong.opt

并编辑内容:

charon.plugins.classic-tong.timeout = 

就可以了。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919