History

bpf: Switch BPF UAPI #define constants used from BPF program side to enums

Switch BPF UAPI constants, previously defined as #define macro, to anonymous enum values. This preserves constants values and behavior in expressions, but has added advantaged of being captured as part of DWARF and, subsequently, BTF type info. Which, in turn, greatly improves usefulness of generated vmlinux.h for BPF applications, as it will not require BPF users to copy/paste various flags and constants, which are frequently used with BPF helpers. Only those constants that are used/useful from BPF program side are converted.

Andrii Nakryiko committed 6 years ago

Commit 1aae4bd1 parent 320a3602 files · +219 −133Browse files

Showing the changes to include/uapi/linux (1 of 2 files). Show all

Unified · Split

include/uapi/linux/bpf.h+109−66
@@ -325,44 +325,46 @@ enum bpf_attach_type { · 324 unmodified lines
325#define BPF_PSEUDO_CALL 1325#define BPF_PSEUDO_CALL 1
326 326
327/* flags for BPF_MAP_UPDATE_ELEM command */327/* flags for BPF_MAP_UPDATE_ELEM command */
328#define BPF_ANY 0 /* create new element or update existing */328enum {
329#define BPF_NOEXIST 1 /* create new element if it didn't exist */329 BPF_ANY = 0, /* create new element or update existing */
330#define BPF_EXIST 2 /* update existing element */330 BPF_NOEXIST = 1, /* create new element if it didn't exist */
331#define BPF_F_LOCK 4 /* spin_lock-ed map_lookup/map_update */331 BPF_EXIST = 2, /* update existing element */
332 BPF_F_LOCK = 4, /* spin_lock-ed map_lookup/map_update */
333};
332 334
333/* flags for BPF_MAP_CREATE command */335/* flags for BPF_MAP_CREATE command */
334#define BPF_F_NO_PREALLOC (1U << 0)336enum {
337 BPF_F_NO_PREALLOC = (1U << 0),
335/* Instead of having one common LRU list in the338/* Instead of having one common LRU list in the
336 * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list339 * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list
337 * which can scale and perform better.340 * which can scale and perform better.
338 * Note, the LRU nodes (including free nodes) cannot be moved341 * Note, the LRU nodes (including free nodes) cannot be moved
339 * across different LRU lists.342 * across different LRU lists.
340 */343 */
341#define BPF_F_NO_COMMON_LRU (1U << 1)344 BPF_F_NO_COMMON_LRU = (1U << 1),
342/* Specify numa node during map creation */345/* Specify numa node during map creation */
343#define BPF_F_NUMA_NODE (1U << 2)346 BPF_F_NUMA_NODE = (1U << 2),
344
345#define BPF_OBJ_NAME_LEN 16U
346 347
347/* Flags for accessing BPF object from syscall side. */348/* Flags for accessing BPF object from syscall side. */
348#define BPF_F_RDONLY (1U << 3)349 BPF_F_RDONLY = (1U << 3),
349#define BPF_F_WRONLY (1U << 4)350 BPF_F_WRONLY = (1U << 4),
350 351
351/* Flag for stack_map, store build_id+offset instead of pointer */352/* Flag for stack_map, store build_id+offset instead of pointer */
352#define BPF_F_STACK_BUILD_ID (1U << 5)353 BPF_F_STACK_BUILD_ID = (1U << 5),
353 354
354/* Zero-initialize hash function seed. This should only be used for testing. */355/* Zero-initialize hash function seed. This should only be used for testing. */
355#define BPF_F_ZERO_SEED (1U << 6)356 BPF_F_ZERO_SEED = (1U << 6),
356 357
357/* Flags for accessing BPF object from program side. */358/* Flags for accessing BPF object from program side. */
358#define BPF_F_RDONLY_PROG (1U << 7)359 BPF_F_RDONLY_PROG = (1U << 7),
359#define BPF_F_WRONLY_PROG (1U << 8)360 BPF_F_WRONLY_PROG = (1U << 8),
360 361
361/* Clone map from listener for newly accepted socket */362/* Clone map from listener for newly accepted socket */
362#define BPF_F_CLONE (1U << 9)363 BPF_F_CLONE = (1U << 9),
363 364
364/* Enable memory-mapping BPF map */365/* Enable memory-mapping BPF map */
365#define BPF_F_MMAPABLE (1U << 10)366 BPF_F_MMAPABLE = (1U << 10),
367};
366 368
367/* Flags for BPF_PROG_QUERY. */369/* Flags for BPF_PROG_QUERY. */
368 370
@@ -391,6 +393,8 @@ struct bpf_stack_build_id { · 22 unmodified lines
391 };393 };
392};394};
393 395
396#define BPF_OBJ_NAME_LEN 16U
397
394union bpf_attr {398union bpf_attr {
395 struct { /* anonymous struct used by BPF_MAP_CREATE command */399 struct { /* anonymous struct used by BPF_MAP_CREATE command */
396 __u32 map_type; /* one of enum bpf_map_type */400 __u32 map_type; /* one of enum bpf_map_type */
@@ -3045,72 +3049,100 @@ enum bpf_func_id { · 2648 unmodified lines
3045/* All flags used by eBPF helper functions, placed here. */3049/* All flags used by eBPF helper functions, placed here. */
3046 3050
3047/* BPF_FUNC_skb_store_bytes flags. */3051/* BPF_FUNC_skb_store_bytes flags. */
3048#define BPF_F_RECOMPUTE_CSUM (1ULL << 0)3052enum {
3049#define BPF_F_INVALIDATE_HASH (1ULL << 1)3053 BPF_F_RECOMPUTE_CSUM = (1ULL << 0),
3054 BPF_F_INVALIDATE_HASH = (1ULL << 1),
3055};
3050 3056
3051/* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.3057/* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
3052 * First 4 bits are for passing the header field size.3058 * First 4 bits are for passing the header field size.
3053 */3059 */
3054#define BPF_F_HDR_FIELD_MASK 0xfULL3060enum {
3061 BPF_F_HDR_FIELD_MASK = 0xfULL,
3062};
3055 3063
3056/* BPF_FUNC_l4_csum_replace flags. */3064/* BPF_FUNC_l4_csum_replace flags. */
3057#define BPF_F_PSEUDO_HDR (1ULL << 4)3065enum {
3058#define BPF_F_MARK_MANGLED_0 (1ULL << 5)3066 BPF_F_PSEUDO_HDR = (1ULL << 4),
3059#define BPF_F_MARK_ENFORCE (1ULL << 6)3067 BPF_F_MARK_MANGLED_0 = (1ULL << 5),
3068 BPF_F_MARK_ENFORCE = (1ULL << 6),
3069};
3060 3070
3061/* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */3071/* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */
3062#define BPF_F_INGRESS (1ULL << 0)3072enum {
3073 BPF_F_INGRESS = (1ULL << 0),
3074};
3063 3075
3064/* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */3076/* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */
3065#define BPF_F_TUNINFO_IPV6 (1ULL << 0)3077enum {
3078 BPF_F_TUNINFO_IPV6 = (1ULL << 0),
3079};
3066 3080
3067/* flags for both BPF_FUNC_get_stackid and BPF_FUNC_get_stack. */3081/* flags for both BPF_FUNC_get_stackid and BPF_FUNC_get_stack. */
3068#define BPF_F_SKIP_FIELD_MASK 0xffULL3082enum {
3069#define BPF_F_USER_STACK (1ULL << 8)3083 BPF_F_SKIP_FIELD_MASK = 0xffULL,
3084 BPF_F_USER_STACK = (1ULL << 8),
3070/* flags used by BPF_FUNC_get_stackid only. */3085/* flags used by BPF_FUNC_get_stackid only. */
3071#define BPF_F_FAST_STACK_CMP (1ULL << 9)3086 BPF_F_FAST_STACK_CMP = (1ULL << 9),
3072#define BPF_F_REUSE_STACKID (1ULL << 10)3087 BPF_F_REUSE_STACKID = (1ULL << 10),
3073/* flags used by BPF_FUNC_get_stack only. */3088/* flags used by BPF_FUNC_get_stack only. */
3074#define BPF_F_USER_BUILD_ID (1ULL << 11)3089 BPF_F_USER_BUILD_ID = (1ULL << 11),
3090};
3075 3091
3076/* BPF_FUNC_skb_set_tunnel_key flags. */3092/* BPF_FUNC_skb_set_tunnel_key flags. */
3077#define BPF_F_ZERO_CSUM_TX (1ULL << 1)3093enum {
3078#define BPF_F_DONT_FRAGMENT (1ULL << 2)3094 BPF_F_ZERO_CSUM_TX = (1ULL << 1),
3079#define BPF_F_SEQ_NUMBER (1ULL << 3)3095 BPF_F_DONT_FRAGMENT = (1ULL << 2),
3096 BPF_F_SEQ_NUMBER = (1ULL << 3),
3097};
3080 3098
3081/* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and3099/* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
3082 * BPF_FUNC_perf_event_read_value flags.3100 * BPF_FUNC_perf_event_read_value flags.
3083 */3101 */
3084#define BPF_F_INDEX_MASK 0xffffffffULL3102enum {
3085#define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK3103 BPF_F_INDEX_MASK = 0xffffffffULL,
3104 BPF_F_CURRENT_CPU = BPF_F_INDEX_MASK,
3086/* BPF_FUNC_perf_event_output for sk_buff input context. */3105/* BPF_FUNC_perf_event_output for sk_buff input context. */
3087#define BPF_F_CTXLEN_MASK (0xfffffULL << 32)3106 BPF_F_CTXLEN_MASK = (0xfffffULL << 32),
3107};
3088 3108
3089/* Current network namespace */3109/* Current network namespace */
3090#define BPF_F_CURRENT_NETNS (-1L)3110enum {
3111 BPF_F_CURRENT_NETNS = (-1L),
3112};
3091 3113
3092/* BPF_FUNC_skb_adjust_room flags. */3114/* BPF_FUNC_skb_adjust_room flags. */
3093#define BPF_F_ADJ_ROOM_FIXED_GSO (1ULL << 0)3115enum {
3116 BPF_F_ADJ_ROOM_FIXED_GSO = (1ULL << 0),
3117 BPF_F_ADJ_ROOM_ENCAP_L3_IPV4 = (1ULL << 1),
3118 BPF_F_ADJ_ROOM_ENCAP_L3_IPV6 = (1ULL << 2),
3119 BPF_F_ADJ_ROOM_ENCAP_L4_GRE = (1ULL << 3),
3120 BPF_F_ADJ_ROOM_ENCAP_L4_UDP = (1ULL << 4),
3121};
3094 3122
3095#define BPF_ADJ_ROOM_ENCAP_L2_MASK 0xff3123enum {
3096#define BPF_ADJ_ROOM_ENCAP_L2_SHIFT 563124 BPF_ADJ_ROOM_ENCAP_L2_MASK = 0xff,
3125 BPF_ADJ_ROOM_ENCAP_L2_SHIFT = 56,
3126};
3097 3127
3098#define BPF_F_ADJ_ROOM_ENCAP_L3_IPV4 (1ULL << 1)
3099#define BPF_F_ADJ_ROOM_ENCAP_L3_IPV6 (1ULL << 2)
3100#define BPF_F_ADJ_ROOM_ENCAP_L4_GRE (1ULL << 3)
3101#define BPF_F_ADJ_ROOM_ENCAP_L4_UDP (1ULL << 4)
3102#define BPF_F_ADJ_ROOM_ENCAP_L2(len) (((__u64)len & \3128#define BPF_F_ADJ_ROOM_ENCAP_L2(len) (((__u64)len & \
3103 BPF_ADJ_ROOM_ENCAP_L2_MASK) \3129 BPF_ADJ_ROOM_ENCAP_L2_MASK) \
3104 << BPF_ADJ_ROOM_ENCAP_L2_SHIFT)3130 << BPF_ADJ_ROOM_ENCAP_L2_SHIFT)
3105 3131
3106/* BPF_FUNC_sysctl_get_name flags. */3132/* BPF_FUNC_sysctl_get_name flags. */
3107#define BPF_F_SYSCTL_BASE_NAME (1ULL << 0)3133enum {
3134 BPF_F_SYSCTL_BASE_NAME = (1ULL << 0),
3135};
3108 3136
3109/* BPF_FUNC_sk_storage_get flags */3137/* BPF_FUNC_sk_storage_get flags */
3110#define BPF_SK_STORAGE_GET_F_CREATE (1ULL << 0)3138enum {
3139 BPF_SK_STORAGE_GET_F_CREATE = (1ULL << 0),
3140};
3111 3141
3112/* BPF_FUNC_read_branch_records flags. */3142/* BPF_FUNC_read_branch_records flags. */
3113#define BPF_F_GET_BRANCH_RECORDS_SIZE (1ULL << 0)3143enum {
3144 BPF_F_GET_BRANCH_RECORDS_SIZE = (1ULL << 0),
3145};
3114 3146
3115/* Mode for BPF_FUNC_skb_adjust_room helper. */3147/* Mode for BPF_FUNC_skb_adjust_room helper. */
3116enum bpf_adj_room_mode {3148enum bpf_adj_room_mode {
@@ -3529,13 +3561,14 @@ struct bpf_sock_ops { · 412 unmodified lines
3529};3561};
3530 3562
3531/* Definitions for bpf_sock_ops_cb_flags */3563/* Definitions for bpf_sock_ops_cb_flags */
3532#define BPF_SOCK_OPS_RTO_CB_FLAG (1<<0)3564enum {
3533#define BPF_SOCK_OPS_RETRANS_CB_FLAG (1<<1)3565 BPF_SOCK_OPS_RTO_CB_FLAG = (1<<0),
3534#define BPF_SOCK_OPS_STATE_CB_FLAG (1<<2)3566 BPF_SOCK_OPS_RETRANS_CB_FLAG = (1<<1),
3535#define BPF_SOCK_OPS_RTT_CB_FLAG (1<<3)3567 BPF_SOCK_OPS_STATE_CB_FLAG = (1<<2),
3536#define BPF_SOCK_OPS_ALL_CB_FLAGS 0xF /* Mask of all currently3568 BPF_SOCK_OPS_RTT_CB_FLAG = (1<<3),
3537 * supported cb flags3569/* Mask of all currently supported cb flags */
3538 */3570 BPF_SOCK_OPS_ALL_CB_FLAGS = 0xF,
3571};
3539 3572
3540/* List of known BPF sock_ops operators.3573/* List of known BPF sock_ops operators.
3541 * New entries can only be added at the end3574 * New entries can only be added at the end
@@ -3614,8 +3647,10 @@ enum { · 72 unmodified lines
3614 BPF_TCP_MAX_STATES /* Leave at the end! */3647 BPF_TCP_MAX_STATES /* Leave at the end! */
3615};3648};
3616 3649
3617#define TCP_BPF_IW 1001 /* Set TCP initial congestion window */3650enum {
3618#define TCP_BPF_SNDCWND_CLAMP 1002 /* Set sndcwnd_clamp */3651 TCP_BPF_IW = 1001, /* Set TCP initial congestion window */
3652 TCP_BPF_SNDCWND_CLAMP = 1002, /* Set sndcwnd_clamp */
3653};
3619 3654
3620struct bpf_perf_event_value {3655struct bpf_perf_event_value {
3621 __u64 counter;3656 __u64 counter;
@@ -3623,12 +3658,16 @@ struct bpf_perf_event_value { · 1 unmodified line
3623 __u64 running;3658 __u64 running;
3624};3659};
3625 3660
3626#define BPF_DEVCG_ACC_MKNOD (1ULL << 0)3661enum {
3627#define BPF_DEVCG_ACC_READ (1ULL << 1)3662 BPF_DEVCG_ACC_MKNOD = (1ULL << 0),
3628#define BPF_DEVCG_ACC_WRITE (1ULL << 2)3663 BPF_DEVCG_ACC_READ = (1ULL << 1),
3664 BPF_DEVCG_ACC_WRITE = (1ULL << 2),
3665};
3629 3666
3630#define BPF_DEVCG_DEV_BLOCK (1ULL << 0)3667enum {
3631#define BPF_DEVCG_DEV_CHAR (1ULL << 1)3668 BPF_DEVCG_DEV_BLOCK = (1ULL << 0),
3669 BPF_DEVCG_DEV_CHAR = (1ULL << 1),
3670};
3632 3671
3633struct bpf_cgroup_dev_ctx {3672struct bpf_cgroup_dev_ctx {
3634 /* access_type encoded as (BPF_DEVCG_ACC_* << 16) | BPF_DEVCG_DEV_* */3673 /* access_type encoded as (BPF_DEVCG_ACC_* << 16) | BPF_DEVCG_DEV_* */
@@ -3644,8 +3683,10 @@ struct bpf_raw_tracepoint_args { · 9 unmodified lines
3644/* DIRECT: Skip the FIB rules and go to FIB table associated with device3683/* DIRECT: Skip the FIB rules and go to FIB table associated with device
3645 * OUTPUT: Do lookup from egress perspective; default is ingress3684 * OUTPUT: Do lookup from egress perspective; default is ingress
3646 */3685 */
3647#define BPF_FIB_LOOKUP_DIRECT (1U << 0)3686enum {
3648#define BPF_FIB_LOOKUP_OUTPUT (1U << 1)3687 BPF_FIB_LOOKUP_DIRECT = (1U << 0),
3688 BPF_FIB_LOOKUP_OUTPUT = (1U << 1),
3689};
3649 3690
3650enum {3691enum {
3651 BPF_FIB_LKUP_RET_SUCCESS, /* lookup successful */3692 BPF_FIB_LKUP_RET_SUCCESS, /* lookup successful */
@@ -3717,9 +3758,11 @@ enum bpf_task_fd_type { · 65 unmodified lines
3717 BPF_FD_TYPE_URETPROBE, /* filename + offset */3758 BPF_FD_TYPE_URETPROBE, /* filename + offset */
3718};3759};
3719 3760
3720#define BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG (1U << 0)3761enum {
3721#define BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL (1U << 1)3762 BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG = (1U << 0),
3722#define BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP (1U << 2)3763 BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL = (1U << 1),
3764 BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP = (1U << 2),
3765};
3723 3766
3724struct bpf_flow_keys {3767struct bpf_flow_keys {
3725 __u16 nhoff;3768 __u16 nhoff;