VPP中ACL(访问控制列表)的使用——系列二

本文详细介绍了VPP环境下ACL_PLUGIN与CLASSIFY模块的测试流程及结果,涵盖三层、二层、四层数据包过滤,黑白名单实现,以及多策略表链与单一策略表多session测试。

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

目录

 

一、ACL_PLUGIN测试

1.三层测试

2.黑名单实现

3.二层测试

二、CLASSIFY测试

1.二层测试

2.三层测试

3.四层测试

4.Hex测试:某session中配置多个过滤条件

5.多table组成表链测试

6.单table配多条session测试


一、ACL_PLUGIN测试

1.三层测试

因为acl_plugin默认采用白名单机制,策略挂载到端口后,未匹配到数据包全部拒绝。所以直接采用permit即可生效。同时,可直接ip掩码,例如10.10.150.0/24格式,提供了很高灵活性。

  • 数据流入方向input/output 端口permit测试
  • 数据流出方向input/output 端口permit测试

##步骤1.配置访问控制规则

vat# acl_add_replace ipv4 permit src 10.10.150.0/24

vat# acl_add_replace ipv4 permit dst 10.10.150.0/24

##如果指定网段前缀24,第四字节需要为0,即10.10.150.0/24才行。

 

##步骤2.将某些控制规则配置到某端口,下面8条分别测试(input /output均可生效,且为白名单机制)

vat# acl_interface_set_acl_list eth2 input 0 1        #允许通过150网段,拦截其他网段

vat# acl_interface_set_acl_list eth2 output 0    #默认拦截所有网段,acl没生效因src 150

vat# acl_interface_set_acl_list eth1 input 0         #默认拦截所有网段,acl没生效因src 150

vat# acl_interface_set_acl_list eth1 output 0        #允许通过150网段,拦截其他网段

 

##步骤3.查询端口绑定情况确认成功

vat# acl_interface_list_dump

实验结论:验证端口的input output方向挂载acl均可生效,但src和dst需要斟酌指定。

2.黑名单实现

因默认机制为白名单方式,所以实现黑名单功能至少需要2条acl控制规则,并同时挂载某端口。通过调整挂载acl序号顺序,判断多个挂载规则表之间关系。

##1.配置访问控制规则

vat# acl_add_replace permit, ipv6 permit

vat# acl_add_replace ipv4 deny src 10.10.150.0/24

 

## 2.将某些控制规则配置到某端口,下面分别测试不同ACL执行顺序(input /output均可生效,且为白名单机制)

##先允许所有包通过,后拒绝某网段,实验结果是全部包通过

vat# acl_interface_set_acl_list eth1 output 0 1

 

##先拒绝某网段,后允许所有包通过,实验结果是拒绝150网段,剩下未匹配包都通过

vat# acl_interface_set_acl_list eth1 output 1 0    

 

vat#acl_interface_list_dump           #查询端口绑定情况确认成功

实验结论:对于符合第一条规则的数据包击中,则不往后执行。未击中,执行后续acl规则。

3.二层测试

##步骤1.配置访问控制规则

vat# macip_acl_add ipv4 permit ip 10.10.150.0/24 mac 64:00:6a:1d:75:06 mask ff:ff:ff:ff:ff:ff

 

##步骤2.将某些控制规则配置到某端口

vat# macip_acl_interface_add_del eth1 add acl 0

 

##步骤3.查询端口绑定情况确认成功

vat# macip_acl_interface_get

vat# macip_acl_dump

二、CLASSIFY测试

1.二层测试

对源MAC为64:00:6a:1d:75:06数据包进行拒绝。

# classify table mask l2 src buckets 16

# classify session acl-hit-next deny opaque-index 0 table-index 0 match l2 src 64:00:6a:1d:75:06

# set int input acl intfc eth2 l2-table 0   ##测试不可行,无拦截(测试失败)

# set int input acl intfc eth2 ip4-table 0 ##测试可行(ip4-table生效,l2-table不生效)

#查看并从端口删除策略表

# show inacl type l2

# set int input acl intfc eth1 ip4-table 0 del   ##解除端口绑定

# classify table table 0 del                                ##删除某table策略表

vpp# show classify tables       //查看表 show classify tables verbose

vpp# show outacl type ip4      //查看出接口挂载策略表情况

实验结果:

策略挂载到eth2 input后,实现功能,图片显示数据包击中策略,被拦截证实的图片。测试策略表仅挂在eth2的input方向成功,output失败。同时,挂载eth1的input和output 均不生效。

150.2 ping 200.2 不通,删除session后ping通 //效果实现

100.2 ping 150.2 不通,删除session后通 //效果实现

2.三层测试

(1)对源IP为10.10.150.2的ICMP数据包进行拒绝。测试可行

# classify table mask l3 ip4 src buckets 16

# classify session acl-hit-next deny opaque-index 0 table-index 1 match l3 ip4 src 10.10.150.2 proto 01

# set int input acl intfc eth2 ip4-table 1         ##测试可行,实现拦截(测试成功)

# set int output acl intfc eth2 ip4-table 1       ##测试不可行,无拦截(测试失败)

# set int input acl intfc eth1 ip4-table 1         ##测试不可行,无拦截(测试失败)

# set int output acl intfc eth1 ip4-table 1       ##测试不可行,无拦截(测试失败)

#查看并从端口删除策略表

# show inacl type ip4

# set int input acl intfc eth1 ip4-table 1 del

实验结果:

执行set int input acl intfc eth2 ip4-table 1时,测试成功,实现指定拦截。

150.2  ping  200.2  不通

150.2  ping  100.2  不通

100.2  ping  200.2  通

100.2  ping  150.2  不通

2添加dest 拦截测试

分别挂载到eth1端口的input output端口。

# classify table mask l3 ip4 dst table 2

# classify session acl-hit-next deny table-index 2 match l3 ip4 dst 10.10.200.2

# set int input acl intfc eth2 ip4-table 1         ##测试实现拦截

# set int output acl intfc eth2 ip4-table 1       ##测试失败,无拦截

# set int input acl intfc eth1 ip4-table 1         ##测试失败,无拦截

# set int output acl intfc eth1 ip4-table 1       ##测试失败,无拦截

测试发现仅挂eth2的input流入方向生效,output不生效;同时,挂载端口eth1无法生效。

3.四层测试

对源IP地址为10.10.150.2的TCP数据包进行拒绝。l4创建acl table必须添加l3参数,指定session时l4后参数为src_port 和dst_port。

 

# classify table mask l3 ip4 src l4 dst_port

# classify session acl-hit-next deny table-index 3 match l3 ip4 src 10.10.150.2 l4 dst_port 12865

# set int input acl intfc eth2 ip4-table 3

#查看并删除该网口之前绑定策略表

# show inacl type ip4

# set int input acl intfc eth2 ip4-table 3 del

使用netperf发送数据报,实现成功拦截端口号为12865的TCP数据报文。

4.Hex测试:某session中配置多个过滤条件

  1. 对源MAC为00:0c:29:e9:0e:9c(且)源IP为10.10. 150.2的ICMP包进行过滤。

Ip proto Offset 10B, Ip src 13B begin。

# classify table mask hex

000000000000ffffffffffff0000000000000000000000ff0000ffffffff000000000000

# classify session acl-hit-next deny opaque-index 0 table-index 0 match hex

00000000000064006a1d750600000000000000000000000100000a0a9602000000000000

# set int input acl intfc eth2 ip4-table 0

(2)对源IP地址为10.10. 150.0/24网段的所有ICMP数据包进行过滤,即match参数中的0x0a0a96,proto即match参数中的0x01。

# classify table mask hex

0000000000000000000000000000000000000000000000ff0000ffffff0000000000

 

# classify session acl-hit-next deny opaque-index 0 table-index 0 match hex

00000000000000000000000000000000000000000000000100000a0a9600000000000000

# set int input acl intfc eth2 ip4-table 0

实验结果: 实现整个网段的ICMP过滤功能,修改150.2为150.4进行测试拦截成功。

5.多table组成表链测试

(1)使用多个表过滤源IP地址和源MAC地址,即将参数next-table指向下一个策略表。对源MAC为00:0c:29:e9:0e:9c或源IP为10.10.150.2的数据包进行拒绝。

 

# classify table mask l3 ip4 src

# classify session acl-hit-next deny opaque-index 0 table-index 3 match l3 ip4 src 10.10.150.2

##查看表show classify tables [verbose]

# classify table mask l2 src next-table 0

# classify session acl-hit-next deny opaque-index 1 table-index 4 match l2 src 00:0c:29:e9:0e:9c

# set int input acl intfc eth1 ip4-table 1

 

结果:先执行table1,没匹配成功MAC,则执行下一表table0匹配。此时table2 src ip有匹配成功数据包21个。则执行动作数据包拒绝通过。

 

(2)ACL表0禁止来源是10.10.150.0/24网段的数据包访问,表1禁止来源是10.10.150.2的数据包访问,即表0、表1是覆盖关系。

##创建table0端口

# classify table mask hex

0000000000000000000000000000000000000000000000ff0000ffffff00000000000000 table 0

# classify session acl-hit-next deny opaque-index 0 table-index 0 match hex

00000000000000000000000000000000000000000000000100000a0a9600000000000000

##创建table1端口

# classify table mask hex

0000000000000000000000000000000000000000000000ff0000ffffffff00000000000000 table 1

# classify session acl-hit-next deny opaque-index 0 table-index 1 match hex

00000000000000000000000000000000000000000000000100000a0a960200000000000000

##添加table索引

#classify table table 0 next-table 1

##将table挂到eth2端口

# set int input acl intfc eth2 ip4-table 0

实验结果:只hit到网段拦截,但下一跳具体ip无拦截。

结论:若数据包匹配成功,则执行动作;匹配失败则匹配下一表。

3)白名单permit实现

classify默认采用黑名单模式,需要直接指定拒绝策略,则其他未匹配数据包均能通过。通常cisco产品具有添deny any关键字,但classify中无any关键字,session中只能指定具体值。测试案例,仅允许10.10.150.2的IP访问通过,其他拒绝。

##创建table0端口,拒绝所有10.10.150.0/24网段的ICMP包

# classify table mask hex

0000000000000000000000000000000000000000000000ff0000ffffff00000000000000 table 0

# classify session acl-hit-next deny opaque-index 0 table-index 0 match hex

00000000000000000000000000000000000000000000000100000a0a9600000000000000

##创建table1端口,允许10.10.150.2通过

# classify table mask hex

0000000000000000000000000000000000000000000000ff0000ffffffff00000000000000 table 1

# classify session acl-hit-next permit opaque-index 0 table-index 1 match hex

00000000000000000000000000000000000000000000000100000a0a960200000000000000

##添加table索引

 

##下面命令行1、2分别执行,表示挂载顺序。测试table表链执行关系

##1#classify table table 0 next-table 1     ##table0挂载eth2端口后,拦截150.2数据包

##2#classify table table 1 next-table 0   ##table1挂载eth2端口后,允许150.2数据包通过,有hit。同时,不允许150.3通过,有hit。实现白名单控制。

 

##将table挂到eth2端口

# set int input acl intfc eth2 ip4-table 1

实验结果:首先匹配到数据包会执行动作,就不会匹配往后策略表。未匹配到则继续匹配策略表。对150网段内主机IP任意修改,拦截ping200网段数据包,实现网段测试。

实验结论:table表连接都是或的关系,只要某数据包有命中,就不会往下执行

  1. table表的循环索引

table表死循环的测试,在挂端口后设置循环列表,vpp,vppctl进程仍在运行,但都vpp,vppctl都卡死;VPP其他网段无法ping通。

结论:挂端口后不可形成循环链表,需挂端口前设置好索引关系,或挂端口后处理好索引关系。

6.单table配多条session测试

对发往10.10.200.2,源IP地址为10.10.150.2、10.10.150.3、10.10.100.2、10.10.100.3的数据包进行过滤。证实table可以同时挂多个端口并生效,并每条table中设置多条session。

# classify table mask l3 ip4 src buckets 16

# classify session acl-hit-next deny opaque-index 0 table-index 4 match l3 ip4 src 10.10.150.2

# classify session acl-hit-next deny opaque-index 1 table-index 4 match l3 ip4 src 10.10.150.3

# classify session acl-hit-next deny opaque-index 1 table-index 4 match l3 ip4 src 10.10.100.2

# classify session acl-hit-next deny opaque-index 1 table-index 4 match l3 ip4 src 10.10.100.3

# set int input acl intfc eth2 ip4-table 0

# set int input acl intfc eth0 ip4-table 0

 

 

### 如何在 VPP 中禁用 ICMP 或关闭 ping 功能 在向量封包处理器 (VPP) 的环境中,可以通过配置策略来实现对特定协议的支持或限制。对于禁用 ICMP 或者阻止 Ping 请求的功能需求,可以采用以下几种方式: #### 方法一:通过 ACL访问控制列表)过滤 ICMP 流量 ACL 是一种常见的网络流量管理工具,在 VPP 中也可以用来定义规则以允许或拒绝某些类型的流量。为了禁用 ICMP/Ping 功能,可以在 ACL 中添加一条规则用于丢弃所有入站和出站的 ICMP 数据包。 以下是创建并应用 ACL 来屏蔽 ICMP 的具体操作: ```bash vpp# create acl deny ip4 proto icmp action drop ^[^1] ``` 这条命令的作用是建立一个新的 ACL 规则集,其中指定 IPv4 协议下的 ICMP 类型数据包被直接丢弃而不转发给目标设备。 #### 方法:修改接口设置以忽略 ICMP Echo Requests 另一种更简单的方法是从软件层面调整网卡行为使其不响应外部发起的 ICMP echo request 报文。这通常涉及更改相应端口上的参数选项。 虽然官方文档并未提供明确的一键开关指令专门针对此场景,但理论上可通过自定义脚本或者编辑启动配置文件达到相同效果: 假设我们希望对名为 `pg0` 的物理接口执行此类变更,则可尝试运行如下CLI语句序列: ```bash set int state pg0 down # 关闭选定接口暂时停止其活动状态 [^2] set interface disable-packet-input pg0 true # 设置该接口不再接收任何新来的帧/报文输入流 [^3] set int state pg0 up # 重新激活接口保持其他正常通信不受影响的同时避开ICMP请求处理逻辑 [^4] ``` 以上步骤会有效抑制来自这个方向的一切探测信号直至再次手动恢复默认模式为止。 #### 方法三:利用防火墙插件增强安全性防护能力 如果项目环境支持额外安装第三方模块的话,那么考虑引入基于 iptables 或 nftables 架构构建起来的安全框架不失为明智之举。这些高级别的解决方案不仅能够满足当前提出的单一功能性诉求——即封锁Ping服务;而且还能为进一步优化整体架构奠定坚实基础。 例如启用 IPtables 插件之后就可以轻松编写类似的规则条目从而彻底隔绝不必要的干扰源。 ```bash iptables -A INPUT -p icmp --icmp-type echo-request -j DROP # 添加INPUT链表项匹配到所有的进入系统的Echo Request消息并将它们抛弃掉 [^5] ``` 请注意实际部署过程中可能还需要根据具体情况适当调整路径名以及权限等级等问题才能顺利完成整个流程。 --- ### 提供代码片段说明如何自动化部分过程 下面给出一段 Python 脚本来演示怎样借助 subprocess 库调用上述提到的一些基本运维动作组合而成完整的解决办法之一版本号兼容性未经测试请谨慎选用! ```python import subprocess def disable_icmp_on_vpp(interface_name="pg0"): commands = [ f"vppctl set int state {interface_name} down", f"vppctl set interface disable-packet-input {interface_name} true", f"vppctl set int state {interface_name} up" ] results = [] for cmd in commands: result = subprocess.run(cmd, shell=True, capture_output=True, text=True) results.append({"command":cmd,"output":result.stdout.strip(),"error":result.stderr.strip()}) return results if __name__ == "__main__": outcome = disable_icmp_on_vpp() for entry in outcome: print(f"{entry['command']}:\nSTDOUT:{entry['output']}\nSTDERR:{entry['error']}") ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值