Skip to content

Commit

Permalink
bpf_printk test
Browse files Browse the repository at this point in the history
  • Loading branch information
llamb-jump committed Aug 15, 2023
1 parent ac66410 commit e00bea7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/tango/xdp/build-xdp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
# which is not supported for the eBPF target -- the kernel verifier
# provides such safety features.

# bash strict mode
set -euo pipefail
IFS=$'\n\t'
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "${SCRIPT_DIR}"

clang \
-std=c17 \
-I./opt/include \
Expand Down
25 changes: 14 additions & 11 deletions src/tango/xdp/fd_xdp_redirect_prog.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "fd_xdp_redirect_prog.h"

#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>


/* TODO: Some devices only support one XSK which requires multiplexing
Expand All @@ -30,20 +31,21 @@

/* Metadata ***********************************************************/

char __license[] __attribute__(( section("license") )) = "Apache-2.0";
char LICENSE[] SEC("license") = "GPL";
//char __license[] __attribute__(( section("license") )) = "GPL";

/* eBPF syscalls ******************************************************/

static void *
(* bpf_map_lookup_elem)( void * map,
void const * key)
= (void *)1U;

static long
(* bpf_redirect_map)( void * map,
ulong key,
ulong flags )
= (void *)51U;
//static void *
//(* bpf_map_lookup_elem)( void * map,
// void const * key)
// = (void *)1U;
//
//static long
//(* bpf_redirect_map)( void * map,
// ulong key,
// ulong flags )
// = (void *)51U;

/* eBPF maps **********************************************************/

Expand All @@ -67,6 +69,7 @@ extern uint fd_xdp_udp_dsts __attribute__((section("maps")));
Returns an XDP action code in XDP_{PASS,REDIRECT,DROP}. */
__attribute__(( section("xdp"), used ))
int fd_xdp_redirect( struct xdp_md *ctx ) {
bpf_printk("neat\n");

uchar const * data = (uchar const*)(ulong)ctx->data;
uchar const * data_end = (uchar const*)(ulong)ctx->data_end;
Expand Down
Binary file modified src/tango/xdp/fd_xdp_redirect_prog.o
Binary file not shown.

0 comments on commit e00bea7

Please sign in to comment.