Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ARRAY_OF_MAPS and HASH_OF_MAPS #297

Open
masibw opened this issue Jun 18, 2021 · 0 comments
Open

Support ARRAY_OF_MAPS and HASH_OF_MAPS #297

masibw opened this issue Jun 18, 2021 · 0 comments

Comments

@masibw
Copy link

masibw commented Jun 18, 2021

Hi all, thanks for the good library.

I wanna use ARRAY_OF_MAPS and HASH_OF_MAPS. I think I have to provide a file descriptor of the maps. But I think there is no way to get the table file descriptor.

Maybe ID is not file descriptor. We need int(C.bpf_table_fd_id(mod, table.id)), , is It?

Also, if the key of the parent table's key is a string and the value is a file descriptor, I don't think it is possible to set this value even if the Get File Descriptor function exists.

test.c

BPF_ARRAY(innerMap, int, 32);
BPF_HASH_OF_MAPS(parentMap, "innerMap", 10);

... some codes ...

main.go

type ParentKey struct{
  ID string
}

	m := bpf.NewModule(string(bpfText), []string{})

	parentTable := bpf.NewTable(m.TableId("parentMap"), m)

	innerTable := bpf.NewTable(m.TableId("innerMap"), m)
        key, _ := innerTable.KeyStrToBytes("1")
        leaf, _ := innerTable.LeafStrToBytes("11")

	if err := table.Set(key, leaf); err != nil {
		fmt.Fprintf(os.Stderr, "Failed to add data to rules: %s\n", err)
		os.Exit(1)
	}

	parentKey := &ParentKey{
	     ID: "test_id",
	}

        fd := innerTable.Fd() // I need this function

        // I think `cgo argument has Go pointer to Go pointer` error will be occured, also  parentTable.Set is not satisfied this usecase. 
	if err := parentTable.SetP(parentKey, fd); err != nil {
		fmt.Fprintf(os.Stderr, "Failed to add data to policyList: %s\n", err)
		os.Exit(1)
	}

The assumption is that if I want to use a string in a Map, I need to wrap it in a structure, right?

Maybe We need SetMap(key unsafe.Pointer, fd int) error

This was referenced Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant