[dev][crypto][strongswan] 有关strongswan的forward policy的源码分析
一
默认情况下,我们使用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的源码分析的更多相关文章
- [ipsec][strongswan] strongswan源码分析--(一)SA整体分析
strongswan SA分析(一) 1 概念 下面主要介绍两个本文将要阐述的核心概念.他们是SA和SP.注意,这不是一篇不需要背景知识的文章.作者认为你适合阅读接下来内容的的前提是,你已经具备了一下 ...
- [dev][ipsec][dpdk] strongswan/dpdk源码分析之ipsec算法配置过程
1 简述 storngswan的配置里用一种固定格式的字符串设置了用于协商的预定义算法.在包协商过程中strongswan将字符串转换为固定的枚举值封在数据包里用于传输. 协商成功之后,这组被协商选中 ...
- [ipsec][strongswan] strongswan源码分析-- (三) xfrm与strongswan内核接口分析
目录 strongwan sa分析(三) xfrm与strongswan内核接口分析 1. strongswan的实现 2. 交互机制 4. xfrm的消息通信的实现 strongwan sa分析(三 ...
- [ipsec][strongswan]strongswan源码分析--(零)引子
目录 strongswan sa 资料 编译 启动 进程信息 结构 架构图与插件 配置运行 传统配置方法 新的配置方法 其他配置方法 详细的配置文档 配置示例 用法 加密库 libgmp libcry ...
- [ipsec][strongswan] strongswan源码分析--(五)plugin的配置文件的添加方法与管理架构解析
前言 我们知道,strongswan是基于插件式管理的.不同的插件有不同的配置文件,在这下面, 我们以netlink的插件为例:etc/strongswan.d/charon/kernel-netli ...
- [ipsec][strongswan] strongswan源码分析-- (二)rekey/reauth机制分析
目录 strongwan sa分析(二) 名词约定 rekey/reauth 机制分析 1 概述 2 reauth 3 CHILD SA rekey 4 IKE SA rekey 5 其他 stron ...
- [ipsec][strongswan] strongswan源码分析--(〇)总体架构图
history: 2019-06-05, 增加配置文件解析部分. 2019-06-05,增加plugin优先级排序部分. charon进程初始化阶段的流程图 约定: 实线代表流程图. 虚线代表调用栈, ...
- [ipsec][strongswan] strongswan源码分析--(四)plugin加载优先级原理
前言 如前所述, 我们知道,strongswan以插件功能来提供各种各样的功能.插件之间彼此相互提供功能,同时也有可能提供重复的功能. 这个时候,便需要一个优先级关系,来保证先后加载顺序. 方法 在配 ...
- java.security.SecureRandom源码分析 java.security.egd=file:/dev/./urandom
SecureRandom在java各种组件中使用广泛,可以可靠的产生随机数.但在大量产生随机数的场景下,性能会较低. 这时可以使用"-Djava.security.egd=file:/dev ...
随机推荐
- android TabLayout设置选中标签字体加粗功能
实现 TabLayout 选中tab标签字体加粗功能如下: xml文件中定义: <android.support.design.widget.TabLayout android:id=" ...
- SQL Server - case when...then...else...end
Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex ' THEN '男' ' THEN '女' ELSE '其他' END --Case搜索函数 ' T ...
- GPS车辆监控系统的启动方式
我们通常用到的GPS车辆监控系统都有哪些启动方式,又有什么区别呢?通常GPS车辆监控系统都有热启.冷启.温启的技术指标,现参考如下:GPS开机定位分为冷启动.温启动和热启动三种:一.冷启动:以下几种情 ...
- Mac 安装JRE 1.8
最近使用React Native,运行android版本时,需要jre 1.8,但是用oracle 的安装文件安装完毕后,在控制台java -version输出的还是 1.7版本.发现是环境变量没配对 ...
- Hive快捷查询:不启用Mapreduce job启用Fetch task三种方式介绍
如果查询表的某一列,Hive中默认会启用MapReduce job来完成这个任务,如下: hive>select id,name from m limit 10;--执行时hive会启用MapR ...
- laravel 黑名单功能实现
创建黑名单表迁移:php artisan make:model Models/BlackFeeds -m (生成模型和迁移文件) 迁移文件中创建如下字段: public function up( ...
- Python内置模块之-hashlib
一 .概述 摘要算法又称哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度固定的数据串(通常用16进制的字符串表示). 摘要算法的特点 不论data大小,摘要结果是固定长度 单向函数, ...
- Sass 增强语法的样式表
功能: 完全兼容CSS3 相对CSS,扩展了变量.嵌套和mixins 对控制颜色和其他值的非常有用的方法 高级功能,如库的直接控制 良好的格式,自定义输出 语法 对于Sass,有两种语法. 一种叫SC ...
- django 第二天
进行了前后端简单的链接 view 视图代码如下 from django.shortcuts import render from django.http import HttpResponse fro ...
- 解决 RecyclerView 在Android Studio已经导入情况下还无法实例引用问题
系统:Windows 10 IDE::android studio 1. 问题:RecyclerView 在Android Studio已经导入情况下还无法实例引用问题 由于RecyclerView是 ...