默认情况下,我们使用strongswan建立了一个ipsec隧道之后,建立的policy如下:

[root@D129 OUTPUT]# ip xfrm policy
src 10.129.0.0/ dst 10.9.0.0/
dir out priority ptype main
tmpl src 192.168.8.129 dst 192.168.8.9
proto esp spi 0x5623adc0 reqid mode tunnel
src 10.9.0.0/ dst 10.129.0.0/
dir fwd priority ptype main
tmpl src 192.168.8.9 dst 192.168.8.129
proto esp reqid mode tunnel
src 10.9.0.0/ dst 10.129.0.0/
dir in priority ptype main
tmpl src 192.168.8.9 dst 192.168.8.129
proto esp reqid mode tunnel

通过观察,我们能够总结到:

1.  一共有三条policy,分别是IN类型,OUT类型,FWD类型。

2.  IN和FWD的原目的IP对,template原目的IP对相同。OUT类型与之相反。

然而,我们所了解到的内容,并不仅局限于此。接下来阅读两端strongswan的代码

https://github.com/strongswan/strongswan/blob/5.7.2/src/libcharon/sa/child_sa.c

static status_t install_policies_inbound(private_child_sa_t *this,
host_t *my_addr, host_t *other_addr, traffic_selector_t *my_ts,
... ...
if (this->mode != MODE_TRANSPORT)
{
in_id.dir = POLICY_FWD;
status |= charon->kernel->add_policy(charon->kernel, &in_id, &in_policy);
}
return status;
}
... ...
static status_t install_policies_outbound(private_child_sa_t *this,
host_t *my_addr, host_t *other_addr, traffic_selector_t *my_ts,
... ...
out_id.dir = POLICY_FWD;
other_sa->reqid = ;
if (priority == POLICY_PRIORITY_DEFAULT)
{
out_policy.prio = POLICY_PRIORITY_ROUTED;
}
status |= charon->kernel->add_policy(charon->kernel, &out_id,
&out_policy);
/* reset the reqid for any other further policies */
other_sa->reqid = this->reqid;
}
return status;
}

通过上面的代码,可以观察到,无论是IN或OUT方向,都有其分别对应的FWD policy。并由sa的具体参数配置决定。

child_sa_t * child_sa_create(host_t *me, host_t* other,
child_cfg_t *config, uint32_t reqid, bool encap,
... ...
.policies_fwd_out = config->has_option(config, OPT_FWD_OUT_POLICIES),
... ...
}

这个参数见swanctl.conf的手册

      connections.<conn>.children.<child>.policies_fwd_out [no]
Whether to install outbound FWD IPsec policies or not. Enabling this is required in case there is a drop policy that would match and block forwarded traffic for this CHILD_SA.

还有一段注释,帮助理解。

        /* install an "outbound" FWD policy in case there is a drop policy
* matching outbound forwarded traffic, to allow another tunnel to use
* the reversed subnets and do the same we don't set a reqid (this also
* allows the kernel backend to distinguish between the two types of
* FWD policies). To avoid problems with symmetrically overlapping
* policies of two SAs we install them with reduced priority. As they
* basically act as bypass policies for drop policies we use a higher
* priority than is used for them. */

也就是说,开启“第三节”里提到的配置之后。strongswan对每一个sa产生的policy,将不是“第一节”中提到的三个,

而是四个,一个IN,一个OUT,两个FWD,两个FWD各自与IN,OUT参数一致。

[dev][crypto][strongswan] 有关strongswan的forward policy的源码分析的更多相关文章

  1. [ipsec][strongswan] strongswan源码分析--(一)SA整体分析

    strongswan SA分析(一) 1 概念 下面主要介绍两个本文将要阐述的核心概念.他们是SA和SP.注意,这不是一篇不需要背景知识的文章.作者认为你适合阅读接下来内容的的前提是,你已经具备了一下 ...

  2. [dev][ipsec][dpdk] strongswan/dpdk源码分析之ipsec算法配置过程

    1 简述 storngswan的配置里用一种固定格式的字符串设置了用于协商的预定义算法.在包协商过程中strongswan将字符串转换为固定的枚举值封在数据包里用于传输. 协商成功之后,这组被协商选中 ...

  3. [ipsec][strongswan] strongswan源码分析-- (三) xfrm与strongswan内核接口分析

    目录 strongwan sa分析(三) xfrm与strongswan内核接口分析 1. strongswan的实现 2. 交互机制 4. xfrm的消息通信的实现 strongwan sa分析(三 ...

  4. [ipsec][strongswan]strongswan源码分析--(零)引子

    目录 strongswan sa 资料 编译 启动 进程信息 结构 架构图与插件 配置运行 传统配置方法 新的配置方法 其他配置方法 详细的配置文档 配置示例 用法 加密库 libgmp libcry ...

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

    前言 我们知道,strongswan是基于插件式管理的.不同的插件有不同的配置文件,在这下面, 我们以netlink的插件为例:etc/strongswan.d/charon/kernel-netli ...

  6. [ipsec][strongswan] strongswan源码分析-- (二)rekey/reauth机制分析

    目录 strongwan sa分析(二) 名词约定 rekey/reauth 机制分析 1 概述 2 reauth 3 CHILD SA rekey 4 IKE SA rekey 5 其他 stron ...

  7. [ipsec][strongswan] strongswan源码分析--(〇)总体架构图

    history: 2019-06-05, 增加配置文件解析部分. 2019-06-05,增加plugin优先级排序部分. charon进程初始化阶段的流程图 约定: 实线代表流程图. 虚线代表调用栈, ...

  8. [ipsec][strongswan] strongswan源码分析--(四)plugin加载优先级原理

    前言 如前所述, 我们知道,strongswan以插件功能来提供各种各样的功能.插件之间彼此相互提供功能,同时也有可能提供重复的功能. 这个时候,便需要一个优先级关系,来保证先后加载顺序. 方法 在配 ...

  9. java.security.SecureRandom源码分析 java.security.egd=file:/dev/./urandom

    SecureRandom在java各种组件中使用广泛,可以可靠的产生随机数.但在大量产生随机数的场景下,性能会较低. 这时可以使用"-Djava.security.egd=file:/dev ...

随机推荐

  1. php程序员招聘

    岗位要求:-1年以上WEB端开发经验.-熟悉PHP语言的开发工作,熟练掌握LNMP开发,并具备良好的编程风格.-熟悉 http协议,掌握css js ajax 相关技术应用.-熟悉关系型数据,NOSQ ...

  2. IIS 一键安装及卸载

    IIS6:适用于win server 2003:: ******************* :: * 安装 :: ******************* :Install Cls @echo. &am ...

  3. 入坑C++之vs 新建C++项目

    首先呢,下载一个visual  studio 2017的编辑器工具,可能有最新的2019年的版本,根据自己喜欢选择哪个版本就好了 visual studio IDE下载地址:https://visua ...

  4. matplotlib坐标轴设置续-【老鱼学matplotlib】

    本次会讲解如何修改坐标轴的位置. 要修改轴,就要先得到当前轴:plt.gca(),这个函数名挺怪的,其实是如下英文字母的首字母:get current axis,也就是得到当前的坐标轴. import ...

  5. Redis数据结构之ziplist

    本文及后续文章,Redis版本均是v3.2.8 本篇文章我们来分析下一种特殊编码的双向链表-ziplist(压缩列表),这种数据结构的功能是将一系列数据与其编码信息存储在一块连续的内存区域,这块内存物 ...

  6. Python中append()与extend()的区别

    列表方法append()和extend()之间的差异: append:在最后追加对象 x = [1, 2, 3] x.append([4, 5]) print (x) 结果 [1, 2, 3, [4, ...

  7. 微信小程序做radio,可以拖动进度条

    很简单的一个音乐播放器 data:{ src: 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4a ...

  8. python3.7 打包成exe程序(只需两行命令)

    根据博客作者louniuous的python3.7 打包成exe的一种方法 pyinstaller一文改编简化 环境:pycharm2018.1+win7+python3.7 工具:pyinstall ...

  9. svn提交按钮灰选

    1.当我新建了一个文件或者文件夹,要提交的时候出现ok按钮灰选,提交不了. 解决方法:提交信息多写一些字儿就可以了,挥着回车换行也行 2.报错:you need to upgrade the work ...

  10. Tutorial中的Hello2代码

    该hello2应用程序是一个Web模块,它使用Java Servlet技术来显示问候语和响应. 1.GreetingServlet.java源码文件: 1 @WebServlet("/gre ...