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

Add sockmap support #179

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

dippynark
Copy link

@dippynark dippynark changed the title Add sockmap support WIP: Add sockmap support Apr 2, 2019
@dippynark dippynark force-pushed the 177-add-sockmap-support branch from 9ab9abc to 64760e6 Compare April 2, 2019 19:34
@dippynark dippynark changed the title WIP: Add sockmap support Add sockmap support Apr 2, 2019
elf/elf.go Outdated
@@ -555,6 +555,7 @@ func (b *Module) Load(parameters map[string]SectionParams) error {
isTracepoint := strings.HasPrefix(secName, "tracepoint/")
isSchedCls := strings.HasPrefix(secName, "sched_cls/")
isSchedAct := strings.HasPrefix(secName, "sched_act/")
isSkSkb := strings.HasPrefix(secName, "sk/skb/")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gobpf and libbpf unfortunately diverged in the way they name sections:
https://github.com/torvalds/linux/blob/v5.0/tools/lib/bpf/libbpf.c#L2610-L2662

But when possible, could we adopt the same section names as in libbpf? That would be:

  • sk_skb/stream_parser
  • sk_skb/stream_verdict

@@ -133,4 +140,16 @@ int socket__dummy(struct __sk_buff *skb)
return 0;
}

SEC("sk/skb/parser/dummy_sockmap")
int parser_dummy(struct __sk_buff *skb)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter should be struct sk_msg_md *msg.

Ditto in verdict_dummy.

Copy link
Author

@dippynark dippynark Apr 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think struct __sk_buff * is correct:

and the verifier converts references to struct __sk_buff * fields to the real struct sk_buff * at load time. Maybe I'm missing something?

tests/dummy.c Outdated
@@ -81,6 +81,13 @@ struct bpf_map_def SEC("maps/dummy_array_custom") dummy_array_custom = {
.pinning = PIN_CUSTOM_NS,
};

struct bpf_map_def SEC("maps/dummy_sockmap") sock_map = {
.type = BPF_MAP_TYPE_SOCKMAP,
.key_size = sizeof(int),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it worth giving a more realistic key struct? Such as:

struct sock_key {
        __u32 sip4;
        __u32 dip4;
        __u32 sport;
        __u32 dport;
};

More complex example on:
https://github.com/cilium/cilium/blob/506bd14/bpf/sockops/bpf_sockops.h#L21-L46

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, have added your example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add BPF_PROG_TYPE_SK_SKB support to gobpf/elf
3 participants