IPsec配置

SP670标准网卡支持IPsec配置。

IPsec实现具体功能使用的额外配置的参考流程:

  1. 安装rpm驱动

    安装SDK、NIC和IPSEC驱动,安装驱动的具体操作请参见单独安装驱动。在IPsec驱动安装后,ipsec卸载功能自动开启。

    驱动安装顺序为:SDK驱动、NIC驱动、IPsec驱动。

  2. 绑定网络接口

    1. 进行网络通信前,要将IP地址绑定到相应的网络接口,一个网络接口对应一个PF,使用以下命令对PF切分成VF,参数说明如表1所示。
      echo page_num > /sys/bus/pci/devices/bdf_info/sriov_numvfs
      表1 参数说明

      参数

      参数说明

      page_num

      切分VF数量,单PF切分上限为127。

      bdf_info

      PF/VF设备的BDF号,通过lspci查询。

    2. 使用以下命令进行IP地址与网络接口的绑定,参数说明如表2所示。
      ip address add host_ip dev eth_interface
      表2 参数说明

      参数

      参数说明

      host_ip

      该主机的IP地址。

      eth_interface

      所使用的网卡设备对应的网络接口。

  3. IPsec会话配置

    IPsec会话建议使用Strongswan工具建立链接,不建议使用ip xfrm静态命令配置。

    • IKE自动协商:使用Strongswan建立连接

      StrongSwan是一个跨平台的IPsec开源项目,用于建立IPsec的通信环境,负责实现IKE协商。SP670应用场景推荐使用5.9.10版本的strongSwan应用,可以通过配置路径“/etc/strongswan/swanctl/conf.d/”下的swanctl.conf文件确定连接所使用的信息,具体配置如图1所示。

      图1 配置操作

      确定配置文件内容后,使用以下命令在一端进行IKE协商准备和加载。

      systemctl start strongswan

      systemctl enable strongswan

      swanctl --load-all

      在另一端做相同的准备加载工作,并建立IKE连接。

      systemctl start strongswan

      systemctl enable strongswan

      swanctl --load-all

      swanctl --initiate --child host_name

      参数

      参数说明

      host_name

      StrongSwan配置文件中通信主机对,格式为host_name-host_name,例如:host0-host0。

    • IP Xfrm手动配置

      IP Xfrm(IP Transform)是为IP数据包提供加密和身份验证等安全功能的配置信息的Linux工具,负责在应用层下发SA和SP,使用IP Xfrm可以在不建立IKE连接的情况下,通过配置SA/SP资源实现安全资源的卸载与绑定。可通过ip xfrm state helpip xfrm policy help命令查看IP Xfrm提供的数种可扩展的SA、SP配置模板,以下提供两种配置命令参考,参数说明如表3所示。

      在配置SA/SP时,在数据通信的一端需要配置成对的SA和SP,分别为入方向的流量和出方向设置安全策略。

      • SP 配置

        ip xfrm policy add dir direction src source_ip dst destination_ip proto ip_proto offload packet dev eth_interface tmpl proto ipsec_protocol src source_ip dst destination_ip spi spi_value mode traffic_mode reqid reqid_num

      • SA配置:基于不同加密算法的选择,SA提供两种格式的配置命令。

        AES_GCM算法

        ip xfrm state add proto ipsec_protocol src source_ip dst destination_ip spi spi_value mode tunnel reqid reqid_num flag esn replay-window replay_window_size aead 'rfc4106(gcm(aes))' enc_key_valuesalt_value key_length sel src source_ip dst destination_ip proto ip_proto offload packet dev eth_interface dir direction

        其他加密认证算法组合:

        ip xfrm state add proto ipsec_protocol src source_ip dst destination_ip spi spi_value mode tunnel reqid reqid_num flag esn replay-window replay_window_size enc enc_name enc_key_value enc_key_length auth auth_name auth_key_value auth_key_length sel src source_ip dst destination_ip proto ip_proto offload packet dev eth_interface dir direction

      表3 参数说明

      参数

      参数说明

      direction

      流量方向。

      • 出:out
      • 入:in

      source_ip

      发送方源IP地址。

      destination_ip

      接收方目的地址。

      ip_proto

      IP协议类型(TCP/UDP)。

      eth_interface

      所使用的网卡设备对应的网络接口

      ipsec_protocol

      IPsec封装协议类型(ESP)。

      spi_value

      安全参数索引

      traffic_mode

      IPsec流量封装模式。

      • 传输:transport
      • 隧道:tunnel

      reqid_num

      优先级参数。

      replay_window_size

      防重放窗口大小,范围:[0, 64]。

      enc_key_valuesalt_value

      • enc_key_value:加密算法密钥
      • salt_value:盐值

      enc_name

      加密算法名称。具体请参考表1

      enc_key_value

      加密算法密钥。

      enc_key_length

      加密算法密钥长度。

      salt_value

      盐值。

      auth_name

      认证算法名称。

      auth_key_value

      认证算法密钥。

      auth_key_length

      认证算法密钥长度。

  4. VLAN配置

    使用以下命令在Host上配置VLAN,参数说明如表4所示。

    ip link add link eth_interface name eth_interface.vid type vlan id vid

    ip addr add host_ip brd broadcast_address dev eth_interface.vid

    ip link set dev eth_interface.vid up

    表4 参数说明

    参数

    参数说明

    eth_interface

    所使用的网卡设备对应的网络接口。

    vid

    vlan序列号。

    host_ip

    主机地址。

    broadcast_address

    广播地址。

  5. VXLAN配置

    VXLAN点对点配置方案如图2所示。

    图2 点对点配置方案

    使用以下命令在Host0进行VXLAN配置。

    ip address add eth0_ip dev eth_interface

    ip link add vxlan_name type vxlan id vid dstport destination_port remote eth1_ip local eth0_ip dev eth_interface

    ip addr add vxlan0_ip dev vxlan_name

    ip link set vxlan_name up

    表5 参数说明

    参数

    参数说明

    eth0_ip/eth1_ip

    网络接口绑定的IP地址。

    eth_interface

    所使用的网卡设备对应的网络接口。

    vid

    vlan序列号。

    vxlan0_ip/vxlan1_ip

    vxlan绑定的IP地址。

    vxlan_name

    vxlan设备号。例如:vxlan0。

    destination_port

    目的端口号。

  6. NAT-T的配置

    • 可选:IP Xfrm手动配置

      使用以下命令在SA中配置封装模式,将封装的源端口和目的端口设置为4500,参数说明如表6所示。

      ip xfrm state add proto ipsec_protocol src source_ip dst destination_ip spi spi_value mode traffic_mode reqid reqid_num flag esn replay-window replay_window_size aead enc_name enc_key_valuesalt_value key_length sel src source_ip dst destination_ip proto ip_proto encap espinudp sport dport offload packet dev eth_interface dir direction

      表6 参数说明

      参数

      参数说明

      ipsec_protocol

      IPsec封装协议类型(ESP)。

      source_ip

      发送方源IP地址。

      destination_ip

      接收方目的地址。

      spi_value

      安全参数索引。

      traffic_mode

      IPsec流量封装模式。

      • 传输:transport
      • 隧道:tunnel

      reqid_num

      优先级参数。

      replay_window_size

      防重放窗口大小,范围:[0,64]。

      enc_name

      加密算法名称。

      enc_key_value

      加密算法密钥。

      enc_key_length

      加密算法密钥长度。

      ip_proto

      IP协议类型(TCP/UDP)。

      sport

      NAT-T头部源端口。

      dport

      NAT-T头部目的端口。

      eth_interface

      所使用的网卡设备对应的网络接口。

      direction

      流量方向。

      • 出:out
      • 入:in
    • IKE自动协商

      当IPsec设备处于NAT网关之后时,控制面自动配置SA中的封装模式,无需添加额外配置参数。