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

loader: Fixes for map creation from daemon #10728

Merged
merged 3 commits into from Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 36 additions & 35 deletions bpf/bpf_alignchecker.c
Expand Up @@ -21,52 +21,53 @@
#include "lib/policy_log.h"
#include "sockops/bpf_sockops.h"

// DECLARE_STRUCT declares a unique usage of the struct 'x' on the stack.
// DECLARE declares a unique usage of the union or struct 'x' on the stack.
//
// To prevent compiler from optimizing away the var, we pass a reference
// to the var to a BPF helper function which accepts a reference as
// an argument.
#define DECLARE_STRUCT(x, iter) \
{ \
struct x s ## iter = {}; \
trace_printk("%p", 1, &s ## iter); \
iter++; \
#define DECLARE(datatype, x, iter) \
{ \
datatype x s ## iter = {}; \
trace_printk("%p", 1, &s ## iter); \
iter++; \
}

// This function is a placeholder for C struct definitions shared with Go, and
// it's never being executed.
int main() {
int iter = 0;

DECLARE_STRUCT(ipv4_ct_tuple, iter);
DECLARE_STRUCT(ipv6_ct_tuple, iter);
DECLARE_STRUCT(ct_entry, iter);
DECLARE_STRUCT(ipcache_key, iter);
DECLARE_STRUCT(remote_endpoint_info, iter);
DECLARE_STRUCT(lb4_key, iter);
DECLARE_STRUCT(lb4_service, iter);
DECLARE_STRUCT(lb4_backend, iter);
DECLARE_STRUCT(lb6_key, iter);
DECLARE_STRUCT(lb6_service, iter);
DECLARE_STRUCT(lb6_backend, iter);
DECLARE_STRUCT(endpoint_key, iter);
DECLARE_STRUCT(endpoint_info, iter);
DECLARE_STRUCT(metrics_key, iter);
DECLARE_STRUCT(metrics_value, iter);
DECLARE_STRUCT(sock_key, iter);
DECLARE_STRUCT(policy_key, iter);
DECLARE_STRUCT(policy_entry, iter);
DECLARE_STRUCT(ipv4_nat_entry, iter);
DECLARE_STRUCT(ipv6_nat_entry, iter);
DECLARE_STRUCT(trace_notify, iter);
DECLARE_STRUCT(drop_notify, iter);
DECLARE_STRUCT(policy_verdict_notify, iter);
DECLARE_STRUCT(debug_msg, iter);
DECLARE_STRUCT(debug_capture_msg, iter);
DECLARE_STRUCT(ipv4_revnat_tuple, iter);
DECLARE_STRUCT(ipv4_revnat_entry, iter);
DECLARE_STRUCT(ipv6_revnat_tuple, iter);
DECLARE_STRUCT(ipv6_revnat_entry, iter);
DECLARE(struct, ipv4_ct_tuple, iter);
DECLARE(struct, ipv6_ct_tuple, iter);
DECLARE(struct, ct_entry, iter);
DECLARE(struct, ipcache_key, iter);
DECLARE(struct, remote_endpoint_info, iter);
DECLARE(struct, lb4_key, iter);
DECLARE(struct, lb4_service, iter);
DECLARE(struct, lb4_backend, iter);
DECLARE(struct, lb6_key, iter);
DECLARE(struct, lb6_service, iter);
DECLARE(struct, lb6_backend, iter);
DECLARE(struct, endpoint_key, iter);
DECLARE(struct, endpoint_info, iter);
DECLARE(struct, metrics_key, iter);
DECLARE(struct, metrics_value, iter);
DECLARE(struct, sock_key, iter);
DECLARE(struct, policy_key, iter);
DECLARE(struct, policy_entry, iter);
DECLARE(struct, ipv4_nat_entry, iter);
DECLARE(struct, ipv6_nat_entry, iter);
DECLARE(struct, trace_notify, iter);
DECLARE(struct, drop_notify, iter);
DECLARE(struct, policy_verdict_notify, iter);
DECLARE(struct, debug_msg, iter);
DECLARE(struct, debug_capture_msg, iter);
DECLARE(struct, ipv4_revnat_tuple, iter);
DECLARE(struct, ipv4_revnat_entry, iter);
DECLARE(struct, ipv6_revnat_tuple, iter);
DECLARE(struct, ipv6_revnat_entry, iter);
DECLARE(union, macaddr, iter);

return 0;
}
14 changes: 14 additions & 0 deletions pkg/datapath/alignchecker/alignchecker.go
Expand Up @@ -21,11 +21,14 @@ import (
"github.com/cilium/cilium/pkg/bpf"
"github.com/cilium/cilium/pkg/maps/ctmap"
"github.com/cilium/cilium/pkg/maps/eppolicymap"
"github.com/cilium/cilium/pkg/maps/eventsmap"
ipcachemap "github.com/cilium/cilium/pkg/maps/ipcache"
"github.com/cilium/cilium/pkg/maps/lbmap"
"github.com/cilium/cilium/pkg/maps/lxcmap"
"github.com/cilium/cilium/pkg/maps/metricsmap"
"github.com/cilium/cilium/pkg/maps/neighborsmap"
"github.com/cilium/cilium/pkg/maps/policymap"
"github.com/cilium/cilium/pkg/maps/signalmap"
"github.com/cilium/cilium/pkg/maps/sockmap"
"github.com/cilium/cilium/pkg/maps/tunnel"
)
Expand Down Expand Up @@ -64,6 +67,8 @@ func CheckStructAlignments(path string) error {
"ipv4_revnat_entry": {reflect.TypeOf(lbmap.SockRevNat4Value{})},
"ipv6_revnat_tuple": {reflect.TypeOf(lbmap.SockRevNat6Key{})},
"ipv6_revnat_entry": {reflect.TypeOf(lbmap.SockRevNat6Value{})},
"v6addr": {reflect.TypeOf(neighborsmap.Key6{})},
"macaddr": {reflect.TypeOf(neighborsmap.Value{})},
// TODO: alignchecker does not support nested structs yet.
// "ipv4_nat_entry": {reflect.TypeOf(nat.NatEntry4{})},
// "ipv6_nat_entry": {reflect.TypeOf(nat.NatEntry6{})},
Expand All @@ -83,10 +88,19 @@ func CheckStructAlignments(path string) error {
reflect.TypeOf(lbmap.RevNat4Key{}),
reflect.TypeOf(lbmap.RevNat6Key{}),
},
"__u32": {
reflect.TypeOf(signalmap.Key{}),
reflect.TypeOf(signalmap.Value{}),
reflect.TypeOf(eventsmap.Key{}),
reflect.TypeOf(eventsmap.Value{}),
reflect.TypeOf(policymap.CallKey{}),
reflect.TypeOf(policymap.CallValue{}),
},
"int": {
reflect.TypeOf(sockmap.SockmapValue{}),
reflect.TypeOf(eppolicymap.EPPolicyValue{}),
},
"__be32": {reflect.TypeOf(neighborsmap.Key4{})},
}
return check.CheckStructAlignments(path, toCheckSizes, false)
}
3 changes: 2 additions & 1 deletion pkg/datapath/loader/cache.go
Expand Up @@ -42,6 +42,7 @@ var ignoredELFPrefixes = []string{
"IPV6_NODEPORT", // Global
"ROUTER_IP", // Global
"SNAT_IPV6_EXTERNAL", // Global
"cilium_call_policy", // Global
"cilium_ct", // All CT maps, including local
"cilium_encrypt_state", // Global
"cilium_events", // Global
Expand All @@ -50,7 +51,7 @@ var ignoredELFPrefixes = []string{
"cilium_lxc", // Global
"cilium_metrics", // Global
"cilium_nodeport_neigh", // All nodeport neigh maps
"cilium_policy", // Global
"cilium_policy", // All policy maps
"cilium_proxy", // Global
"cilium_signals", // Global
"cilium_snat", // All SNAT maps
Expand Down
1 change: 1 addition & 0 deletions pkg/maps/neighborsmap/neighborsmap.go
Expand Up @@ -49,6 +49,7 @@ type Key6 struct {
// +k8s:deepcopy-gen:interfaces=github.com/cilium/cilium/pkg/bpf.MapValue
type Value struct {
pchaigno marked this conversation as resolved.
Show resolved Hide resolved
macaddr types.MACAddr
pad uint16
}

// GetKeyPtr returns the unsafe pointer to the BPF key
Expand Down