-
Notifications
You must be signed in to change notification settings - Fork 312
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
base: master
Are you sure you want to change the base?
Add sockmap support #179
Conversation
9ab9abc
to
64760e6
Compare
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/") |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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:
- https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/progs/sockmap_parse_prog.c#L16
- https://elixir.bootlin.com/linux/v4.18/source/kernel/bpf/sockmap.c#L1497
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), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Adds support for attaching parser and redirect programs to sockmaps. This fixes #177