我正在尝试使用来自
https://github.com/cilium/ebpf/blob/master/map.go#L952-L1038的
BatchUpdate
和BatchDelete
API。根据我的理解,我需要创建 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批量更新和删除
来自包的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)