[dev][dpdk][crypto] dpdk加解密设备与IPSEC

本文深入探讨DPDK的加解密框架、设备及安全协议,重点介绍了加密设备类型、调度机制、API接口,以及RTE_IPSEC库在处理IPSEC报文中的作用。涉及内容包括设备初始化、硬件offload、安全会话和API接口等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

概述

分三部分,加解密框架(crypto framework),加解密设备(crypto dev),安全协议(Security Framework)

×  API,设计思路等,都在加解密框架里:见文档:http://doc.dpdk.org/guides-18.11/prog_guide/cryptodev_lib.html

×  设备层的事情,加解密设备的分类,调度,主备等,见文档:http://doc.dpdk.org/guides-18.11/cryptodevs/index.html

×  ESP,PDCP等网络加密协议相关的事情,主要功能是整合NIC pmd和Crypto pmd,见文档:http://doc.dpdk.org/guides-18.11/prog_guide/rte_security.html

 

另外还有一个追加的部分,ipsec (rte_ipsec)

*  这一部分主要是对前面三个部分的整合封装调用,用来专门处理ipsec报文。见文档:http://doc.dpdk.org/guides/prog_guide/ipsec_lib.html

 

画个图:

 

 

如果,以上三个文档,你都读完了,那么请不要再往下读了。内容重复。且本人懒惰,多以摘要为主,写的也不好  :)

 

一般编程模型

画了一张图,还没完全整理好,后续有可能会再更新,也有可能不更新了。

是参考dpdk的这个例子里的流程画的:http://doc.dpdk.org/guides/sample_app_ug/ipsec_secgw.html

 

初始化加密设备的一般流程。

 

 

设备就绪后的一般使用流程。(需要关注的是:在分析rte_ipsec的源码过程中,并没有发现对API rte_crypto_op_attach_sym_session的调用。奇怪。。。)

    // TODO init dpdk crypto things.
    // 1. init sa->xforms  like function sa_add_rules()
    // 2. init two parameter ipsec_xform/crypto_xform
    // 2. ipsec_sa_init()
    //    2.1 rte_ipsec_sa_init()
    // 3. create_session
    //    3.1 rte_security_session_create()
    //    3.2 rte_cryptodev_sym_session_create()
    //    3.3 rte_cryptodev_sym_session_init()
    // 3.4 rte_ipsec_session_prepare()
    //    3.4.1 sa->ips->pkt_func = ipsec_sa_pkt_func_select()
    // 3.5 rte_ipsec_pkt_process()
    //    3.5.1 sa->ips->pkt_func.process()
    // 3.6 rte_ipsec_pkt_crypto_prepare()
    //    3.6.1 sa->ips->pkt_func.prepare()
    // 7 rte_cryptodev_enqueue_burst()
    // 8.rte_cryptodev_dequeue_burst()
    // 9 rte_ipsec_pkt_crypto_group()
    // 10 rte_ipsec_pkt_process()
    //    3.5.1 sa->ips->pkt_func.process()
    // outbound
    // 4 rte_security_attach_session()
    // 5 rte_crypto_op_attach_sym_session()
    // 6 rte_security_set_pkt_metadata()
    // 7.rte_cryptodev_enqueue_burst()
    // 8 rte_cryptodev_dequeue_burst()

 

 

 

第二部分,设备(crypto dev)

所有的加解密设备大概分为以下几种:openssl,null,硬件架构相关的设备。

null为纯软件的最小实现,可以用来调试等。

硬件相关的主要包括,Intel,arm,NXP,AMD,QAT卡等。

还有一种,基于VIRTIO的PMD设备。

不同的设备,所支持的加解密算法也各有不同,有一个详细的对比列表,见:

http://doc.dpdk.org/guides-18.11/cryptodevs/overview.html

设备调度

在各设备的上层,还有一个调度设备,用于管理和协调多个加解密设备直接的数据流。叫做 cryptodev scheduler PMD

http://doc.dpdk.org/guides-18.11/cryptodevs/scheduler.html

 

接口API

加解密设备的调度API(schduler)

http://doc.dpdk.org/api-18.11/rte__cryptodev__scheduler_8h.html

 

加解密设备的使用API (cryptodev)

http://doc.dpdk.org/api-18.11/rte__cryptodev_8h.html

 

第一部分  框架(crypto framework)

架构设计文档:http://doc.dpdk.org/guides-18.11/prog_guide/cryptodev_lib.html

设计理念

The cryptodev library follows the same basic principles as those used in DPDKs Ethernet Device framework. 
The Crypto framework provides a generic Crypto device framework which supports both physical (hardware)
and virtual (software) Crypto devices as well as a generic Crypto API which allows Crypto devices to be
managed and configured and supports Crypto operations to be provisioned on Crypto poll mode driver.

设备初始化方法

A。 初始化设备

实体设备:与PCI网卡相同。

虚拟设备:1. 可以使用 --vdev参数在dpdk程序启动时使用。2. 在运行时使用api:

rte_vdev_init("crypto_aesni_mb",
                  "max_nb_queue_pairs=2,socket_id=0")

 

B。配置设备

设备识别:用Id或name

设备配置:使用api:

int rte_cryptodev_configure(uint8_t dev_id,
                            struct rte_cryptodev_config *config)

struct rte_cryptodev_config {
    int socket_id;
    /**< Socket to allocate resources on */
    uint16_t nb_queue_pairs;
    /**< Number of queue pairs to configure on device */
};

 

C。配置queue


 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值