Commit 4bcd220a authored by Brenden Blanco's avatar Brenden Blanco

Change indentation in bpf/helpers.h

Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
parent ea7962e0
...@@ -79,76 +79,76 @@ unsigned _version SEC("version") = LINUX_VERSION_CODE; ...@@ -79,76 +79,76 @@ unsigned _version SEC("version") = LINUX_VERSION_CODE;
/* helper functions called from eBPF programs written in C */ /* helper functions called from eBPF programs written in C */
static void *(*bpf_map_lookup_elem)(void *map, void *key) = static void *(*bpf_map_lookup_elem)(void *map, void *key) =
(void *) BPF_FUNC_map_lookup_elem; (void *) BPF_FUNC_map_lookup_elem;
static int (*bpf_map_update_elem)(void *map, void *key, void *value, u64 flags) = static int (*bpf_map_update_elem)(void *map, void *key, void *value, u64 flags) =
(void *) BPF_FUNC_map_update_elem; (void *) BPF_FUNC_map_update_elem;
static int (*bpf_map_delete_elem)(void *map, void *key) = static int (*bpf_map_delete_elem)(void *map, void *key) =
(void *) BPF_FUNC_map_delete_elem; (void *) BPF_FUNC_map_delete_elem;
static int (*bpf_probe_read)(void *dst, u64 size, void *unsafe_ptr) = static int (*bpf_probe_read)(void *dst, u64 size, void *unsafe_ptr) =
(void *) BPF_FUNC_probe_read; (void *) BPF_FUNC_probe_read;
static u64 (*bpf_ktime_get_ns)(void) = static u64 (*bpf_ktime_get_ns)(void) =
(void *) BPF_FUNC_ktime_get_ns; (void *) BPF_FUNC_ktime_get_ns;
static int (*bpf_trace_printk_)(const char *fmt, u64 fmt_size, ...) = static int (*bpf_trace_printk_)(const char *fmt, u64 fmt_size, ...) =
(void *) BPF_FUNC_trace_printk; (void *) BPF_FUNC_trace_printk;
int bpf_trace_printk(const char *fmt, ...) asm("llvm.bpf.extra"); int bpf_trace_printk(const char *fmt, ...) asm("llvm.bpf.extra");
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)
static void bpf_tail_call_(u64 map_fd, void *ctx, int index) { static void bpf_tail_call_(u64 map_fd, void *ctx, int index) {
((void (*)(void *, u64, int))BPF_FUNC_tail_call)(ctx, map_fd, index); ((void (*)(void *, u64, int))BPF_FUNC_tail_call)(ctx, map_fd, index);
} }
static int (*bpf_clone_redirect)(void *ctx, u64 ifindex, u64 flags) = static int (*bpf_clone_redirect)(void *ctx, int ifindex, u32 flags) =
(void *) BPF_FUNC_clone_redirect; (void *) BPF_FUNC_clone_redirect;
static u64 (*bpf_get_smp_processor_id)(void) = static u64 (*bpf_get_smp_processor_id)(void) =
(void *) BPF_FUNC_get_smp_processor_id; (void *) BPF_FUNC_get_smp_processor_id;
static u64 (*bpf_get_current_pid_tgid)(void) = static u64 (*bpf_get_current_pid_tgid)(void) =
(void *) BPF_FUNC_get_current_pid_tgid; (void *) BPF_FUNC_get_current_pid_tgid;
static u64 (*bpf_get_current_uid_gid)(void) = static u64 (*bpf_get_current_uid_gid)(void) =
(void *) BPF_FUNC_get_current_uid_gid; (void *) BPF_FUNC_get_current_uid_gid;
static int (*bpf_get_current_comm)(void *buf, int buf_size) = static int (*bpf_get_current_comm)(void *buf, int buf_size) =
(void *) BPF_FUNC_get_current_comm; (void *) BPF_FUNC_get_current_comm;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)
static u64 (*bpf_get_cgroup_classid)(void *ctx) = static u64 (*bpf_get_cgroup_classid)(void *ctx) =
(void *) BPF_FUNC_get_cgroup_classid; (void *) BPF_FUNC_get_cgroup_classid;
static u64 (*bpf_skb_vlan_push)(void *ctx, u16 proto, u16 vlan_tci) = static u64 (*bpf_skb_vlan_push)(void *ctx, u16 proto, u16 vlan_tci) =
(void *) BPF_FUNC_skb_vlan_push; (void *) BPF_FUNC_skb_vlan_push;
static u64 (*bpf_skb_vlan_pop)(void *ctx) = static u64 (*bpf_skb_vlan_pop)(void *ctx) =
(void *) BPF_FUNC_skb_vlan_pop; (void *) BPF_FUNC_skb_vlan_pop;
static int (*bpf_skb_get_tunnel_key)(void *ctx, void *to, u32 size, u64 flags) = static int (*bpf_skb_get_tunnel_key)(void *ctx, void *to, u32 size, u64 flags) =
(void *) BPF_FUNC_skb_get_tunnel_key; (void *) BPF_FUNC_skb_get_tunnel_key;
static int (*bpf_skb_set_tunnel_key)(void *ctx, void *from, u32 size, u64 flags) = static int (*bpf_skb_set_tunnel_key)(void *ctx, void *from, u32 size, u64 flags) =
(void *) BPF_FUNC_skb_set_tunnel_key; (void *) BPF_FUNC_skb_set_tunnel_key;
#endif #endif
#endif
/* llvm builtin functions that eBPF C program may use to /* llvm builtin functions that eBPF C program may use to
* emit BPF_LD_ABS and BPF_LD_IND instructions * emit BPF_LD_ABS and BPF_LD_IND instructions
*/ */
struct sk_buff; struct sk_buff;
unsigned long long load_byte(void *skb, unsigned long long load_byte(void *skb,
unsigned long long off) asm("llvm.bpf.load.byte"); unsigned long long off) asm("llvm.bpf.load.byte");
unsigned long long load_half(void *skb, unsigned long long load_half(void *skb,
unsigned long long off) asm("llvm.bpf.load.half"); unsigned long long off) asm("llvm.bpf.load.half");
unsigned long long load_word(void *skb, unsigned long long load_word(void *skb,
unsigned long long off) asm("llvm.bpf.load.word"); unsigned long long off) asm("llvm.bpf.load.word");
/* a helper structure used by eBPF C program /* a helper structure used by eBPF C program
* to describe map attributes to elf_bpf loader * to describe map attributes to elf_bpf loader
*/ */
struct bpf_map_def { struct bpf_map_def {
unsigned int type; unsigned int type;
unsigned int key_size; unsigned int key_size;
unsigned int value_size; unsigned int value_size;
unsigned int max_entries; unsigned int max_entries;
}; };
static int (*bpf_skb_store_bytes)(void *ctx, unsigned long long off, void *from, static int (*bpf_skb_store_bytes)(void *ctx, unsigned long long off, void *from,
unsigned long long len, unsigned long long flags) = unsigned long long len, unsigned long long flags) =
(void *) BPF_FUNC_skb_store_bytes; (void *) BPF_FUNC_skb_store_bytes;
static int (*bpf_l3_csum_replace)(void *ctx, unsigned long long off, unsigned long long from, static int (*bpf_l3_csum_replace)(void *ctx, unsigned long long off, unsigned long long from,
unsigned long long to, unsigned long long flags) = unsigned long long to, unsigned long long flags) =
(void *) BPF_FUNC_l3_csum_replace; (void *) BPF_FUNC_l3_csum_replace;
static int (*bpf_l4_csum_replace)(void *ctx, unsigned long long off, unsigned long long from, static int (*bpf_l4_csum_replace)(void *ctx, unsigned long long off, unsigned long long from,
unsigned long long to, unsigned long long flags) = unsigned long long to, unsigned long long flags) =
(void *) BPF_FUNC_l4_csum_replace; (void *) BPF_FUNC_l4_csum_replace;
static inline u16 bpf_ntohs(u16 val) { static inline u16 bpf_ntohs(u16 val) {
/* will be recognized by gcc into rotate insn and eventually rolw 8 */ /* will be recognized by gcc into rotate insn and eventually rolw 8 */
...@@ -201,24 +201,24 @@ static inline void bpf_store_dword(void *skb, u64 off, u64 val) { ...@@ -201,24 +201,24 @@ static inline void bpf_store_dword(void *skb, u64 off, u64 val) {
static unsigned int bpf_log2(unsigned int v) static unsigned int bpf_log2(unsigned int v)
{ {
unsigned int r; unsigned int r;
unsigned int shift; unsigned int shift;
r = (v > 0xFFFF) << 4; v >>= r; r = (v > 0xFFFF) << 4; v >>= r;
shift = (v > 0xFF) << 3; v >>= shift; r |= shift; shift = (v > 0xFF) << 3; v >>= shift; r |= shift;
shift = (v > 0xF) << 2; v >>= shift; r |= shift; shift = (v > 0xF) << 2; v >>= shift; r |= shift;
shift = (v > 0x3) << 1; v >>= shift; r |= shift; shift = (v > 0x3) << 1; v >>= shift; r |= shift;
r |= (v >> 1); r |= (v >> 1);
return r; return r;
} }
static unsigned int bpf_log2l(unsigned long v) static unsigned int bpf_log2l(unsigned long v)
{ {
unsigned int hi = v >> 32; unsigned int hi = v >> 32;
if (hi) if (hi)
return bpf_log2(hi) + 32 + 1; return bpf_log2(hi) + 32 + 1;
else else
return bpf_log2(v) + 1; return bpf_log2(v) + 1;
} }
struct bpf_context; struct bpf_context;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment