如何为 IP/CIDR 创建 LPM trie 记录的切片

问题描述 投票:0回答:1

我正在尝试使用来自

https://github.com/cilium/ebpf/blob/master/map.go#L952-L1038
BatchUpdate
BatchDeleteAPI。根据我的理解,我需要创建 IP/CIRD 的 LPM trie 切片,例如:如果我有
denyIPs := []string{"10.11.15.114/32", "127.0.0.1/32"}
,我需要将
denyIPs
转换为 LPM trie 切片,我用谷歌搜索但无法找到示例 I可以学习(还是Golang新手)。我的意图是取代我的 https://github.com/vincentmli/xdp-firewall/blob/main/main.go#L78-L102批量更新和删除

go ip trie ebpf
1个回答
0
投票

来自包的docs

BatchUpdate 使用多个键和值更新地图 同时地。 "keys" 和 "values" 必须是 slice 类型,一个指针 切片或缓冲区将不起作用。

和(最新的)v0.10.0 source -

BatchUpdate
需要
keys
values
的相同长度的切片:

func (m *Map) BatchDelete(keys interface{}, opts *BatchOptions) (int, error)

所以像:

var m = ebfp.Map{}              // created elsewhere
var opts = &ebfp.BatchOptions{} // put options here

var (
    zones = []string{"internal", "localhost"}
    ips   = []string{"10.11.15.114/32", "127.0.0.1/32"}
)

count, err := m.BatchDelete(zones, ips, opts)
© www.soinside.com 2019 - 2024. All rights reserved.