默认情况下,我们使用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. IDEA 中使用MyBatis-generator 自动生成MyBatis代码

    0.在Intellij IDEA创建maven项目 1. 在maven项目的pom.xml 添加mybatis-generator-maven-plugin 插件 <build> < ...

  2. Selenium Navigation

    Navigating Navigate a link with WebDriver: driver.get("http://www.google.com") 1.Interacti ...

  3. vim简单使用教程【转】

    vim的学习曲线相当的大(参看各种文本编辑器的学习曲线),所以,如果你一开始看到的是一大堆VIM的命令分类,你一定会对这个编辑器失去兴趣的.下面的文章翻译自<Learn Vim Progress ...

  4. Beta冲刺(2/7)

    目录 摘要 团队部分 个人部分 摘要 队名:小白吃 组长博客:hjj 作业博客:beta冲刺(2/7) 团队部分 后敬甲(组长) 过去两天完成了哪些任务 整理博客 做了点商家数据表格 接下来的计划 做 ...

  5. JVM--01

    ---恢复内容开始--- jdk  jre  jvm 的关系 java7的结构图 java8 jvm内存溢出 jdk /bin 目录下的jconsole java发展历史 oak:用在嵌入式设备上 相 ...

  6. Laravel 生成migration ,boolean字段字段转为tinyInteger

    Schema::create('consults', function (Blueprint $table) { $table->increments('id'); $table->str ...

  7. 【原创】大叔经验分享(27)linux服务器升级glibc故障恢复

    redhat6系统默认安装的glibc-2.12,有的软件依赖的是glibc-2.14,这时需要升级glibc,下载安装 http://ftp.gnu.org/gnu/glibc/glibc-2.14 ...

  8. 【原创】大叔经验分享(5)oozie提交spark任务如何添加依赖

    spark任务添加依赖的方式: 1 如果是local方式运行,可以通过--jars来添加依赖: 2 如果是yarn方式运行,可以通过spark.yarn.jars来添加依赖: 这两种方式在oozie上 ...

  9. linux软件管理

    People who cannot find time for recreation are obliged sooner or later to find time for illness.腾不出时 ...

  10. 2、使用rpm包安装grafana

    Grafana最新版本4.3.1安装从官网下载相关的rpm包 http://docs.grafana.org/installation/rpm/ 1.下载二进制包,安装 [root@localhost ...