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

fix the dependencies of old loader #421

Merged
merged 4 commits into from
May 21, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions basic02-prog-by-name/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,6 @@ sudo ./xdp_loader --dev veth-basic02 --progname xdp_drop_func
sudo ./xdp_loader --dev veth-basic02 --progname xdp_pass_func
#+end_example

The testenv script also has a helper command for "load" which will use the
=xdp_loader= program in the current directory:
#+begin_example
sudo ../testenv/testenv.sh load --name veth-basic02
sudo ../testenv/testenv.sh load --name veth-basic02 -- --unload-all
sudo ../testenv/testenv.sh load --name veth-basic02 -- --progname xdp_drop_func
sudo ../testenv/testenv.sh load --name veth-basic02 -- --progname xdp_pass_func
#+end_example

*** A note about: The test environment and veth packets directions
When you load an XDP program on the interface visible on your host machine,
it will operate on all packets arriving *to* that interface. And since
Expand Down
1 change: 1 addition & 0 deletions common/xdp_stats_kern.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct {
__type(key, __u32);
__type(value, struct datarec);
__uint(max_entries, XDP_ACTION_MAX);
__uint(pinning, LIBBPF_PIN_BY_NAME);
} xdp_stats_map SEC(".maps");

static __always_inline
Expand Down
4 changes: 2 additions & 2 deletions packet01-parsing/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ programs.

* Setup notes

We will use the loader from the basic04 lesson. The Makefile in this directory
We will use the loader from xdp-tools. The Makefile in this directory
contains a rule to copy it over to this directory, so you can run it as
=./xdp_loader= after running =make=. The =testenv.sh= script will use this
=./xdp-loader= after running =make=. The =testenv.sh= script will use this
when run with the =load= command. In the example below, we assume you've
installed the alias for testenv (by running =eval $(./testenv.sh alias)=),
so all examples will use the short =t= command to refer to the =testenv.sh=
Expand Down
26 changes: 13 additions & 13 deletions packet03-redirecting/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ supported and load the XDP program. Note that we also need to load a dummy
section.
#+begin_src sh
$ t setup -n test --legacy-ip
$ t exec -n test -- ./xdp_loader -d veth0 -F --progsec xdp_pass
$ t load -n test -- -F --progsec xdp_icmp_echo
$ t exec -n test -- ./xdp-loader load --prog-name xdp_pass_func veth0 xdp_prog_kern.o
$ t load -n test -- --prog-name xdp_icmp_echo_func xdp_prog_kern.o
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are three invocations of xdp_loader at the end of the README file as well. Let's include those while you're fixing things up :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback.
updated README.

#+end_src
Ping the host and use the =xdp_stat= program to check that the ICMP echo server
actually returned =XDP_TX=. Repeat for both address families (you can pass
Expand Down Expand Up @@ -134,7 +134,7 @@ Setup the two environments, patch the =xdp_redirect= program accordingly, and
attach it to the =right= interface. Don't forget to attach a dummy program to
the left /inner/ interface like this:
#+begin_src sh
$ t exec -n left -- ./xdp_loader -d veth0 -F --progsec xdp_pass
$ t exec -n left -- ./xdp-loader load --prog-name xdp_pass_func veth0 xdp_prog_kern.o
#+end_src
To test load the program, enter the right environment, and ping the /inner/
interface of the left environment (your IPv6 address may be different):
Expand Down Expand Up @@ -186,13 +186,13 @@ the =xdp_prog_user.c= program.
To test the code, configure environment as in the Assignment 2 and install the
=xdp_redirect_map= program on both interfaces:
#+begin_src sh
$ t load -n left -- -F --progsec xdp_redirect_map
$ t load -n right -- -F --progsec xdp_redirect_map
$ t load -n left -- --prog-name xdp_redirect_map_func xdp_prog_kern.o
$ t load -n right -- --prog-name xdp_redirect_map_func xdp_prog_kern.o
#+end_src
Don't forget about dummy programs for inner interfaces:
#+begin_src sh
$ t exec -n left -- ./xdp_loader -d veth0 -F --progsec xdp_pass
$ t exec -n right -- ./xdp_loader -d veth0 -F --progsec xdp_pass
$ t exec -n left -- ./xdp-loader load --prog-name xdp_pass_func veth0 xdp_prog_kern.o
$ t exec -n right -- ./xdp-loader load --prog-name xdp_pass_func veth0 xdp_prog_kern.o
#+end_src
Configure parameters for both interfaces using the new =xdp_prog_user= helper.
For simplicity there is a new special helper, =t redirect=, which will
Expand Down Expand Up @@ -277,13 +277,13 @@ $ t setup -n tres --legacy-ip
$ sudo sysctl net.ipv4.conf.all.forwarding=1
$ sudo sysctl net.ipv6.conf.all.forwarding=1

$ t load -n uno -- -F --progsec xdp_router
$ t load -n dos -- -F --progsec xdp_router
$ t load -n tres -- -F --progsec xdp_router
$ t load -n uno -- --prog-name xdp_router_func xdp_prog_kern.o
$ t load -n dos -- --prog-name xdp_router_func xdp_prog_kern.o
$ t load -n tres -- --prog-name xdp_router_func xdp_prog_kern.o

$ t exec -n uno -- ./xdp_loader -d veth0 -F --progsec xdp_pass
$ t exec -n dos -- ./xdp_loader -d veth0 -F --progsec xdp_pass
$ t exec -n tres -- ./xdp_loader -d veth0 -F --progsec xdp_pass
$ t exec -n uno -- ./xdp-loader load --prog-name xdp_pass_func veth0 xdp_prog_kern.o
$ t exec -n dos -- ./xdp-loader load --prog-name xdp_pass_func veth0 xdp_prog_kern.o
$ t exec -n tres -- ./xdp-loader load --prog-name xdp_pass_func veth0 xdp_prog_kern.o

$ sudo ./xdp_stats -d uno
$ sudo ./xdp_stats -d dos
Expand Down
2 changes: 2 additions & 0 deletions packet03-redirecting/xdp_prog_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct {
__type(key, int);
__type(value, int);
__uint(max_entries, 256);
__uint(pinning, LIBBPF_PIN_BY_NAME);
} tx_port SEC(".maps");


Expand All @@ -28,6 +29,7 @@ struct {
__type(key, unsigned char[ETH_ALEN]);
__type(value, unsigned char[ETH_ALEN]);
__uint(max_entries, 1);
__uint(pinning, LIBBPF_PIN_BY_NAME);
} redirect_params SEC(".maps");

static __always_inline void swap_src_dst_mac(struct ethhdr *eth)
Expand Down
8 changes: 5 additions & 3 deletions testenv/testenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CLEANUP_FUNC=
STATEFILE=
CMD=
NS=
XDP_LOADER=./xdp_loader
XDP_LOADER=./xdp-loader
XDP_STATS=./xdp_stats
LEGACY_IP=0
USE_VLAN=0
Expand Down Expand Up @@ -450,15 +450,17 @@ xdp_load()
get_nsname && ensure_nsname

[ -x "$XDP_LOADER" ] || die "Loader '$XDP_LOADER' is not executable"
$XDP_LOADER --dev "$NS" "$@"
local objfile=${!#}
local load_opts="${@:1:$#-1} --pin-path /sys/fs/bpf/$NS"
$XDP_LOADER load $load_opts $NS $objfile
}

xdp_unload()
{
get_nsname && ensure_nsname

[ -x "$XDP_LOADER" ] || die "Loader '$XDP_LOADER' is not executable"
$XDP_LOADER --dev "$NS" --unload "$@"
$XDP_LOADER unload "$@" "$NS"
}

xdp_stats()
Expand Down