VPP classify ACL

本文对VPP 的classify ACL的使用做一些简单说明:

1、配置流程

1> 配置一个classify table

vpp cmd: 

classify table [miss-next|l2-miss_next|acl-miss-next <next_index>]
                    mask <mask-value> buckets <nn> [skip <n>] [match <n>]
                    [current-data-flag <n>] [current-data-offset <n>] [table <n>]
                    [memory-size <nn>[M][G]] [next-table <n>]
                    [del] [del-chain]

2> 向table中添加控制session

classify session [hit-next|l2-input-hit-next|l2-output-hit-next|acl-hit-next <next_index>|policer-hit-next <policer_name>]
                    table-index <nn> match [hex] [l2] [l3 ip4] [opaque-index <index>]
                    [action set-ip4-fib-id|set-ip6-fib-id|set-sr-policy-index <n>] [del]

3> 在接口上启用 ACL 表

set interface input acl intfc <int> [ip4-table <index>]  [ip6-table <index>] [l2-table <index>] [del]

set interface output acl intfc <int> [ip4-table <index>]  [ip6-table <index>] [l2-table <index>] [del]

2、classify table命令说明

classify table [miss-next|l2-miss_next|acl-miss-next <next_index>]
                    mask <mask-value> buckets <nn> [skip <n>] [match <n>]
                    [current-data-flag <n>] [current-data-offset <n>] [table <n>]
                    [memory-size <nn>[M][G]] [next-table <n>]
                    [del] [del-chain]

查看table:show classify tables [index <nn>]

在这些配置中主要的是mask;

首先来看一个配置用例:

classify table mask l3 ip4  version src dst proto 

该配置表明该表匹配的是ip头的对应字段包括:版本号、源ip\目的ip\协议;

在来看看该配置对应的mask的数据:

    0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xF0 0x00

    0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xFF 0x00 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF

    0xFF 0xFF 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 

部分参数说明:

[miss-next|l2-miss_next|acl-miss-next <next_index>]:

mask <mask-value>:设置该表是用数据包中的哪些字段用于过滤;(mask是以16个字节为一组的数据)

下面列了一部分mask的配置命令:

     mask hex 112233445566

     mask l2 [dst] [src]  [proto]
            0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x00 0x00 0x00 0x00 0x00 0x00 0xFF 0xFF 0x00 0x00
            mask l3 [ip4|ip6]  [version] [src] [dst] [proto] [hdr_length] [tos] [length] [fragment_id] [ttl] [protocol] [checksum]

     mask l4 [ tcp [src | dst]  | udp [src_port | dst_port]  | src_port  | dst_port ]

buckets <nn>:buckets的最大数目

skip <n>:mask中跳过的全0数据的组数

match <n>:mask中有效组数

current-data-flag <n>:标识数据包过滤的头信息获取是从vbuff的curretn_data处加current-data-offset 获取

current-data-offset <n>:与current-data-flag配合使用

table <n>:表索引;新增就不填,只有更新表信息才指定索引;

[memory-size <nn>[M][G]]:classify table对应结构中mheap的大小

3、classify session命令说明

classify session [hit-next|l2-input-hit-next|l2-output-hit-next|acl-hit-next <next_index>|policer-hit-next <policer_name>]
                    table-index <nn> match [hex] [l2] [l3 ip4] [opaque-index <index>]
                    [action set-ip4-fib-id|set-ip6-fib-id|set-sr-policy-index <n>] [del]

[hit-next|l2-input-hit-next|l2-output-hit-next|acl-hit-next <next_index>|policer-hit-next <policer_name>]:指定匹配成功后的操作;

例如:acl-hit-next deny 匹配成功丢弃

           acl-hit-next ip4-node lh-test 匹配成功将下一条的节点设置为lh-test

table-index <nn>:指定该session所属表索引

match [hex] [l2] [l3 ip4] :指定上面classify table中mask对应字段的具体值;

例如:match l3 ip4 src 172.16.101.53 匹配ip头的源地址为172.16.101.53的包;

 

4、vpp中的流程
 

1> classify table

创建如果未指定table <n>就认为是新增:会在vnet_classify_main.tables

typedef struct vnet_classify_table_t
{
  u32x4 *mask;/*在跳过N个向量后应用掩码*/
  vnet_classify_bucket_t *buckets;
  vnet_classify_entry_t *entries;//classify session的结构
  /* 配置参数 */
  u32 match_n_vectors;//mask以u32x4(16字节)字节对齐mask的组数
  u32 skip_n_vectors;//跳过的u32x4个数
  u32 nbuckets;//设置buckets中有效的向量索引
  u32 log2_nbuckets;
  u32 linear_buckets;
  int entries_per_page;
  u32 active_elements;
  u32 current_data_flag;/*解析数据包的头从设置的偏移处获取 current_data_offset*/
  int current_data_offset;
  u32 data_offset;
  u32 next_table_index; /* 下一张表的索引 try */
  u32 miss_next_index; /* 没有匹配上的数据包下一跳的索引 Miss next index, return if next_table_index = 0 */
  vnet_classify_entry_t **working_copies; /* Per-bucket working copies, one per thread */
  int *working_copy_lengths;
  vnet_classify_bucket_t saved_bucket;
  vnet_classify_entry_t **freelists; /* Free entry freelists */
  u8 *name;
  void *mheap; /* Private allocation arena, protected by the writer lock */
  volatile u32 *writer_lock; /* Writer (only) lock for this table */
} vnet_classify_table_t;

 

2> classify session

通过 table-index <nn>指定的索引到vnet_classify_main.tables中获取对应的ACL表;

确定对应的hash值找到对应的bucket:

hash = vnet_classify_hash_packet (t, key_minus_skip);//key_minus_skip就是数据包的头

bucket_index = hash & (t->nbuckets - 1);

b = &t->buckets[bucket_index];

后面在数据包通过ip4-inacl这个节点进行处理的时候也是这样进行匹配到对应的session的

 

 

 

 

 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值