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個字節(jié)為一組的數據)
下面列了一部分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 匹配成功將下一條的節(jié)點設置為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
創(chuàng)建如果未指定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字節(jié))字節(jié)對齊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這個節(jié)點進行處理的時候也是這樣進行匹配到對應的session的
?
?
?
?
?
?
總結
以上是生活随笔為你收集整理的VPP classify ACL的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: access设置 dolby_win10
- 下一篇: 【electron】nsis重编译,自定