selftests: bpf: Move bpf_printk to bpf_helpers.h
bpf_printk is a macro which is commonly used to print out debug messages in BPF programs and it was copied in many selftests and samples. Since all of them include bpf_helpers.h, this change moves the macro there. Signed-off-by: Michal Rostecki <mrostecki@opensuse.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
5762a20b11
commit
37739d1b4f
@ -8,6 +8,14 @@
|
|||||||
*/
|
*/
|
||||||
#define SEC(NAME) __attribute__((section(NAME), used))
|
#define SEC(NAME) __attribute__((section(NAME), used))
|
||||||
|
|
||||||
|
/* helper macro to print out debug messages */
|
||||||
|
#define bpf_printk(fmt, ...) \
|
||||||
|
({ \
|
||||||
|
char ____fmt[] = fmt; \
|
||||||
|
bpf_trace_printk(____fmt, sizeof(____fmt), \
|
||||||
|
##__VA_ARGS__); \
|
||||||
|
})
|
||||||
|
|
||||||
/* 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, const void *key) =
|
static void *(*bpf_map_lookup_elem)(void *map, const void *key) =
|
||||||
(void *) BPF_FUNC_map_lookup_elem;
|
(void *) BPF_FUNC_map_lookup_elem;
|
||||||
|
@ -5,13 +5,6 @@
|
|||||||
|
|
||||||
int _version SEC("version") = 1;
|
int _version SEC("version") = 1;
|
||||||
|
|
||||||
#define bpf_printk(fmt, ...) \
|
|
||||||
({ \
|
|
||||||
char ____fmt[] = fmt; \
|
|
||||||
bpf_trace_printk(____fmt, sizeof(____fmt), \
|
|
||||||
##__VA_ARGS__); \
|
|
||||||
})
|
|
||||||
|
|
||||||
SEC("sk_skb1")
|
SEC("sk_skb1")
|
||||||
int bpf_prog1(struct __sk_buff *skb)
|
int bpf_prog1(struct __sk_buff *skb)
|
||||||
{
|
{
|
||||||
|
@ -5,13 +5,6 @@
|
|||||||
|
|
||||||
int _version SEC("version") = 1;
|
int _version SEC("version") = 1;
|
||||||
|
|
||||||
#define bpf_printk(fmt, ...) \
|
|
||||||
({ \
|
|
||||||
char ____fmt[] = fmt; \
|
|
||||||
bpf_trace_printk(____fmt, sizeof(____fmt), \
|
|
||||||
##__VA_ARGS__); \
|
|
||||||
})
|
|
||||||
|
|
||||||
SEC("sk_msg1")
|
SEC("sk_msg1")
|
||||||
int bpf_prog1(struct sk_msg_md *msg)
|
int bpf_prog1(struct sk_msg_md *msg)
|
||||||
{
|
{
|
||||||
|
@ -5,13 +5,6 @@
|
|||||||
|
|
||||||
int _version SEC("version") = 1;
|
int _version SEC("version") = 1;
|
||||||
|
|
||||||
#define bpf_printk(fmt, ...) \
|
|
||||||
({ \
|
|
||||||
char ____fmt[] = fmt; \
|
|
||||||
bpf_trace_printk(____fmt, sizeof(____fmt), \
|
|
||||||
##__VA_ARGS__); \
|
|
||||||
})
|
|
||||||
|
|
||||||
struct bpf_map_def SEC("maps") sock_map_rx = {
|
struct bpf_map_def SEC("maps") sock_map_rx = {
|
||||||
.type = BPF_MAP_TYPE_SOCKMAP,
|
.type = BPF_MAP_TYPE_SOCKMAP,
|
||||||
.key_size = sizeof(int),
|
.key_size = sizeof(int),
|
||||||
|
@ -6,13 +6,6 @@
|
|||||||
#include "bpf_helpers.h"
|
#include "bpf_helpers.h"
|
||||||
#include "bpf_endian.h"
|
#include "bpf_endian.h"
|
||||||
|
|
||||||
#define bpf_printk(fmt, ...) \
|
|
||||||
({ \
|
|
||||||
char ____fmt[] = fmt; \
|
|
||||||
bpf_trace_printk(____fmt, sizeof(____fmt), \
|
|
||||||
##__VA_ARGS__); \
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Packet parsing state machine helpers. */
|
/* Packet parsing state machine helpers. */
|
||||||
#define cursor_advance(_cursor, _len) \
|
#define cursor_advance(_cursor, _len) \
|
||||||
({ void *_tmp = _cursor; _cursor += _len; _tmp; })
|
({ void *_tmp = _cursor; _cursor += _len; _tmp; })
|
||||||
|
@ -15,13 +15,6 @@
|
|||||||
#include <linux/udp.h>
|
#include <linux/udp.h>
|
||||||
#include "bpf_helpers.h"
|
#include "bpf_helpers.h"
|
||||||
|
|
||||||
#define bpf_printk(fmt, ...) \
|
|
||||||
({ \
|
|
||||||
char ____fmt[] = fmt; \
|
|
||||||
bpf_trace_printk(____fmt, sizeof(____fmt), \
|
|
||||||
##__VA_ARGS__); \
|
|
||||||
})
|
|
||||||
|
|
||||||
static __u32 rol32(__u32 word, unsigned int shift)
|
static __u32 rol32(__u32 word, unsigned int shift)
|
||||||
{
|
{
|
||||||
return (word << shift) | (word >> ((-shift) & 31));
|
return (word << shift) | (word >> ((-shift) & 31));
|
||||||
|
@ -28,13 +28,6 @@
|
|||||||
* are established and verdicts are decided.
|
* are established and verdicts are decided.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define bpf_printk(fmt, ...) \
|
|
||||||
({ \
|
|
||||||
char ____fmt[] = fmt; \
|
|
||||||
bpf_trace_printk(____fmt, sizeof(____fmt), \
|
|
||||||
##__VA_ARGS__); \
|
|
||||||
})
|
|
||||||
|
|
||||||
struct bpf_map_def SEC("maps") sock_map = {
|
struct bpf_map_def SEC("maps") sock_map = {
|
||||||
.type = TEST_MAP_TYPE,
|
.type = TEST_MAP_TYPE,
|
||||||
.key_size = sizeof(int),
|
.key_size = sizeof(int),
|
||||||
|
Loading…
Reference in New Issue
Block a user